@uniformdev/context 17.5.1-alpha.130 → 17.5.1-alpha.131

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.d.ts CHANGED
@@ -15,6 +15,8 @@ declare type ClientOptions = {
15
15
  bearerToken?: string | null;
16
16
  /** The Uniform project ID to connect to */
17
17
  projectId?: string | null;
18
+ /** The Uniform branch name to connect to */
19
+ branchName?: string | null;
18
20
  /** Specify a fetch implementation to use when fetching data. Useful if you want to only polyfill selectively. */
19
21
  fetch?: typeof fetch;
20
22
  /**
package/dist/api/api.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var S=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ie=(r,e,t)=>e in r?S(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var oe=(r,e)=>{for(var t in e)S(r,t,{get:e[t],enumerable:!0})},ne=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of re(e))!se.call(r,o)&&o!==t&&S(r,o,{get:()=>e[o],enumerable:!(s=te(e,o))||s.enumerable});return r};var ae=r=>ne(S({},"__esModule",{value:!0}),r);var m=(r,e,t)=>(ie(r,typeof e!="symbol"?e+"":e,t),t),pe=(r,e,t)=>{if(!e.has(r))throw TypeError("Cannot "+t)};var i=(r,e,t)=>(pe(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 me={};oe(me,{AggregateClient:()=>y,ApiClient:()=>n,ApiClientError:()=>P,CachedAggregateClient:()=>J,CachedContextClient:()=>_,CachedDimensionClient:()=>M,CachedEnrichmentClient:()=>K,CachedManifestClient:()=>z,CachedQuirkClient:()=>F,CachedSignalClient:()=>X,ContextClient:()=>N,DimensionClient:()=>f,EnrichmentClient:()=>u,ManifestClient:()=>x,QuirkClient:()=>g,SignalClient:()=>d,UncachedAggregateClient:()=>L,UncachedContextClient:()=>Z,UncachedDimensionClient:()=>V,UncachedEnrichmentClient:()=>H,UncachedManifestClient:()=>q,UncachedQuirkClient:()=>B,UncachedSignalClient:()=>W,computeDimensionDefinitionDisplayData:()=>ee,computeDimensionDisplayData:()=>ce,computeDimensionDisplayName:()=>le,nullLimitPolicy:()=>v});module.exports=ae(me);var v=async r=>await r(),P=class extends Error{constructor(t,s,o,a,p,l){super(`${t}
2
- ${a}${p?" "+p:""} (${s} ${o}${l?` Request ID: ${l}`:""})`);this.errorMessage=t;this.fetchMethod=s;this.fetchUri=o;this.statusCode=a;this.statusText=p;this.requestId=l;Object.setPrototypeOf(this,P.prototype)}};var n=class{constructor(e){m(this,"options");var s,o,a,p,l,h;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:(o=e.apiKey)!=null?o:null,projectId:(a=e.projectId)!=null?a:null,bearerToken:(p=e.bearerToken)!=null?p:null,limitPolicy:(l=e.limitPolicy)!=null?l:v,bypassCache:(h=e.bypassCache)!=null?h:!1}}async apiClient(e,t){return this.options.limitPolicy(async()=>{var a;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 o=await this.options.fetch(e.toString(),{...t,headers:{...t==null?void 0:t.headers,...s}});if(!o.ok){let p="";try{let l=await o.text();try{let h=JSON.parse(l);h.errorMessage?p=Array.isArray(h.errorMessage)?h.errorMessage.join(", "):h.errorMessage:p=l}catch(h){p=l}}catch(l){p="General error"}throw new P(p,(a=t==null?void 0:t.method)!=null?a:"GET",e.toString(),o.status,o.statusText,n.getRequestId(o))}return t!=null&&t.expectNoContent?null:await o.json()})}createUrl(e,t){let s=new URL(`${this.options.apiHost}${e}`);return Object.entries(t!=null?t:{}).forEach(([o,a])=>{var p;typeof a!="undefined"&&a!==null&&s.searchParams.append(o,Array.isArray(a)?a.join(","):(p=a==null?void 0:a.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 L=class extends y{constructor(e){super({...e,bypassCache:!0})}},J=class extends y{constructor(e){super({...e,bypassCache:!1})}};var $="_";function ee(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 ce(r,e){var t,s,o,a;if((s=(t=e.project.pz)==null?void 0:t.agg)!=null&&s[r])return{dim:r,name:r,type:"Aggregate"};if((a=(o=e.project.pz)==null?void 0:o.sig)!=null&&a[r])return{dim:r,name:r,type:"Signal"};if(r.indexOf($)>=0){let[p,l]=r.split($);return{dim:r,name:l,type:"Enrichment",category:p}}}function le(r){let{type:e,name:t}=ee(r);return`${e}: ${t}`}var A,Q=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(Q,A),{...e,projectId:t});return await this.apiClient(s)}},f=Q;A=new WeakMap,c(f,A,"/api/v2/dimension");var V=class extends f{constructor(e){super({...e,bypassCache:!0})}},M=class extends f{constructor(e){super({...e,bypassCache:!1})}};var O,w,C=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(C,O),{...e,projectId:t});return await this.apiClient(s)}async upsertCategory(e){let t=this.createUrl(i(C,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(C,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(C,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(C,w));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},u=C;O=new WeakMap,w=new WeakMap,c(u,O,"/api/v1/enrichments"),c(u,w,"/api/v1/enrichment-values");var H=class extends u{constructor(e){super({...e,bypassCache:!0})}},K=class extends u{constructor(e){super({...e,bypassCache:!1})}};var k,Y=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(Y,k),{...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})}},x=Y;k=new WeakMap,c(x,k,"/api/v2/manifest");var q=class extends x{constructor(e){super({...e,bypassCache:!0})}},z=class extends x{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})}},g=R;j=new WeakMap,c(g,j,"/api/v2/quirk");var B=class extends g{constructor(e){super({...e,bypassCache:!0})}},F=class extends g{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})}},d=I;E=new WeakMap,c(d,E,"/api/v2/signal");var W=class extends d{constructor(e){super({...e,bypassCache:!0})}},X=class extends d{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 N=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 u(e),this.aggregates=new y(e),this.dimensions=new f(e),this.manifest=new x(e),this.quirks=new g(e),this.signals=new d(e),this.tests=new T(e)}},Z=class extends N{constructor(e){super({...e,bypassCache:!0})}},_=class extends N{constructor(e){super({...e,bypassCache:!1})}};0&&(module.exports={AggregateClient,ApiClient,ApiClientError,CachedAggregateClient,CachedContextClient,CachedDimensionClient,CachedEnrichmentClient,CachedManifestClient,CachedQuirkClient,CachedSignalClient,ContextClient,DimensionClient,EnrichmentClient,ManifestClient,QuirkClient,SignalClient,UncachedAggregateClient,UncachedContextClient,UncachedDimensionClient,UncachedEnrichmentClient,UncachedManifestClient,UncachedQuirkClient,UncachedSignalClient,computeDimensionDefinitionDisplayData,computeDimensionDisplayData,computeDimensionDisplayName,nullLimitPolicy});
1
+ "use strict";var S=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var ie=Object.prototype.hasOwnProperty;var oe=(r,e,t)=>e in r?S(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var ne=(r,e)=>{for(var t in e)S(r,t,{get:e[t],enumerable:!0})},ae=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of se(e))!ie.call(r,o)&&o!==t&&S(r,o,{get:()=>e[o],enumerable:!(s=re(e,o))||s.enumerable});return r};var pe=r=>ae(S({},"__esModule",{value:!0}),r);var m=(r,e,t)=>(oe(r,typeof e!="symbol"?e+"":e,t),t),ce=(r,e,t)=>{if(!e.has(r))throw TypeError("Cannot "+t)};var i=(r,e,t)=>(ce(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 ue={};ne(ue,{AggregateClient:()=>y,ApiClient:()=>n,ApiClientError:()=>P,CachedAggregateClient:()=>J,CachedContextClient:()=>_,CachedDimensionClient:()=>M,CachedEnrichmentClient:()=>K,CachedManifestClient:()=>z,CachedQuirkClient:()=>F,CachedSignalClient:()=>X,ContextClient:()=>N,DimensionClient:()=>f,EnrichmentClient:()=>u,ManifestClient:()=>x,QuirkClient:()=>g,SignalClient:()=>d,UncachedAggregateClient:()=>L,UncachedContextClient:()=>Z,UncachedDimensionClient:()=>V,UncachedEnrichmentClient:()=>H,UncachedManifestClient:()=>q,UncachedQuirkClient:()=>B,UncachedSignalClient:()=>W,computeDimensionDefinitionDisplayData:()=>te,computeDimensionDisplayData:()=>le,computeDimensionDisplayName:()=>me,nullLimitPolicy:()=>v});module.exports=pe(ue);var v=async r=>await r(),P=class extends Error{constructor(t,s,o,a,p,l){super(`${t}
2
+ ${a}${p?" "+p:""} (${s} ${o}${l?` Request ID: ${l}`:""})`);this.errorMessage=t;this.fetchMethod=s;this.fetchUri=o;this.statusCode=a;this.statusText=p;this.requestId=l;Object.setPrototypeOf(this,P.prototype)}};var n=class{constructor(e){m(this,"options");var s,o,a,p,l,h,ee;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:(o=e.apiKey)!=null?o:null,projectId:(a=e.projectId)!=null?a:null,bearerToken:(p=e.bearerToken)!=null?p:null,limitPolicy:(l=e.limitPolicy)!=null?l:v,bypassCache:(h=e.bypassCache)!=null?h:!1,branchName:(ee=e.branchName)!=null?ee:null}}async apiClient(e,t){return this.options.limitPolicy(async()=>{var a;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 o=await this.options.fetch(e.toString(),{...t,headers:{...t==null?void 0:t.headers,...s}});if(!o.ok){let p="";try{let l=await o.text();try{let h=JSON.parse(l);h.errorMessage?p=Array.isArray(h.errorMessage)?h.errorMessage.join(", "):h.errorMessage:p=l}catch(h){p=l}}catch(l){p="General error"}throw new P(p,(a=t==null?void 0:t.method)!=null?a:"GET",e.toString(),o.status,o.statusText,n.getRequestId(o))}return t!=null&&t.expectNoContent?null:await o.json()})}createUrl(e,t){let s=new URL(`${this.options.apiHost}${e}`);return Object.entries(t!=null?t:{}).forEach(([o,a])=>{var p;typeof a!="undefined"&&a!==null&&s.searchParams.append(o,Array.isArray(a)?a.join(","):(p=a==null?void 0:a.toString())!=null?p:"")}),this.options.branchName&&s.searchParams.append("branch",this.options.branchName),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 L=class extends y{constructor(e){super({...e,bypassCache:!0})}},J=class extends y{constructor(e){super({...e,bypassCache:!1})}};var $="_";function te(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 le(r,e){var t,s,o,a;if((s=(t=e.project.pz)==null?void 0:t.agg)!=null&&s[r])return{dim:r,name:r,type:"Aggregate"};if((a=(o=e.project.pz)==null?void 0:o.sig)!=null&&a[r])return{dim:r,name:r,type:"Signal"};if(r.indexOf($)>=0){let[p,l]=r.split($);return{dim:r,name:l,type:"Enrichment",category:p}}}function me(r){let{type:e,name:t}=te(r);return`${e}: ${t}`}var A,Q=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(Q,A),{...e,projectId:t});return await this.apiClient(s)}},f=Q;A=new WeakMap,c(f,A,"/api/v2/dimension");var V=class extends f{constructor(e){super({...e,bypassCache:!0})}},M=class extends f{constructor(e){super({...e,bypassCache:!1})}};var O,w,C=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(C,O),{...e,projectId:t});return await this.apiClient(s)}async upsertCategory(e){let t=this.createUrl(i(C,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(C,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(C,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(C,w));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}},u=C;O=new WeakMap,w=new WeakMap,c(u,O,"/api/v1/enrichments"),c(u,w,"/api/v1/enrichment-values");var H=class extends u{constructor(e){super({...e,bypassCache:!0})}},K=class extends u{constructor(e){super({...e,bypassCache:!1})}};var k,Y=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(Y,k),{...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})}},x=Y;k=new WeakMap,c(x,k,"/api/v2/manifest");var q=class extends x{constructor(e){super({...e,bypassCache:!0})}},z=class extends x{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})}},g=R;j=new WeakMap,c(g,j,"/api/v2/quirk");var B=class extends g{constructor(e){super({...e,bypassCache:!0})}},F=class extends g{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})}},d=I;E=new WeakMap,c(d,E,"/api/v2/signal");var W=class extends d{constructor(e){super({...e,bypassCache:!0})}},X=class extends d{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 N=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 u(e),this.aggregates=new y(e),this.dimensions=new f(e),this.manifest=new x(e),this.quirks=new g(e),this.signals=new d(e),this.tests=new T(e)}},Z=class extends N{constructor(e){super({...e,bypassCache:!0})}},_=class extends N{constructor(e){super({...e,bypassCache:!1})}};0&&(module.exports={AggregateClient,ApiClient,ApiClientError,CachedAggregateClient,CachedContextClient,CachedDimensionClient,CachedEnrichmentClient,CachedManifestClient,CachedQuirkClient,CachedSignalClient,ContextClient,DimensionClient,EnrichmentClient,ManifestClient,QuirkClient,SignalClient,UncachedAggregateClient,UncachedContextClient,UncachedDimensionClient,UncachedEnrichmentClient,UncachedManifestClient,UncachedQuirkClient,UncachedSignalClient,computeDimensionDefinitionDisplayData,computeDimensionDisplayData,computeDimensionDisplayName,nullLimitPolicy});
package/dist/api/api.mjs CHANGED
@@ -1,2 +1,2 @@
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 k="_";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 ye(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(k)>=0){let[p,l]=r.split(k);return{dim:r,name:l,type:"Enrichment",category:p}}}function fe(r){let{type:e,name:t}=re(r);return`${e}: ${t}`}var N,v=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(v,N),{...e,projectId:t});return await this.apiClient(s)}},f=v;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,L=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(L,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=L;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})}};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,ye as computeDimensionDisplayData,fe as computeDimensionDisplayName,J as nullLimitPolicy};
1
+ var ee=Object.defineProperty;var te=(r,e,t)=>e in r?ee(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var m=(r,e,t)=>(te(r,typeof e!="symbol"?e+"":e,t),t),re=(r,e,t)=>{if(!e.has(r))throw TypeError("Cannot "+t)};var i=(r,e,t)=>(re(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 $=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,J;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:$,bypassCache:(u=e.bypassCache)!=null?u:!1,branchName:(J=e.branchName)!=null?J:null}}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:"")}),this.options.branchName&&s.searchParams.append("branch",this.options.branchName),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 V=class extends y{constructor(e){super({...e,bypassCache:!0})}},M=class extends y{constructor(e){super({...e,bypassCache:!1})}};var k="_";function se(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 fe(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(k)>=0){let[p,l]=r.split(k);return{dim:r,name:l,type:"Enrichment",category:p}}}function xe(r){let{type:e,name:t}=se(r);return`${e}: ${t}`}var N,v=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(v,N),{...e,projectId:t});return await this.apiClient(s)}},f=v;N=new WeakMap,c(f,N,"/api/v2/dimension");var Q=class extends f{constructor(e){super({...e,bypassCache:!0})}},H=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 K=class extends h{constructor(e){super({...e,bypassCache:!0})}},q=class extends h{constructor(e){super({...e,bypassCache:!1})}};var S,L=class extends n{constructor(e){super(e)}async get(e){let{projectId:t}=this.options,s=this.createUrl(i(L,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=L;S=new WeakMap,c(g,S,"/api/v2/manifest");var z=class extends g{constructor(e){super({...e,bypassCache:!0})}},Y=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 B=class extends d{constructor(e){super({...e,bypassCache:!0})}},F=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 W=class extends P{constructor(e){super({...e,bypassCache:!0})}},X=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)}},Z=class extends A{constructor(e){super({...e,bypassCache:!0})}},_=class extends A{constructor(e){super({...e,bypassCache:!1})}};export{y as AggregateClient,n as ApiClient,C as ApiClientError,M as CachedAggregateClient,_ as CachedContextClient,H as CachedDimensionClient,q as CachedEnrichmentClient,Y as CachedManifestClient,F as CachedQuirkClient,X as CachedSignalClient,A as ContextClient,f as DimensionClient,h as EnrichmentClient,g as ManifestClient,d as QuirkClient,P as SignalClient,V as UncachedAggregateClient,Z as UncachedContextClient,Q as UncachedDimensionClient,K as UncachedEnrichmentClient,z as UncachedManifestClient,B as UncachedQuirkClient,W as UncachedSignalClient,se as computeDimensionDefinitionDisplayData,fe as computeDimensionDisplayData,xe as computeDimensionDisplayName,$ as nullLimitPolicy};
package/dist/cli/cli.js CHANGED
@@ -122,7 +122,7 @@ ${g.join(`
122
122
  ${m==null?void 0:m.message}`)),m}}}return{objects:s(),deleteObject:async o=>{await(0,Dp.unlink)(o)},writeObject:async o=>{p?me(o.object,a,(0,Ot.join)(e,`${p(o.object)}.${a}`)):me(o.object,a,d(o.id))}}}function pl(e,a){if(!a&&!il.default.existsSync(e))return{};let t=B1(e);if(typeof t!="object")throw new Error(`Package ${e} does not appear valid.`);return t}function rl(e,a){me(a,void 0,e)}async function we({source:e,target:a,compareContents:t=(d,s)=>(0,nl.default)(d.object,s.object,(o,l,m)=>m==="created"||m==="modified"?!0:void 0),mode:i,allowEmptySource:p=!1,whatIf:r=!1,log:n=()=>{}}){var d,s;let o=new Map;for await(let c of a.objects)o.set(c.id,c);let l=[],m=!1;for await(let c of e.objects){m=!0;let u=c.id,g=o.get(u);if(g){if(!t(c,g)&&(i==="createOrUpdate"||i==="mirror")){let v=async(h,_)=>{var A;if(!r)try{await a.writeObject(h,_)}catch(L){throw new Op(L,h)}n({action:"update",id:u,providerId:h.providerId,displayName:(A=h.displayName)!=null?A:h.providerId,whatIf:r,diff:Ao(_.object,h.object)})};l.push(v(c,g))}o.delete(u)}else{let v=async(h,_)=>{var A;if(!r)try{await a.writeObject(h)}catch(L){throw new Op(L,h)}n({action:"create",id:_,providerId:_,displayName:(A=h.displayName)!=null?A:h.providerId,whatIf:r,diff:Qn("",JSON.stringify(h.object,null,2))})};l.push(v(c,u))}}if(await Promise.all(l),i==="mirror"){if(!m&&!p)throw new Error("Source is empty and mode is mirror. This would cause deletion of everything in the target, and most likely indicates an error in source definition.");let c=[];o.forEach(async u=>{let g=async v=>{var h;if(!r)try{await a.deleteObject(v.providerId,v)}catch(_){throw new Op(_,v)}n({action:"delete",id:v.id,providerId:v.providerId,displayName:(h=v.displayName)!=null?h:v.providerId,whatIf:r,diff:Qn(JSON.stringify(v.object,null,2),"")})};c.push(g(u))}),await Promise.all(c)}await Promise.all([(d=e.onSyncComplete)==null?void 0:d.call(e,!1),(s=a.onSyncComplete)==null?void 0:s.call(a,!0)])}var Op=class extends Error{constructor(e,a){var t;super(`Error syncing ${(t=a.displayName)!=null?t:a.providerId} (${a.providerId})
123
123
  ${e}`),this.stack=void 0,Object.setPrototypeOf(this,Op.prototype)}},Et=xr(Ar());function be(e){let{diffMode:a="off",indent:t,prefix:i}=e!=null?e:{};return function({action:p,displayName:r,whatIf:n,diff:d}){let s="";switch(p){case"create":s=Et.default.green("[A]");break;case"update":s=Et.default.white("[U]");break;case"delete":s=Et.default.yellow("[D]");break}let o="";(a==="on"||a==="update"&&p==="update")&&(o=`
124
124
  `+d.map(l=>l.added?Et.default.green(l.value):l.removed?Et.default.red(l.value):l.value).join("")),console.log(`${t!=null?t:""}${n?Et.default.gray("[WHATIF]"):""}${s}${i!=null?i:""} ${r}${o}`)}}var dl=async e=>await e(),k1=class extends Error{constructor(t,i,p,r,n,d){super(`${t}
125
- ${r}${n?" "+n:""} (${i} ${p}${d?` Request ID: ${d}`:""})`);this.errorMessage=t;this.fetchMethod=i;this.fetchUri=p;this.statusCode=r;this.statusText=n;this.requestId=d;Object.setPrototypeOf(this,k1.prototype)}};var We=class{constructor(a){Ed(this,"options");var i,p,r,n,d,s;if(!a.apiKey&&!a.bearerToken)throw new Error("You must provide an API key or a bearer token");let t=a.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={...a,fetch:t,apiHost:(i=a.apiHost)!=null?i:"https://uniform.app",apiKey:(p=a.apiKey)!=null?p:null,projectId:(r=a.projectId)!=null?r:null,bearerToken:(n=a.bearerToken)!=null?n:null,limitPolicy:(d=a.limitPolicy)!=null?d:dl,bypassCache:(s=a.bypassCache)!=null?s:!1}}async apiClient(a,t){return this.options.limitPolicy(async()=>{var r;let i=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`};this.options.bypassCache&&(i["x-bypass-cache"]="true");let p=await this.options.fetch(a.toString(),{...t,headers:{...t==null?void 0:t.headers,...i}});if(!p.ok){let n="";try{let d=await p.text();try{let s=JSON.parse(d);s.errorMessage?n=Array.isArray(s.errorMessage)?s.errorMessage.join(", "):s.errorMessage:n=d}catch(s){n=d}}catch(d){n="General error"}throw new k1(n,(r=t==null?void 0:t.method)!=null?r:"GET",a.toString(),p.status,p.statusText,We.getRequestId(p))}return t!=null&&t.expectNoContent?null:await p.json()})}createUrl(a,t){let i=new URL(`${this.options.apiHost}${a}`);return Object.entries(t!=null?t:{}).forEach(([p,r])=>{var n;typeof r!="undefined"&&r!==null&&i.searchParams.append(p,Array.isArray(r)?r.join(","):(n=r==null?void 0:r.toString())!=null?n:"")}),i}static getRequestId(a){let t=a.headers.get("apigw-requestid");if(t)return t}};var Nt,ci=class extends We{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(oe(ci,Nt),{...a,projectId:t});return await this.apiClient(i)}async upsert(a){let t=this.createUrl(oe(ci,Nt));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async remove(a){let t=this.createUrl(oe(ci,Nt));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},Tp=ci;Nt=new WeakMap,p1(Tp,Nt,"/api/v2/aggregate");var Xe=class extends Tp{constructor(a){super({...a,bypassCache:!0})}};var sl={command:"get <id>",describe:"Fetch an aggregate",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Aggregate public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{let d=j(t),o=await new Xe({apiKey:a,apiHost:e,fetch:d,projectId:r}).get({aggregateId:i});o.aggregates.length===0?(console.error("Aggregate did not exist"),process.exit(1)):me(o.aggregates[0],p,n)}};var ol={command:"list",describe:"List aggregates",aliases:["ls"],builder:e=>Ee(F(I(e))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r})=>{let n=j(t),s=await new Xe({apiKey:a,apiHost:e,fetch:n,projectId:r}).get({});me(s.aggregates,i,p)}};var va=e=>e.id,wa=e=>`${e.name} (pid: ${e.id})`;function Pp({client:e,type:a}){async function*t(){let p=(await e.get({type:a})).aggregates;for await(let r of p)yield{id:va(r),displayName:wa(r),providerId:r.id,object:r}}let i=[];return{objects:t(),deleteObject:async p=>{await e.remove({aggregateId:p})},writeObject:async p=>{await e.upsert({aggregate:p.object,skipInputs:!0}),i.push(p.object)},complete:async()=>{await Promise.all(i.map(p=>e.upsert({aggregate:p,skipInputs:!1})))}}}function Ae(e,a){return pl(e,a)}function D1(e,a){rl(e,a)}var ll=i1(require("p-limit")),Te=(0,ll.default)(8);var ml={command:"pull <directory>",describe:"Pulls all aggregates to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the aggregates to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new Xe({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Te}),m=Pp({client:l}),c;if(Ne(i)){let v=Ae(i,!1);c=await Se({objects:(g=v.aggregates)!=null?g:[],selectIdentifier:va,selectDisplayName:wa,onSyncComplete:async(h,_)=>{v.aggregates=_,D1(i,v)}})}else c=await De({directory:i,selectIdentifier:va,selectDisplayName:wa,format:p});await we({source:m,target:c,mode:r,whatIf:n,log:be({diffMode:s})})}};var cl={command:"push <directory>",describe:"Pushes all aggregates from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the aggregates from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new Xe({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Te}),l;if(Ne(i)){let g=Ae(i,!0);l=await Se({objects:(u=g.aggregates)!=null?u:[],selectIdentifier:va,selectDisplayName:wa})}else l=await De({directory:i,selectIdentifier:va,selectDisplayName:wa});let c=Pp({client:o});await we({source:l,target:c,mode:p,whatIf:r,log:be({diffMode:d})}),await c.complete()}};var ul={command:"remove <id>",aliases:["delete","rm"],describe:"Delete an aggregate",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Aggregate public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new Xe({apiKey:a,apiHost:e,fetch:r,projectId:p}).remove({aggregateId:i})}};var fl={command:"update <filename>",aliases:["put"],describe:"Insert or update an aggregate",builder:e=>F(I(e.positional("filename",{demandOption:!0,describe:"Aggregate file to put"}))),handler:async({apiHost:e,apiKey:a,proxy:t,filename:i,project:p})=>{let r=j(t),n=new Xe({apiKey:a,apiHost:e,fetch:r,projectId:p}),d=B1(i);await n.upsert({aggregate:d})}};var hl={command:"aggregate <command>",aliases:["agg","intent","audience"],describe:"Commands for Context aggregates (intents, audiences)",builder:e=>e.command(ml).command(cl).command(sl).command(ul).command(ol).command(fl).demandCommand(),handler:()=>{Ke.help()}};var Dt,fi,Za=class extends We{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(oe(Za,Dt),{...a,projectId:t});return await this.apiClient(i)}async upsertCategory(a){let t=this.createUrl(oe(Za,Dt));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async removeCategory(a){let t=this.createUrl(oe(Za,Dt));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async upsertValue(a){let t=this.createUrl(oe(Za,fi));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async removeValue(a){let t=this.createUrl(oe(Za,fi));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},ui=Za;Dt=new WeakMap,fi=new WeakMap,p1(ui,Dt,"/api/v1/enrichments"),p1(ui,fi,"/api/v1/enrichment-values");var A1=class extends ui{constructor(a){super({...a,bypassCache:!0})}};var gl={command:"get <id>",describe:"Fetch an enrichment category and its values",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Enrichment category public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{var l,m;let d=j(t),o=(m=(l=await new A1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get())==null?void 0:l.enrichments)==null?void 0:m.filter(c=>c.id===i);o.length===0?(console.error("Enrichment did not exist"),process.exit(1)):me(o[0],p,n)}};var vl={command:"list",describe:"List enrichments",aliases:["ls"],builder:e=>Ee(F(I(e))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r})=>{let n=j(t),s=await new A1({apiKey:a,apiHost:e,fetch:n,projectId:r}).get();me(s.enrichments,i,p)}};var ba=e=>e.id,ya=e=>`${e.name} (pid: ${e.id})`;function Fp({client:e}){async function*a(){let t=(await e.get()).enrichments;for await(let i of t)yield{id:ba(i),displayName:ya(i),providerId:i.id,object:i}}return{objects:a(),deleteObject:async t=>{await e.removeCategory({enrichmentId:t})},writeObject:async(t,i)=>{var n,d;await e.upsertCategory({enrichment:t.object});let p=wl({categoryId:t.id,values:t.object.values}),r=wl({categoryId:t.id,values:(d=(n=i==null?void 0:i.object)==null?void 0:n.values)!=null?d:[],client:e});await we({source:p,target:r,mode:"mirror",whatIf:!1,log:be({diffMode:"off",prefix:` ${t.displayName} value`,indent:"> "})})}}}var wl=({client:e,categoryId:a,values:t})=>({objects:async function*(){for(let p of t)yield{id:p.id,providerId:p.id,object:p,displayName:`${p.value} (pid: ${p.id})`}}(),deleteObject:async p=>{if(!e)throw new Error("Provider is read only");await e.removeValue({enrichmentId:a,enrichmentValueId:p})},writeObject:async p=>{if(!e)throw new Error("Provider is read only");await e.upsertValue({enrichmentId:a,enrichmentValue:p.object})}});var bl={command:"pull <directory>",describe:"Pulls all enrichments to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the enrichments to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new A1({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Te}),m=Fp({client:l}),c;if(Ne(i)){let v=Ae(i,!1);c=await Se({objects:(g=v.enrichments)!=null?g:[],selectIdentifier:ba,selectDisplayName:ya,onSyncComplete:async(h,_)=>{v.enrichments=_,D1(i,v)}})}else c=await De({directory:i,selectIdentifier:ba,selectDisplayName:ya,format:p});await we({source:m,target:c,mode:r,whatIf:n,log:be({diffMode:s})})}};var yl={command:"push <directory>",describe:"Pushes all enrichments from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the enrichments from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new A1({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Te}),l;if(Ne(i)){let g=Ae(i,!0);l=await Se({objects:(u=g.enrichments)!=null?u:[],selectIdentifier:ba,selectDisplayName:ya})}else l=await De({directory:i,selectIdentifier:ba,selectDisplayName:ya});let c=Fp({client:o});await we({source:l,target:c,mode:p,whatIf:r,log:be({diffMode:d})})}};var _l={command:"remove <id>",aliases:["delete","rm"],describe:"Delete an enrichment category and its values",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Enrichment category public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new A1({apiKey:a,apiHost:e,fetch:r,projectId:p}).removeCategory({enrichmentId:i})}};var xl={command:"enrichment <command>",aliases:["enr"],describe:"Commands for Context enrichments",builder:e=>e.command(bl).command(yl).command(gl).command(_l).command(vl).demandCommand(),handler:()=>{Ke.help()}};var Rp=i1(yd()),Ql=require("fs"),xd=require("process");var Up,_d=class extends We{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(oe(_d,Up),{...a,projectId:t});return await this.apiClient(i)}async publish(){let{projectId:a}=this.options,t=this.createUrl("/api/v1/publish",{siteId:a});await this.apiClient(t,{method:"POST",expectNoContent:!0})}},kp=_d;Up=new WeakMap,p1(kp,Up,"/api/v2/manifest");var It=class extends kp{constructor(a){super({...a,bypassCache:!0})}};var Jl={command:"get [output]",aliases:["dl","download"],describe:"Download the Uniform Context manifest for a project",builder:e=>F(I(e.option("preview",{describe:"If set, fetches the unpublished preview manifest (The API key must have permission)",default:!1,type:"boolean",alias:["d"]}).option("output",{string:!0,alias:"o",default:process.env.UNIFORM_MANIFEST_PATH,describe:"Path to write manifest to. Defaults to UNIFORM_MANIFEST_PATH env if set.",demandOption:!0}))),handler:async({apiKey:e,apiHost:a,proxy:t,output:i,project:p,preview:r})=>{let n=j(t),d=new It({apiHost:a,projectId:p,apiKey:e,fetch:n});try{let s=await d.get({preview:r}),o=JSON.stringify(s,null,2);i?(0,Ql.writeFile)(i,o,l=>{l&&(console.error(`Error writing file to ${i}
125
+ ${r}${n?" "+n:""} (${i} ${p}${d?` Request ID: ${d}`:""})`);this.errorMessage=t;this.fetchMethod=i;this.fetchUri=p;this.statusCode=r;this.statusText=n;this.requestId=d;Object.setPrototypeOf(this,k1.prototype)}};var We=class{constructor(a){Ed(this,"options");var i,p,r,n,d,s,o;if(!a.apiKey&&!a.bearerToken)throw new Error("You must provide an API key or a bearer token");let t=a.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={...a,fetch:t,apiHost:(i=a.apiHost)!=null?i:"https://uniform.app",apiKey:(p=a.apiKey)!=null?p:null,projectId:(r=a.projectId)!=null?r:null,bearerToken:(n=a.bearerToken)!=null?n:null,limitPolicy:(d=a.limitPolicy)!=null?d:dl,bypassCache:(s=a.bypassCache)!=null?s:!1,branchName:(o=a.branchName)!=null?o:null}}async apiClient(a,t){return this.options.limitPolicy(async()=>{var r;let i=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`};this.options.bypassCache&&(i["x-bypass-cache"]="true");let p=await this.options.fetch(a.toString(),{...t,headers:{...t==null?void 0:t.headers,...i}});if(!p.ok){let n="";try{let d=await p.text();try{let s=JSON.parse(d);s.errorMessage?n=Array.isArray(s.errorMessage)?s.errorMessage.join(", "):s.errorMessage:n=d}catch(s){n=d}}catch(d){n="General error"}throw new k1(n,(r=t==null?void 0:t.method)!=null?r:"GET",a.toString(),p.status,p.statusText,We.getRequestId(p))}return t!=null&&t.expectNoContent?null:await p.json()})}createUrl(a,t){let i=new URL(`${this.options.apiHost}${a}`);return Object.entries(t!=null?t:{}).forEach(([p,r])=>{var n;typeof r!="undefined"&&r!==null&&i.searchParams.append(p,Array.isArray(r)?r.join(","):(n=r==null?void 0:r.toString())!=null?n:"")}),this.options.branchName&&i.searchParams.append("branch",this.options.branchName),i}static getRequestId(a){let t=a.headers.get("apigw-requestid");if(t)return t}};var Nt,ci=class extends We{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(oe(ci,Nt),{...a,projectId:t});return await this.apiClient(i)}async upsert(a){let t=this.createUrl(oe(ci,Nt));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async remove(a){let t=this.createUrl(oe(ci,Nt));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},Tp=ci;Nt=new WeakMap,p1(Tp,Nt,"/api/v2/aggregate");var Xe=class extends Tp{constructor(a){super({...a,bypassCache:!0})}};var sl={command:"get <id>",describe:"Fetch an aggregate",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Aggregate public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{let d=j(t),o=await new Xe({apiKey:a,apiHost:e,fetch:d,projectId:r}).get({aggregateId:i});o.aggregates.length===0?(console.error("Aggregate did not exist"),process.exit(1)):me(o.aggregates[0],p,n)}};var ol={command:"list",describe:"List aggregates",aliases:["ls"],builder:e=>Ee(F(I(e))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r})=>{let n=j(t),s=await new Xe({apiKey:a,apiHost:e,fetch:n,projectId:r}).get({});me(s.aggregates,i,p)}};var va=e=>e.id,wa=e=>`${e.name} (pid: ${e.id})`;function Pp({client:e,type:a}){async function*t(){let p=(await e.get({type:a})).aggregates;for await(let r of p)yield{id:va(r),displayName:wa(r),providerId:r.id,object:r}}let i=[];return{objects:t(),deleteObject:async p=>{await e.remove({aggregateId:p})},writeObject:async p=>{await e.upsert({aggregate:p.object,skipInputs:!0}),i.push(p.object)},complete:async()=>{await Promise.all(i.map(p=>e.upsert({aggregate:p,skipInputs:!1})))}}}function Ae(e,a){return pl(e,a)}function D1(e,a){rl(e,a)}var ll=i1(require("p-limit")),Te=(0,ll.default)(8);var ml={command:"pull <directory>",describe:"Pulls all aggregates to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the aggregates to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new Xe({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Te}),m=Pp({client:l}),c;if(Ne(i)){let v=Ae(i,!1);c=await Se({objects:(g=v.aggregates)!=null?g:[],selectIdentifier:va,selectDisplayName:wa,onSyncComplete:async(h,_)=>{v.aggregates=_,D1(i,v)}})}else c=await De({directory:i,selectIdentifier:va,selectDisplayName:wa,format:p});await we({source:m,target:c,mode:r,whatIf:n,log:be({diffMode:s})})}};var cl={command:"push <directory>",describe:"Pushes all aggregates from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the aggregates from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new Xe({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Te}),l;if(Ne(i)){let g=Ae(i,!0);l=await Se({objects:(u=g.aggregates)!=null?u:[],selectIdentifier:va,selectDisplayName:wa})}else l=await De({directory:i,selectIdentifier:va,selectDisplayName:wa});let c=Pp({client:o});await we({source:l,target:c,mode:p,whatIf:r,log:be({diffMode:d})}),await c.complete()}};var ul={command:"remove <id>",aliases:["delete","rm"],describe:"Delete an aggregate",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Aggregate public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new Xe({apiKey:a,apiHost:e,fetch:r,projectId:p}).remove({aggregateId:i})}};var fl={command:"update <filename>",aliases:["put"],describe:"Insert or update an aggregate",builder:e=>F(I(e.positional("filename",{demandOption:!0,describe:"Aggregate file to put"}))),handler:async({apiHost:e,apiKey:a,proxy:t,filename:i,project:p})=>{let r=j(t),n=new Xe({apiKey:a,apiHost:e,fetch:r,projectId:p}),d=B1(i);await n.upsert({aggregate:d})}};var hl={command:"aggregate <command>",aliases:["agg","intent","audience"],describe:"Commands for Context aggregates (intents, audiences)",builder:e=>e.command(ml).command(cl).command(sl).command(ul).command(ol).command(fl).demandCommand(),handler:()=>{Ke.help()}};var Dt,fi,Za=class extends We{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(oe(Za,Dt),{...a,projectId:t});return await this.apiClient(i)}async upsertCategory(a){let t=this.createUrl(oe(Za,Dt));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async removeCategory(a){let t=this.createUrl(oe(Za,Dt));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async upsertValue(a){let t=this.createUrl(oe(Za,fi));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async removeValue(a){let t=this.createUrl(oe(Za,fi));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},ui=Za;Dt=new WeakMap,fi=new WeakMap,p1(ui,Dt,"/api/v1/enrichments"),p1(ui,fi,"/api/v1/enrichment-values");var A1=class extends ui{constructor(a){super({...a,bypassCache:!0})}};var gl={command:"get <id>",describe:"Fetch an enrichment category and its values",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Enrichment category public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{var l,m;let d=j(t),o=(m=(l=await new A1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get())==null?void 0:l.enrichments)==null?void 0:m.filter(c=>c.id===i);o.length===0?(console.error("Enrichment did not exist"),process.exit(1)):me(o[0],p,n)}};var vl={command:"list",describe:"List enrichments",aliases:["ls"],builder:e=>Ee(F(I(e))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r})=>{let n=j(t),s=await new A1({apiKey:a,apiHost:e,fetch:n,projectId:r}).get();me(s.enrichments,i,p)}};var ba=e=>e.id,ya=e=>`${e.name} (pid: ${e.id})`;function Fp({client:e}){async function*a(){let t=(await e.get()).enrichments;for await(let i of t)yield{id:ba(i),displayName:ya(i),providerId:i.id,object:i}}return{objects:a(),deleteObject:async t=>{await e.removeCategory({enrichmentId:t})},writeObject:async(t,i)=>{var n,d;await e.upsertCategory({enrichment:t.object});let p=wl({categoryId:t.id,values:t.object.values}),r=wl({categoryId:t.id,values:(d=(n=i==null?void 0:i.object)==null?void 0:n.values)!=null?d:[],client:e});await we({source:p,target:r,mode:"mirror",whatIf:!1,log:be({diffMode:"off",prefix:` ${t.displayName} value`,indent:"> "})})}}}var wl=({client:e,categoryId:a,values:t})=>({objects:async function*(){for(let p of t)yield{id:p.id,providerId:p.id,object:p,displayName:`${p.value} (pid: ${p.id})`}}(),deleteObject:async p=>{if(!e)throw new Error("Provider is read only");await e.removeValue({enrichmentId:a,enrichmentValueId:p})},writeObject:async p=>{if(!e)throw new Error("Provider is read only");await e.upsertValue({enrichmentId:a,enrichmentValue:p.object})}});var bl={command:"pull <directory>",describe:"Pulls all enrichments to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the enrichments to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new A1({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Te}),m=Fp({client:l}),c;if(Ne(i)){let v=Ae(i,!1);c=await Se({objects:(g=v.enrichments)!=null?g:[],selectIdentifier:ba,selectDisplayName:ya,onSyncComplete:async(h,_)=>{v.enrichments=_,D1(i,v)}})}else c=await De({directory:i,selectIdentifier:ba,selectDisplayName:ya,format:p});await we({source:m,target:c,mode:r,whatIf:n,log:be({diffMode:s})})}};var yl={command:"push <directory>",describe:"Pushes all enrichments from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the enrichments from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new A1({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Te}),l;if(Ne(i)){let g=Ae(i,!0);l=await Se({objects:(u=g.enrichments)!=null?u:[],selectIdentifier:ba,selectDisplayName:ya})}else l=await De({directory:i,selectIdentifier:ba,selectDisplayName:ya});let c=Fp({client:o});await we({source:l,target:c,mode:p,whatIf:r,log:be({diffMode:d})})}};var _l={command:"remove <id>",aliases:["delete","rm"],describe:"Delete an enrichment category and its values",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Enrichment category public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new A1({apiKey:a,apiHost:e,fetch:r,projectId:p}).removeCategory({enrichmentId:i})}};var xl={command:"enrichment <command>",aliases:["enr"],describe:"Commands for Context enrichments",builder:e=>e.command(bl).command(yl).command(gl).command(_l).command(vl).demandCommand(),handler:()=>{Ke.help()}};var Rp=i1(yd()),Ql=require("fs"),xd=require("process");var Up,_d=class extends We{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(oe(_d,Up),{...a,projectId:t});return await this.apiClient(i)}async publish(){let{projectId:a}=this.options,t=this.createUrl("/api/v1/publish",{siteId:a});await this.apiClient(t,{method:"POST",expectNoContent:!0})}},kp=_d;Up=new WeakMap,p1(kp,Up,"/api/v2/manifest");var It=class extends kp{constructor(a){super({...a,bypassCache:!0})}};var Jl={command:"get [output]",aliases:["dl","download"],describe:"Download the Uniform Context manifest for a project",builder:e=>F(I(e.option("preview",{describe:"If set, fetches the unpublished preview manifest (The API key must have permission)",default:!1,type:"boolean",alias:["d"]}).option("output",{string:!0,alias:"o",default:process.env.UNIFORM_MANIFEST_PATH,describe:"Path to write manifest to. Defaults to UNIFORM_MANIFEST_PATH env if set.",demandOption:!0}))),handler:async({apiKey:e,apiHost:a,proxy:t,output:i,project:p,preview:r})=>{let n=j(t),d=new It({apiHost:a,projectId:p,apiKey:e,fetch:n});try{let s=await d.get({preview:r}),o=JSON.stringify(s,null,2);i?(0,Ql.writeFile)(i,o,l=>{l&&(console.error(`Error writing file to ${i}
126
126
  `,l),(0,xd.exit)(1)),console.log(Rp.default.green(`\u2705 ${i} has been updated from ${a}`))}):console.log(o)}catch(s){let o;s instanceof k1?(s.statusCode===403&&(o=`The API key ${e} did not have permissions to fetch the manifest. Ensure ${r?"Uniform Context > Read Drafts":"Uniform Context > Manifest > Read"} permissions are granted.`),o=s.message):o=s.toString(),console.error(Rp.default.red("\u26A0 Error fetching Context manifest")),console.error(Rp.default.gray(` \u2757 ${o}`)),(0,xd.exit)(1)}}};var Ad=i1(yd()),Zl=require("process");var Xl={command:"publish",describe:"Publish the Uniform Context manifest for a project",builder:e=>F(I(e)),handler:async({apiKey:e,apiHost:a,proxy:t,project:i})=>{let p=j(t);try{await new It({apiHost:a,projectId:i,apiKey:e,fetch:p}).publish()}catch(r){let n;r instanceof k1?(r.statusCode===403&&(n=`The API key ${e} did not have permissions to publish the manifest. Ensure Uniform Context > Manifest > Publish permissions are granted.`),n=r.message):n=r.toString(),console.error(Ad.default.red("\u26A0 Error publishing Context manifest")),console.error(Ad.default.gray(` \u2757 ${n}`)),(0,Zl.exit)(1)}}};var e6={command:"manifest <command>",describe:"Commands for context manifests",aliases:["man"],builder:e=>e.command(Jl).command(Xl).demandCommand(),handler:()=>{Ke.help()}};var Mt,vi=class extends We{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(oe(vi,Mt),{...a,projectId:t});return await this.apiClient(i)}async upsert(a){let t=this.createUrl(oe(vi,Mt));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async remove(a){let t=this.createUrl(oe(vi,Mt));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},$p=vi;Mt=new WeakMap,p1($p,Mt,"/api/v2/quirk");var e1=class extends $p{constructor(a){super({...a,bypassCache:!0})}};var a6={command:"get <id>",describe:"Fetch a quirk",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Quirk public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{let d=j(t),o=await new e1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get({quirkId:i,withIntegrations:!0});o.quirks.length===0?(console.error("Quirk did not exist"),process.exit(1)):me(o.quirks[0],p,n)}};var t6={command:"list",describe:"List quirks",aliases:["ls"],builder:e=>Ee(F(I(e.option("withIntegrations",{alias:["i"],describe:"Whether to include meta-quirks created by integrations in the list. Defaults to false.",type:"boolean"})))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r,withIntegrations:n})=>{let d=j(t),o=await new e1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get({withIntegrations:n});me(o.quirks,i,p)}};var _a=e=>e.id,xa=e=>`${e.name} (pid: ${e.id})`;function qp({client:e}){async function*a(){let t=(await e.get({withIntegrations:!1})).quirks;for await(let i of t)yield{id:_a(i),displayName:xa(i),providerId:i.id,object:i}}return{objects:a(),deleteObject:async t=>{await e.remove({quirkId:t})},writeObject:async t=>{await e.upsert({quirk:t.object})}}}var i6={command:"pull <directory>",describe:"Pulls all quirks to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the quirks to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new e1({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Te}),m=qp({client:l}),c;if(Ne(i)){let v=Ae(i,!1);c=await Se({objects:(g=v.quirks)!=null?g:[],selectIdentifier:_a,selectDisplayName:xa,onSyncComplete:async(h,_)=>{v.quirks=_,D1(i,v)}})}else c=await De({directory:i,selectIdentifier:_a,selectDisplayName:xa,format:p});await we({source:m,target:c,mode:r,whatIf:n,log:be({diffMode:s})})}};var p6={command:"push <directory>",describe:"Pushes all quirks from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the quirks from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new e1({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Te}),l;if(Ne(i)){let g=Ae(i,!0);l=await Se({objects:(u=g.quirks)!=null?u:[],selectIdentifier:_a,selectDisplayName:xa})}else l=await De({directory:i,selectIdentifier:_a,selectDisplayName:xa});let c=qp({client:o});await we({source:l,target:c,mode:p,whatIf:r,log:be({diffMode:d})})}};var r6={command:"remove <id>",aliases:["delete","rm"],describe:"Delete a quirk",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Quirk public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new e1({apiKey:a,apiHost:e,fetch:r,projectId:p}).remove({quirkId:i})}};var n6={command:"update <filename>",aliases:["put"],describe:"Insert or update a quirk",builder:e=>F(I(e.positional("filename",{demandOption:!0,describe:"Quirk file to put"}))),handler:async({apiHost:e,apiKey:a,proxy:t,filename:i,project:p})=>{let r=j(t),n=new e1({apiKey:a,apiHost:e,fetch:r,projectId:p}),d=B1(i);await n.upsert({quirk:d})}};var d6={command:"quirk <command>",aliases:["qk"],describe:"Commands for Context quirks",builder:e=>e.command(i6).command(p6).command(a6).command(r6).command(t6).command(n6).demandCommand(),handler:()=>{Ke.help()}};var Vt,wi=class extends We{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(oe(wi,Vt),{...a,projectId:t});return await this.apiClient(i)}async upsert(a){let t=this.createUrl(oe(wi,Vt));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async remove(a){let t=this.createUrl(oe(wi,Vt));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},Hp=wi;Vt=new WeakMap,p1(Hp,Vt,"/api/v2/signal");var a1=class extends Hp{constructor(a){super({...a,bypassCache:!0})}};var s6={command:"get <id>",describe:"Fetch a signal",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Signal public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{let d=j(t),o=await new a1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get({signalId:i});o.signals.length===0?(console.error("Signal did not exist"),process.exit(1)):me(o.signals[0],p,n)}};var o6={command:"list",describe:"List signals",aliases:["ls"],builder:e=>Ee(F(I(e))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r})=>{let n=j(t),s=await new a1({apiKey:a,apiHost:e,fetch:n,projectId:r}).get();me(s.signals,i,p)}};var Aa=e=>e.id,Ca=e=>`${e.name} (pid: ${e.id})`;function Wp({client:e}){async function*a(){let t=(await e.get()).signals;for await(let i of t)yield{id:Aa(i),displayName:Ca(i),providerId:i.id,object:i}}return{objects:a(),deleteObject:async t=>{await e.remove({signalId:t})},writeObject:async t=>{await e.upsert({signal:t.object})}}}var l6={command:"pull <directory>",describe:"Pulls all signals to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the signals to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new a1({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Te}),m=Wp({client:l}),c;if(Ne(i)){let v=Ae(i,!1);c=await Se({objects:(g=v.signals)!=null?g:[],selectIdentifier:Aa,selectDisplayName:Ca,onSyncComplete:async(h,_)=>{v.signals=_,D1(i,v)}})}else c=await De({directory:i,selectIdentifier:Aa,selectDisplayName:Ca,format:p});await we({source:m,target:c,mode:r,whatIf:n,log:be({diffMode:s})})}};var m6={command:"push <directory>",describe:"Pushes all signals from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the signals from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new a1({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Te}),l;if(Ne(i)){let g=Ae(i,!0);l=await Se({objects:(u=g.signals)!=null?u:[],selectIdentifier:Aa,selectDisplayName:Ca})}else l=await De({directory:i,selectIdentifier:Aa,selectDisplayName:Ca});let c=Wp({client:o});await we({source:l,target:c,mode:p,whatIf:r,log:be({diffMode:d})})}};var c6={command:"remove <id>",aliases:["delete","rm"],describe:"Delete a signal",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Signal public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new a1({apiKey:a,apiHost:e,fetch:r,projectId:p}).remove({signalId:i})}};var u6={command:"update <filename>",aliases:["put"],describe:"Insert or update a signal",builder:e=>F(I(e.positional("filename",{demandOption:!0,describe:"Signal file to put"}))),handler:async({apiHost:e,apiKey:a,proxy:t,filename:i,project:p})=>{let r=j(t),n=new a1({apiKey:a,apiHost:e,fetch:r,projectId:p}),d=B1(i);await n.upsert({signal:d})}};var f6={command:"signal <command>",aliases:["sig"],describe:"Commands for Context signals",builder:e=>e.command(l6).command(m6).command(s6).command(c6).command(o6).command(u6).demandCommand(),handler:()=>{Ke.help()}};var Lt,bi=class extends We{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(oe(bi,Lt),{...a,projectId:t});return await this.apiClient(i)}async upsert(a){let t=this.createUrl(oe(bi,Lt));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async remove(a){let t=this.createUrl(oe(bi,Lt));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},zp=bi;Lt=new WeakMap,p1(zp,Lt,"/api/v2/test");var t1=class extends zp{constructor(a){super({...a,bypassCache:!0})}};var h6={command:"get <id>",describe:"Fetch a test",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Test public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{let d=j(t),o=await new t1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get({testId:i});o.tests.length===0?(console.error("Test did not exist"),process.exit(1)):me(o.tests[0],p,n)}};var g6={command:"list",describe:"List tests",aliases:["ls"],builder:e=>Ee(F(I(e))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r})=>{let n=j(t),s=await new t1({apiKey:a,apiHost:e,fetch:n,projectId:r}).get();me(s.tests,i,p)}};var Sa=e=>e.id,Ea=e=>`${e.name} (pid: ${e.id})`;function Gp({client:e}){async function*a(){let t=(await e.get()).tests;for await(let i of t)yield{id:Sa(i),displayName:Ea(i),providerId:i.id,object:i}}return{objects:a(),deleteObject:async t=>{await e.remove({testId:t})},writeObject:async t=>{await e.upsert({test:t.object})}}}var v6={command:"pull <directory>",describe:"Pulls all tests to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the tests to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new t1({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Te}),m=Gp({client:l}),c;if(Ne(i)){let v=Ae(i,!1);c=await Se({objects:(g=v.tests)!=null?g:[],selectIdentifier:Sa,selectDisplayName:Ea,onSyncComplete:async(h,_)=>{v.tests=_,D1(i,v)}})}else c=await De({directory:i,selectIdentifier:Sa,selectDisplayName:Ea,format:p});await we({source:m,target:c,mode:r,whatIf:n,log:be({diffMode:s})})}};var w6={command:"push <directory>",describe:"Pushes all tests from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the tests from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new t1({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Te}),l;if(Ne(i)){let g=Ae(i,!0);l=await Se({objects:(u=g.tests)!=null?u:[],selectIdentifier:Sa,selectDisplayName:Ea})}else l=await De({directory:i,selectIdentifier:Sa,selectDisplayName:Ea});let c=Gp({client:o});await we({source:l,target:c,mode:p,whatIf:r,log:be({diffMode:d})})}};var b6={command:"remove <id>",aliases:["delete","rm"],describe:"Delete a test",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Test public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new t1({apiKey:a,apiHost:e,fetch:r,projectId:p}).remove({testId:i})}};var y6={command:"update <filename>",aliases:["put"],describe:"Insert or update a test",builder:e=>F(I(e.positional("filename",{demandOption:!0,describe:"Test file to put"}))),handler:async({apiHost:e,apiKey:a,proxy:t,filename:i,project:p})=>{let r=j(t),n=new t1({apiKey:a,apiHost:e,fetch:r,projectId:p}),d=B1(i);await n.upsert({test:d})}};var _6={command:"test <command>",describe:"Commands for Context A/B tests",builder:e=>e.command(v6).command(w6).command(h6).command(b6).command(g6).command(y6).demandCommand(),handler:()=>{Ke.help()}};var E7={commands:[{command:"context <command>",aliases:["ctx"],describe:"Uniform Context commands",builder:e=>e.command(e6).command(f6).command(xl).command(hl).command(d6).command(_6).demandCommand(),handler:()=>{Ke.showHelp()}}]};0&&(module.exports={readContextPackage,uniformCLI,writeContextPackage});
127
127
  /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
128
128
  /**
package/dist/cli/cli.mjs CHANGED
@@ -122,7 +122,7 @@ ${g.join(`
122
122
  ${m==null?void 0:m.message}`)),m}}}return{objects:s(),deleteObject:async o=>{await l7(o)},writeObject:async o=>{p?ce(o.object,a,Xn(e,`${p(o.object)}.${a}`)):ce(o.object,a,d(o.id))}}}function $o(e,a){if(!a&&!f7.existsSync(e))return{};let t=V1(e);if(typeof t!="object")throw new Error(`Package ${e} does not appear valid.`);return t}function qo(e,a){ce(a,void 0,e)}async function be({source:e,target:a,compareContents:t=(d,s)=>(0,Ho.default)(d.object,s.object,(o,l,m)=>m==="created"||m==="modified"?!0:void 0),mode:i,allowEmptySource:p=!1,whatIf:r=!1,log:n=()=>{}}){var d,s;let o=new Map;for await(let c of a.objects)o.set(c.id,c);let l=[],m=!1;for await(let c of e.objects){m=!0;let u=c.id,g=o.get(u);if(g){if(!t(c,g)&&(i==="createOrUpdate"||i==="mirror")){let v=async(h,_)=>{var A;if(!r)try{await a.writeObject(h,_)}catch(L){throw new _p(L,h)}n({action:"update",id:u,providerId:h.providerId,displayName:(A=h.displayName)!=null?A:h.providerId,whatIf:r,diff:oo(_.object,h.object)})};l.push(v(c,g))}o.delete(u)}else{let v=async(h,_)=>{var A;if(!r)try{await a.writeObject(h)}catch(L){throw new _p(L,h)}n({action:"create",id:_,providerId:_,displayName:(A=h.displayName)!=null?A:h.providerId,whatIf:r,diff:kn("",JSON.stringify(h.object,null,2))})};l.push(v(c,u))}}if(await Promise.all(l),i==="mirror"){if(!m&&!p)throw new Error("Source is empty and mode is mirror. This would cause deletion of everything in the target, and most likely indicates an error in source definition.");let c=[];o.forEach(async u=>{let g=async v=>{var h;if(!r)try{await a.deleteObject(v.providerId,v)}catch(_){throw new _p(_,v)}n({action:"delete",id:v.id,providerId:v.providerId,displayName:(h=v.displayName)!=null?h:v.providerId,whatIf:r,diff:kn(JSON.stringify(v.object,null,2),"")})};c.push(g(u))}),await Promise.all(c)}await Promise.all([(d=e.onSyncComplete)==null?void 0:d.call(e,!1),(s=a.onSyncComplete)==null?void 0:s.call(a,!0)])}var _p=class extends Error{constructor(e,a){var t;super(`Error syncing ${(t=a.displayName)!=null?t:a.providerId} (${a.providerId})
123
123
  ${e}`),this.stack=void 0,Object.setPrototypeOf(this,_p.prototype)}},Ct=cr(ur());function ye(e){let{diffMode:a="off",indent:t,prefix:i}=e!=null?e:{};return function({action:p,displayName:r,whatIf:n,diff:d}){let s="";switch(p){case"create":s=Ct.default.green("[A]");break;case"update":s=Ct.default.white("[U]");break;case"delete":s=Ct.default.yellow("[D]");break}let o="";(a==="on"||a==="update"&&p==="update")&&(o=`
124
124
  `+d.map(l=>l.added?Ct.default.green(l.value):l.removed?Ct.default.red(l.value):l.value).join("")),console.log(`${t!=null?t:""}${n?Ct.default.gray("[WHATIF]"):""}${s}${i!=null?i:""} ${r}${o}`)}}var Wo=async e=>await e(),L1=class extends Error{constructor(t,i,p,r,n,d){super(`${t}
125
- ${r}${n?" "+n:""} (${i} ${p}${d?` Request ID: ${d}`:""})`);this.errorMessage=t;this.fetchMethod=i;this.fetchUri=p;this.statusCode=r;this.statusText=n;this.requestId=d;Object.setPrototypeOf(this,L1.prototype)}};var ze=class{constructor(a){gd(this,"options");var i,p,r,n,d,s;if(!a.apiKey&&!a.bearerToken)throw new Error("You must provide an API key or a bearer token");let t=a.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={...a,fetch:t,apiHost:(i=a.apiHost)!=null?i:"https://uniform.app",apiKey:(p=a.apiKey)!=null?p:null,projectId:(r=a.projectId)!=null?r:null,bearerToken:(n=a.bearerToken)!=null?n:null,limitPolicy:(d=a.limitPolicy)!=null?d:Wo,bypassCache:(s=a.bypassCache)!=null?s:!1}}async apiClient(a,t){return this.options.limitPolicy(async()=>{var r;let i=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`};this.options.bypassCache&&(i["x-bypass-cache"]="true");let p=await this.options.fetch(a.toString(),{...t,headers:{...t==null?void 0:t.headers,...i}});if(!p.ok){let n="";try{let d=await p.text();try{let s=JSON.parse(d);s.errorMessage?n=Array.isArray(s.errorMessage)?s.errorMessage.join(", "):s.errorMessage:n=d}catch(s){n=d}}catch(d){n="General error"}throw new L1(n,(r=t==null?void 0:t.method)!=null?r:"GET",a.toString(),p.status,p.statusText,ze.getRequestId(p))}return t!=null&&t.expectNoContent?null:await p.json()})}createUrl(a,t){let i=new URL(`${this.options.apiHost}${a}`);return Object.entries(t!=null?t:{}).forEach(([p,r])=>{var n;typeof r!="undefined"&&r!==null&&i.searchParams.append(p,Array.isArray(r)?r.join(","):(n=r==null?void 0:r.toString())!=null?n:"")}),i}static getRequestId(a){let t=a.headers.get("apigw-requestid");if(t)return t}};var St,si=class extends ze{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(le(si,St),{...a,projectId:t});return await this.apiClient(i)}async upsert(a){let t=this.createUrl(le(si,St));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async remove(a){let t=this.createUrl(le(si,St));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},xp=si;St=new WeakMap,p1(xp,St,"/api/v2/aggregate");var e1=class extends xp{constructor(a){super({...a,bypassCache:!0})}};var zo={command:"get <id>",describe:"Fetch an aggregate",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Aggregate public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{let d=j(t),o=await new e1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get({aggregateId:i});o.aggregates.length===0?(console.error("Aggregate did not exist"),process.exit(1)):ce(o.aggregates[0],p,n)}};var Go={command:"list",describe:"List aggregates",aliases:["ls"],builder:e=>Ee(F(I(e))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r})=>{let n=j(t),s=await new e1({apiKey:a,apiHost:e,fetch:n,projectId:r}).get({});ce(s.aggregates,i,p)}};var ha=e=>e.id,ga=e=>`${e.name} (pid: ${e.id})`;function Ap({client:e,type:a}){async function*t(){let p=(await e.get({type:a})).aggregates;for await(let r of p)yield{id:ha(r),displayName:ga(r),providerId:r.id,object:r}}let i=[];return{objects:t(),deleteObject:async p=>{await e.remove({aggregateId:p})},writeObject:async p=>{await e.upsert({aggregate:p.object,skipInputs:!0}),i.push(p.object)},complete:async()=>{await Promise.all(i.map(p=>e.upsert({aggregate:p,skipInputs:!1})))}}}function Te(e,a){return $o(e,a)}function B1(e,a){qo(e,a)}import h7 from"p-limit";var Pe=h7(8);var Yo={command:"pull <directory>",describe:"Pulls all aggregates to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the aggregates to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new e1({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Pe}),m=Ap({client:l}),c;if(Ne(i)){let v=Te(i,!1);c=await Se({objects:(g=v.aggregates)!=null?g:[],selectIdentifier:ha,selectDisplayName:ga,onSyncComplete:async(h,_)=>{v.aggregates=_,B1(i,v)}})}else c=await De({directory:i,selectIdentifier:ha,selectDisplayName:ga,format:p});await be({source:m,target:c,mode:r,whatIf:n,log:ye({diffMode:s})})}};var Ko={command:"push <directory>",describe:"Pushes all aggregates from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the aggregates from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new e1({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Pe}),l;if(Ne(i)){let g=Te(i,!0);l=await Se({objects:(u=g.aggregates)!=null?u:[],selectIdentifier:ha,selectDisplayName:ga})}else l=await De({directory:i,selectIdentifier:ha,selectDisplayName:ga});let c=Ap({client:o});await be({source:l,target:c,mode:p,whatIf:r,log:ye({diffMode:d})}),await c.complete()}};var Qo={command:"remove <id>",aliases:["delete","rm"],describe:"Delete an aggregate",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Aggregate public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new e1({apiKey:a,apiHost:e,fetch:r,projectId:p}).remove({aggregateId:i})}};var Jo={command:"update <filename>",aliases:["put"],describe:"Insert or update an aggregate",builder:e=>F(I(e.positional("filename",{demandOption:!0,describe:"Aggregate file to put"}))),handler:async({apiHost:e,apiKey:a,proxy:t,filename:i,project:p})=>{let r=j(t),n=new e1({apiKey:a,apiHost:e,fetch:r,projectId:p}),d=V1(i);await n.upsert({aggregate:d})}};var Zo={command:"aggregate <command>",aliases:["agg","intent","audience"],describe:"Commands for Context aggregates (intents, audiences)",builder:e=>e.command(Yo).command(Ko).command(zo).command(Qo).command(Go).command(Jo).demandCommand(),handler:()=>{Qe.help()}};var Et,li,Ja=class extends ze{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(le(Ja,Et),{...a,projectId:t});return await this.apiClient(i)}async upsertCategory(a){let t=this.createUrl(le(Ja,Et));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async removeCategory(a){let t=this.createUrl(le(Ja,Et));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async upsertValue(a){let t=this.createUrl(le(Ja,li));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async removeValue(a){let t=this.createUrl(le(Ja,li));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},oi=Ja;Et=new WeakMap,li=new WeakMap,p1(oi,Et,"/api/v1/enrichments"),p1(oi,li,"/api/v1/enrichment-values");var x1=class extends oi{constructor(a){super({...a,bypassCache:!0})}};var Xo={command:"get <id>",describe:"Fetch an enrichment category and its values",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Enrichment category public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{var l,m;let d=j(t),o=(m=(l=await new x1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get())==null?void 0:l.enrichments)==null?void 0:m.filter(c=>c.id===i);o.length===0?(console.error("Enrichment did not exist"),process.exit(1)):ce(o[0],p,n)}};var el={command:"list",describe:"List enrichments",aliases:["ls"],builder:e=>Ee(F(I(e))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r})=>{let n=j(t),s=await new x1({apiKey:a,apiHost:e,fetch:n,projectId:r}).get();ce(s.enrichments,i,p)}};var va=e=>e.id,wa=e=>`${e.name} (pid: ${e.id})`;function Cp({client:e}){async function*a(){let t=(await e.get()).enrichments;for await(let i of t)yield{id:va(i),displayName:wa(i),providerId:i.id,object:i}}return{objects:a(),deleteObject:async t=>{await e.removeCategory({enrichmentId:t})},writeObject:async(t,i)=>{var n,d;await e.upsertCategory({enrichment:t.object});let p=al({categoryId:t.id,values:t.object.values}),r=al({categoryId:t.id,values:(d=(n=i==null?void 0:i.object)==null?void 0:n.values)!=null?d:[],client:e});await be({source:p,target:r,mode:"mirror",whatIf:!1,log:ye({diffMode:"off",prefix:` ${t.displayName} value`,indent:"> "})})}}}var al=({client:e,categoryId:a,values:t})=>({objects:async function*(){for(let p of t)yield{id:p.id,providerId:p.id,object:p,displayName:`${p.value} (pid: ${p.id})`}}(),deleteObject:async p=>{if(!e)throw new Error("Provider is read only");await e.removeValue({enrichmentId:a,enrichmentValueId:p})},writeObject:async p=>{if(!e)throw new Error("Provider is read only");await e.upsertValue({enrichmentId:a,enrichmentValue:p.object})}});var tl={command:"pull <directory>",describe:"Pulls all enrichments to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the enrichments to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new x1({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Pe}),m=Cp({client:l}),c;if(Ne(i)){let v=Te(i,!1);c=await Se({objects:(g=v.enrichments)!=null?g:[],selectIdentifier:va,selectDisplayName:wa,onSyncComplete:async(h,_)=>{v.enrichments=_,B1(i,v)}})}else c=await De({directory:i,selectIdentifier:va,selectDisplayName:wa,format:p});await be({source:m,target:c,mode:r,whatIf:n,log:ye({diffMode:s})})}};var il={command:"push <directory>",describe:"Pushes all enrichments from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the enrichments from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new x1({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Pe}),l;if(Ne(i)){let g=Te(i,!0);l=await Se({objects:(u=g.enrichments)!=null?u:[],selectIdentifier:va,selectDisplayName:wa})}else l=await De({directory:i,selectIdentifier:va,selectDisplayName:wa});let c=Cp({client:o});await be({source:l,target:c,mode:p,whatIf:r,log:ye({diffMode:d})})}};var pl={command:"remove <id>",aliases:["delete","rm"],describe:"Delete an enrichment category and its values",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Enrichment category public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new x1({apiKey:a,apiHost:e,fetch:r,projectId:p}).removeCategory({enrichmentId:i})}};var rl={command:"enrichment <command>",aliases:["enr"],describe:"Commands for Context enrichments",builder:e=>e.command(tl).command(il).command(Xo).command(pl).command(el).demandCommand(),handler:()=>{Qe.help()}};var jp=Za(od());import{writeFile as B7}from"fs";import{exit as jl}from"process";var Fp,ld=class extends ze{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(le(ld,Fp),{...a,projectId:t});return await this.apiClient(i)}async publish(){let{projectId:a}=this.options,t=this.createUrl("/api/v1/publish",{siteId:a});await this.apiClient(t,{method:"POST",expectNoContent:!0})}},Pp=ld;Fp=new WeakMap,p1(Pp,Fp,"/api/v2/manifest");var Pt=class extends Pp{constructor(a){super({...a,bypassCache:!0})}};var Il={command:"get [output]",aliases:["dl","download"],describe:"Download the Uniform Context manifest for a project",builder:e=>F(I(e.option("preview",{describe:"If set, fetches the unpublished preview manifest (The API key must have permission)",default:!1,type:"boolean",alias:["d"]}).option("output",{string:!0,alias:"o",default:process.env.UNIFORM_MANIFEST_PATH,describe:"Path to write manifest to. Defaults to UNIFORM_MANIFEST_PATH env if set.",demandOption:!0}))),handler:async({apiKey:e,apiHost:a,proxy:t,output:i,project:p,preview:r})=>{let n=j(t),d=new Pt({apiHost:a,projectId:p,apiKey:e,fetch:n});try{let s=await d.get({preview:r}),o=JSON.stringify(s,null,2);i?B7(i,o,l=>{l&&(console.error(`Error writing file to ${i}
125
+ ${r}${n?" "+n:""} (${i} ${p}${d?` Request ID: ${d}`:""})`);this.errorMessage=t;this.fetchMethod=i;this.fetchUri=p;this.statusCode=r;this.statusText=n;this.requestId=d;Object.setPrototypeOf(this,L1.prototype)}};var ze=class{constructor(a){gd(this,"options");var i,p,r,n,d,s,o;if(!a.apiKey&&!a.bearerToken)throw new Error("You must provide an API key or a bearer token");let t=a.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={...a,fetch:t,apiHost:(i=a.apiHost)!=null?i:"https://uniform.app",apiKey:(p=a.apiKey)!=null?p:null,projectId:(r=a.projectId)!=null?r:null,bearerToken:(n=a.bearerToken)!=null?n:null,limitPolicy:(d=a.limitPolicy)!=null?d:Wo,bypassCache:(s=a.bypassCache)!=null?s:!1,branchName:(o=a.branchName)!=null?o:null}}async apiClient(a,t){return this.options.limitPolicy(async()=>{var r;let i=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`};this.options.bypassCache&&(i["x-bypass-cache"]="true");let p=await this.options.fetch(a.toString(),{...t,headers:{...t==null?void 0:t.headers,...i}});if(!p.ok){let n="";try{let d=await p.text();try{let s=JSON.parse(d);s.errorMessage?n=Array.isArray(s.errorMessage)?s.errorMessage.join(", "):s.errorMessage:n=d}catch(s){n=d}}catch(d){n="General error"}throw new L1(n,(r=t==null?void 0:t.method)!=null?r:"GET",a.toString(),p.status,p.statusText,ze.getRequestId(p))}return t!=null&&t.expectNoContent?null:await p.json()})}createUrl(a,t){let i=new URL(`${this.options.apiHost}${a}`);return Object.entries(t!=null?t:{}).forEach(([p,r])=>{var n;typeof r!="undefined"&&r!==null&&i.searchParams.append(p,Array.isArray(r)?r.join(","):(n=r==null?void 0:r.toString())!=null?n:"")}),this.options.branchName&&i.searchParams.append("branch",this.options.branchName),i}static getRequestId(a){let t=a.headers.get("apigw-requestid");if(t)return t}};var St,si=class extends ze{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(le(si,St),{...a,projectId:t});return await this.apiClient(i)}async upsert(a){let t=this.createUrl(le(si,St));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async remove(a){let t=this.createUrl(le(si,St));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},xp=si;St=new WeakMap,p1(xp,St,"/api/v2/aggregate");var e1=class extends xp{constructor(a){super({...a,bypassCache:!0})}};var zo={command:"get <id>",describe:"Fetch an aggregate",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Aggregate public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{let d=j(t),o=await new e1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get({aggregateId:i});o.aggregates.length===0?(console.error("Aggregate did not exist"),process.exit(1)):ce(o.aggregates[0],p,n)}};var Go={command:"list",describe:"List aggregates",aliases:["ls"],builder:e=>Ee(F(I(e))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r})=>{let n=j(t),s=await new e1({apiKey:a,apiHost:e,fetch:n,projectId:r}).get({});ce(s.aggregates,i,p)}};var ha=e=>e.id,ga=e=>`${e.name} (pid: ${e.id})`;function Ap({client:e,type:a}){async function*t(){let p=(await e.get({type:a})).aggregates;for await(let r of p)yield{id:ha(r),displayName:ga(r),providerId:r.id,object:r}}let i=[];return{objects:t(),deleteObject:async p=>{await e.remove({aggregateId:p})},writeObject:async p=>{await e.upsert({aggregate:p.object,skipInputs:!0}),i.push(p.object)},complete:async()=>{await Promise.all(i.map(p=>e.upsert({aggregate:p,skipInputs:!1})))}}}function Te(e,a){return $o(e,a)}function B1(e,a){qo(e,a)}import h7 from"p-limit";var Pe=h7(8);var Yo={command:"pull <directory>",describe:"Pulls all aggregates to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the aggregates to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new e1({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Pe}),m=Ap({client:l}),c;if(Ne(i)){let v=Te(i,!1);c=await Se({objects:(g=v.aggregates)!=null?g:[],selectIdentifier:ha,selectDisplayName:ga,onSyncComplete:async(h,_)=>{v.aggregates=_,B1(i,v)}})}else c=await De({directory:i,selectIdentifier:ha,selectDisplayName:ga,format:p});await be({source:m,target:c,mode:r,whatIf:n,log:ye({diffMode:s})})}};var Ko={command:"push <directory>",describe:"Pushes all aggregates from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the aggregates from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new e1({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Pe}),l;if(Ne(i)){let g=Te(i,!0);l=await Se({objects:(u=g.aggregates)!=null?u:[],selectIdentifier:ha,selectDisplayName:ga})}else l=await De({directory:i,selectIdentifier:ha,selectDisplayName:ga});let c=Ap({client:o});await be({source:l,target:c,mode:p,whatIf:r,log:ye({diffMode:d})}),await c.complete()}};var Qo={command:"remove <id>",aliases:["delete","rm"],describe:"Delete an aggregate",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Aggregate public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new e1({apiKey:a,apiHost:e,fetch:r,projectId:p}).remove({aggregateId:i})}};var Jo={command:"update <filename>",aliases:["put"],describe:"Insert or update an aggregate",builder:e=>F(I(e.positional("filename",{demandOption:!0,describe:"Aggregate file to put"}))),handler:async({apiHost:e,apiKey:a,proxy:t,filename:i,project:p})=>{let r=j(t),n=new e1({apiKey:a,apiHost:e,fetch:r,projectId:p}),d=V1(i);await n.upsert({aggregate:d})}};var Zo={command:"aggregate <command>",aliases:["agg","intent","audience"],describe:"Commands for Context aggregates (intents, audiences)",builder:e=>e.command(Yo).command(Ko).command(zo).command(Qo).command(Go).command(Jo).demandCommand(),handler:()=>{Qe.help()}};var Et,li,Ja=class extends ze{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(le(Ja,Et),{...a,projectId:t});return await this.apiClient(i)}async upsertCategory(a){let t=this.createUrl(le(Ja,Et));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async removeCategory(a){let t=this.createUrl(le(Ja,Et));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async upsertValue(a){let t=this.createUrl(le(Ja,li));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async removeValue(a){let t=this.createUrl(le(Ja,li));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},oi=Ja;Et=new WeakMap,li=new WeakMap,p1(oi,Et,"/api/v1/enrichments"),p1(oi,li,"/api/v1/enrichment-values");var x1=class extends oi{constructor(a){super({...a,bypassCache:!0})}};var Xo={command:"get <id>",describe:"Fetch an enrichment category and its values",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Enrichment category public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{var l,m;let d=j(t),o=(m=(l=await new x1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get())==null?void 0:l.enrichments)==null?void 0:m.filter(c=>c.id===i);o.length===0?(console.error("Enrichment did not exist"),process.exit(1)):ce(o[0],p,n)}};var el={command:"list",describe:"List enrichments",aliases:["ls"],builder:e=>Ee(F(I(e))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r})=>{let n=j(t),s=await new x1({apiKey:a,apiHost:e,fetch:n,projectId:r}).get();ce(s.enrichments,i,p)}};var va=e=>e.id,wa=e=>`${e.name} (pid: ${e.id})`;function Cp({client:e}){async function*a(){let t=(await e.get()).enrichments;for await(let i of t)yield{id:va(i),displayName:wa(i),providerId:i.id,object:i}}return{objects:a(),deleteObject:async t=>{await e.removeCategory({enrichmentId:t})},writeObject:async(t,i)=>{var n,d;await e.upsertCategory({enrichment:t.object});let p=al({categoryId:t.id,values:t.object.values}),r=al({categoryId:t.id,values:(d=(n=i==null?void 0:i.object)==null?void 0:n.values)!=null?d:[],client:e});await be({source:p,target:r,mode:"mirror",whatIf:!1,log:ye({diffMode:"off",prefix:` ${t.displayName} value`,indent:"> "})})}}}var al=({client:e,categoryId:a,values:t})=>({objects:async function*(){for(let p of t)yield{id:p.id,providerId:p.id,object:p,displayName:`${p.value} (pid: ${p.id})`}}(),deleteObject:async p=>{if(!e)throw new Error("Provider is read only");await e.removeValue({enrichmentId:a,enrichmentValueId:p})},writeObject:async p=>{if(!e)throw new Error("Provider is read only");await e.upsertValue({enrichmentId:a,enrichmentValue:p.object})}});var tl={command:"pull <directory>",describe:"Pulls all enrichments to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the enrichments to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new x1({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Pe}),m=Cp({client:l}),c;if(Ne(i)){let v=Te(i,!1);c=await Se({objects:(g=v.enrichments)!=null?g:[],selectIdentifier:va,selectDisplayName:wa,onSyncComplete:async(h,_)=>{v.enrichments=_,B1(i,v)}})}else c=await De({directory:i,selectIdentifier:va,selectDisplayName:wa,format:p});await be({source:m,target:c,mode:r,whatIf:n,log:ye({diffMode:s})})}};var il={command:"push <directory>",describe:"Pushes all enrichments from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the enrichments from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new x1({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Pe}),l;if(Ne(i)){let g=Te(i,!0);l=await Se({objects:(u=g.enrichments)!=null?u:[],selectIdentifier:va,selectDisplayName:wa})}else l=await De({directory:i,selectIdentifier:va,selectDisplayName:wa});let c=Cp({client:o});await be({source:l,target:c,mode:p,whatIf:r,log:ye({diffMode:d})})}};var pl={command:"remove <id>",aliases:["delete","rm"],describe:"Delete an enrichment category and its values",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Enrichment category public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new x1({apiKey:a,apiHost:e,fetch:r,projectId:p}).removeCategory({enrichmentId:i})}};var rl={command:"enrichment <command>",aliases:["enr"],describe:"Commands for Context enrichments",builder:e=>e.command(tl).command(il).command(Xo).command(pl).command(el).demandCommand(),handler:()=>{Qe.help()}};var jp=Za(od());import{writeFile as B7}from"fs";import{exit as jl}from"process";var Fp,ld=class extends ze{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(le(ld,Fp),{...a,projectId:t});return await this.apiClient(i)}async publish(){let{projectId:a}=this.options,t=this.createUrl("/api/v1/publish",{siteId:a});await this.apiClient(t,{method:"POST",expectNoContent:!0})}},Pp=ld;Fp=new WeakMap,p1(Pp,Fp,"/api/v2/manifest");var Pt=class extends Pp{constructor(a){super({...a,bypassCache:!0})}};var Il={command:"get [output]",aliases:["dl","download"],describe:"Download the Uniform Context manifest for a project",builder:e=>F(I(e.option("preview",{describe:"If set, fetches the unpublished preview manifest (The API key must have permission)",default:!1,type:"boolean",alias:["d"]}).option("output",{string:!0,alias:"o",default:process.env.UNIFORM_MANIFEST_PATH,describe:"Path to write manifest to. Defaults to UNIFORM_MANIFEST_PATH env if set.",demandOption:!0}))),handler:async({apiKey:e,apiHost:a,proxy:t,output:i,project:p,preview:r})=>{let n=j(t),d=new Pt({apiHost:a,projectId:p,apiKey:e,fetch:n});try{let s=await d.get({preview:r}),o=JSON.stringify(s,null,2);i?B7(i,o,l=>{l&&(console.error(`Error writing file to ${i}
126
126
  `,l),jl(1)),console.log(jp.default.green(`\u2705 ${i} has been updated from ${a}`))}):console.log(o)}catch(s){let o;s instanceof L1?(s.statusCode===403&&(o=`The API key ${e} did not have permissions to fetch the manifest. Ensure ${r?"Uniform Context > Read Drafts":"Uniform Context > Manifest > Read"} permissions are granted.`),o=s.message):o=s.toString(),console.error(jp.default.red("\u26A0 Error fetching Context manifest")),console.error(jp.default.gray(` \u2757 ${o}`)),jl(1)}}};var md=Za(od());import{exit as k7}from"process";var Ml={command:"publish",describe:"Publish the Uniform Context manifest for a project",builder:e=>F(I(e)),handler:async({apiKey:e,apiHost:a,proxy:t,project:i})=>{let p=j(t);try{await new Pt({apiHost:a,projectId:i,apiKey:e,fetch:p}).publish()}catch(r){let n;r instanceof L1?(r.statusCode===403&&(n=`The API key ${e} did not have permissions to publish the manifest. Ensure Uniform Context > Manifest > Publish permissions are granted.`),n=r.message):n=r.toString(),console.error(md.default.red("\u26A0 Error publishing Context manifest")),console.error(md.default.gray(` \u2757 ${n}`)),k7(1)}}};var Vl={command:"manifest <command>",describe:"Commands for context manifests",aliases:["man"],builder:e=>e.command(Il).command(Ml).demandCommand(),handler:()=>{Qe.help()}};var Ft,ui=class extends ze{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(le(ui,Ft),{...a,projectId:t});return await this.apiClient(i)}async upsert(a){let t=this.createUrl(le(ui,Ft));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async remove(a){let t=this.createUrl(le(ui,Ft));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},Ip=ui;Ft=new WeakMap,p1(Ip,Ft,"/api/v2/quirk");var a1=class extends Ip{constructor(a){super({...a,bypassCache:!0})}};var Ll={command:"get <id>",describe:"Fetch a quirk",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Quirk public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{let d=j(t),o=await new a1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get({quirkId:i,withIntegrations:!0});o.quirks.length===0?(console.error("Quirk did not exist"),process.exit(1)):ce(o.quirks[0],p,n)}};var Bl={command:"list",describe:"List quirks",aliases:["ls"],builder:e=>Ee(F(I(e.option("withIntegrations",{alias:["i"],describe:"Whether to include meta-quirks created by integrations in the list. Defaults to false.",type:"boolean"})))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r,withIntegrations:n})=>{let d=j(t),o=await new a1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get({withIntegrations:n});ce(o.quirks,i,p)}};var ba=e=>e.id,ya=e=>`${e.name} (pid: ${e.id})`;function Mp({client:e}){async function*a(){let t=(await e.get({withIntegrations:!1})).quirks;for await(let i of t)yield{id:ba(i),displayName:ya(i),providerId:i.id,object:i}}return{objects:a(),deleteObject:async t=>{await e.remove({quirkId:t})},writeObject:async t=>{await e.upsert({quirk:t.object})}}}var kl={command:"pull <directory>",describe:"Pulls all quirks to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the quirks to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new a1({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Pe}),m=Mp({client:l}),c;if(Ne(i)){let v=Te(i,!1);c=await Se({objects:(g=v.quirks)!=null?g:[],selectIdentifier:ba,selectDisplayName:ya,onSyncComplete:async(h,_)=>{v.quirks=_,B1(i,v)}})}else c=await De({directory:i,selectIdentifier:ba,selectDisplayName:ya,format:p});await be({source:m,target:c,mode:r,whatIf:n,log:ye({diffMode:s})})}};var Ul={command:"push <directory>",describe:"Pushes all quirks from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the quirks from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new a1({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Pe}),l;if(Ne(i)){let g=Te(i,!0);l=await Se({objects:(u=g.quirks)!=null?u:[],selectIdentifier:ba,selectDisplayName:ya})}else l=await De({directory:i,selectIdentifier:ba,selectDisplayName:ya});let c=Mp({client:o});await be({source:l,target:c,mode:p,whatIf:r,log:ye({diffMode:d})})}};var Rl={command:"remove <id>",aliases:["delete","rm"],describe:"Delete a quirk",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Quirk public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new a1({apiKey:a,apiHost:e,fetch:r,projectId:p}).remove({quirkId:i})}};var $l={command:"update <filename>",aliases:["put"],describe:"Insert or update a quirk",builder:e=>F(I(e.positional("filename",{demandOption:!0,describe:"Quirk file to put"}))),handler:async({apiHost:e,apiKey:a,proxy:t,filename:i,project:p})=>{let r=j(t),n=new a1({apiKey:a,apiHost:e,fetch:r,projectId:p}),d=V1(i);await n.upsert({quirk:d})}};var ql={command:"quirk <command>",aliases:["qk"],describe:"Commands for Context quirks",builder:e=>e.command(kl).command(Ul).command(Ll).command(Rl).command(Bl).command($l).demandCommand(),handler:()=>{Qe.help()}};var jt,fi=class extends ze{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(le(fi,jt),{...a,projectId:t});return await this.apiClient(i)}async upsert(a){let t=this.createUrl(le(fi,jt));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async remove(a){let t=this.createUrl(le(fi,jt));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},Vp=fi;jt=new WeakMap,p1(Vp,jt,"/api/v2/signal");var t1=class extends Vp{constructor(a){super({...a,bypassCache:!0})}};var Hl={command:"get <id>",describe:"Fetch a signal",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Signal public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{let d=j(t),o=await new t1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get({signalId:i});o.signals.length===0?(console.error("Signal did not exist"),process.exit(1)):ce(o.signals[0],p,n)}};var Wl={command:"list",describe:"List signals",aliases:["ls"],builder:e=>Ee(F(I(e))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r})=>{let n=j(t),s=await new t1({apiKey:a,apiHost:e,fetch:n,projectId:r}).get();ce(s.signals,i,p)}};var _a=e=>e.id,xa=e=>`${e.name} (pid: ${e.id})`;function Lp({client:e}){async function*a(){let t=(await e.get()).signals;for await(let i of t)yield{id:_a(i),displayName:xa(i),providerId:i.id,object:i}}return{objects:a(),deleteObject:async t=>{await e.remove({signalId:t})},writeObject:async t=>{await e.upsert({signal:t.object})}}}var zl={command:"pull <directory>",describe:"Pulls all signals to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the signals to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new t1({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Pe}),m=Lp({client:l}),c;if(Ne(i)){let v=Te(i,!1);c=await Se({objects:(g=v.signals)!=null?g:[],selectIdentifier:_a,selectDisplayName:xa,onSyncComplete:async(h,_)=>{v.signals=_,B1(i,v)}})}else c=await De({directory:i,selectIdentifier:_a,selectDisplayName:xa,format:p});await be({source:m,target:c,mode:r,whatIf:n,log:ye({diffMode:s})})}};var Gl={command:"push <directory>",describe:"Pushes all signals from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the signals from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new t1({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Pe}),l;if(Ne(i)){let g=Te(i,!0);l=await Se({objects:(u=g.signals)!=null?u:[],selectIdentifier:_a,selectDisplayName:xa})}else l=await De({directory:i,selectIdentifier:_a,selectDisplayName:xa});let c=Lp({client:o});await be({source:l,target:c,mode:p,whatIf:r,log:ye({diffMode:d})})}};var Yl={command:"remove <id>",aliases:["delete","rm"],describe:"Delete a signal",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Signal public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new t1({apiKey:a,apiHost:e,fetch:r,projectId:p}).remove({signalId:i})}};var Kl={command:"update <filename>",aliases:["put"],describe:"Insert or update a signal",builder:e=>F(I(e.positional("filename",{demandOption:!0,describe:"Signal file to put"}))),handler:async({apiHost:e,apiKey:a,proxy:t,filename:i,project:p})=>{let r=j(t),n=new t1({apiKey:a,apiHost:e,fetch:r,projectId:p}),d=V1(i);await n.upsert({signal:d})}};var Ql={command:"signal <command>",aliases:["sig"],describe:"Commands for Context signals",builder:e=>e.command(zl).command(Gl).command(Hl).command(Yl).command(Wl).command(Kl).demandCommand(),handler:()=>{Qe.help()}};var It,hi=class extends ze{constructor(a){super(a)}async get(a){let{projectId:t}=this.options,i=this.createUrl(le(hi,It),{...a,projectId:t});return await this.apiClient(i)}async upsert(a){let t=this.createUrl(le(hi,It));await this.apiClient(t,{method:"PUT",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}async remove(a){let t=this.createUrl(le(hi,It));await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...a,projectId:this.options.projectId}),expectNoContent:!0})}},Bp=hi;It=new WeakMap,p1(Bp,It,"/api/v2/test");var i1=class extends Bp{constructor(a){super({...a,bypassCache:!0})}};var Jl={command:"get <id>",describe:"Fetch a test",builder:e=>Ee(F(I(e.positional("id",{demandOption:!0,describe:"Test public ID to fetch"})))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,format:p,project:r,filename:n})=>{let d=j(t),o=await new i1({apiKey:a,apiHost:e,fetch:d,projectId:r}).get({testId:i});o.tests.length===0?(console.error("Test did not exist"),process.exit(1)):ce(o.tests[0],p,n)}};var Zl={command:"list",describe:"List tests",aliases:["ls"],builder:e=>Ee(F(I(e))),handler:async({apiHost:e,apiKey:a,proxy:t,format:i,filename:p,project:r})=>{let n=j(t),s=await new i1({apiKey:a,apiHost:e,fetch:n,projectId:r}).get();ce(s.tests,i,p)}};var Aa=e=>e.id,Ca=e=>`${e.name} (pid: ${e.id})`;function kp({client:e}){async function*a(){let t=(await e.get()).tests;for await(let i of t)yield{id:Aa(i),displayName:Ca(i),providerId:i.id,object:i}}return{objects:a(),deleteObject:async t=>{await e.remove({testId:t})},writeObject:async t=>{await e.upsert({test:t.object})}}}var Xl={command:"pull <directory>",describe:"Pulls all tests to local files in a directory",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to save the tests to. If a filename ending in yaml or json is used, a package file will be created instead of files in the directory.",type:"string"}).option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes no files",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new files, update nothing. "createOrUpdate" = create new files, update existing, delete nothing. "mirror" = create, update, and delete to mirror state',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,format:p,mode:r,whatIf:n,project:d,diff:s})=>{var g;let o=j(t),l=new i1({apiKey:a,apiHost:e,fetch:o,projectId:d,limitPolicy:Pe}),m=kp({client:l}),c;if(Ne(i)){let v=Te(i,!1);c=await Se({objects:(g=v.tests)!=null?g:[],selectIdentifier:Aa,selectDisplayName:Ca,onSyncComplete:async(h,_)=>{v.tests=_,B1(i,v)}})}else c=await De({directory:i,selectIdentifier:Aa,selectDisplayName:Ca,format:p});await be({source:m,target:c,mode:r,whatIf:n,log:ye({diffMode:s})})}};var e6={command:"push <directory>",describe:"Pushes all tests from files in a directory or package to Uniform",builder:e=>F(I(Oe(e.positional("directory",{describe:"Directory to read the tests from. If a filename is used, a package will be read instead.",type:"string"}).option("what-if",{alias:["w"],describe:"What-if mode reports what would be done but changes nothing",default:!1,type:"boolean"}).option("mode",{alias:["m"],describe:'What kind of changes can be made. "create" = create new, update nothing. "createOrUpdate" = create new, update existing, delete nothing. "mirror" = create, update, and delete',choices:["create","createOrUpdate","mirror"],default:"mirror",type:"string"})))),handler:async({apiHost:e,apiKey:a,proxy:t,directory:i,mode:p,whatIf:r,project:n,diff:d})=>{var u;let s=j(t),o=new i1({apiKey:a,apiHost:e,fetch:s,projectId:n,limitPolicy:Pe}),l;if(Ne(i)){let g=Te(i,!0);l=await Se({objects:(u=g.tests)!=null?u:[],selectIdentifier:Aa,selectDisplayName:Ca})}else l=await De({directory:i,selectIdentifier:Aa,selectDisplayName:Ca});let c=kp({client:o});await be({source:l,target:c,mode:p,whatIf:r,log:ye({diffMode:d})})}};var a6={command:"remove <id>",aliases:["delete","rm"],describe:"Delete a test",builder:e=>F(I(e.positional("id",{demandOption:!0,describe:"Test public ID to delete"}))),handler:async({apiHost:e,apiKey:a,proxy:t,id:i,project:p})=>{let r=j(t);await new i1({apiKey:a,apiHost:e,fetch:r,projectId:p}).remove({testId:i})}};var t6={command:"update <filename>",aliases:["put"],describe:"Insert or update a test",builder:e=>F(I(e.positional("filename",{demandOption:!0,describe:"Test file to put"}))),handler:async({apiHost:e,apiKey:a,proxy:t,filename:i,project:p})=>{let r=j(t),n=new i1({apiKey:a,apiHost:e,fetch:r,projectId:p}),d=V1(i);await n.upsert({test:d})}};var i6={command:"test <command>",describe:"Commands for Context A/B tests",builder:e=>e.command(Xl).command(e6).command(Jl).command(a6).command(Zl).command(t6).demandCommand(),handler:()=>{Qe.help()}};var c_={commands:[{command:"context <command>",aliases:["ctx"],describe:"Uniform Context commands",builder:e=>e.command(Vl).command(Ql).command(rl).command(Zo).command(ql).command(i6).demandCommand(),handler:()=>{Qe.showHelp()}}]};export{Te as readContextPackage,c_ as uniformCLI,B1 as writeContextPackage};
127
127
  /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
128
128
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/context",
3
- "version": "17.5.1-alpha.130+3fac779b1",
3
+ "version": "17.5.1-alpha.131+1a06e230b",
4
4
  "description": "Uniform Context core package",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -58,8 +58,8 @@
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/js-cookie": "3.0.2",
61
- "@types/yargs": "17.0.14",
62
- "@uniformdev/cli": "^17.5.1-alpha.130+3fac779b1",
61
+ "@types/yargs": "17.0.15",
62
+ "@uniformdev/cli": "^17.5.1-alpha.131+1a06e230b",
63
63
  "benny": "3.7.1",
64
64
  "yargs": "17.6.2"
65
65
  },
@@ -76,5 +76,5 @@
76
76
  "publishConfig": {
77
77
  "access": "public"
78
78
  },
79
- "gitHead": "3fac779b1b42a1afeb05156cb51768a98573438f"
79
+ "gitHead": "1a06e230be7112298a5d5bf6d93bd66c9cbc39f6"
80
80
  }