@uniformdev/canvas 12.2.0 → 12.2.1-alpha.107
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/LICENSE.txt +1 -1
- package/README.md +5 -5
- package/dist/chunk-FS5XXLSV.mjs +2 -0
- package/dist/cli/cli.d.ts +14 -0
- package/dist/cli/cli.js +4 -0
- package/dist/cli/cli.mjs +3 -0
- package/dist/createEventBus-39df132f.d.ts +253 -0
- package/dist/index.d.ts +361 -0
- package/dist/index.esm.js +4 -0
- package/dist/index.js +5 -0
- package/dist/index.mjs +4 -0
- package/package.json +33 -33
- package/dist/cjs/CanvasClient.d.ts +0 -50
- package/dist/cjs/CanvasClient.js +0 -1
- package/dist/cjs/cli/arraySyncEngineDataSource.d.ts +0 -10
- package/dist/cjs/cli/arraySyncEngineDataSource.js +0 -1
- package/dist/cjs/cli/cli.d.ts +0 -3
- package/dist/cjs/cli/cli.js +0 -1
- package/dist/cjs/cli/commands/component/_util.d.ts +0 -3
- package/dist/cjs/cli/commands/component/_util.js +0 -1
- package/dist/cjs/cli/commands/component/get.d.ts +0 -7
- package/dist/cjs/cli/commands/component/get.js +0 -1
- package/dist/cjs/cli/commands/component/list.d.ts +0 -6
- package/dist/cjs/cli/commands/component/list.js +0 -1
- package/dist/cjs/cli/commands/component/pull.d.ts +0 -10
- package/dist/cjs/cli/commands/component/pull.js +0 -1
- package/dist/cjs/cli/commands/component/push.d.ts +0 -9
- package/dist/cjs/cli/commands/component/push.js +0 -1
- package/dist/cjs/cli/commands/component/remove.d.ts +0 -7
- package/dist/cjs/cli/commands/component/remove.js +0 -1
- package/dist/cjs/cli/commands/component/update.d.ts +0 -7
- package/dist/cjs/cli/commands/component/update.js +0 -1
- package/dist/cjs/cli/commands/component.d.ts +0 -2
- package/dist/cjs/cli/commands/component.js +0 -1
- package/dist/cjs/cli/commands/composition/_util.d.ts +0 -3
- package/dist/cjs/cli/commands/composition/_util.js +0 -1
- package/dist/cjs/cli/commands/composition/get.d.ts +0 -8
- package/dist/cjs/cli/commands/composition/get.js +0 -1
- package/dist/cjs/cli/commands/composition/list.d.ts +0 -8
- package/dist/cjs/cli/commands/composition/list.js +0 -1
- package/dist/cjs/cli/commands/composition/pull.d.ts +0 -10
- package/dist/cjs/cli/commands/composition/pull.js +0 -1
- package/dist/cjs/cli/commands/composition/push.d.ts +0 -9
- package/dist/cjs/cli/commands/composition/push.js +0 -1
- package/dist/cjs/cli/commands/composition/remove.d.ts +0 -7
- package/dist/cjs/cli/commands/composition/remove.js +0 -1
- package/dist/cjs/cli/commands/composition/update.d.ts +0 -7
- package/dist/cjs/cli/commands/composition/update.js +0 -1
- package/dist/cjs/cli/commands/composition.d.ts +0 -2
- package/dist/cjs/cli/commands/composition.js +0 -1
- package/dist/cjs/cli/componentDefinitionEngineDataSource.d.ts +0 -7
- package/dist/cjs/cli/componentDefinitionEngineDataSource.js +0 -1
- package/dist/cjs/cli/componentInstanceEngineDataSource.d.ts +0 -9
- package/dist/cjs/cli/componentInstanceEngineDataSource.js +0 -1
- package/dist/cjs/cli/fileSyncEngineDataSource.d.ts +0 -9
- package/dist/cjs/cli/fileSyncEngineDataSource.js +0 -1
- package/dist/cjs/cli/package.d.ts +0 -7
- package/dist/cjs/cli/package.js +0 -1
- package/dist/cjs/cli/syncEngine.d.ts +0 -49
- package/dist/cjs/cli/syncEngine.js +0 -1
- package/dist/cjs/cli/syncEngineConsoleLogger.d.ts +0 -5
- package/dist/cjs/cli/syncEngineConsoleLogger.js +0 -1
- package/dist/cjs/cli/util.d.ts +0 -43
- package/dist/cjs/cli/util.js +0 -1
- package/dist/cjs/enhancement/EnhancerBuilder.d.ts +0 -66
- package/dist/cjs/enhancement/EnhancerBuilder.js +0 -1
- package/dist/cjs/enhancement/UniqueBatchEntries.d.ts +0 -17
- package/dist/cjs/enhancement/UniqueBatchEntries.js +0 -1
- package/dist/cjs/enhancement/batchEnhancer.d.ts +0 -39
- package/dist/cjs/enhancement/batchEnhancer.js +0 -1
- package/dist/cjs/enhancement/compose.d.ts +0 -6
- package/dist/cjs/enhancement/compose.js +0 -1
- package/dist/cjs/enhancement/createLimitPolicy.d.ts +0 -8
- package/dist/cjs/enhancement/createLimitPolicy.js +0 -1
- package/dist/cjs/enhancement/enhance.d.ts +0 -18
- package/dist/cjs/enhancement/enhance.js +0 -1
- package/dist/cjs/enhancement/localize.d.ts +0 -11
- package/dist/cjs/enhancement/localize.js +0 -1
- package/dist/cjs/enhancement/walkComponentTree.d.ts +0 -14
- package/dist/cjs/enhancement/walkComponentTree.js +0 -1
- package/dist/cjs/index.d.ts +0 -17
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/preview/EventNames.d.ts +0 -1
- package/dist/cjs/preview/EventNames.js +0 -1
- package/dist/cjs/preview/createEventBus.d.ts +0 -6
- package/dist/cjs/preview/createEventBus.js +0 -1
- package/dist/cjs/preview/getChannelName.d.ts +0 -1
- package/dist/cjs/preview/getChannelName.js +0 -1
- package/dist/cjs/preview/subscribeToComposition.d.ts +0 -13
- package/dist/cjs/preview/subscribeToComposition.js +0 -1
- package/dist/cjs/types/componentDefinitions.d.ts +0 -90
- package/dist/cjs/types/componentDefinitions.js +0 -1
- package/dist/cjs/types/componentInstances.d.ts +0 -104
- package/dist/cjs/types/componentInstances.js +0 -1
- package/dist/cjs/types/enhancement.d.ts +0 -79
- package/dist/cjs/types/enhancement.js +0 -1
- package/dist/cjs/types/index.d.ts +0 -3
- package/dist/cjs/types/index.js +0 -1
- package/dist/cjs/utils/constants.d.ts +0 -20
- package/dist/cjs/utils/constants.js +0 -1
- package/dist/cjs/utils/isSystemComponentDefinition.d.ts +0 -2
- package/dist/cjs/utils/isSystemComponentDefinition.js +0 -1
- package/dist/cjs/utils/mapSlotToPersonalizedVariations.d.ts +0 -7
- package/dist/cjs/utils/mapSlotToPersonalizedVariations.js +0 -1
- package/dist/esm/CanvasClient.d.ts +0 -50
- package/dist/esm/CanvasClient.js +0 -1
- package/dist/esm/cli/arraySyncEngineDataSource.d.ts +0 -10
- package/dist/esm/cli/arraySyncEngineDataSource.js +0 -1
- package/dist/esm/cli/cli.d.ts +0 -3
- package/dist/esm/cli/cli.js +0 -1
- package/dist/esm/cli/commands/component/_util.d.ts +0 -3
- package/dist/esm/cli/commands/component/_util.js +0 -1
- package/dist/esm/cli/commands/component/get.d.ts +0 -7
- package/dist/esm/cli/commands/component/get.js +0 -1
- package/dist/esm/cli/commands/component/list.d.ts +0 -6
- package/dist/esm/cli/commands/component/list.js +0 -1
- package/dist/esm/cli/commands/component/pull.d.ts +0 -10
- package/dist/esm/cli/commands/component/pull.js +0 -1
- package/dist/esm/cli/commands/component/push.d.ts +0 -9
- package/dist/esm/cli/commands/component/push.js +0 -1
- package/dist/esm/cli/commands/component/remove.d.ts +0 -7
- package/dist/esm/cli/commands/component/remove.js +0 -1
- package/dist/esm/cli/commands/component/update.d.ts +0 -7
- package/dist/esm/cli/commands/component/update.js +0 -1
- package/dist/esm/cli/commands/component.d.ts +0 -2
- package/dist/esm/cli/commands/component.js +0 -1
- package/dist/esm/cli/commands/composition/_util.d.ts +0 -3
- package/dist/esm/cli/commands/composition/_util.js +0 -1
- package/dist/esm/cli/commands/composition/get.d.ts +0 -8
- package/dist/esm/cli/commands/composition/get.js +0 -1
- package/dist/esm/cli/commands/composition/list.d.ts +0 -8
- package/dist/esm/cli/commands/composition/list.js +0 -1
- package/dist/esm/cli/commands/composition/pull.d.ts +0 -10
- package/dist/esm/cli/commands/composition/pull.js +0 -1
- package/dist/esm/cli/commands/composition/push.d.ts +0 -9
- package/dist/esm/cli/commands/composition/push.js +0 -1
- package/dist/esm/cli/commands/composition/remove.d.ts +0 -7
- package/dist/esm/cli/commands/composition/remove.js +0 -1
- package/dist/esm/cli/commands/composition/update.d.ts +0 -7
- package/dist/esm/cli/commands/composition/update.js +0 -1
- package/dist/esm/cli/commands/composition.d.ts +0 -2
- package/dist/esm/cli/commands/composition.js +0 -1
- package/dist/esm/cli/componentDefinitionEngineDataSource.d.ts +0 -7
- package/dist/esm/cli/componentDefinitionEngineDataSource.js +0 -1
- package/dist/esm/cli/componentInstanceEngineDataSource.d.ts +0 -9
- package/dist/esm/cli/componentInstanceEngineDataSource.js +0 -1
- package/dist/esm/cli/fileSyncEngineDataSource.d.ts +0 -9
- package/dist/esm/cli/fileSyncEngineDataSource.js +0 -1
- package/dist/esm/cli/package.d.ts +0 -7
- package/dist/esm/cli/package.js +0 -1
- package/dist/esm/cli/syncEngine.d.ts +0 -49
- package/dist/esm/cli/syncEngine.js +0 -1
- package/dist/esm/cli/syncEngineConsoleLogger.d.ts +0 -5
- package/dist/esm/cli/syncEngineConsoleLogger.js +0 -1
- package/dist/esm/cli/util.d.ts +0 -43
- package/dist/esm/cli/util.js +0 -1
- package/dist/esm/enhancement/EnhancerBuilder.d.ts +0 -66
- package/dist/esm/enhancement/EnhancerBuilder.js +0 -1
- package/dist/esm/enhancement/UniqueBatchEntries.d.ts +0 -17
- package/dist/esm/enhancement/UniqueBatchEntries.js +0 -1
- package/dist/esm/enhancement/batchEnhancer.d.ts +0 -39
- package/dist/esm/enhancement/batchEnhancer.js +0 -1
- package/dist/esm/enhancement/compose.d.ts +0 -6
- package/dist/esm/enhancement/compose.js +0 -1
- package/dist/esm/enhancement/createLimitPolicy.d.ts +0 -8
- package/dist/esm/enhancement/createLimitPolicy.js +0 -1
- package/dist/esm/enhancement/enhance.d.ts +0 -18
- package/dist/esm/enhancement/enhance.js +0 -1
- package/dist/esm/enhancement/localize.d.ts +0 -11
- package/dist/esm/enhancement/localize.js +0 -1
- package/dist/esm/enhancement/walkComponentTree.d.ts +0 -14
- package/dist/esm/enhancement/walkComponentTree.js +0 -1
- package/dist/esm/index.d.ts +0 -17
- package/dist/esm/index.js +0 -1
- package/dist/esm/preview/EventNames.d.ts +0 -1
- package/dist/esm/preview/EventNames.js +0 -0
- package/dist/esm/preview/createEventBus.d.ts +0 -6
- package/dist/esm/preview/createEventBus.js +0 -1
- package/dist/esm/preview/getChannelName.d.ts +0 -1
- package/dist/esm/preview/getChannelName.js +0 -1
- package/dist/esm/preview/subscribeToComposition.d.ts +0 -13
- package/dist/esm/preview/subscribeToComposition.js +0 -1
- package/dist/esm/types/componentDefinitions.d.ts +0 -90
- package/dist/esm/types/componentDefinitions.js +0 -0
- package/dist/esm/types/componentInstances.d.ts +0 -104
- package/dist/esm/types/componentInstances.js +0 -0
- package/dist/esm/types/enhancement.d.ts +0 -79
- package/dist/esm/types/enhancement.js +0 -0
- package/dist/esm/types/index.d.ts +0 -3
- package/dist/esm/types/index.js +0 -1
- package/dist/esm/utils/constants.d.ts +0 -20
- package/dist/esm/utils/constants.js +0 -1
- package/dist/esm/utils/isSystemComponentDefinition.d.ts +0 -2
- package/dist/esm/utils/isSystemComponentDefinition.js +0 -1
- package/dist/esm/utils/mapSlotToPersonalizedVariations.d.ts +0 -7
- package/dist/esm/utils/mapSlotToPersonalizedVariations.js +0 -1
package/LICENSE.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
© 2021 Uniform Systems, Inc. All Rights Reserved.
|
1
|
+
© 2021 Uniform Systems, Inc. All Rights Reserved.
|
2
2
|
See details of Uniform Systems, Inc. Master Subscription Agreement here: https://uniform.dev/eula
|
package/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
Uniform Canvas JavaScript SDK
|
2
|
-
|
3
|
-
Contains the Canvas API client, Canvas CLI, and core typings.
|
4
|
-
|
5
|
-
part of the [Uniform Platform](https://uniform.app). See our [documentation](https://docs.uniform.app) for more details.
|
1
|
+
Uniform Canvas JavaScript SDK
|
2
|
+
|
3
|
+
Contains the Canvas API client, Canvas CLI, and core typings.
|
4
|
+
|
5
|
+
part of the [Uniform Platform](https://uniform.app). See our [documentation](https://docs.uniform.app) for more details.
|
@@ -0,0 +1,2 @@
|
|
1
|
+
import u from"p-throttle";import f from"p-retry";function h({throttle:p={interval:1e3,limit:10},retry:e={retries:1,factor:1.66}}){let t=p?u(p):null;return function(s){let i=async()=>await s();if(t&&(i=t(i)),e){let n=i;i=()=>f(n,e)}return i()}}var P=async p=>await p();var a=class extends Error{constructor(e,t,o,s,i){super(`${e}
|
2
|
+
${s}${i?" "+i:""} (${t} ${o})`);this.errorMessage=e;this.fetchMethod=t;this.fetchUri=o;this.statusCode=s;this.statusText=i;Object.setPrototypeOf(this,a.prototype)}},A=class{constructor(e){var o,s,i,n,r;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:(o=e.apiHost)!=null?o:"https://uniform.app",apiKey:(s=e.apiKey)!=null?s:null,projectId:(i=e.projectId)!=null?i:null,bearerToken:(n=e.bearerToken)!=null?n:null,limitPolicy:(r=e.limitPolicy)!=null?r:h({})}}async getCompositionList(e){let{projectId:t}=this.options,o=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(o)}async getCompositionBySlug(e){let{projectId:t}=this.options,o=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(o)}async getCompositionById(e){let{projectId:t}=this.options,o=this.createUrl("/api/v1/canvas",{...e,projectId:t});return await this.apiClient(o)}async updateComposition(e){let t=this.createUrl("/api/v1/canvas");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComposition(e){let t=this.createUrl("/api/v1/canvas");await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async getComponentDefinitions(e){let{projectId:t}=this.options,o=this.createUrl("/api/v1/canvas-definitions",{...e,projectId:t});return await this.apiClient(o)}async updateComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"PUT",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async removeComponentDefinition(e){let t=this.createUrl("/api/v1/canvas-definitions");await this.apiClient(t,{method:"DELETE",body:JSON.stringify({...e,projectId:this.options.projectId}),expectNoContent:!0})}async apiClient(e,t){return this.options.limitPolicy(async()=>{var i;let o=this.options.apiKey?{"x-api-key":this.options.apiKey}:{Authorization:`Bearer ${this.options.bearerToken}`},s=await this.options.fetch(e.toString(),{...t,headers:{...t==null?void 0:t.headers,...o}});if(!s.ok){let n="";try{let r=await s.text();try{let c=JSON.parse(r);c.errorMessage?n=Array.isArray(c.errorMessage)?c.errorMessage.join(", "):c.errorMessage:n=r}catch(c){n=r}}catch(r){n="General error"}throw new a(n,(i=t==null?void 0:t.method)!=null?i:"GET",e.toString(),s.status)}return(t==null?void 0:t.expectNoContent)?null:await s.json()})}createUrl(e,t){let o=new URL(`${this.options.apiHost}${e}`);return Object.entries(t!=null?t:{}).forEach(([s,i])=>{var n;typeof i!==void 0&&i!==null&&o.searchParams.append(s,(n=i==null?void 0:i.toString())!=null?n:"")}),o}};var g="$personalization",S="$test",w="$localization",N="intentTag",E="locale",j="pz",x="test",b="localized",U=0,_=64;export{h as a,P as b,a as c,A as d,g as e,S as f,w as g,N as h,E as i,j,x as k,b as l,U as m,_ as n};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { UniformCLIPlugin } from '@uniformdev/cli';
|
2
|
+
import { o as ComponentDefinition, d as CompositionAPIResponse } from '../createEventBus-39df132f';
|
3
|
+
import 'pusher-js';
|
4
|
+
|
5
|
+
declare type CanvasPackage = {
|
6
|
+
components?: Array<ComponentDefinition>;
|
7
|
+
compositions?: Array<CompositionAPIResponse>;
|
8
|
+
};
|
9
|
+
declare function readCanvasPackage(filename: string, assertExists: boolean): CanvasPackage;
|
10
|
+
declare function writeCanvasPackage(filename: string, packageContents: CanvasPackage): void;
|
11
|
+
|
12
|
+
declare const uniformCLI: UniformCLIPlugin;
|
13
|
+
|
14
|
+
export { CanvasPackage, readCanvasPackage, uniformCLI, writeCanvasPackage };
|
package/dist/cli/cli.js
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
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})},Ye=(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=>Ye(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:()=>w,uniformCLI:()=>qe,writeCanvasPackage:()=>G});var Ve=m(require("yargs"));var je=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}
|
2
|
+
${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 n,i,r,a,s;if(!t.apiKey&&!t.bearerToken)throw new Error("You must provide an API key or a bearer token");let o=t.fetch;if(!o)if(typeof window!="undefined")o=window.fetch.bind(window);else if(typeof fetch!="undefined")o=fetch;else throw new Error("You must provide or polyfill a fetch implementation when not in a browser");this.options={...t,fetch:o,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 j(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 Y(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*q(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=>j(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=>j(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.
|
3
|
+
${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=q(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=`
|
4
|
+
`+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 w(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=w(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=w(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")),we={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(we).demandCommand(),handler:()=>je.default.help()};var Fe=m(require("yargs"));var De=m(require("isomorphic-unfetch")),Ee={command:"get <id>",describe:"Fetch a composition",builder:e=>j(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=Y(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=>j(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=q(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:Y(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=w(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=w(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 qe={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});
|
package/dist/cli/cli.mjs
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
import{d as p,m as Y,n as V}from"../chunk-FS5XXLSV.mjs";import We from"yargs";import xe from"yargs";import{dump as le,load as fe}from"js-yaml";import{writeFileSync as ge}from"fs";import{extname as B}from"path";import{readFileSync as ue}from"fs";import ye from"p-limit";function f(e){var o,t;return e.option("apiKey",{describe:"Uniform API key. Defaults to CANVAS_CLI_API_KEY or UNIFORM_API_KEY env. Supports dotenv.",default:(t=(o=process.env.CANVAS_CLI_API_KEY)!=null?o:process.env.UPM_CLI_API_KEY)!=null?t: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 g(e){var o,t;return e.option("project",{describe:"Uniform project ID. Defaults to CANVAS_CLI_PROJECT_ID or UNIFORM_PROJECT_ID env. Supports dotenv.",default:(t=(o=process.env.CANVAS_CLI_PROJECT_ID)!=null?o:process.env.UPM_CLI_PROJECT_ID)!=null?t:process.env.UNIFORM_PROJECT_ID,demandOption:!0,type:"string",alias:["p"]})}function O(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 D(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 P(e){let o=B(e);return o===".yaml"||o===".yml"||o===".json"}function j(e,o,t){let n;if(t&&!o){let i=B(t);i===".yaml"||i===".yml"?o="yaml":i===".json"&&(o="json")}else if(!o)throw new Error("Format must be specified when no filename is passed");switch(o){case"json":n=JSON.stringify(e,null,2);break;case"yaml":n=le(e);break;default:throw new Error(`Unsupported format: ${o}`)}t?ge(t,n,"utf8"):console.log(n)}function v(e){let o=ue(e,"utf8");return fe(o,{filename:e,json:!0})}function G(e){let o={...e};return delete o.projectId,delete o.state,o}function w(e){return e.option("state",{type:"string",describe:"Composition state to fetch.",choices:["preview","published"],default:"preview"})}async function*J(e,o){let t=o.pageSize||100,n=0,i=[];do{i=await e(n,t);for(let s of i)yield s;n+=t}while(i.length===t)}function E(e){let o=Number(e);if(!isNaN(o))return o;if(!e)return V;if(typeof e!="string")throw new Error('state must be "published", "preview", or a number');return e==="preview"?Y:V}var I=ye(8);import Ce from"isomorphic-unfetch";var q={command:"get <id>",describe:"Fetch a component definition",builder:e=>O(f(g(e.positional("id",{demandOption:!0,describe:"Component definition public ID to fetch"})))),handler:async({apiHost:e,apiKey:o,id:t,format:n,project:i,filename:s})=>{let r=await new p({apiKey:o,apiHost:e,fetch:Ce,projectId:i}).getComponentDefinitions({componentId:t,limit:1});r.componentDefinitions.length===0?(console.error("Component did not exist"),process.exit(1)):j(r.componentDefinitions[0],n,s)}};import be from"isomorphic-unfetch";var Q={command:"list",describe:"List component definitions",aliases:["ls"],builder:e=>O(f(g(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:o,limit:t,offset:n,format:i,filename:s,project:c})=>{let a=await new p({apiKey:o,apiHost:e,fetch:be,projectId:c}).getComponentDefinitions({limit:t,offset:n});j(a.componentDefinitions,i,s)}};import Ee from"isomorphic-unfetch";import{diffJson as Ae,diffLines as X}from"diff";import he from"lodash.isequalwith";async function M({source:e,target:o,compareContents:t=(r,a)=>he(r.object,a.object,(m,y,C)=>C==="created"||C==="updated"?!0:void 0),mode:n,allowEmptySource:i=!1,whatIf:s=!1,log:c=()=>{}}){var y,C;let r=new Map;for await(let u of o.objects)r.set(u.id,u);let a=[],m=!1;for await(let u of e.objects){m=!0;let b=u.id,S=r.get(b);if(S){if(!t(u,S)&&(n==="createOrUpdate"||n==="mirror")){let h=async(A,$)=>{var W;s||await o.writeObject(A),c({action:"update",id:b,providerId:A.providerId,displayName:(W=A.displayName)!=null?W:A.providerId,whatIf:s,diff:Ae($.object,A.object)})};a.push(h(u,S))}r.delete(b)}else{let h=async(A,$)=>{var W;s||await o.writeObject(A),c({action:"create",id:$,providerId:$,displayName:(W=A.displayName)!=null?W:A.providerId,whatIf:s,diff:X("",JSON.stringify(A.object,null,2))})};a.push(h(u,b))}}if(await Promise.all(a),n==="mirror"){if(!m&&!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 u=[];r.forEach(async b=>{let S=async h=>{var A;s||await o.deleteObject(h.providerId),c({action:"delete",id:h.id,providerId:h.providerId,displayName:(A=h.displayName)!=null?A:h.providerId,whatIf:s,diff:X(JSON.stringify(h.object,null,2),"")})};u.push(S(b))}),await Promise.all(u)}await Promise.all([(y=e.onSyncComplete)==null?void 0:y.call(e,!1),(C=o.onSyncComplete)==null?void 0:C.call(o,!0)])}import Se from"chalk";import{existsSync as je,mkdirSync as we}from"fs";import{readdir as Oe,unlink as De}from"fs/promises";import{extname as Pe,join as Z}from"path";async function T({directory:e,format:o="yaml",selectIdentifier:t,selectDisplayName:n=t}){je(e)||we(e,{recursive:!0});let s=await Oe(e,"utf-8"),c=new Set(s.filter(m=>{let y=Pe(m);return y===".json"||y===".yaml"||y===".yml"})),r=m=>Z(e,`${m}.${o}`);async function*a(){for(let m of c){let y=Z(e,m);try{let C=await v(y);yield{id:t(C),displayName:n(C),providerId:y,object:C}}catch(C){throw console.error(Se.red(`Failed to read ${y}, data is likely invalid.
|
2
|
+
${C==null?void 0:C.message}`)),C}}}return{objects:a(),deleteObject:async m=>{await De(m)},writeObject:async m=>{j(m.object,o,r(m.id))}}}var x=e=>e.id,k=e=>`${e.name} (pid: ${e.id})`;function K({client:e}){async function*o(){let t=J(async(n,i)=>(await e.getComponentDefinitions({limit:i,offset:n})).componentDefinitions,{pageSize:100});for await(let n of t)yield{id:x(n),displayName:k(n),providerId:n.id,object:n}}return{objects:o(),deleteObject:async t=>{await e.removeComponentDefinition({componentId:t})},writeObject:async t=>{await e.updateComponentDefinition({componentDefinition:t.object})}}}import R from"chalk";function F({diffMode:e}){return function({action:t,displayName:n,whatIf:i,diff:s}){let c="";switch(t){case"create":c=R.green("[A]");break;case"update":c=R.white("[U]");break;case"delete":c=R.yellow("[D]");break}let r="";(e==="on"||e==="update"&&t==="update")&&(r=`
|
3
|
+
`+s.map(a=>a.added?R.green(a.value):a.removed?R.red(a.value):a.value).join("")),console.log(`${i?R.gray("[WHATIF]"):""}${c} ${n}${r}`)}}import ve from"fs";function L(e,o){if(!o&&!ve.existsSync(e))return{};let t=v(e);if(typeof t!="object")throw new Error(`Package ${e} does not appear valid.`);return t}function z(e,o){j(o,void 0,e)}async function _({objects:e,selectIdentifier:o,selectDisplayName:t=o,onSyncComplete:n}){let i=e.reduce((r,a)=>{let m=o(a);if(r[m])throw new Error(`Identifier ${m} was not unique.`);return r[m]={id:m,object:a,providerId:m,displayName:t(a)},r},{});async function*s(){for(let r of Object.values(i))yield r}function c(){return Object.entries(i).sort((r,a)=>r[0].localeCompare(a[0])).map(r=>r[1].object)}return{objects:s(),deleteObject:async r=>{delete i[r]},writeObject:async r=>{let a=o(r.object);i[a]=r},extractCurrent:c,onSyncComplete:n?r=>n(r,c()):void 0}}var ee={command:"pull <directory>",describe:"Pulls all component definitions to local files in a directory",builder:e=>f(g(D(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:o,directory:t,format:n,mode:i,whatIf:s,project:c,diff:r})=>{var u;let a=new p({apiKey:o,apiHost:e,fetch:Ee,projectId:c,limitPolicy:I}),m=K({client:a}),y;if(P(t)){let b=L(t,!1);y=await _({objects:(u=b.components)!=null?u:[],selectIdentifier:x,selectDisplayName:k,onSyncComplete:async(S,h)=>{b.components=h,z(t,b)}})}else y=await T({directory:t,selectIdentifier:x,selectDisplayName:k,format:n});await M({source:m,target:y,mode:i,whatIf:s,log:F({diffMode:r})})}};import Ie from"isomorphic-unfetch";var oe={command:"push <directory>",describe:"Pushes all component definitions from files in a directory to Uniform Optimize",builder:e=>f(g(D(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:o,directory:t,mode:n,whatIf:i,project:s,diff:c})=>{var C;let r=new p({apiKey:o,apiHost:e,fetch:Ie,projectId:s,limitPolicy:I}),a;if(P(t)){let u=L(t,!0);a=await _({objects:(C=u.components)!=null?C:[],selectIdentifier:x,selectDisplayName:k})}else a=await T({directory:t,selectIdentifier:x,selectDisplayName:k});let y=K({client:r});await M({source:a,target:y,mode:n,whatIf:i,log:F({diffMode:c})})}};import Me from"isomorphic-unfetch";var te={command:"remove <id>",aliases:["delete","rm"],describe:"Delete a component definition",builder:e=>f(g(e.positional("id",{demandOption:!0,describe:"Component definition public ID to delete"}))),handler:async({apiHost:e,apiKey:o,id:t,project:n})=>{await new p({apiKey:o,apiHost:e,fetch:Me,projectId:n}).removeComponentDefinition({componentId:t})}};import Te from"isomorphic-unfetch";var ne={command:"update <filename>",aliases:["put"],describe:"Insert or update a component definition",builder:e=>f(g(e.positional("filename",{demandOption:!0,describe:"Component definition file to put"}))),handler:async({apiHost:e,apiKey:o,filename:t,project:n})=>{let i=new p({apiKey:o,apiHost:e,fetch:Te,projectId:n}),s=v(t);await i.updateComponentDefinition({componentDefinition:s})}};var ie={command:"component <command>",aliases:["def"],describe:"Commands for Canvas component definitions",builder:e=>e.command(ee).command(oe).command(q).command(te).command(Q).command(ne).demandCommand(),handler:()=>xe.help()};import Re from"yargs";import ke from"isomorphic-unfetch";var re={command:"get <id>",describe:"Fetch a composition",builder:e=>O(f(g(w(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:o,id:t,format:n,filename:i,state:s,project:c,resolvePatterns:r})=>{let a=new p({apiKey:o,apiHost:e,fetch:ke,projectId:c}),m=G(await a.getCompositionById({compositionId:t,state:E(s),skipPatternResolution:!r}));j(m,n,i)}};import Fe from"isomorphic-unfetch";var se={command:"list",describe:"List compositions",aliases:["ls"],builder:e=>O(f(g(w(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:o,limit:t,offset:n,format:i,filename:s,project:c,state:r,resolvePatterns:a})=>{let y=await new p({apiKey:o,apiHost:e,fetch:Fe,projectId:c}).getCompositionList({limit:t,offset:n,state:E(r),skipPatternResolution:!a});j(y.compositions,i,s)}};import Le from"isomorphic-unfetch";var U=e=>e.composition._id,N=e=>{var o,t;return`${(t=(o=e.composition._name)!=null?o:e.composition._slug)!=null?t:e.composition._id} (pid: ${e.composition._id})`};function H({client:e,state:o}){let t=E(o);async function*n(){let i=J(async(s,c)=>(await e.getCompositionList({limit:c,offset:s,state:t,skipPatternResolution:!0})).compositions,{pageSize:100});for await(let s of i)yield{id:U(s),displayName:N(s),providerId:s.composition._id,object:G(s)}}return{objects:n(),deleteObject:async i=>{await e.removeComposition({compositionId:i})},writeObject:async i=>{await e.updateComposition({...i.object,state:t})}}}var ae={command:"pull <directory>",describe:"Pulls all compositions to local files in a directory",builder:e=>f(g(w(D(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:o,directory:t,format:n,mode:i,whatIf:s,state:c,project:r,diff:a})=>{var b;let m=new p({apiKey:o,apiHost:e,fetch:Le,projectId:r,limitPolicy:I}),y=H({client:m,state:c}),C=P(t),u;if(C){let S=L(t,!1);u=await _({objects:(b=S==null?void 0:S.compositions)!=null?b:[],selectIdentifier:U,selectDisplayName:N,onSyncComplete:async(h,A)=>{S.compositions=A,z(t,S)}})}else u=await T({directory:t,selectIdentifier:U,selectDisplayName:N,format:n});await M({source:y,target:u,mode:i,whatIf:s,log:F({diffMode:a})})}};import _e from"isomorphic-unfetch";var ce={command:"push <directory>",describe:"Pushes all compositions from files in a directory to Uniform Optimize",builder:e=>f(g(w(D(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:o,directory:t,mode:n,whatIf:i,state:s,project:c,diff:r})=>{var u;let a=new p({apiKey:o,apiHost:e,fetch:_e,projectId:c,limitPolicy:I}),m;if(P(t)){let b=L(t,!0);m=await _({objects:(u=b.compositions)!=null?u:[],selectIdentifier:U,selectDisplayName:N})}else m=await T({directory:t,selectIdentifier:U,selectDisplayName:N});let C=H({client:a,state:s});await M({source:m,target:C,mode:n,whatIf:i,log:F({diffMode:r})})}};import Ue from"isomorphic-unfetch";var me={command:"remove <id>",aliases:["delete","rm"],describe:"Delete a composition",builder:e=>f(g(e.positional("id",{demandOption:!0,describe:"Composition public ID to delete"}))),handler:async({apiHost:e,apiKey:o,id:t,project:n})=>{await new p({apiKey:o,apiHost:e,fetch:Ue,projectId:n}).removeComposition({compositionId:t})}};import Ne from"isomorphic-unfetch";var pe={command:"update <filename>",aliases:["put"],describe:"Insert or update a composition",builder:e=>f(g(w(e.positional("filename",{demandOption:!0,describe:"Composition file to put"})))),handler:async({apiHost:e,apiKey:o,filename:t,project:n,state:i})=>{let s=new p({apiKey:o,apiHost:e,fetch:Ne,projectId:n}),c=v(t);await s.updateComposition({...c,state:E(i)})}};var de={command:"composition <command>",describe:"Commands for Canvas compositions",aliases:["comp"],builder:e=>e.command(ae).command(ce).command(re).command(me).command(se).command(pe).demandCommand(),handler:()=>{Re.help()}};var Qn={commands:[{command:"canvas <command>",aliases:["cv","pm","presentation"],describe:"Uniform Canvas commands",builder:e=>e.command(de).command(ie).demandCommand(),handler:()=>{We.showHelp()}}]};export{L as readCanvasPackage,Qn as uniformCLI,z as writeCanvasPackage};
|
@@ -0,0 +1,253 @@
|
|
1
|
+
import Pusher from 'pusher-js';
|
2
|
+
|
3
|
+
/** Shape of the GET response from /api/v1/canvas-definitions */
|
4
|
+
declare type ComponentDefinitionAPIResponse = {
|
5
|
+
componentDefinitions: Array<ComponentDefinition>;
|
6
|
+
};
|
7
|
+
/** Shape of the PUT request body for /api/v1/canvas-definitions */
|
8
|
+
declare type ComponentDefinitionAPIPutRequest = {
|
9
|
+
componentDefinition: CreatingComponentDefinition;
|
10
|
+
projectId: string;
|
11
|
+
};
|
12
|
+
/** Shape of the DELETE request body for /api/v1/canvas-definitions */
|
13
|
+
declare type ComponentDefinitionAPIDeleteRequest = {
|
14
|
+
/** Public ID of the component definition to delete */
|
15
|
+
componentId: string;
|
16
|
+
/** Project ID that the component definition lives on */
|
17
|
+
projectId: string;
|
18
|
+
};
|
19
|
+
/** Query parameter options for GET /api/v1/canvas-definitions */
|
20
|
+
declare type ComponentDefinitionListAPIOptions = {
|
21
|
+
/** Limit list to one result by ID (response remains an array) */
|
22
|
+
componentId?: string;
|
23
|
+
/** Number of records to skip */
|
24
|
+
offset?: number;
|
25
|
+
/** Max number of records to return (defaults to 100) */
|
26
|
+
limit?: number;
|
27
|
+
projectId: string;
|
28
|
+
};
|
29
|
+
/** The definition of a component parameter */
|
30
|
+
declare type ComponentDefinitionParameter<TConfig = unknown> = {
|
31
|
+
/** Public ID of the parameter (used in code). Do not change after creation. */
|
32
|
+
id: string;
|
33
|
+
/** Friendly name of the parameter */
|
34
|
+
name: string;
|
35
|
+
/** Type name of the parameter (provided by a Uniform integration) */
|
36
|
+
type: string;
|
37
|
+
/** The configuration object for the type (type-specific) */
|
38
|
+
typeConfig?: TConfig;
|
39
|
+
};
|
40
|
+
/** The definition of a component variant */
|
41
|
+
declare type ComponentDefinitionVariant = {
|
42
|
+
/** Public ID of the variant (used in code). Do not change after creation. */
|
43
|
+
id: string;
|
44
|
+
/** Friendly name of the variant */
|
45
|
+
name: string;
|
46
|
+
};
|
47
|
+
/** The definition of a component slug */
|
48
|
+
declare type ComponentDefinitionSlugSettings = {
|
49
|
+
/**
|
50
|
+
* Is slug required
|
51
|
+
* no: slug is optional
|
52
|
+
* yes: slug is required
|
53
|
+
* disabled: slug is disabled and will not be shown in the editor
|
54
|
+
* @default no
|
55
|
+
*/
|
56
|
+
required?: 'no' | 'yes' | 'disabled';
|
57
|
+
/** Slug uniqueness configuration.
|
58
|
+
* no = no unique constraint
|
59
|
+
* local = must be unique within this component type
|
60
|
+
* global = must be unique across all component types
|
61
|
+
* @default no
|
62
|
+
*/
|
63
|
+
unique?: 'no' | 'local' | 'global';
|
64
|
+
/** Regular expression slugs must match */
|
65
|
+
regularExpression?: string;
|
66
|
+
/**
|
67
|
+
* Custom error message when regular expression validation fails.
|
68
|
+
* Has no effect if `regularExpression` is not set.
|
69
|
+
*/
|
70
|
+
regularExpressionMessage?: string;
|
71
|
+
};
|
72
|
+
/** The definition of a named component slot that can contain other components */
|
73
|
+
declare type ComponentDefinitionSlot = {
|
74
|
+
/** Public ID of the slot (used in code). Do not change after creation. */
|
75
|
+
id: string;
|
76
|
+
/** Friendly name of the slot */
|
77
|
+
name: string;
|
78
|
+
/** Whether this slot inherits its allowed components from the parent slot it lives in. If true, allowedComponents is irrelevant. */
|
79
|
+
inheritAllowedComponents: boolean;
|
80
|
+
/** A list of component definition public IDs that are allowed in this named slot */
|
81
|
+
allowedComponents: Array<string>;
|
82
|
+
/** Minimum valid number of components in this slot */
|
83
|
+
minComponents?: number;
|
84
|
+
/** Maximum valid number of components in this slot */
|
85
|
+
maxComponents?: number;
|
86
|
+
};
|
87
|
+
/** Defines a component type that can live on a Composition */
|
88
|
+
declare type ComponentDefinition = {
|
89
|
+
/** Public ID of the component (used in code). Do not change after creation. */
|
90
|
+
id: string;
|
91
|
+
/** Friendly name of the component definition */
|
92
|
+
name: string;
|
93
|
+
/** Icon name for the component definition (e.g. 'screen') */
|
94
|
+
icon: string;
|
95
|
+
/**
|
96
|
+
* The public ID of the parameter whose value should be used to create a display title for this component in the UI.
|
97
|
+
* The parameter type must support being used as a title parameter for this to work.
|
98
|
+
*/
|
99
|
+
titleParameter?: string | null;
|
100
|
+
/** Whether this component type can be the root of a composition. If false, this component is only used within slots on other components. */
|
101
|
+
canBeComposition?: boolean;
|
102
|
+
/** The parameters for this component. Parameters are key-value pairs that can be anything from text values to links to CMS entries. */
|
103
|
+
parameters?: Array<ComponentDefinitionParameter>;
|
104
|
+
/** The named slots for this component; placement areas where arrays of other components can be added. */
|
105
|
+
slots?: Array<ComponentDefinitionSlot>;
|
106
|
+
/** Named variants for this component; enables creation of visual variants that use the same parameter data/ */
|
107
|
+
variants?: Array<ComponentDefinitionVariant>;
|
108
|
+
/** Setting for slug validation */
|
109
|
+
slugSettings?: ComponentDefinitionSlugSettings;
|
110
|
+
/** Created date string for this definition */
|
111
|
+
created?: string;
|
112
|
+
/** Updated date string for this definition */
|
113
|
+
updated?: string;
|
114
|
+
/** Modified date string for this definition */
|
115
|
+
modified?: string;
|
116
|
+
};
|
117
|
+
/** Defines a component type that can live on a Composition, when it is being created or updated */
|
118
|
+
declare type CreatingComponentDefinition = Omit<Partial<ComponentDefinition>, 'created' | 'modified' | 'id' | 'name'> & {
|
119
|
+
id: string;
|
120
|
+
name: string;
|
121
|
+
};
|
122
|
+
|
123
|
+
/** @deprecated use CANVAS_DRAFT_STATE and CANVAS_PUBLISHED_STATE instead */
|
124
|
+
declare type CompositionFetchState = 'preview' | 'published' | number;
|
125
|
+
/** The GET response from /api/v1/canvas when `component` or `slug` params are specified */
|
126
|
+
declare type CompositionAPIResponse = {
|
127
|
+
/** The state of the layout. See CANVAS_DRAFT_STATE and CANVAS_PUBLISHED_STATE. */
|
128
|
+
state: number;
|
129
|
+
/** The project ID that this layout data is part of */
|
130
|
+
projectId: string;
|
131
|
+
/** Layout data being read or written */
|
132
|
+
composition: RootComponentInstance;
|
133
|
+
/** Whether this composition is a pattern (can be referenced by other compositions) */
|
134
|
+
pattern: boolean;
|
135
|
+
/** Created date string for this definition */
|
136
|
+
created?: string;
|
137
|
+
/** Modified date string for this definition */
|
138
|
+
modified?: string;
|
139
|
+
};
|
140
|
+
/** Shape of the PUT request body for /api/v1/canvas */
|
141
|
+
declare type CompositionAPIPutRequest = Omit<CompositionAPIResponse, 'projectId'> & {
|
142
|
+
projectId: string;
|
143
|
+
};
|
144
|
+
/** Shape of the DELETE request body for /api/v1/canvas */
|
145
|
+
declare type CompositionAPIDeleteRequest = {
|
146
|
+
/** Public ID of the composition to delete */
|
147
|
+
compositionId: string;
|
148
|
+
/** Project ID that the composition lives on. */
|
149
|
+
projectId: string;
|
150
|
+
/** The state to delete. If unspecified, all states will be deleted. See CANVAS_DRAFT_STATE and CANVAS_PUBLISHED_STATE. */
|
151
|
+
state?: number;
|
152
|
+
};
|
153
|
+
/** The GET response from /api/v1/canvas when `component` or `slug` are not specified */
|
154
|
+
declare type CompositionListAPIResponse = {
|
155
|
+
compositions: Array<CompositionAPIResponse>;
|
156
|
+
};
|
157
|
+
/** Query parameter options for GET /api/v1/canvas */
|
158
|
+
declare type CompositionAPIOptions = {
|
159
|
+
/** Specify a single composition ID to fetch. Changes response from list to single. */
|
160
|
+
compositionId?: string;
|
161
|
+
/** Specify a single composition to fetch by slug. Changes response from list to single. */
|
162
|
+
slug?: string;
|
163
|
+
/** The project the composition(s) are on. */
|
164
|
+
projectId: string;
|
165
|
+
/** The component type to filter by */
|
166
|
+
type?: string;
|
167
|
+
/** Number of records to skip */
|
168
|
+
offset?: number;
|
169
|
+
/** Max number of records to return (defaults to 100) */
|
170
|
+
limit?: number;
|
171
|
+
/** State of compositions to fetch. Default = 'published' */
|
172
|
+
state?: number;
|
173
|
+
/**
|
174
|
+
* Signals a Canvas enhancer proxy to skip processing enhancements to the data and return raw data only.
|
175
|
+
* This improves performance if you do not require enhanced component data.
|
176
|
+
* If calling the Canvas API directly with no enhancer proxy, this has no effect.
|
177
|
+
*/
|
178
|
+
skipEnhance?: boolean;
|
179
|
+
/**
|
180
|
+
* If true, any pattern references in the composition will be left unresolved.
|
181
|
+
* This is appropriate if you intend to serialize the composition data without pattern
|
182
|
+
* data embedded into it, and serialize the pattern data separately.
|
183
|
+
*/
|
184
|
+
skipPatternResolution?: boolean;
|
185
|
+
};
|
186
|
+
declare type ComponentParameter<TValue = unknown> = {
|
187
|
+
/** The type of the parameter. Determines how it is displayed when editing, and tells the consumer how to process it. */
|
188
|
+
type: string;
|
189
|
+
/**
|
190
|
+
* The value of the parameter.
|
191
|
+
* Any JSON-serializable value is acceptable.
|
192
|
+
*/
|
193
|
+
value: TValue;
|
194
|
+
};
|
195
|
+
/**
|
196
|
+
* Defines the shape of a component instance served by the composition API.
|
197
|
+
*/
|
198
|
+
declare type ComponentInstance = {
|
199
|
+
/** Type of the component instance (public_id of its definition) */
|
200
|
+
type: string;
|
201
|
+
/** Component parameter values for the component instance */
|
202
|
+
parameters?: Record<string, ComponentParameter>;
|
203
|
+
/** Public ID of alternate visual appearance for this component, if any selected */
|
204
|
+
variant?: string;
|
205
|
+
/** Slots containing any sub-components */
|
206
|
+
slots?: Record<string, ComponentInstance[]>;
|
207
|
+
/** Data for the component instance, provided by a component enhancer. Never set in unenhanced data. */
|
208
|
+
data?: Record<string, unknown>;
|
209
|
+
/** Indicates this component instance should be sourced from a pattern library pattern */
|
210
|
+
_pattern?: string;
|
211
|
+
/**
|
212
|
+
* If an error occurs resolving a pattern reference, it is left unresolved and this property is set to indicate why.
|
213
|
+
* CYCLIC: A cyclic pattern graph was detected, which could not be resolved because it would cause an infinite loop.
|
214
|
+
* NOTFOUND: The pattern ID referenced could not be found. It may have been deleted, or not be published yet.
|
215
|
+
*/
|
216
|
+
_patternError?: 'CYCLIC' | 'NOTFOUND';
|
217
|
+
};
|
218
|
+
/** Defines the shape of the root component in a composition */
|
219
|
+
declare type RootComponentInstance = ComponentInstance & {
|
220
|
+
/** The public UUID of the composition. */
|
221
|
+
_id?: string;
|
222
|
+
/** Slug pattern of this component. */
|
223
|
+
_slug?: string | null;
|
224
|
+
/** Friendly name of this component. */
|
225
|
+
_name?: string;
|
226
|
+
};
|
227
|
+
|
228
|
+
/**
|
229
|
+
* Pusher-js is large (80k) and not tree shakable so it is always bundled if directly referenced,
|
230
|
+
* when it's only needed during preview mode. To avoid bundling it for all, we use an old-school
|
231
|
+
* write-a-script-tag hack to load it in a poor man's approximation of a dynamic import ;)
|
232
|
+
*/
|
233
|
+
declare type ChannelSubscription = {
|
234
|
+
addEventHandler: (eventName: string, handler: (data: unknown) => void) => () => void;
|
235
|
+
unsubscribe: () => void;
|
236
|
+
};
|
237
|
+
declare type PreviewEventBus = {
|
238
|
+
subscribe: (channel: string) => ChannelSubscription;
|
239
|
+
};
|
240
|
+
declare global {
|
241
|
+
interface Window {
|
242
|
+
Pusher?: typeof Pusher;
|
243
|
+
__UNIFORM_EVENT_BUS__?: PreviewEventBus;
|
244
|
+
}
|
245
|
+
}
|
246
|
+
/**
|
247
|
+
* Creates an event bus client to receive updates from Canvas
|
248
|
+
* IMPORTANT: in a server-side context this will always return undefined
|
249
|
+
* IMPORTANT: in a browser context this is cached in window and does not create multiple instances
|
250
|
+
*/
|
251
|
+
declare function createEventBus(): Promise<PreviewEventBus | undefined>;
|
252
|
+
|
253
|
+
export { ComponentInstance as C, PreviewEventBus as P, RootComponentInstance as R, ComponentParameter as a, CompositionAPIOptions as b, CompositionListAPIResponse as c, CompositionAPIResponse as d, CompositionAPIPutRequest as e, CompositionAPIDeleteRequest as f, ComponentDefinitionListAPIOptions as g, ComponentDefinitionAPIResponse as h, ComponentDefinitionAPIPutRequest as i, ComponentDefinitionAPIDeleteRequest as j, ComponentDefinitionParameter as k, ComponentDefinitionVariant as l, ComponentDefinitionSlugSettings as m, ComponentDefinitionSlot as n, ComponentDefinition as o, CreatingComponentDefinition as p, CompositionFetchState as q, ChannelSubscription as r, createEventBus as s };
|