@uniformdev/canvas
Advanced tools
Comparing version 13.0.0 to 13.0.1-alpha.70
import { UniformCLIPlugin } from '@uniformdev/cli'; | ||
import { n as ComponentDefinition, d as CompositionAPIResponse } from '../createEventBus-ada6f4ff'; | ||
import { o as ComponentDefinition, d as CompositionAPIResponse } from '../createEventBus-39df132f'; | ||
import 'pusher-js'; | ||
@@ -4,0 +4,0 @@ |
var We=Object.create;var H=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var He=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var oe=e=>H(e,"__esModule",{value:!0});var ze=(e,t)=>{oe(e);for(var o in t)H(e,o,{get:t[o],enumerable:!0})},qe=(e,t,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Je(t))!Ke.call(e,n)&&n!=="default"&&H(e,n,{get:()=>t[n],enumerable:!(o=Ge(t,n))||o.enumerable});return e},m=e=>qe(oe(H(e!=null?We(He(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);ze(exports,{readCanvasPackage:()=>j,uniformCLI:()=>Ye,writeCanvasPackage:()=>G});var Ve=m(require("yargs"));var we=m(require("yargs"));var ne=m(require("p-throttle")),ie=m(require("p-retry"));function re({throttle:e={interval:1e3,limit:10},retry:t={retries:1,factor:1.66}}){let o=e?(0,ne.default)(e):null;return function(i){let r=async()=>await i();if(o&&(r=o(r)),t){let a=r;r=()=>(0,ie.default)(a,t)}return r()}}var K=class extends Error{constructor(t,o,n,i,r){super(`${t} | ||
${i}${r?" "+r:""} (${o} ${n})`);this.errorMessage=t;this.fetchMethod=o;this.fetchUri=n;this.statusCode=i;this.statusText=r;Object.setPrototypeOf(this,K.prototype)}},d=class{constructor(t){var o,n,i,r,a,s;if(!t.apiKey&&!t.bearerToken)throw new Error("You must provide an API key or a bearer token");this.options={...t,fetch:(o=t.fetch)!=null?o:fetch,apiHost:(n=t.apiHost)!=null?n:"https://uniform.app",apiKey:(i=t.apiKey)!=null?i:null,projectId:(r=t.projectId)!=null?r:null,bearerToken:(a=t.bearerToken)!=null?a:null,limitPolicy:(s=t.limitPolicy)!=null?s:re({})}}async getCompositionList(t){let{projectId:o}=this.options,n=this.createUrl("/api/v1/canvas",{...t,projectId:o});return await this.apiClient(n)}async getCompositionBySlug(t){let{projectId:o}=this.options,n=this.createUrl("/api/v1/canvas",{...t,projectId:o});return await this.apiClient(n)}async getCompositionById(t){let{projectId:o}=this.options,n=this.createUrl("/api/v1/canvas",{...t,projectId:o});return await this.apiClient(n)}async updateComposition(t){let o=this.createUrl("/api/v1/canvas");await this.apiClient(o,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(t){let o=this.createUrl("/api/v1/canvas");await this.apiClient(o,{method:"DELETE",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async getComponentDefinitions(t){let{projectId:o}=this.options,n=this.createUrl("/api/v1/canvas-definitions",{...t,projectId:o});return await this.apiClient(n)}async updateComponentDefinition(t){let o=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(o,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(t){let o=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(o,{method:"DELETE",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(t,o){return this.options.limitPolicy(async()=>{var r;let n=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},i=await fetch(t.toString(),{...o,headers:{...o==null?void 0:o.headers,...n}});if(!i.ok){let a="";try{let s=await i.text();try{let c=JSON.parse(s);c.errorMessage?a=Array.isArray(c.errorMessage)?c.errorMessage.join(", "):c.errorMessage:a=s}catch(c){a=s}}catch(s){a="General error"}throw new K(a,(r=o==null?void 0:o.method)!=null?r:"GET",t.toString(),i.status)}return(o==null?void 0:o.expectNoContent)?null:await i.json()})}createUrl(t,o){let n=new URL(`${this.options.apiHost}${t}`);return Object.entries(o!=null?o:{}).forEach(([i,r])=>{var a;typeof r!==void 0&&r!==null&&n.searchParams.append(i,(a=r==null?void 0:r.toString())!=null?a:"")}),n}};var z=m(require("js-yaml")),ae=m(require("fs")),te=m(require("path")),ce=m(require("fs"));var se=0,ee=64;var pe=m(require("p-limit"));function f(e){var t,o;return e.option("apiKey",{describe:"Uniform API key. Defaults to CANVAS_CLI_API_KEY or UNIFORM_API_KEY env. Supports dotenv.",default:(o=(t=process.env.CANVAS_CLI_API_KEY)!=null?t:process.env.UPM_CLI_API_KEY)!=null?o:process.env.UNIFORM_API_KEY,demandOption:!0,type:"string"}).option("apiHost",{describe:"Uniform host. Defaults to UNIFORM_CLI_BASE_URL env or https://uniform.app. Supports dotenv.",default:process.env.UNIFORM_CLI_BASE_URL||"https://uniform.app",demandOption:!0,type:"string"})}function u(e){var t,o;return e.option("project",{describe:"Uniform project ID. Defaults to CANVAS_CLI_PROJECT_ID or UNIFORM_PROJECT_ID env. Supports dotenv.",default:(o=(t=process.env.CANVAS_CLI_PROJECT_ID)!=null?t:process.env.UPM_CLI_PROJECT_ID)!=null?o:process.env.UNIFORM_PROJECT_ID,demandOption:!0,type:"string",alias:["p"]})}function w(e){return e.option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("filename",{alias:["o"],describe:"Output filename. If not specified, write to stdout.",type:"string"})}function I(e){return e.option("diff",{describe:"Whether to show diffs in stdout. off = no diffs; update = on for updates; on = updates, creates, deletes",default:"off",type:"string",choices:["off","update","on"],alias:["d"]})}function D(e){let t=(0,te.extname)(e);return t===".yaml"||t===".yml"||t===".json"}function O(e,t,o){let n;if(o&&!t){let i=(0,te.extname)(o);i===".yaml"||i===".yml"?t="yaml":i===".json"&&(t="json")}else if(!t)throw new Error("Format must be specified when no filename is passed");switch(t){case"json":n=JSON.stringify(e,null,2);break;case"yaml":n=(0,z.dump)(e);break;default:throw new Error(`Unsupported format: ${t}`)}o?(0,ae.writeFileSync)(o,n,"utf8"):console.log(n)}function E(e){let t=(0,ce.readFileSync)(e,"utf8");return(0,z.load)(t,{filename:e,json:!0})}function q(e){let t={...e};return delete t.projectId,delete t.state,t}function P(e){return e.option("state",{type:"string",describe:"Composition state to fetch.",choices:["preview","published"],default:"preview"})}async function*Y(e,t){let o=t.pageSize||100,n=0,i=[];do{i=await e(n,o);for(let r of i)yield r;n+=o}while(i.length===o)}function v(e){let t=Number(e);if(!isNaN(t))return t;if(!e)return ee;if(typeof e!="string")throw new Error('state must be "published", "preview", or a number');return e==="preview"?se:ee}var T=(0,pe.default)(8);var me=m(require("isomorphic-unfetch")),le={command:"get <id>",describe:"Fetch a component definition",builder:e=>w(f(u(e.positional("id",{demandOption:!0,describe:"Component definition public ID to fetch"})))),handler:async({apiHost:e,apiKey:t,id:o,format:n,project:i,filename:r})=>{let s=await new d({apiKey:t,apiHost:e,fetch:me.default,projectId:i}).getComponentDefinitions({componentId:o,limit:1});s.componentDefinitions.length===0?(console.error("Component did not exist"),process.exit(1)):O(s.componentDefinitions[0],n,r)}};var de=m(require("isomorphic-unfetch")),fe={command:"list",describe:"List component definitions",aliases:["ls"],builder:e=>w(f(u(e.options({offset:{describe:"Number of rows to skip before fetching",type:"number",default:0},limit:{describe:"Number of rows to fetch",type:"number",default:20}})))),handler:async({apiHost:e,apiKey:t,limit:o,offset:n,format:i,filename:r,project:a})=>{let c=await new d({apiKey:t,apiHost:e,fetch:de.default,projectId:a}).getComponentDefinitions({limit:o,offset:n});O(c.componentDefinitions,i,r)}};var Ce=m(require("isomorphic-unfetch"));var V=m(require("diff")),ue=m(require("lodash.isequalwith"));async function x({source:e,target:t,compareContents:o=(s,c)=>(0,ue.default)(s.object,c.object,(p,y,C)=>C==="created"||C==="updated"?!0:void 0),mode:n,allowEmptySource:i=!1,whatIf:r=!1,log:a=()=>{}}){var y,C;let s=new Map;for await(let g of t.objects)s.set(g.id,g);let c=[],p=!1;for await(let g of e.objects){p=!0;let h=g.id,S=s.get(h);if(S){if(!o(g,S)&&(n==="createOrUpdate"||n==="mirror")){let b=async(A,J)=>{var $;r||await t.writeObject(A),a({action:"update",id:h,providerId:A.providerId,displayName:($=A.displayName)!=null?$:A.providerId,whatIf:r,diff:(0,V.diffJson)(J.object,A.object)})};c.push(b(g,S))}s.delete(h)}else{let b=async(A,J)=>{var $;r||await t.writeObject(A),a({action:"create",id:J,providerId:J,displayName:($=A.displayName)!=null?$:A.providerId,whatIf:r,diff:(0,V.diffLines)("",JSON.stringify(A.object,null,2))})};c.push(b(g,h))}}if(await Promise.all(c),n==="mirror"){if(!p&&!i)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 g=[];s.forEach(async h=>{let S=async b=>{var A;r||await t.deleteObject(b.providerId),a({action:"delete",id:b.id,providerId:b.providerId,displayName:(A=b.displayName)!=null?A:b.providerId,whatIf:r,diff:(0,V.diffLines)(JSON.stringify(b.object,null,2),"")})};g.push(S(h))}),await Promise.all(g)}await Promise.all([(y=e.onSyncComplete)==null?void 0:y.call(e,!1),(C=t.onSyncComplete)==null?void 0:C.call(t,!0)])}var ge=m(require("chalk")),B=m(require("fs")),Z=m(require("fs/promises")),W=m(require("path"));async function M({directory:e,format:t="yaml",selectIdentifier:o,selectDisplayName:n=o}){(0,B.existsSync)(e)||(0,B.mkdirSync)(e,{recursive:!0});let r=await(0,Z.readdir)(e,"utf-8"),a=new Set(r.filter(p=>{let y=(0,W.extname)(p);return y===".json"||y===".yaml"||y===".yml"})),s=p=>(0,W.join)(e,`${p}.${t}`);async function*c(){for(let p of a){let y=(0,W.join)(e,p);try{let C=await E(y);yield{id:o(C),displayName:n(C),providerId:y,object:C}}catch(C){throw console.error(ge.default.red(`Failed to read ${y}, data is likely invalid. | ||
${i}${r?" "+r:""} (${o} ${n})`);this.errorMessage=t;this.fetchMethod=o;this.fetchUri=n;this.statusCode=i;this.statusText=r;Object.setPrototypeOf(this,K.prototype)}},d=class{constructor(t){var o,n,i,r,a,s;if(!t.apiKey&&!t.bearerToken)throw new Error("You must provide an API key or a bearer token");this.options={...t,fetch:(o=t.fetch)!=null?o:fetch,apiHost:(n=t.apiHost)!=null?n:"https://uniform.app",apiKey:(i=t.apiKey)!=null?i:null,projectId:(r=t.projectId)!=null?r:null,bearerToken:(a=t.bearerToken)!=null?a:null,limitPolicy:(s=t.limitPolicy)!=null?s:re({})}}async getCompositionList(t){let{projectId:o}=this.options,n=this.createUrl("/api/v1/canvas",{...t,projectId:o});return await this.apiClient(n)}async getCompositionBySlug(t){let{projectId:o}=this.options,n=this.createUrl("/api/v1/canvas",{...t,projectId:o});return await this.apiClient(n)}async getCompositionById(t){let{projectId:o}=this.options,n=this.createUrl("/api/v1/canvas",{...t,projectId:o});return await this.apiClient(n)}async updateComposition(t){let o=this.createUrl("/api/v1/canvas");await this.apiClient(o,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(t){let o=this.createUrl("/api/v1/canvas");await this.apiClient(o,{method:"DELETE",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async getComponentDefinitions(t){let{projectId:o}=this.options,n=this.createUrl("/api/v1/canvas-definitions",{...t,projectId:o});return await this.apiClient(n)}async updateComponentDefinition(t){let o=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(o,{method:"PUT",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(t){let o=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(o,{method:"DELETE",body:JSON.stringify({...t,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(t,o){return this.options.limitPolicy(async()=>{var r;let n=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},i=await this.options.fetch(t.toString(),{...o,headers:{...o==null?void 0:o.headers,...n}});if(!i.ok){let a="";try{let s=await i.text();try{let c=JSON.parse(s);c.errorMessage?a=Array.isArray(c.errorMessage)?c.errorMessage.join(", "):c.errorMessage:a=s}catch(c){a=s}}catch(s){a="General error"}throw new K(a,(r=o==null?void 0:o.method)!=null?r:"GET",t.toString(),i.status)}return(o==null?void 0:o.expectNoContent)?null:await i.json()})}createUrl(t,o){let n=new URL(`${this.options.apiHost}${t}`);return Object.entries(o!=null?o:{}).forEach(([i,r])=>{var a;typeof r!==void 0&&r!==null&&n.searchParams.append(i,(a=r==null?void 0:r.toString())!=null?a:"")}),n}};var z=m(require("js-yaml")),ae=m(require("fs")),te=m(require("path")),ce=m(require("fs"));var se=0,ee=64;var pe=m(require("p-limit"));function f(e){var t,o;return e.option("apiKey",{describe:"Uniform API key. Defaults to CANVAS_CLI_API_KEY or UNIFORM_API_KEY env. Supports dotenv.",default:(o=(t=process.env.CANVAS_CLI_API_KEY)!=null?t:process.env.UPM_CLI_API_KEY)!=null?o:process.env.UNIFORM_API_KEY,demandOption:!0,type:"string"}).option("apiHost",{describe:"Uniform host. Defaults to UNIFORM_CLI_BASE_URL env or https://uniform.app. Supports dotenv.",default:process.env.UNIFORM_CLI_BASE_URL||"https://uniform.app",demandOption:!0,type:"string"})}function u(e){var t,o;return e.option("project",{describe:"Uniform project ID. Defaults to CANVAS_CLI_PROJECT_ID or UNIFORM_PROJECT_ID env. Supports dotenv.",default:(o=(t=process.env.CANVAS_CLI_PROJECT_ID)!=null?t:process.env.UPM_CLI_PROJECT_ID)!=null?o:process.env.UNIFORM_PROJECT_ID,demandOption:!0,type:"string",alias:["p"]})}function w(e){return e.option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("filename",{alias:["o"],describe:"Output filename. If not specified, write to stdout.",type:"string"})}function I(e){return e.option("diff",{describe:"Whether to show diffs in stdout. off = no diffs; update = on for updates; on = updates, creates, deletes",default:"off",type:"string",choices:["off","update","on"],alias:["d"]})}function D(e){let t=(0,te.extname)(e);return t===".yaml"||t===".yml"||t===".json"}function O(e,t,o){let n;if(o&&!t){let i=(0,te.extname)(o);i===".yaml"||i===".yml"?t="yaml":i===".json"&&(t="json")}else if(!t)throw new Error("Format must be specified when no filename is passed");switch(t){case"json":n=JSON.stringify(e,null,2);break;case"yaml":n=(0,z.dump)(e);break;default:throw new Error(`Unsupported format: ${t}`)}o?(0,ae.writeFileSync)(o,n,"utf8"):console.log(n)}function E(e){let t=(0,ce.readFileSync)(e,"utf8");return(0,z.load)(t,{filename:e,json:!0})}function q(e){let t={...e};return delete t.projectId,delete t.state,t}function P(e){return e.option("state",{type:"string",describe:"Composition state to fetch.",choices:["preview","published"],default:"preview"})}async function*Y(e,t){let o=t.pageSize||100,n=0,i=[];do{i=await e(n,o);for(let r of i)yield r;n+=o}while(i.length===o)}function v(e){let t=Number(e);if(!isNaN(t))return t;if(!e)return ee;if(typeof e!="string")throw new Error('state must be "published", "preview", or a number');return e==="preview"?se:ee}var T=(0,pe.default)(8);var me=m(require("isomorphic-unfetch")),le={command:"get <id>",describe:"Fetch a component definition",builder:e=>w(f(u(e.positional("id",{demandOption:!0,describe:"Component definition public ID to fetch"})))),handler:async({apiHost:e,apiKey:t,id:o,format:n,project:i,filename:r})=>{let s=await new d({apiKey:t,apiHost:e,fetch:me.default,projectId:i}).getComponentDefinitions({componentId:o,limit:1});s.componentDefinitions.length===0?(console.error("Component did not exist"),process.exit(1)):O(s.componentDefinitions[0],n,r)}};var de=m(require("isomorphic-unfetch")),fe={command:"list",describe:"List component definitions",aliases:["ls"],builder:e=>w(f(u(e.options({offset:{describe:"Number of rows to skip before fetching",type:"number",default:0},limit:{describe:"Number of rows to fetch",type:"number",default:20}})))),handler:async({apiHost:e,apiKey:t,limit:o,offset:n,format:i,filename:r,project:a})=>{let c=await new d({apiKey:t,apiHost:e,fetch:de.default,projectId:a}).getComponentDefinitions({limit:o,offset:n});O(c.componentDefinitions,i,r)}};var Ce=m(require("isomorphic-unfetch"));var V=m(require("diff")),ue=m(require("lodash.isequalwith"));async function x({source:e,target:t,compareContents:o=(s,c)=>(0,ue.default)(s.object,c.object,(p,y,C)=>C==="created"||C==="updated"?!0:void 0),mode:n,allowEmptySource:i=!1,whatIf:r=!1,log:a=()=>{}}){var y,C;let s=new Map;for await(let g of t.objects)s.set(g.id,g);let c=[],p=!1;for await(let g of e.objects){p=!0;let h=g.id,S=s.get(h);if(S){if(!o(g,S)&&(n==="createOrUpdate"||n==="mirror")){let b=async(A,J)=>{var $;r||await t.writeObject(A),a({action:"update",id:h,providerId:A.providerId,displayName:($=A.displayName)!=null?$:A.providerId,whatIf:r,diff:(0,V.diffJson)(J.object,A.object)})};c.push(b(g,S))}s.delete(h)}else{let b=async(A,J)=>{var $;r||await t.writeObject(A),a({action:"create",id:J,providerId:J,displayName:($=A.displayName)!=null?$:A.providerId,whatIf:r,diff:(0,V.diffLines)("",JSON.stringify(A.object,null,2))})};c.push(b(g,h))}}if(await Promise.all(c),n==="mirror"){if(!p&&!i)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 g=[];s.forEach(async h=>{let S=async b=>{var A;r||await t.deleteObject(b.providerId),a({action:"delete",id:b.id,providerId:b.providerId,displayName:(A=b.displayName)!=null?A:b.providerId,whatIf:r,diff:(0,V.diffLines)(JSON.stringify(b.object,null,2),"")})};g.push(S(h))}),await Promise.all(g)}await Promise.all([(y=e.onSyncComplete)==null?void 0:y.call(e,!1),(C=t.onSyncComplete)==null?void 0:C.call(t,!0)])}var ge=m(require("chalk")),B=m(require("fs")),Z=m(require("fs/promises")),W=m(require("path"));async function M({directory:e,format:t="yaml",selectIdentifier:o,selectDisplayName:n=o}){(0,B.existsSync)(e)||(0,B.mkdirSync)(e,{recursive:!0});let r=await(0,Z.readdir)(e,"utf-8"),a=new Set(r.filter(p=>{let y=(0,W.extname)(p);return y===".json"||y===".yaml"||y===".yml"})),s=p=>(0,W.join)(e,`${p}.${t}`);async function*c(){for(let p of a){let y=(0,W.join)(e,p);try{let C=await E(y);yield{id:o(C),displayName:n(C),providerId:y,object:C}}catch(C){throw console.error(ge.default.red(`Failed to read ${y}, data is likely invalid. | ||
${C==null?void 0:C.message}`)),C}}}return{objects:c(),deleteObject:async p=>{await(0,Z.unlink)(p)},writeObject:async p=>{O(p.object,t,s(p.id))}}}var R=e=>e.id,L=e=>`${e.name} (pid: ${e.id})`;function Q({client:e}){async function*t(){let o=Y(async(n,i)=>(await e.getComponentDefinitions({limit:i,offset:n})).componentDefinitions,{pageSize:100});for await(let n of o)yield{id:R(n),displayName:L(n),providerId:n.id,object:n}}return{objects:t(),deleteObject:async o=>{await e.removeComponentDefinition({componentId:o})},writeObject:async o=>{await e.updateComponentDefinition({componentDefinition:o.object})}}}var F=m(require("chalk"));function k({diffMode:e}){return function({action:o,displayName:n,whatIf:i,diff:r}){let a="";switch(o){case"create":a=F.default.green("[A]");break;case"update":a=F.default.white("[U]");break;case"delete":a=F.default.yellow("[D]");break}let s="";(e==="on"||e==="update"&&o==="update")&&(s=` | ||
`+r.map(c=>c.added?F.default.green(c.value):c.removed?F.default.red(c.value):c.value).join("")),console.log(`${i?F.default.gray("[WHATIF]"):""}${a} ${n}${s}`)}}var ye=m(require("fs"));function j(e,t){if(!t&&!ye.default.existsSync(e))return{};let o=E(e);if(typeof o!="object")throw new Error(`Package ${e} does not appear valid.`);return o}function G(e,t){O(t,void 0,e)}async function _({objects:e,selectIdentifier:t,selectDisplayName:o=t,onSyncComplete:n}){let i=e.reduce((s,c)=>{let p=t(c);if(s[p])throw new Error(`Identifier ${p} was not unique.`);return s[p]={id:p,object:c,providerId:p,displayName:o(c)},s},{});async function*r(){for(let s of Object.values(i))yield s}function a(){return Object.entries(i).sort((s,c)=>s[0].localeCompare(c[0])).map(s=>s[1].object)}return{objects:r(),deleteObject:async s=>{delete i[s]},writeObject:async s=>{let c=t(s.object);i[c]=s},extractCurrent:a,onSyncComplete:n?s=>n(s,a()):void 0}}var he={command:"pull <directory>",describe:"Pulls all component definitions to local files in a directory",builder:e=>f(u(I(e.positional("directory",{describe:"Directory to save the component definitions 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:t,directory:o,format:n,mode:i,whatIf:r,project:a,diff:s})=>{var g;let c=new d({apiKey:t,apiHost:e,fetch:Ce.default,projectId:a,limitPolicy:T}),p=Q({client:c}),y;if(D(o)){let h=j(o,!1);y=await _({objects:(g=h.components)!=null?g:[],selectIdentifier:R,selectDisplayName:L,onSyncComplete:async(S,b)=>{h.components=b,G(o,h)}})}else y=await M({directory:o,selectIdentifier:R,selectDisplayName:L,format:n});await x({source:p,target:y,mode:i,whatIf:r,log:k({diffMode:s})})}};var Ae=m(require("isomorphic-unfetch"));var be={command:"push <directory>",describe:"Pushes all component definitions from files in a directory to Uniform Optimize",builder:e=>f(u(I(e.positional("directory",{describe:"Directory to read the component definitions 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:t,directory:o,mode:n,whatIf:i,project:r,diff:a})=>{var C;let s=new d({apiKey:t,apiHost:e,fetch:Ae.default,projectId:r,limitPolicy:T}),c;if(D(o)){let g=j(o,!0);c=await _({objects:(C=g.components)!=null?C:[],selectIdentifier:R,selectDisplayName:L})}else c=await M({directory:o,selectIdentifier:R,selectDisplayName:L});let y=Q({client:s});await x({source:c,target:y,mode:n,whatIf:i,log:k({diffMode:a})})}};var Se=m(require("isomorphic-unfetch")),Oe={command:"remove <id>",aliases:["delete","rm"],describe:"Delete a component definition",builder:e=>f(u(e.positional("id",{demandOption:!0,describe:"Component definition public ID to delete"}))),handler:async({apiHost:e,apiKey:t,id:o,project:n})=>{await new d({apiKey:t,apiHost:e,fetch:Se.default,projectId:n}).removeComponentDefinition({componentId:o})}};var Pe=m(require("isomorphic-unfetch")),je={command:"update <filename>",aliases:["put"],describe:"Insert or update a component definition",builder:e=>f(u(e.positional("filename",{demandOption:!0,describe:"Component definition file to put"}))),handler:async({apiHost:e,apiKey:t,filename:o,project:n})=>{let i=new d({apiKey:t,apiHost:e,fetch:Pe.default,projectId:n}),r=E(o);await i.updateComponentDefinition({componentDefinition:r})}};var Ie={command:"component <command>",aliases:["def"],describe:"Commands for Canvas component definitions",builder:e=>e.command(he).command(be).command(le).command(Oe).command(fe).command(je).demandCommand(),handler:()=>we.default.help()};var Fe=m(require("yargs"));var De=m(require("isomorphic-unfetch")),Ee={command:"get <id>",describe:"Fetch a composition",builder:e=>w(f(u(P(e.positional("id",{demandOption:!0,describe:"Composition public ID to fetch"}).option({resolvePatterns:{type:"boolean",default:!1,describe:"Resolve pattern references in the composition"}}))))),handler:async({apiHost:e,apiKey:t,id:o,format:n,filename:i,state:r,project:a,resolvePatterns:s})=>{let c=new d({apiKey:t,apiHost:e,fetch:De.default,projectId:a}),p=q(await c.getCompositionById({compositionId:o,state:v(r),skipPatternResolution:!s}));O(p,n,i)}};var ve=m(require("isomorphic-unfetch")),Te={command:"list",describe:"List compositions",aliases:["ls"],builder:e=>w(f(u(P(e.options({offset:{describe:"Number of rows to skip before fetching",type:"number",default:0},limit:{describe:"Number of rows to fetch",type:"number",default:20},resolvePatterns:{type:"boolean",default:!1,describe:"Resolve pattern references in the composition"}}))))),handler:async({apiHost:e,apiKey:t,limit:o,offset:n,format:i,filename:r,project:a,state:s,resolvePatterns:c})=>{let y=await new d({apiKey:t,apiHost:e,fetch:ve.default,projectId:a}).getCompositionList({limit:o,offset:n,state:v(s),skipPatternResolution:!c});O(y.compositions,i,r)}};var xe=m(require("isomorphic-unfetch"));var N=e=>e.composition._id,U=e=>{var t,o;return`${(o=(t=e.composition._name)!=null?t:e.composition._slug)!=null?o:e.composition._id} (pid: ${e.composition._id})`};function X({client:e,state:t}){let o=v(t);async function*n(){let i=Y(async(r,a)=>(await e.getCompositionList({limit:a,offset:r,state:o,skipPatternResolution:!0})).compositions,{pageSize:100});for await(let r of i)yield{id:N(r),displayName:U(r),providerId:r.composition._id,object:q(r)}}return{objects:n(),deleteObject:async i=>{await e.removeComposition({compositionId:i})},writeObject:async i=>{await e.updateComposition({...i.object,state:o})}}}var Me={command:"pull <directory>",describe:"Pulls all compositions to local files in a directory",builder:e=>f(u(P(I(e.positional("directory",{describe:"Directory to save the component definitions 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:t,directory:o,format:n,mode:i,whatIf:r,state:a,project:s,diff:c})=>{var h;let p=new d({apiKey:t,apiHost:e,fetch:xe.default,projectId:s,limitPolicy:T}),y=X({client:p,state:a}),C=D(o),g;if(C){let S=j(o,!1);g=await _({objects:(h=S==null?void 0:S.compositions)!=null?h:[],selectIdentifier:N,selectDisplayName:U,onSyncComplete:async(b,A)=>{S.compositions=A,G(o,S)}})}else g=await M({directory:o,selectIdentifier:N,selectDisplayName:U,format:n});await x({source:y,target:g,mode:i,whatIf:r,log:k({diffMode:c})})}};var Re=m(require("isomorphic-unfetch"));var Le={command:"push <directory>",describe:"Pushes all compositions from files in a directory to Uniform Optimize",builder:e=>f(u(P(I(e.positional("directory",{describe:"Directory to read the component definitions 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:t,directory:o,mode:n,whatIf:i,state:r,project:a,diff:s})=>{var g;let c=new d({apiKey:t,apiHost:e,fetch:Re.default,projectId:a,limitPolicy:T}),p;if(D(o)){let h=j(o,!0);p=await _({objects:(g=h.compositions)!=null?g:[],selectIdentifier:N,selectDisplayName:U})}else p=await M({directory:o,selectIdentifier:N,selectDisplayName:U});let C=X({client:c,state:r});await x({source:p,target:C,mode:n,whatIf:i,log:k({diffMode:s})})}};var ke=m(require("isomorphic-unfetch")),_e={command:"remove <id>",aliases:["delete","rm"],describe:"Delete a composition",builder:e=>f(u(e.positional("id",{demandOption:!0,describe:"Composition public ID to delete"}))),handler:async({apiHost:e,apiKey:t,id:o,project:n})=>{await new d({apiKey:t,apiHost:e,fetch:ke.default,projectId:n}).removeComposition({compositionId:o})}};var Ne=m(require("isomorphic-unfetch")),Ue={command:"update <filename>",aliases:["put"],describe:"Insert or update a composition",builder:e=>f(u(P(e.positional("filename",{demandOption:!0,describe:"Composition file to put"})))),handler:async({apiHost:e,apiKey:t,filename:o,project:n,state:i})=>{let r=new d({apiKey:t,apiHost:e,fetch:Ne.default,projectId:n}),a=E(o);await r.updateComposition({...a,state:v(i)})}};var $e={command:"composition <command>",describe:"Commands for Canvas compositions",aliases:["comp"],builder:e=>e.command(Me).command(Le).command(Ee).command(_e).command(Te).command(Ue).demandCommand(),handler:()=>Fe.default.help()};var Ye={commands:[{command:"canvas <command>",aliases:["cv","pm","presentation"],describe:"Uniform Canvas commands",builder:e=>e.command($e).command(Ie).demandCommand(),handler:()=>{Ve.default.showHelp()}}]};0&&(module.exports={readCanvasPackage,uniformCLI,writeCanvasPackage}); |
@@ -1,3 +0,3 @@ | ||
import { C as ComponentInstance, a as ComponentParameter, b as CompositionAPIOptions, c as CompositionListAPIResponse, d as CompositionAPIResponse, e as CompositionAPIPutRequest, f as CompositionAPIDeleteRequest, g as ComponentDefinitionListAPIOptions, h as ComponentDefinitionAPIResponse, i as ComponentDefinitionAPIPutRequest, j as ComponentDefinitionAPIDeleteRequest, P as PreviewEventBus } from './createEventBus-ada6f4ff'; | ||
export { q as ChannelSubscription, n as ComponentDefinition, j as ComponentDefinitionAPIDeleteRequest, i as ComponentDefinitionAPIPutRequest, h as ComponentDefinitionAPIResponse, g as ComponentDefinitionListAPIOptions, k as ComponentDefinitionParameter, m as ComponentDefinitionSlot, l as ComponentDefinitionVariant, C as ComponentInstance, a as ComponentParameter, f as CompositionAPIDeleteRequest, b as CompositionAPIOptions, e as CompositionAPIPutRequest, d as CompositionAPIResponse, p as CompositionFetchState, c as CompositionListAPIResponse, o as CreatingComponentDefinition, P as PreviewEventBus, R as RootComponentInstance, r as createEventBus } from './createEventBus-ada6f4ff'; | ||
import { C as ComponentInstance, a as ComponentParameter, b as CompositionAPIOptions, c as CompositionListAPIResponse, d as CompositionAPIResponse, e as CompositionAPIPutRequest, f as CompositionAPIDeleteRequest, g as ComponentDefinitionListAPIOptions, h as ComponentDefinitionAPIResponse, i as ComponentDefinitionAPIPutRequest, j as ComponentDefinitionAPIDeleteRequest, P as PreviewEventBus } from './createEventBus-39df132f'; | ||
export { r as ChannelSubscription, o as ComponentDefinition, j as ComponentDefinitionAPIDeleteRequest, i as ComponentDefinitionAPIPutRequest, h as ComponentDefinitionAPIResponse, g as ComponentDefinitionListAPIOptions, k as ComponentDefinitionParameter, n as ComponentDefinitionSlot, m as ComponentDefinitionSlugSettings, l as ComponentDefinitionVariant, C as ComponentInstance, a as ComponentParameter, f as CompositionAPIDeleteRequest, b as CompositionAPIOptions, e as CompositionAPIPutRequest, d as CompositionAPIResponse, q as CompositionFetchState, c as CompositionListAPIResponse, p as CreatingComponentDefinition, P as PreviewEventBus, R as RootComponentInstance, s as createEventBus } from './createEventBus-39df132f'; | ||
import { Options } from 'p-throttle'; | ||
@@ -4,0 +4,0 @@ import { Options as Options$1 } from 'p-retry'; |
@@ -1,4 +0,4 @@ | ||
import{a as L,b as l,c as k,d as M,e as j,f as F,g as P,h as v,i as g,j as $,k as N,l as A,m as U,n as z}from"./chunk-Y7BBT5AF.mjs";function u(o,e){let n=[{ancestorsAndSelf:[{component:o,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let t=n.pop();if(!t)continue;let r=t.ancestorsAndSelf[0];e(r.component,t.ancestorsAndSelf,{replaceComponent:i=>{Object.assign(r.component,i),["parameters","variant","slots","data","_pattern","_patternError"].forEach(s=>{i[s]||delete r.component[s]})},removeComponent:()=>{let{parentSlot:i,parentSlotIndex:c}=t.ancestorsAndSelf[0],s=t.ancestorsAndSelf[1];if(i&&typeof c!="undefined")s.component.slots[i].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:i=>{let c=Array.isArray(i)?i:[i],{parentSlot:s,parentSlotIndex:p}=t.ancestorsAndSelf[0],m=t.ancestorsAndSelf[1];if(s&&typeof p!="undefined")m.component.slots[s].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let a=r.component.slots;if(a){let i=Object.keys(a);for(let c=i.length-1;c>=0;c--){let s=i[c],p=a[s];for(let m=p.length-1;m>=0;m--)n.push({ancestorsAndSelf:[{component:p[m],parentSlot:s,parentSlotIndex:m},...t.ancestorsAndSelf]})}}}while(n.length>0)}function f(o){let e=[];for(let n=o.length-1;n>=0;n--){let{parentSlot:t,parentSlotIndex:r}=o[n];t&&r!==void 0&&e.push(`${t}[${r}]`)}return`.${e.join(".")}`}var b=class{constructor(e,n){this.groups=e.reduce((t,r)=>{var i;let a=n(r.args);return t[a]=(i=t[a])!=null?i:[],t[a].push(r),t},{})}resolveKey(e,n){this.groups[e].forEach(t=>t.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(t=>{t.isCompleted||t.resolve(e)})})}};var y=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({name:r,enhancer:this._resolveParameterEnhancer(n)})),this}parameterType(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({type:r,enhancer:this._resolveParameterEnhancer(n)})),this}data(e,n){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof n=="function"?{enhanceOne:n}:n),this}resolveParameterEnhancer(e,n){var t;return(t=this._paramMatches.find(r=>r.name&&r.name===e||r.type&&r.type===n.type||!r.type&&!r.name))==null?void 0:t.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},_=class{constructor(){this._componentIndex={};this._rootBuilder=new y}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,n){return this._rootBuilder.parameterName(e,n),this}parameterType(e,n){return this._rootBuilder.parameterType(e,n),this}data(e,n){return this._rootBuilder.data(e,n),this}component(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>{this._componentIndex[r]=this._componentIndex[r]||new y,n(this._componentIndex[r])}),this}resolveParameterEnhancer(e,n,t){let r=this._componentIndex[e.type];if(r){let a=r.resolveParameterEnhancer(n,t);if(a)return a}return this._rootBuilder.resolveParameterEnhancer(n,t)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),t=this._componentIndex[e.type];if(t){n=new Map(n);for(let[r,a]of t.resolveComponentEnhancers())n.set(r,a)}return n}};var w=class{constructor(e,n,t){this._resolve=e;this._reject=n;this.args=t;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function Q({handleBatch:o,shouldQueue:e,limitPolicy:n}){let t=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((c,s)=>{t.push(new w(c,s,i))})},completeAll:async()=>{if(t.length>0){try{await o(t)}catch(c){t.forEach(s=>s.reject(c))}if(t.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let i=t.length;return t=[],i},limitPolicy:n}}async function Z({composition:o,enhancers:e,context:n,onErrors:t=r=>{throw new Error(r.map(a=>`${a.message} | ||
import{a as M,b as u,c as j,d as F,e as $,f as N,g,h as A,i as w,j as U,k as z,l as T,m as V,n as W}from"./chunk-7QAQ7JMT.mjs";function f(o,e){let n=[{ancestorsAndSelf:[{component:o,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let t=n.pop();if(!t)continue;let r=t.ancestorsAndSelf[0];e(r.component,t.ancestorsAndSelf,{replaceComponent:i=>{Object.assign(r.component,i),["parameters","variant","slots","data","_pattern","_patternError"].forEach(s=>{i[s]||delete r.component[s]})},removeComponent:()=>{let{parentSlot:i,parentSlotIndex:c}=t.ancestorsAndSelf[0],s=t.ancestorsAndSelf[1];if(i&&typeof c!="undefined")s.component.slots[i].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:i=>{let c=Array.isArray(i)?i:[i],{parentSlot:s,parentSlotIndex:p}=t.ancestorsAndSelf[0],m=t.ancestorsAndSelf[1];if(s&&typeof p!="undefined")m.component.slots[s].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let a=r.component.slots;if(a){let i=Object.keys(a);for(let c=i.length-1;c>=0;c--){let s=i[c],p=a[s];for(let m=p.length-1;m>=0;m--)n.push({ancestorsAndSelf:[{component:p[m],parentSlot:s,parentSlotIndex:m},...t.ancestorsAndSelf]})}}}while(n.length>0)}function C(o){let e=[];for(let n=o.length-1;n>=0;n--){let{parentSlot:t,parentSlotIndex:r}=o[n];t&&r!==void 0&&e.push(`${t}[${r}]`)}return`.${e.join(".")}`}var I=class{constructor(e,n){this.groups=e.reduce((t,r)=>{var i;let a=n(r.args);return t[a]=(i=t[a])!=null?i:[],t[a].push(r),t},{})}resolveKey(e,n){this.groups[e].forEach(t=>t.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(t=>{t.isCompleted||t.resolve(e)})})}};var E=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({name:r,enhancer:this._resolveParameterEnhancer(n)})),this}parameterType(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>this._paramMatches.push({type:r,enhancer:this._resolveParameterEnhancer(n)})),this}data(e,n){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof n=="function"?{enhanceOne:n}:n),this}resolveParameterEnhancer(e,n){var t;return(t=this._paramMatches.find(r=>r.name&&r.name===e||r.type&&r.type===n.type||!r.type&&!r.name))==null?void 0:t.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},R=class{constructor(){this._componentIndex={};this._rootBuilder=new E}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,n){return this._rootBuilder.parameterName(e,n),this}parameterType(e,n){return this._rootBuilder.parameterType(e,n),this}data(e,n){return this._rootBuilder.data(e,n),this}component(e,n){return(Array.isArray(e)?e:[e]).forEach(r=>{this._componentIndex[r]=this._componentIndex[r]||new E,n(this._componentIndex[r])}),this}resolveParameterEnhancer(e,n,t){let r=this._componentIndex[e.type];if(r){let a=r.resolveParameterEnhancer(n,t);if(a)return a}return this._rootBuilder.resolveParameterEnhancer(n,t)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),t=this._componentIndex[e.type];if(t){n=new Map(n);for(let[r,a]of t.resolveComponentEnhancers())n.set(r,a)}return n}};var x=class{constructor(e,n,t){this._resolve=e;this._reject=n;this.args=t;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function D({handleBatch:o,shouldQueue:e,limitPolicy:n}){let t=[];return{enhanceOne:async i=>{if(!e||e(i))return new Promise((c,s)=>{t.push(new x(c,s,i))})},completeAll:async()=>{if(t.length>0){try{await o(t)}catch(c){t.forEach(s=>s.reject(c))}if(t.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let i=t.length;return t=[],i},limitPolicy:n}}async function J({composition:o,enhancers:e,context:n,onErrors:t=r=>{throw new Error(r.map(a=>`${a.message} | ||
${typeof a.error=="object"&&"stack"in a.error?a.error.stack:a.error}`).join(` | ||
`))}}){let r=[],a=new Set,i=new Set;u(o,(s,p)=>{var h;Object.entries((h=s.parameters)!=null?h:{}).forEach(([C,E])=>{let d=e.resolveParameterEnhancer(s,C,E);d&&(i.add(d),r.push(R(s,p,C,E,d,n)))});let m=e.resolveComponentEnhancers(s);r.push(I(s,p,m,n)),a.add(m)}),r.push(...Array.from(a).flatMap(s=>Array.from(s).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:l)(()=>p.completeAll())}catch(h){return{error:h,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),r.push(...Array.from(i).map(async s=>{var p;try{s.completeAll&&await((p=s.limitPolicy)!=null?p:l)(()=>s.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(r)).flatMap(s=>Array.isArray(s)?s:[s]).filter(s=>s);c.length&&t(c)}async function I(o,e,n,t){return n.size&&(o.data={}),await Promise.all(Array.from(n).map(async([r,a])=>{var i;try{let s=await(a.completeAll?l:(i=a.limitPolicy)!=null?i:l)(async()=>a.enhanceOne({component:o,context:t}));s!=null&&(o.data[r]=s)}catch(c){let s=`Component ${f(e)} (type: ${o.type}): data.${r} enhancer threw exception. Data key will not be present.`;return delete o.data[r],{message:s,error:c}}}))}async function R(o,e,n,t,r,a){var i;try{let s=await(r.completeAll?l:(i=r.limitPolicy)!=null?i:l)(async()=>r.enhanceOne({parameter:t,parameterName:n,component:o,context:a}));s===null?delete o.parameters[n]:typeof s=="undefined"?o.parameters[n]={...t,value:t.value}:o.parameters[n]={...t,value:s}}catch(c){let s=`Component ${f(e)} (type: ${o.type}): enhancing parameter ${n} (type: ${t.type}) threw exception. Parameter will be removed.`;return delete o.parameters[n],{message:s,error:c}}}var J=(o,...e)=>({enhanceOne:t=>{let r=o.enhanceOne(t);for(let a of e){let i=S(r)?r:Promise.resolve(r),c="enhanceOne"in a?a.enhanceOne:a;r=i.then(s=>c({...t,parameter:{type:t.parameter.type,value:s}}))}return r},completeAll:()=>{var t,r;for(let a of e)if("completeAll"in a)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(r=(t=o.completeAll)==null?void 0:t.call(o))!=null?r:Promise.resolve(0)}});function S(o){return!!o&&(typeof o=="object"||typeof o=="function")&&typeof o.then=="function"}var ee=o=>o.startsWith("$");function re(o){return o?o.map(e=>{var n,t;return{...e,intentTag:(t=(n=e.parameters)==null?void 0:n[v])==null?void 0:t.value}}):[]}var T="https://js.pusher.com/7.0.3/pusher.min.js";async function B(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((o,e)=>{let n=setTimeout(()=>{window.Pusher&&o(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${T}"><\/script> manually.`)},5e3),t=document.createElement("script");t.src=T,t.addEventListener("load",()=>{clearTimeout(n),o(window.Pusher)}),document.head.appendChild(t)})}async function ae(){let o=await B();if(!o)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new o("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:t=>{let r=n.subscribe(t);return{unsubscribe:()=>n.unsubscribe(t),addEventHandler:(a,i)=>(r.bind(a,i),()=>r.unbind(a,i))}}}}return e}function x(o,e,n){return`${o}.${e}@${n}`}function pe({projectId:o,compositionId:e,compositionState:n=0,eventBus:{subscribe:t},callback:r,event:a="updated"}){let i=x(o,e,n),c=t(i),s=c.addEventHandler(a,r);return()=>{s(),c.unsubscribe()}}function O({component:o}){var t;let e={},n=(t=o.slots)==null?void 0:t[A];return n==null||n.forEach(r=>{var i;let a=(i=r.parameters)==null?void 0:i[g];(a==null?void 0:a.value)&&typeof a.value=="string"&&(e[a.value]=e[a.value]||[],e[a.value].push(r))}),e}function ue({composition:o,locale:e}){u(o,(n,t,r)=>{if(n.type===P){let a=O({component:n}),i=typeof e=="string"?e:e({component:n,locales:a}),c;if(i&&(c=a[i]),c==null?void 0:c.length){let[s,...p]=c;r.replaceComponent(s),p.length&&r.insertAfter(p)}else r.removeComponent()}})}export{w as BatchEntry,U as CANVAS_DRAFT_STATE,v as CANVAS_INTENT_TAG_PARAM,g as CANVAS_LOCALE_TAG_PARAM,A as CANVAS_LOCALIZATION_SLOT,P as CANVAS_LOCALIZATION_TYPE,$ as CANVAS_PERSONALIZE_SLOT,j as CANVAS_PERSONALIZE_TYPE,z as CANVAS_PUBLISHED_STATE,N as CANVAS_TEST_SLOT,F as CANVAS_TEST_TYPE,M as CanvasClient,k as CanvasClientError,y as ChildEnhancerBuilder,_ as EnhancerBuilder,b as UniqueBatchEntries,J as compose,Q as createBatchEnhancer,ae as createEventBus,L as createLimitPolicy,Z as enhance,O as extractLocales,x as getChannelName,f as getComponentPath,ee as isSystemComponentDefinition,ue as localize,re as mapSlotToPersonalizedVariations,l as nullLimitPolicy,pe as subscribeToComposition,u as walkComponentTree}; | ||
`))}}){let r=[],a=new Set,i=new Set;f(o,(s,p)=>{var d;Object.entries((d=s.parameters)!=null?d:{}).forEach(([P,v])=>{let y=e.resolveParameterEnhancer(s,P,v);y&&(i.add(y),r.push(B(s,p,P,v,y,n)))});let m=e.resolveComponentEnhancers(s);r.push(S(s,p,m,n)),a.add(m)}),r.push(...Array.from(a).flatMap(s=>Array.from(s).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:u)(()=>p.completeAll())}catch(d){return{error:d,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),r.push(...Array.from(i).map(async s=>{var p;try{s.completeAll&&await((p=s.limitPolicy)!=null?p:u)(()=>s.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(r)).flatMap(s=>Array.isArray(s)?s:[s]).filter(s=>s);c.length&&t(c)}async function S(o,e,n,t){return n.size&&(o.data={}),await Promise.all(Array.from(n).map(async([r,a])=>{var i;try{let s=await(a.completeAll?u:(i=a.limitPolicy)!=null?i:u)(async()=>a.enhanceOne({component:o,context:t}));s!=null&&(o.data[r]=s)}catch(c){let s=`Component ${C(e)} (type: ${o.type}): data.${r} enhancer threw exception. Data key will not be present.`;return delete o.data[r],{message:s,error:c}}}))}async function B(o,e,n,t,r,a){var i;try{let s=await(r.completeAll?u:(i=r.limitPolicy)!=null?i:u)(async()=>r.enhanceOne({parameter:t,parameterName:n,component:o,context:a}));s===null?delete o.parameters[n]:typeof s=="undefined"?o.parameters[n]={...t,value:t.value}:o.parameters[n]={...t,value:s}}catch(c){let s=`Component ${C(e)} (type: ${o.type}): enhancing parameter ${n} (type: ${t.type}) threw exception. Parameter will be removed.`;return delete o.parameters[n],{message:s,error:c}}}var ee=(o,...e)=>({enhanceOne:t=>{let r=o.enhanceOne(t);for(let a of e){let i=O(r)?r:Promise.resolve(r),c="enhanceOne"in a?a.enhanceOne:a;r=i.then(s=>c({...t,parameter:{type:t.parameter.type,value:s}}))}return r},completeAll:()=>{var t,r;for(let a of e)if("completeAll"in a)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(r=(t=o.completeAll)==null?void 0:t.call(o))!=null?r:Promise.resolve(0)}});function O(o){return!!o&&(typeof o=="object"||typeof o=="function")&&typeof o.then=="function"}var te=o=>o.startsWith("$");function ae(o){return o?o.map(e=>{var n,t;return{...e,intentTag:(t=(n=e.parameters)==null?void 0:n[A])==null?void 0:t.value}}):[]}var b="https://js.pusher.com/7.0.3/pusher.min.js";async function L(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((o,e)=>{let n=setTimeout(()=>{window.Pusher&&o(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${b}"><\/script> manually.`)},5e3),t=document.createElement("script");t.src=b,t.addEventListener("load",()=>{clearTimeout(n),o(window.Pusher)}),document.head.appendChild(t)})}async function ie(){let o=await L();if(!o)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new o("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:t=>{let r=n.subscribe(t);return{unsubscribe:()=>n.unsubscribe(t),addEventHandler:(a,i)=>(r.bind(a,i),()=>r.unbind(a,i))}}}}return e}function _(o,e,n){return`${o}.${e}@${n}`}function le({projectId:o,compositionId:e,compositionState:n=0,eventBus:{subscribe:t},callback:r,event:a="updated"}){let i=_(o,e,n),c=t(i),s=c.addEventHandler(a,r);return()=>{s(),c.unsubscribe()}}function k({component:o}){var t;let e={},n=(t=o.slots)==null?void 0:t[T];return n==null||n.forEach(r=>{var i;let a=(i=r.parameters)==null?void 0:i[w];(a==null?void 0:a.value)&&typeof a.value=="string"&&(e[a.value]=e[a.value]||[],e[a.value].push(r))}),e}function fe({composition:o,locale:e}){f(o,(n,t,r)=>{if(n.type===g){let a=k({component:n}),i=typeof e=="string"?e:e({component:n,locales:a}),c;if(i&&(c=a[i]),c==null?void 0:c.length){let[s,...p]=c;r.replaceComponent(s),p.length&&r.insertAfter(p)}else r.removeComponent()}})}export{x as BatchEntry,V as CANVAS_DRAFT_STATE,A as CANVAS_INTENT_TAG_PARAM,w as CANVAS_LOCALE_TAG_PARAM,T as CANVAS_LOCALIZATION_SLOT,g as CANVAS_LOCALIZATION_TYPE,U as CANVAS_PERSONALIZE_SLOT,$ as CANVAS_PERSONALIZE_TYPE,W as CANVAS_PUBLISHED_STATE,z as CANVAS_TEST_SLOT,N as CANVAS_TEST_TYPE,F as CanvasClient,j as CanvasClientError,E as ChildEnhancerBuilder,R as EnhancerBuilder,I as UniqueBatchEntries,ee as compose,D as createBatchEnhancer,ie as createEventBus,M as createLimitPolicy,J as enhance,k as extractLocales,_ as getChannelName,C as getComponentPath,te as isSystemComponentDefinition,fe as localize,ae as mapSlotToPersonalizedVariations,u as nullLimitPolicy,le as subscribeToComposition,f as walkComponentTree}; |
@@ -5,2 +5,2 @@ var $=Object.create;var y=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var _=r=>y(r,"__esModule",{value:!0});var z=(r,e)=>{_(r);for(var n in e)y(r,n,{get:e[n],enumerable:!0})},H=(r,e,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of V(e))!F.call(r,t)&&t!=="default"&&y(r,t,{get:()=>e[t],enumerable:!(n=M(e,t))||n.enumerable});return r},S=r=>H(_(y(r!=null?$(D(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);z(exports,{BatchEntry:()=>A,CANVAS_DRAFT_STATE:()=>ne,CANVAS_INTENT_TAG_PARAM:()=>I,CANVAS_LOCALE_TAG_PARAM:()=>T,CANVAS_LOCALIZATION_SLOT:()=>x,CANVAS_LOCALIZATION_TYPE:()=>v,CANVAS_PERSONALIZE_SLOT:()=>X,CANVAS_PERSONALIZE_TYPE:()=>Y,CANVAS_PUBLISHED_STATE:()=>te,CANVAS_TEST_SLOT:()=>ee,CANVAS_TEST_TYPE:()=>Q,CanvasClient:()=>N,CanvasClientError:()=>f,ChildEnhancerBuilder:()=>E,EnhancerBuilder:()=>L,UniqueBatchEntries:()=>O,compose:()=>J,createBatchEnhancer:()=>q,createEventBus:()=>se,createLimitPolicy:()=>g,enhance:()=>K,extractLocales:()=>U,getChannelName:()=>w,getComponentPath:()=>C,isSystemComponentDefinition:()=>oe,localize:()=>ce,mapSlotToPersonalizedVariations:()=>re,nullLimitPolicy:()=>h,subscribeToComposition:()=>ae,walkComponentTree:()=>d});function d(r,e){let n=[{ancestorsAndSelf:[{component:r,parentSlot:void 0,parentSlotIndex:void 0}]}];do{let t=n.pop();if(!t)continue;let o=t.ancestorsAndSelf[0];e(o.component,t.ancestorsAndSelf,{replaceComponent:s=>{Object.assign(o.component,s),["parameters","variant","slots","data","_pattern","_patternError"].forEach(a=>{s[a]||delete o.component[a]})},removeComponent:()=>{let{parentSlot:s,parentSlotIndex:c}=t.ancestorsAndSelf[0],a=t.ancestorsAndSelf[1];if(s&&typeof c!="undefined")a.component.slots[s].splice(c,1);else throw new Error("Unable to delete composition.")},insertAfter:s=>{let c=Array.isArray(s)?s:[s],{parentSlot:a,parentSlotIndex:p}=t.ancestorsAndSelf[0],m=t.ancestorsAndSelf[1];if(a&&typeof p!="undefined")m.component.slots[a].splice(p+1,0,...c);else throw new Error("Unable to insert after a component not in a slot.")}});let i=o.component.slots;if(i){let s=Object.keys(i);for(let c=s.length-1;c>=0;c--){let a=s[c],p=i[a];for(let m=p.length-1;m>=0;m--)n.push({ancestorsAndSelf:[{component:p[m],parentSlot:a,parentSlotIndex:m},...t.ancestorsAndSelf]})}}}while(n.length>0)}function C(r){let e=[];for(let n=r.length-1;n>=0;n--){let{parentSlot:t,parentSlotIndex:o}=r[n];t&&o!==void 0&&e.push(`${t}[${o}]`)}return`.${e.join(".")}`}var O=class{constructor(e,n){this.groups=e.reduce((t,o)=>{var s;let i=n(o.args);return t[i]=(s=t[i])!=null?s:[],t[i].push(o),t},{})}resolveKey(e,n){this.groups[e].forEach(t=>t.resolve(n))}resolveRemaining(e){Object.keys(this.groups).forEach(n=>{this.groups[n].forEach(t=>{t.isCompleted||t.resolve(e)})})}};var E=class{constructor(){this._paramMatches=Array();this._dataMatches=new Map}parameter(e){return this._paramMatches.push({enhancer:this._resolveParameterEnhancer(e)}),this}parameterName(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({name:o,enhancer:this._resolveParameterEnhancer(n)})),this}parameterType(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>this._paramMatches.push({type:o,enhancer:this._resolveParameterEnhancer(n)})),this}data(e,n){if(this._dataMatches.has(e))throw new Error(`${e} enhancer data key has been used more than once. This will cause data loss.`);return this._dataMatches.set(e,typeof n=="function"?{enhanceOne:n}:n),this}resolveParameterEnhancer(e,n){var t;return(t=this._paramMatches.find(o=>o.name&&o.name===e||o.type&&o.type===n.type||!o.type&&!o.name))==null?void 0:t.enhancer}resolveComponentEnhancers(){return this._dataMatches}_resolveParameterEnhancer(e){return typeof e=="function"?{enhanceOne:e}:e}},L=class{constructor(){this._componentIndex={};this._rootBuilder=new E}parameter(e){return this._rootBuilder.parameter(e),this}parameterName(e,n){return this._rootBuilder.parameterName(e,n),this}parameterType(e,n){return this._rootBuilder.parameterType(e,n),this}data(e,n){return this._rootBuilder.data(e,n),this}component(e,n){return(Array.isArray(e)?e:[e]).forEach(o=>{this._componentIndex[o]=this._componentIndex[o]||new E,n(this._componentIndex[o])}),this}resolveParameterEnhancer(e,n,t){let o=this._componentIndex[e.type];if(o){let i=o.resolveParameterEnhancer(n,t);if(i)return i}return this._rootBuilder.resolveParameterEnhancer(n,t)}resolveComponentEnhancers(e){let n=this._rootBuilder.resolveComponentEnhancers(),t=this._componentIndex[e.type];if(t){n=new Map(n);for(let[o,i]of t.resolveComponentEnhancers())n.set(o,i)}return n}};var A=class{constructor(e,n,t){this._resolve=e;this._reject=n;this.args=t;this._isCompleted=!1}resolve(e){this._resolve(e),this._isCompleted=!0}reject(e){this._reject(e),this._isCompleted=!0}get isCompleted(){return this._isCompleted}};function q({handleBatch:r,shouldQueue:e,limitPolicy:n}){let t=[];return{enhanceOne:async s=>{if(!e||e(s))return new Promise((c,a)=>{t.push(new A(c,a,s))})},completeAll:async()=>{if(t.length>0){try{await r(t)}catch(c){t.forEach(a=>a.reject(c))}if(t.some(c=>!c.isCompleted))throw new Error("The completeAll() function failed to resolve or reject all promises in the batch!")}let s=t.length;return t=[],s},limitPolicy:n}}var j=S(require("p-throttle")),B=S(require("p-retry"));function g({throttle:r={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let n=r?(0,j.default)(r):null;return function(o){let i=async()=>await o();if(n&&(i=n(i)),e){let s=i;i=()=>(0,B.default)(s,e)}return i()}}var h=async r=>await r();async function K({composition:r,enhancers:e,context:n,onErrors:t=o=>{throw new Error(o.map(i=>`${i.message} | ||
`))}}){let o=[],i=new Set,s=new Set;d(r,(a,p)=>{var u;Object.entries((u=a.parameters)!=null?u:{}).forEach(([R,b])=>{let P=e.resolveParameterEnhancer(a,R,b);P&&(s.add(P),o.push(Z(a,p,R,b,P,n)))});let m=e.resolveComponentEnhancers(a);o.push(G(a,p,m,n)),i.add(m)}),o.push(...Array.from(i).flatMap(a=>Array.from(a).map(async([,p])=>{var m;try{p.completeAll&&await((m=p.limitPolicy)!=null?m:h)(()=>p.completeAll())}catch(u){return{error:u,message:"Batch component enhancer failed. Individual failed components should receive their own rejections."}}}))),o.push(...Array.from(s).map(async a=>{var p;try{a.completeAll&&await((p=a.limitPolicy)!=null?p:h)(()=>a.completeAll())}catch(m){return{error:m,message:"Batch parameter enhancer failed. Individual failed parameters should receive their own rejections."}}}));let c=(await Promise.all(o)).flatMap(a=>Array.isArray(a)?a:[a]).filter(a=>a);c.length&&t(c)}async function G(r,e,n,t){return n.size&&(r.data={}),await Promise.all(Array.from(n).map(async([o,i])=>{var s;try{let a=await(i.completeAll?h:(s=i.limitPolicy)!=null?s:h)(async()=>i.enhanceOne({component:r,context:t}));a!=null&&(r.data[o]=a)}catch(c){let a=`Component ${C(e)} (type: ${r.type}): data.${o} enhancer threw exception. Data key will not be present.`;return delete r.data[o],{message:a,error:c}}}))}async function Z(r,e,n,t,o,i){var s;try{let a=await(o.completeAll?h:(s=o.limitPolicy)!=null?s:h)(async()=>o.enhanceOne({parameter:t,parameterName:n,component:r,context:i}));a===null?delete r.parameters[n]:typeof a=="undefined"?r.parameters[n]={...t,value:t.value}:r.parameters[n]={...t,value:a}}catch(c){let a=`Component ${C(e)} (type: ${r.type}): enhancing parameter ${n} (type: ${t.type}) threw exception. Parameter will be removed.`;return delete r.parameters[n],{message:a,error:c}}}var J=(r,...e)=>({enhanceOne:t=>{let o=r.enhanceOne(t);for(let i of e){let s=W(o)?o:Promise.resolve(o),c="enhanceOne"in i?i.enhanceOne:i;o=s.then(a=>c({...t,parameter:{type:t.parameter.type,value:a}}))}return o},completeAll:()=>{var t,o;for(let i of e)if("completeAll"in i)throw new Error("Only the first enhancer in a compose chain can use the completeAll function (batching)");return(o=(t=r.completeAll)==null?void 0:t.call(r))!=null?o:Promise.resolve(0)}});function W(r){return!!r&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"}var f=class extends Error{constructor(e,n,t,o,i){super(`${e} | ||
${o}${i?" "+i:""} (${n} ${t})`);this.errorMessage=e;this.fetchMethod=n;this.fetchUri=t;this.statusCode=o;this.statusText=i;Object.setPrototypeOf(this,f.prototype)}},N=class{constructor(e){var n,t,o,i,s,c;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");this.options={...e,fetch:(n=e.fetch)!=null?n:fetch,apiHost:(t=e.apiHost)!=null?t:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(i=e.projectId)!=null?i:null,bearerToken:(s=e.bearerToken)!=null?s:null,limitPolicy:(c=e.limitPolicy)!=null?c:g({})}}async getCompositionList(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionBySlug(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionById(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async updateComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:n});return await this.apiClient(t)}async updateComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,n){return this.options.limitPolicy(async()=>{var i;let t=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},o=await fetch(e.toString(),{...n,headers:{...n==null?void 0:n.headers,...t}});if(!o.ok){let s="";try{let c=await o.text();try{let a=JSON.parse(c);a.errorMessage?s=Array.isArray(a.errorMessage)?a.errorMessage.join(", "):a.errorMessage:s=c}catch(a){s=c}}catch(c){s="General error"}throw new f(s,(i=n==null?void 0:n.method)!=null?i:"GET",e.toString(),o.status)}return(n==null?void 0:n.expectNoContent)?null:await o.json()})}createUrl(e,n){let t=new URL(`${this.options.apiHost}${e}`);return Object.entries(n!=null?n:{}).forEach(([o,i])=>{var s;typeof i!==void 0&&i!==null&&t.searchParams.append(o,(s=i==null?void 0:i.toString())!=null?s:"")}),t}};var Y="$personalization",Q="$test",v="$localization",I="intentTag",T="locale",X="pz",ee="test",x="localized",ne=0,te=64;var oe=r=>r.startsWith("$");function re(r){return r?r.map(e=>{var n,t;return{...e,intentTag:(t=(n=e.parameters)==null?void 0:n[I])==null?void 0:t.value}}):[]}var k="https://js.pusher.com/7.0.3/pusher.min.js";async function ie(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((r,e)=>{let n=setTimeout(()=>{window.Pusher&&r(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${k}"><\/script> manually.`)},5e3),t=document.createElement("script");t.src=k,t.addEventListener("load",()=>{clearTimeout(n),r(window.Pusher)}),document.head.appendChild(t)})}async function se(){let r=await ie();if(!r)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new r("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:t=>{let o=n.subscribe(t);return{unsubscribe:()=>n.unsubscribe(t),addEventHandler:(i,s)=>(o.bind(i,s),()=>o.unbind(i,s))}}}}return e}function w(r,e,n){return`${r}.${e}@${n}`}function ae({projectId:r,compositionId:e,compositionState:n=0,eventBus:{subscribe:t},callback:o,event:i="updated"}){let s=w(r,e,n),c=t(s),a=c.addEventHandler(i,o);return()=>{a(),c.unsubscribe()}}function U({component:r}){var t;let e={},n=(t=r.slots)==null?void 0:t[x];return n==null||n.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[T];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function ce({composition:r,locale:e}){d(r,(n,t,o)=>{if(n.type===v){let i=U({component:n}),s=typeof e=="string"?e:e({component:n,locales:i}),c;if(s&&(c=i[s]),c==null?void 0:c.length){let[a,...p]=c;o.replaceComponent(a),p.length&&o.insertAfter(p)}else o.removeComponent()}})}0&&(module.exports={BatchEntry,CANVAS_DRAFT_STATE,CANVAS_INTENT_TAG_PARAM,CANVAS_LOCALE_TAG_PARAM,CANVAS_LOCALIZATION_SLOT,CANVAS_LOCALIZATION_TYPE,CANVAS_PERSONALIZE_SLOT,CANVAS_PERSONALIZE_TYPE,CANVAS_PUBLISHED_STATE,CANVAS_TEST_SLOT,CANVAS_TEST_TYPE,CanvasClient,CanvasClientError,ChildEnhancerBuilder,EnhancerBuilder,UniqueBatchEntries,compose,createBatchEnhancer,createEventBus,createLimitPolicy,enhance,extractLocales,getChannelName,getComponentPath,isSystemComponentDefinition,localize,mapSlotToPersonalizedVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree}); | ||
${o}${i?" "+i:""} (${n} ${t})`);this.errorMessage=e;this.fetchMethod=n;this.fetchUri=t;this.statusCode=o;this.statusText=i;Object.setPrototypeOf(this,f.prototype)}},N=class{constructor(e){var n,t,o,i,s,c;if(!e.apiKey&&!e.bearerToken)throw new Error("You must provide an API key or a bearer token");this.options={...e,fetch:(n=e.fetch)!=null?n:fetch,apiHost:(t=e.apiHost)!=null?t:"https://uniform.app",apiKey:(o=e.apiKey)!=null?o:null,projectId:(i=e.projectId)!=null?i:null,bearerToken:(s=e.bearerToken)!=null?s:null,limitPolicy:(c=e.limitPolicy)!=null?c:g({})}}async getCompositionList(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionBySlug(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async getCompositionById(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas",{...e,projectId:n});return await this.apiClient(t)}async updateComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let n=this.createUrl("/api/v1/canvas");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:n}=this.options,t=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:n});return await this.apiClient(t)}async updateComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let n=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(n,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,n){return this.options.limitPolicy(async()=>{var i;let t=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},o=await this.options.fetch(e.toString(),{...n,headers:{...n==null?void 0:n.headers,...t}});if(!o.ok){let s="";try{let c=await o.text();try{let a=JSON.parse(c);a.errorMessage?s=Array.isArray(a.errorMessage)?a.errorMessage.join(", "):a.errorMessage:s=c}catch(a){s=c}}catch(c){s="General error"}throw new f(s,(i=n==null?void 0:n.method)!=null?i:"GET",e.toString(),o.status)}return(n==null?void 0:n.expectNoContent)?null:await o.json()})}createUrl(e,n){let t=new URL(`${this.options.apiHost}${e}`);return Object.entries(n!=null?n:{}).forEach(([o,i])=>{var s;typeof i!==void 0&&i!==null&&t.searchParams.append(o,(s=i==null?void 0:i.toString())!=null?s:"")}),t}};var Y="$personalization",Q="$test",v="$localization",I="intentTag",T="locale",X="pz",ee="test",x="localized",ne=0,te=64;var oe=r=>r.startsWith("$");function re(r){return r?r.map(e=>{var n,t;return{...e,intentTag:(t=(n=e.parameters)==null?void 0:n[I])==null?void 0:t.value}}):[]}var k="https://js.pusher.com/7.0.3/pusher.min.js";async function ie(){if(!(typeof document=="undefined"||typeof window=="undefined"))return window.Pusher?window.Pusher:new Promise((r,e)=>{let n=setTimeout(()=>{window.Pusher&&r(window.Pusher),e(`Unable to load pusher.js; Uniform Canvas live preview disabled. Consider adding <script src="${k}"><\/script> manually.`)},5e3),t=document.createElement("script");t.src=k,t.addEventListener("load",()=>{clearTimeout(n),r(window.Pusher)}),document.head.appendChild(t)})}async function se(){let r=await ie();if(!r)return;let e=window.__UNIFORM_EVENT_BUS__;if(!e){let n=new r("7b5f5abd160fea549ffe",{cluster:"mt1"});n.connect(),console.log("[canvas] \u{1F525} preview connected"),e=window.__UNIFORM_EVENT_BUS__={subscribe:t=>{let o=n.subscribe(t);return{unsubscribe:()=>n.unsubscribe(t),addEventHandler:(i,s)=>(o.bind(i,s),()=>o.unbind(i,s))}}}}return e}function w(r,e,n){return`${r}.${e}@${n}`}function ae({projectId:r,compositionId:e,compositionState:n=0,eventBus:{subscribe:t},callback:o,event:i="updated"}){let s=w(r,e,n),c=t(s),a=c.addEventHandler(i,o);return()=>{a(),c.unsubscribe()}}function U({component:r}){var t;let e={},n=(t=r.slots)==null?void 0:t[x];return n==null||n.forEach(o=>{var s;let i=(s=o.parameters)==null?void 0:s[T];(i==null?void 0:i.value)&&typeof i.value=="string"&&(e[i.value]=e[i.value]||[],e[i.value].push(o))}),e}function ce({composition:r,locale:e}){d(r,(n,t,o)=>{if(n.type===v){let i=U({component:n}),s=typeof e=="string"?e:e({component:n,locales:i}),c;if(s&&(c=i[s]),c==null?void 0:c.length){let[a,...p]=c;o.replaceComponent(a),p.length&&o.insertAfter(p)}else o.removeComponent()}})}0&&(module.exports={BatchEntry,CANVAS_DRAFT_STATE,CANVAS_INTENT_TAG_PARAM,CANVAS_LOCALE_TAG_PARAM,CANVAS_LOCALIZATION_SLOT,CANVAS_LOCALIZATION_TYPE,CANVAS_PERSONALIZE_SLOT,CANVAS_PERSONALIZE_TYPE,CANVAS_PUBLISHED_STATE,CANVAS_TEST_SLOT,CANVAS_TEST_TYPE,CanvasClient,CanvasClientError,ChildEnhancerBuilder,EnhancerBuilder,UniqueBatchEntries,compose,createBatchEnhancer,createEventBus,createLimitPolicy,enhance,extractLocales,getChannelName,getComponentPath,isSystemComponentDefinition,localize,mapSlotToPersonalizedVariations,nullLimitPolicy,subscribeToComposition,walkComponentTree}); |
{ | ||
"name": "@uniformdev/canvas", | ||
"version": "13.0.0", | ||
"version": "13.0.1-alpha.70+21cf4ced", | ||
"description": "Common functionality and types for Uniform Canvas", | ||
@@ -46,17 +46,17 @@ "license": "SEE LICENSE IN LICENSE.txt", | ||
"@types/jest": "27.0.3", | ||
"@types/js-yaml": "4.0.4", | ||
"@types/js-yaml": "4.0.5", | ||
"@types/lodash.isequalwith": "4.4.6", | ||
"@types/node": "16.7.1", | ||
"@types/yargs": "17.0.5", | ||
"@uniformdev/cli": "^13.0.0", | ||
"eslint": "7.32.0", | ||
"@types/node": "16.11.12", | ||
"@types/yargs": "17.0.7", | ||
"@uniformdev/cli": "^13.0.1-alpha.70+21cf4ced", | ||
"eslint": "8.4.1", | ||
"eslint-plugin-react": "7.27.1", | ||
"eslint-plugin-react-hooks": "4.3.0", | ||
"jest": "27.3.1", | ||
"jest": "27.4.4", | ||
"npm-run-all": "4.1.5", | ||
"pusher-js": "7.0.3", | ||
"rimraf": "3.0.2", | ||
"ts-jest": "27.0.7", | ||
"tsup": "5.7.2", | ||
"yargs": "17.2.1" | ||
"ts-jest": "27.1.1", | ||
"tsup": "5.11.1", | ||
"yargs": "17.3.0" | ||
}, | ||
@@ -67,4 +67,4 @@ "peerDependencies": { | ||
"dependencies": { | ||
"@uniformdev/optimize-common": "^13.0.0", | ||
"@uniformdev/optimize-tracker-common": "^13.0.0", | ||
"@uniformdev/optimize-common": "^13.0.1-alpha.70+21cf4ced", | ||
"@uniformdev/optimize-tracker-common": "^13.0.1-alpha.70+21cf4ced", | ||
"chalk": "^4.1.2", | ||
@@ -85,3 +85,3 @@ "diff": "^5.0.0", | ||
}, | ||
"gitHead": "7ca5b6971d631f339cfad85a7c3f415b01d22248" | ||
"gitHead": "21cf4cedab72c4bd29048c47d3a6a772d997985b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109498
894
4
4
+ Added@uniformdev/optimize-common@13.0.1-alpha.83(transitive)
+ Added@uniformdev/optimize-tracker-common@13.0.1-alpha.83(transitive)
- Removed@uniformdev/optimize-common@13.0.0(transitive)
- Removed@uniformdev/optimize-tracker-common@13.0.0(transitive)
Updated@uniformdev/optimize-common@^13.0.1-alpha.70+21cf4ced
Updated@uniformdev/optimize-tracker-common@^13.0.1-alpha.70+21cf4ced