@spiffcommerce/core 21.9.0-alpha.4 → 21.9.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3179,7 +3179,12 @@ declare class FrameStepHandle extends StepHandle<FrameStepData> {
3179
3179
  private frameService;
3180
3180
  selectVariant(variant: Variant): Promise<void>;
3181
3181
  onFrameDataChanged(callback: (frameData: FrameData$1[]) => void): void;
3182
- selectImage(asset: Asset): void;
3182
+ /**
3183
+ * Updates the image selection inside the frame.
3184
+ * @param asset The asset to use.
3185
+ * @param storeAsOriginal Optional: Store this asset as the original, unmodified version of the image. Default: `true`.
3186
+ */
3187
+ selectImage(asset: Asset, storeAsOriginal?: boolean): void;
3183
3188
  /**
3184
3189
  * Removes the background from an image, stores it in the state, and returns the new asset.
3185
3190
  * @param applyNewAsset Optionally applies the new asset as the current image selection. Default: `true`.
package/dist/index.js CHANGED
@@ -506,7 +506,7 @@ class ea {
506
506
  method: "POST",
507
507
  headers: {
508
508
  Accept: "image/png, application/json",
509
- "x-api-key": "30913dbd5df6e6ea74faeb1d064865ce7e727ee2"
509
+ "x-api-key": "2a9a611f0a606b8ef163c7836c3ce7e083bb504b"
510
510
  },
511
511
  body: A
512
512
  });
@@ -11090,13 +11090,23 @@ class Yi extends W {
11090
11090
  t && e(t);
11091
11091
  });
11092
11092
  }
11093
- selectImage(e) {
11093
+ /**
11094
+ * Updates the image selection inside the frame.
11095
+ * @param asset The asset to use.
11096
+ * @param storeAsOriginal Optional: Store this asset as the original, unmodified version of the image. Default: `true`.
11097
+ */
11098
+ selectImage(e, t = !0) {
11094
11099
  var A;
11095
- De.selectImage(this.step, e, this.manager);
11096
- const t = ((A = this.manager.getStepStorage(this.step.stepName)) == null ? void 0 : A.framePatternData) || {};
11097
- this.manager.updateStorage(this.step.stepName, {
11098
- framePatternData: { ...t, originalAssetKey: e.key }
11099
- });
11100
+ if (De.selectImage(this.step, e, this.manager), t) {
11101
+ const a = ((A = this.manager.getStepStorage(this.step.stepName)) == null ? void 0 : A.framePatternData) || {};
11102
+ this.manager.updateStorage(this.step.stepName, {
11103
+ framePatternData: {
11104
+ ...a,
11105
+ originalAssetKey: e.key,
11106
+ backgroundRemovedAssetKey: void 0
11107
+ }
11108
+ });
11109
+ }
11100
11110
  }
11101
11111
  /**
11102
11112
  * Removes the background from an image, stores it in the state, and returns the new asset.
@@ -95,7 +95,7 @@
95
95
  }
96
96
  }
97
97
  }
98
- `,gt=async c=>(await N.getShadowGraphqlClient().query({query:mA,errorPolicy:"all",fetchPolicy:"no-cache",variables:{keys:c}})).data.assets,DA=async c=>(await N.getShadowGraphqlClient().query({query:IA,errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:c}})).data.materials,pA=async(c,e,t,A,n)=>{var i;return(i=(await N.getShadowGraphqlClient().mutate({mutation:fA,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:c,type:e,mimeType:t,anonymous:A,temporary:n}})).data)==null?void 0:i.assetCreate},FA=(c,e)=>{const t=atob(c),A=[];for(let n=0;n<t.length;n++)A.push(t.charCodeAt(n));return new Blob([new Uint8Array(A)],{type:e})};class MA{constructor(){this.cache=new Map,this.bgrmCache=new Map,this.materialCache=new Map,this.loadImageAsFileInfo=async e=>{const t=await e.arrayBuffer();return{name:e.name.substring(e.name.lastIndexOf("/")+1),blob:new Blob([t],{type:e.type})}}}async getLocalOrFromServer(e){if(this.cache.has(e)){const n=this.cache.get(e);if(!n)throw new k("Failed to get asset from cache!");return n}const A=(async()=>(await gt([e]))[0])();return this.cache.set(e,A),A}cacheAsset(e){if(!e.key)throw new k("Asset has no key!");this.cache.has(e.key)||this.cache.set(e.key,Promise.resolve(e))}cacheMaterial(e){if(!e.id)throw new k("Material has no id!");this.materialCache.has(e.id)||this.materialCache.set(e.id,Promise.resolve(e))}async getMaterialLocalOrFromServer(e){if(this.materialCache.has(e))return this.materialCache.get(e);const A=(async()=>(await DA([e]))[0])();return this.materialCache.set(e,A),A}async uploadAssetWithProgress(e,t,A,n,a){const i=await this.dispatchCreateAssetRequest(e,t,n,a);if(!i)throw new Error("Failed to create asset.");return await new Promise((o,s)=>{const r=new XMLHttpRequest;r.open("PUT",i.assetResponse.uploadUrl,!0),r.setRequestHeader("Content-Type",i.mimeType),r.setRequestHeader("Cache-Control","public,max-age=31536000,immutable"),r.upload.onprogress=l=>{l.lengthComputable&&A(l.loaded*100/l.total)},r.onload=()=>{const l=i.assetResponse.asset;He.add(i.assetResponse.asset),o(l)},r.onerror=s,r.send(e.blob)}),this.cacheAsset(i.assetResponse.asset),i.assetResponse.asset}async uploadAsset(e,t,A,n){return this.uploadAssetWithProgress(e,t,()=>{},A,n)}async uploadFile(e,t){const A=!(e.type==="image/svg+xml"||e.type==="application/pdf"),n=A?g.AssetType.Image:g.AssetType.Illustration;if(A){const a=await this.loadImageAsFileInfo(e);return await this.uploadAssetWithProgress(a,n,t,!0)}else{const a={name:e.name,blob:new Blob([e],{type:e.type})};return await this.uploadAssetWithProgress(a,n,t,!0)}}async removeBackgroundFromAsset(e){if(this.bgrmCache.has(e.key))return this.bgrmCache.get(e.key);const A=(async()=>{const n=await g.fetchAsArrayBuffer(e.fileLink),a=await this.removeBackground(new Blob([n],{type:e.mimeType})),i={name:e.key+"_removed_bg",blob:a};return this.uploadAsset(i,e.type,!0)})();return this.bgrmCache.set(e.key,A),A}removePersistedAsset(e){He.remove(e)}getPersistedAssets(){return He.list()}async dispatchCreateAssetRequest(e,t,A,n){const a=e.blob.type?e.blob.type:this.guessMIME(e.name),i=await pA(e.name,t,a,A,n);if(i)return{assetResponse:i,mimeType:a}}async removeBackground(e){const t="https://sdk.photoroom.com/v1/segment",A=new FormData;A.append("image_file",e);try{const n=await g.fetch(t,{method:"POST",headers:{Accept:"image/png, application/json","x-api-key":"30913dbd5df6e6ea74faeb1d064865ce7e727ee2"},body:A});if(n.headers.get("Content-Type")==="image/png")return await n.blob();const i=await n.json();if(i.result_b64)return FA(i.result_b64,"image/png");throw new Error("Failed to remove background from file.")}catch(n){throw console.error("Failed to remove background from file"),n}}guessMIME(e){const t=e.split(".").pop();switch(t){case"glb":return"model/gltf-binary";case"ttf":return"font/ttf";case"mkv":return"video/x-matroska";default:throw new k("Unexpected mimetype: "+t)}}}const re="persistentAssets";class He{static add(e){if(!e.fileLink){console.error("Failed to find cdn link on asset, cannot persist!");return}const t=new Map;t.set(e.key||"",e.fileLink);const A=P.getMap(re);A&&A.forEach((n,a)=>{t.set(a,n)}),P.setMap(re,t)}static remove(e){const t=P.getMap(re);if(!t)return;const A=Array.from(t.entries()).find(n=>n[0]===e);A&&(t.delete(A[0]),P.setMap(re,t))}static list(){const e=P.getMap(re);return e?Array.from(e.entries()).map(t=>({assetKey:t[0],src:t[1]})):[]}}const v=new MA;class yA{constructor(){this.cache={},this.disabled=!1}get(e){if(this.disabled)return;const t=JSON.stringify(e);return this.cache[t]}set(e,t){if(this.disabled)return t;const A=JSON.stringify(e);return this.cache[A]=t,t}disable(e){this.disabled=e}}const Z=new yA,lt=M.gql`
98
+ `,gt=async c=>(await N.getShadowGraphqlClient().query({query:mA,errorPolicy:"all",fetchPolicy:"no-cache",variables:{keys:c}})).data.assets,DA=async c=>(await N.getShadowGraphqlClient().query({query:IA,errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:c}})).data.materials,pA=async(c,e,t,A,n)=>{var i;return(i=(await N.getShadowGraphqlClient().mutate({mutation:fA,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:c,type:e,mimeType:t,anonymous:A,temporary:n}})).data)==null?void 0:i.assetCreate},FA=(c,e)=>{const t=atob(c),A=[];for(let n=0;n<t.length;n++)A.push(t.charCodeAt(n));return new Blob([new Uint8Array(A)],{type:e})};class MA{constructor(){this.cache=new Map,this.bgrmCache=new Map,this.materialCache=new Map,this.loadImageAsFileInfo=async e=>{const t=await e.arrayBuffer();return{name:e.name.substring(e.name.lastIndexOf("/")+1),blob:new Blob([t],{type:e.type})}}}async getLocalOrFromServer(e){if(this.cache.has(e)){const n=this.cache.get(e);if(!n)throw new k("Failed to get asset from cache!");return n}const A=(async()=>(await gt([e]))[0])();return this.cache.set(e,A),A}cacheAsset(e){if(!e.key)throw new k("Asset has no key!");this.cache.has(e.key)||this.cache.set(e.key,Promise.resolve(e))}cacheMaterial(e){if(!e.id)throw new k("Material has no id!");this.materialCache.has(e.id)||this.materialCache.set(e.id,Promise.resolve(e))}async getMaterialLocalOrFromServer(e){if(this.materialCache.has(e))return this.materialCache.get(e);const A=(async()=>(await DA([e]))[0])();return this.materialCache.set(e,A),A}async uploadAssetWithProgress(e,t,A,n,a){const i=await this.dispatchCreateAssetRequest(e,t,n,a);if(!i)throw new Error("Failed to create asset.");return await new Promise((o,s)=>{const r=new XMLHttpRequest;r.open("PUT",i.assetResponse.uploadUrl,!0),r.setRequestHeader("Content-Type",i.mimeType),r.setRequestHeader("Cache-Control","public,max-age=31536000,immutable"),r.upload.onprogress=l=>{l.lengthComputable&&A(l.loaded*100/l.total)},r.onload=()=>{const l=i.assetResponse.asset;He.add(i.assetResponse.asset),o(l)},r.onerror=s,r.send(e.blob)}),this.cacheAsset(i.assetResponse.asset),i.assetResponse.asset}async uploadAsset(e,t,A,n){return this.uploadAssetWithProgress(e,t,()=>{},A,n)}async uploadFile(e,t){const A=!(e.type==="image/svg+xml"||e.type==="application/pdf"),n=A?g.AssetType.Image:g.AssetType.Illustration;if(A){const a=await this.loadImageAsFileInfo(e);return await this.uploadAssetWithProgress(a,n,t,!0)}else{const a={name:e.name,blob:new Blob([e],{type:e.type})};return await this.uploadAssetWithProgress(a,n,t,!0)}}async removeBackgroundFromAsset(e){if(this.bgrmCache.has(e.key))return this.bgrmCache.get(e.key);const A=(async()=>{const n=await g.fetchAsArrayBuffer(e.fileLink),a=await this.removeBackground(new Blob([n],{type:e.mimeType})),i={name:e.key+"_removed_bg",blob:a};return this.uploadAsset(i,e.type,!0)})();return this.bgrmCache.set(e.key,A),A}removePersistedAsset(e){He.remove(e)}getPersistedAssets(){return He.list()}async dispatchCreateAssetRequest(e,t,A,n){const a=e.blob.type?e.blob.type:this.guessMIME(e.name),i=await pA(e.name,t,a,A,n);if(i)return{assetResponse:i,mimeType:a}}async removeBackground(e){const t="https://sdk.photoroom.com/v1/segment",A=new FormData;A.append("image_file",e);try{const n=await g.fetch(t,{method:"POST",headers:{Accept:"image/png, application/json","x-api-key":"2a9a611f0a606b8ef163c7836c3ce7e083bb504b"},body:A});if(n.headers.get("Content-Type")==="image/png")return await n.blob();const i=await n.json();if(i.result_b64)return FA(i.result_b64,"image/png");throw new Error("Failed to remove background from file.")}catch(n){throw console.error("Failed to remove background from file"),n}}guessMIME(e){const t=e.split(".").pop();switch(t){case"glb":return"model/gltf-binary";case"ttf":return"font/ttf";case"mkv":return"video/x-matroska";default:throw new k("Unexpected mimetype: "+t)}}}const re="persistentAssets";class He{static add(e){if(!e.fileLink){console.error("Failed to find cdn link on asset, cannot persist!");return}const t=new Map;t.set(e.key||"",e.fileLink);const A=P.getMap(re);A&&A.forEach((n,a)=>{t.set(a,n)}),P.setMap(re,t)}static remove(e){const t=P.getMap(re);if(!t)return;const A=Array.from(t.entries()).find(n=>n[0]===e);A&&(t.delete(A[0]),P.setMap(re,t))}static list(){const e=P.getMap(re);return e?Array.from(e.entries()).map(t=>({assetKey:t[0],src:t[1]})):[]}}const v=new MA;class yA{constructor(){this.cache={},this.disabled=!1}get(e){if(this.disabled)return;const t=JSON.stringify(e);return this.cache[t]}set(e,t){if(this.disabled)return t;const A=JSON.stringify(e);return this.cache[A]=t,t}disable(e){this.disabled=e}}const Z=new yA,lt=M.gql`
99
99
  fragment OptionFields on Option {
100
100
  id
101
101
  name
@@ -3023,4 +3023,4 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
3023
3023
  }
3024
3024
  }
3025
3025
  }
3026
- `,ne=async c=>{var e;for(const t in c.layouts){const A=c.layouts[t].elements.filter(a=>a.type===g.LayoutElementType.Illustration);for(let a=0;a<A.length;++a){const i=A[a];i.src&&i.svg&&(i.cachedObjectURL=await g.svgObjectURL(i.svg))}const n=c.layouts[t].elements.filter(a=>a.type===g.LayoutElementType.Textbox);for(let a=0;a<n.length;++a){const i=n[a];(e=i.fontData)!=null&&e.assetUrl&&await g.loadFont(i.fontData.assetUrl)}}},fa=async(c,e)=>{var n;const t=await N.getShadowGraphqlClient().query({query:Ba(((n=e==null?void 0:e.assets)==null?void 0:n.metadata)||!1),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:c}}),A=t.data.workflows;if(A===void 0||A.length!==c.length)throw new Error(`Unable to read workflows: ${t.errors??"Length mismatch in response"}`);return A.forEach(a=>{a.steps.forEach(i=>{var o,s,r;delete i.data.__typename,(o=i.option)!=null&&o.id&&((s=i.option.defaultVariant)!=null&&s.asset&&v.cacheAsset(i.option.defaultVariant.asset),i.option.colorProfile&&v.cacheAsset(i.option.colorProfile),(r=i.option.variants)==null||r.forEach(l=>{l.asset&&v.cacheAsset(l.asset),l.displayImage&&v.cacheAsset(l.displayImage),l.thumbnail&&v.cacheAsset(l.thumbnail),l.material&&v.cacheMaterial(l.material)}),Z.set({id:i.option.id},Promise.resolve(i.option)))})}),A},Da=async(c,e)=>{const A=(await e).find(n=>n.id===c);if(!A)throw new Error(`Workflow not found: ${c}`);return A},Ze=async(c,e)=>{const t=c.map(o=>Z.get({id:o,options:e})),A=c.filter((o,s)=>t[s]===void 0);if(A.length===0)return Promise.all(t);const n=fa(A,e),a=A.map(o=>Z.set({id:o,options:e},Da(o,n))),i=t.filter(o=>o!==void 0);return await Promise.all(i.concat(a))},Ee=async(c,e)=>(await Ze([c],e))[0],pa=c=>c.sort((e,t)=>e.index-t.index).map(e=>({id:g.generate(),panelId:e.name,name:e.name,index:e.index,createdAt:new Date,updatedAt:new Date,transparentBackground:e.transparentBackground,height:e.height,width:e.width,previewRegion:e.previewRegion,useEditableArea:e.useEditableArea,editableArea:e.editableArea})),$e=(c,e)=>{const t=c.workflowState,A=t?JSON.parse(t):void 0;return A?Object.values(A.layouts).map(n=>n.layout):pa(e.panels)};class sA{constructor(e){this.updateTransactionState=async t=>{try{return N.getShadowGraphqlClient().mutate({...t,mutation:UA})}catch(A){throw console.error(A),new G("Critical - Unable to synchronize workflow state with server.")}},this.initialized=!1,this.options=e,this.options.applicationKey&&wA(this.options.applicationKey)}getAssetManager(){return v}getCurrencyCode(){if(this.currencyCode===void 0)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!hA())throw new Error("Application key required to use Flow Service.");return new aA}async getIntegration(){return(await N.getShadowGraphqlClient().query({query:ha,errorPolicy:"all"})).data.currentIntegration}async authenticateBundleFromLocalStorage(e){var n,a;const t=P.getMap("bundleOwnerIds");if(t!=null&&t.has(e))return Promise.resolve({success:!0,stakeholderType:ce.Owner});const A=P.getMap("bundlePartnerIds")||new Map;if(A.has(e)){const i=A.get(e),s=(P.getMap("partnerCustomerIds")||new Map).get(i);if(s&&await this.authenticateCustomerId(s)){const l=(a=(n=this.customer)==null?void 0:n.bundleStakeholders)==null?void 0:a.find(B=>{var d;return((d=B.bundle)==null?void 0:d.id)===e});if(l)return Promise.resolve({success:!0,stakeholderType:l.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(e){var l,B,d,w,h,C;const t=N.getShadowGraphqlClient(),A=await t.query({query:wa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:e}});if(!A.data.transactions||A.data.transactions.length===0)throw new Error(`Transaction not found: ${e}`);const n=A.data.transactions[0];if(!((B=(l=n.product)==null?void 0:l.partner)==null?void 0:B.id))throw new Error(`Unable to read transaction: ${e}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const i=P.getMap("transactionOwnerIds");if(i!=null&&i.has(e))return Promise.resolve({success:!0,stakeholderType:ce.Owner});const o=P.getMap("transactionCustomerIds");if(o!=null&&o.has(e)){const E=o.get(e);if(E&&await this.authenticateCustomerId(E)){const Q=((w=(d=this.customer)==null?void 0:d.bundleStakeholders)==null?void 0:w.find(F=>{var I,f;return(f=(I=F.bundle)==null?void 0:I.transactions)==null?void 0:f.some(D=>D.id===e)}))||((C=(h=this.customer)==null?void 0:h.stakeholders)==null?void 0:C.find(F=>{var I;return((I=F.transaction)==null?void 0:I.id)===e}));if(Q)return Promise.resolve({success:!0,stakeholderType:Q.type})}}const r=(await t.query({query:Ea,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!r)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:r.overrideTheme,customLogoLink:n.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(e){const t=P.getMap("transactionCustomerIds");t!=null&&t.has(e)&&(t.delete(e),P.setMap("transactionCustomerIds",t))}getStakeholderTypeForTransaction(e){var A,n;const t=(n=(A=this.customer)==null?void 0:A.stakeholders)==null?void 0:n.find(a=>{var i;return((i=a.transaction)==null?void 0:i.id)===e});if(t)return t.type}async getOrCreateCustomer(e){var i;this.customer=void 0;const t=N.getShadowGraphqlClient(),n=(await t.query({query:Ca,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e}})).data.customer;if(!n.id){const s=(i=(await t.mutate({mutation:ua,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:e}}})).data)==null?void 0:i.customerCreate;if(!s)throw new Error("Unable to create customer.");return this.storeCustomer(s),this.customer=s,{customer:s,isAuthenticated:!1}}this.storeCustomer(n);const a=await this.authenticateCustomerId(n.id);return{customer:this.customer||n,isAuthenticated:a}}async authenticateCustomerId(e){var o;const t=N.getShadowGraphqlClient(),A=P.getMap("customerTokens");if(!(A!=null&&A.has(e)))return!1;const n=A.get(e);if(!n)return!1;const i=(o=(await t.mutate({mutation:Qa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data)==null?void 0:o.customerAuthenticate;return i?(this.storeCustomer(i),ct(n),this.customer=i,!0):!1}async generateVerificationCode(e){await N.getShadowGraphqlClient().mutate({mutation:ma,variables:{emailAddress:e}})}async verifyCode(e,t){var a,i;const n=(a=(await N.getShadowGraphqlClient().mutate({mutation:Ia,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e,verificationCode:t}})).data)==null?void 0:a.customerVerifyCode;if(n!=null&&n.loginToken){if(!((i=n.partner)!=null&&i.id))throw new Error(`Unable to find customer: ${e}`);const o=P.getMap("customerTokens")||new Map;return o.set(n.id,n.loginToken),P.setMap("customerTokens",o),this.storeCustomer(n),ct(n.loginToken),this.customer={...n,loginToken:void 0},!0}return!1}async getNewBundle(e,t,A){var s,r,l;const a=(l=(await N.getShadowGraphqlClient().mutate({mutation:zn(((r=(s=A==null?void 0:A.graphql)==null?void 0:s.productCollection)==null?void 0:r.eagerFetchProducts)||!1),variables:{collectionId:e,initialMetadata:t?Object.entries(t).map((B,d)=>({key:B[0],value:B[1]})):void 0},fetchPolicy:"no-cache"})).data)==null?void 0:l.bundleCreate;if(!(a!=null&&a.id))throw new Error("Unable to create bundle");const i=P.getMap("bundlePartnerIds")||new Map;i.set(a.id,a.partner.id),P.setMap("bundlePartnerIds",i);const o=P.getMap("bundleOwnerIds")||new Map;return o.set(a.id,a.bundleOwnerId),P.setMap("bundleOwnerIds",o),new nA(this,a,void 0,void 0,a.bundleOwnerId)}async getExistingBundle(e,t,A,n){var E,m,Q,F,I,f,D,p,y;const a=P.getMap("bundleOwnerIds"),i=a==null?void 0:a.get(e),s=((E=Object.entries(localStorage).find(([S,x])=>S.startsWith("CognitoIdentityServiceProvider")&&S.endsWith("idToken")))==null?void 0:E[0])||"",r=localStorage.getItem(s),l={};r&&(l.Authorization=`Bearer ${r}`);const B={bundleOwnerId:i,...l,...(m=n==null?void 0:n.graphql)==null?void 0:m.additionalHeaders},d=await N.getShadowGraphqlClient().query({query:Jn(((F=(Q=n==null?void 0:n.graphql)==null?void 0:Q.productCollection)==null?void 0:F.eagerFetchProducts)||!1),variables:{id:e},fetchPolicy:"no-cache",context:{headers:B}});if(!((I=d.data)!=null&&I.bundles)||((f=d.data)==null?void 0:f.bundles.length)===0||!((D=d.data)!=null&&D.bundles[0]))throw new Error(`Unable to find bundle: ${e}`);const w=(p=d.data)==null?void 0:p.bundles[0],h=P.getMap("bundlePartnerIds")||new Map;h.set(w.id,w.partner.id),P.setMap("bundlePartnerIds",h);const C=new nA(this,w,t,A,i,{additionalHeaders:(y=n==null?void 0:n.graphql)==null?void 0:y.additionalHeaders});return await C.getInitializationPromise(),C}async getBundleStakeholders(){var a;if(!this.customer)throw new Error("Customer not authenticated.");const e=await N.getShadowGraphqlClient().query({query:On,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!((a=e.data)!=null&&a.customers)||e.data.customers.length===0)throw new Error("Unable to find customer.");const A=e.data.customers[0].bundleStakeholders||[],n=P.getMap("bundlePartnerIds")||new Map;return A.forEach(i=>{var o,s;(o=i.bundle)!=null&&o.id&&((s=i.bundle.partner)!=null&&s.id)&&n.set(i.bundle.id,i.bundle.partner.id)}),P.setMap("bundlePartnerIds",n),A}async getWorkflowExperience(e,t,A,n){var B,d,w,h,C;if(!n)return await this.getWorkflowExperienceDeprecated(e,t,A);const a=async()=>{var m,Q;const E=N.getShadowGraphqlClient();if(n.type==="transaction"){const{transactionId:F,readOnly:I}=n,f=await E.query({query:me,variables:{ids:[F]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!((m=f.data)!=null&&m.transactions)||f.data.transactions.length===0)throw new G("Existing transaction not found.");const D=(Q=f.data)==null?void 0:Q.transactions[0];if(!D.workflowId)throw new G("Existing transaction has no workflow ID.");const p=await Ee(D.workflowId);if(!D.product)throw new G("Failed to load transaction, product not available.");return{transaction:D,workflow:p,readOnly:I}}if(n.type==="integration"||n.type==="external"){const F=async()=>{const p=n.type==="integration"?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},y=await E.mutate({mutation:Et,variables:{...p,workflowId:n.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!y.data||!y.data.transactionCreate)throw new G("Failed to create transaction!");const S=y.data.transactionCreate;if(!S.product)throw new G("Failed to create transaction, product not available.");return S},I=Ee(n.workflowId,n==null?void 0:n.graphql),[f,D]=await Promise.all([F(),I]);return{transaction:f,workflow:D}}throw new G("No workflow ID provided.")},{transaction:i,workflow:o,readOnly:s}=await a();this.currencyCode=(B=i.product.partner)==null?void 0:B.currencyCode;const r={product:i.product,transaction:i,layouts:[],singleVariantsRenderable:(d=n==null?void 0:n.workflowConfiguration)==null?void 0:d.singleVariantsRenderable,stateMutationFunc:s?async()=>{throw new k("State mutation is forbidden in read only mode!")}:async E=>{const Q=(P.getMap("transactionOwnerIds")||new Map).get(i.id)||void 0;return this.updateTransactionState({...E,context:{transactionOwnerId:Q}})},readOnly:s,workflow:o};if(n.type==="transaction"&&i.workflowState){const E=JSON.parse(i.workflowState);r.layouts=Object.values(E.layouts).map(m=>m.layout),await g.rehydrateSerializedLayout(E),await ne(E),r.reloadedState=E}else if(!s&&n.workflowState){const E=JSON.parse(n.workflowState);r.layouts=Object.values(E.layouts).map(m=>m.layout),await g.rehydrateSerializedLayout(E),await ne(E),r.reloadedState=E}else r.layouts=$e(r.transaction,r.workflow);if(r.renderableContextService=new Me(r.layouts),n.previewService?(r.previewService=n.previewService,(w=r.product)!=null&&w.modelUrl&&(r.modelContainer=r.previewService.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))):(r.previewService=A&&A(o),(h=r.product)!=null&&h.modelUrl&&(r.modelContainer=(C=r.previewService)==null?void 0:C.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))),n.type!=="transaction"){const E=P.getMap("transactionOwnerIds")||new Map;E.set(i.id,i.transactionOwnerId),P.setMap("transactionOwnerIds",E)}else r.isReloadedTransaction=!0;this.initialized=!0,this.experienceOptions=r;const l=new we(this,r);return await l.getWorkflowManager().getInitializationPromise(),n.type!=="transaction"&&this.customer&&await l.attachCustomerDetails({email:this.customer.emailAddress}),l}async getWorkflowExperiences(e,t){if(e.length===0)throw new G("No options provided!");const A=N.getShadowGraphqlClient(),n=async f=>{var S,x;if(f.length===0)return[];const D=f.map(Y=>Y.option.transactionId),p=await A.query({query:me,variables:{ids:D},errorPolicy:"all",fetchPolicy:"no-cache"}),y=p.data.transactions;if(y.length!==f.length){const Y=((x=(S=p.errors)==null?void 0:S[0])==null?void 0:x.message)||"Unknown error";throw new G(`Not all transactions were found: ${Y}`)}return y.map((Y,H)=>{var R;return{transaction:Y,workflowId:Y.workflowId,readOnly:((R=f.find(T=>T.option.transactionId===Y.id))==null?void 0:R.option.readOnly)??!1,index:f[H].index}})},a=async f=>{var y,S,x;if(f.length===0)return[];const D=await A.mutate({mutation:HA,variables:{inputs:f.map(Y=>({integrationProductId:Y.option.type==="integration"?Y.option.integrationProductId:void 0,externalIntegrationId:Y.option.type==="external"?Y.option.externalIntegrationId:void 0,externalProductId:Y.option.type==="external"?Y.option.externalProductId:void 0,workflowId:Y.option.workflowId,claim:!0}))},errorPolicy:"all",fetchPolicy:"no-cache"}),p=(y=D.data)==null?void 0:y.transactionCreateMany;if(!p||p.length===0){const Y=((x=(S=D.errors)==null?void 0:S[0])==null?void 0:x.message)||"Unknown error";throw new G(`Failed to create transactions: ${Y}`)}return p.map((Y,H)=>({transaction:Y,workflowId:Y.workflowId,readOnly:!1,index:f[H].index}))},i=e.map((f,D)=>({option:f,index:D})),o=i.filter(f=>f.option.type==="transaction"),s=i.filter(f=>f.option.type==="integration"||f.option.type==="external"),r=it(o,10),l=it(s,10),B=(await Promise.all([...r.map(n),...l.map(a)])).flat(),d=[...new Set(B.map(f=>f.workflowId))],w=await Ze(d,t),h=new Map(w.map(f=>[f.id,f])),C=P.getMap("transactionOwnerIds")||new Map,E=B.map(async f=>{var T;const{transaction:D,workflowId:p,readOnly:y,index:S}=f,x=h.get(p),Y=e[S];!C.get(D.id)&&D.transactionOwnerId&&C.set(D.id,D.transactionOwnerId);const H=C.get(D.id)||void 0,R={product:D.product,transaction:D,layouts:[],singleVariantsRenderable:(T=Y==null?void 0:Y.workflowConfiguration)==null?void 0:T.singleVariantsRenderable,stateMutationFunc:y?async()=>{throw new k("State mutation is forbidden in read only mode!")}:async b=>this.updateTransactionState({...b,context:{transactionOwnerId:H}}),readOnly:y,workflow:x,isReloadedTransaction:Y.type==="transaction"};if(Y.type==="transaction"&&D.workflowState){const b=JSON.parse(D.workflowState);R.layouts=Object.values(b.layouts||{}).map(z=>z.layout),await g.rehydrateSerializedLayout(b),await ne(b),R.reloadedState=b}else if(!y&&Y.workflowState){const b=JSON.parse(Y.workflowState);R.layouts=Object.values(b.layouts||{}).map(z=>z.layout),await g.rehydrateSerializedLayout(b),await ne(b),R.reloadedState=b}else R.layouts=$e(R.transaction,R.workflow);return R.renderableContextService=new Me(R.layouts),R.delayWorkflowStateSync=!0,this.initialized=!0,this.experienceOptions=R,{experienceOptions:R,index:S,options:Y}});P.setMap("transactionOwnerIds",C);const F=(await Promise.all(E)).sort((f,D)=>f.index-D.index).map(async f=>{const{experienceOptions:D,options:p}=f,y=new we(this,D);return await y.getWorkflowManager().getInitializationPromise(),p.type!=="transaction"&&this.customer&&await y.attachCustomerDetails({email:this.customer.emailAddress}),y}),I=await Promise.all(F);return I.forEach(f=>f.getWorkflowManager().setWorkflowStateSyncEnabled(!0)),I}async initFromIntegrationProduct(e){var i;if(e==="")throw new G("No integration product ID provided.");const A=await N.getShadowGraphqlClient().mutate({mutation:Et,variables:{integrationProductId:e,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!A.data||!A.data.transactionCreate)throw new G("Failed to create transaction!");const n=A.data.transactionCreate;if(!n.product)throw new G("Failed to create transaction, product not available.");this.currencyCode=(i=n.product.partner)==null?void 0:i.currencyCode;const a=P.getMap("transactionOwnerIds")||new Map;a.set(n.id,n.transactionOwnerId),P.setMap("transactionOwnerIds",a),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async o=>this.updateTransactionState({...o,context:{transactionOwnerId:n.transactionOwnerId}})},this.initialized=!0}async initFromTransaction(e,t=!1){var o,s,r,l;if(e==="")throw new G("No transaction ID provided.");const A=N.getShadowGraphqlClient(),n=async()=>{var w,h;const d=(w=(await A.query({query:me,variables:{ids:[e]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:w.transactions[0];if(!d)throw new G("Failed to read transaction.");if(!d.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(h=d.product.partner)==null?void 0:h.currencyCode,this.experienceOptions={product:d.product,transaction:d,layouts:[],stateMutationFunc:async()=>{throw new k("State mutation is forbidden in read only mode!")},readOnly:t},this.initialized=!0};if(t)return await n();const a=P.getMap("transactionOwnerIds")||new Map,i=a.get(e);if(i){const d=(o=(await A.query({query:me,variables:{ids:[e]},errorPolicy:"all"})).data)==null?void 0:o.transactions[0];if(!d)throw new G("Failed to read transaction.");if(!d.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(s=d.product.partner)==null?void 0:s.currencyCode,this.experienceOptions={product:d.product,transaction:d,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:i}}),readOnly:t},this.initialized=!0;return}try{const d=(r=(await A.mutate({mutation:RA,variables:{id:e},errorPolicy:"all"})).data)==null?void 0:r.transactionClaim;if(!d)throw new G("Failed to read transaction.");if(!d.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(l=d.product.partner)==null?void 0:l.currencyCode,d.transactionOwnerId&&(a.set(d.id,d.transactionOwnerId),P.setMap("transactionOwnerIds",a)),this.experienceOptions={product:d.product,transaction:d,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:d.transactionOwnerId}}),readOnly:t},this.initialized=!0}catch{throw new G("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(e,t,A){var n,a,i,o;if(!this.initialized||!this.experienceOptions)throw new G("Cannot launch experience: Not initialized.");if(this.experienceOptions.transaction.workflowId){const s=await Ee(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=s,this.experienceOptions.transaction.workflowState){const l=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(l.layouts).map(B=>B.layout),await g.rehydrateSerializedLayout(l),await ne(l),this.experienceOptions.reloadedState=l}this.experienceOptions.previewService=A&&A(s),this.experienceOptions.renderableContextService=new Me(this.experienceOptions.layouts),(n=this.experienceOptions.product)!=null&&n.modelUrl&&(this.experienceOptions.modelContainer=(a=this.experienceOptions.previewService)==null?void 0:a.loadModel({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}));const r=new we(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}if(e){const r=(P.getMap("transactionOwnerIds")||new Map).get(this.experienceOptions.transaction.id),l=N.getShadowGraphqlClient().mutate({mutation:GA,variables:{workflowId:e,id:this.experienceOptions.transaction.id},context:{transactionOwnerId:r}}),B=Ee(e);if(await Promise.all([l,B]),this.experienceOptions.workflow=await B,t){const w=JSON.parse(t);this.experienceOptions.layouts=Object.values(w.layouts).map(h=>h.layout),await g.rehydrateSerializedLayout(w),await ne(w),this.experienceOptions.reloadedState=w}else this.experienceOptions.layouts=$e(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await B),this.experienceOptions.renderableContextService=new Me(this.experienceOptions.layouts),(i=this.experienceOptions.product)!=null&&i.modelUrl&&(this.experienceOptions.modelContainer=(o=this.experienceOptions.previewService)==null?void 0:o.loadModel({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}));const d=new we(this,this.experienceOptions);return await d.getWorkflowManager().getInitializationPromise(),d}throw new G("No workflow ID provided.")}getPreviewService(){var e;return(e=this.experienceOptions)==null?void 0:e.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new G("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new G("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}configureUrls(e,t,A){W.setHubUrl(e),W.setServerUrl(t),W.setServicesApiUrl(A)}storeCustomer(e){const t=P.getMap("partnerCustomerIds")||new Map;t.set(e.partner.id,e.id),P.setMap("partnerCustomerIds",t)}async getIntegrationProductById(e){var a,i;const n=(a=(await N.getShadowGraphqlClient().query({query:kA,variables:{ids:[e]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:a.integrationProducts;if(!n||n.length===0||!((i=n[0])!=null&&i.id))throw new Error("Integration product not found.");return new qe(n[0])}async getIntegrationProductFromExternalIds(e,t){var i;const a=(i=(await N.getShadowGraphqlClient().query({query:bA,variables:{externalProductId:t,externalIntegrationId:e},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:i.integrationProductFromExternalIds;if(!(a!=null&&a.id))throw new Error("Integration product not found.");return new qe(a)}async getIntegrationProduct(e){return e.type==="integration"?this.getIntegrationProductById(e.integrationProductId):this.getIntegrationProductFromExternalIds(e.externalIntegrationId,e.externalProductId)}}class Fa{getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}async reset(){}updateStateWithServer(e){}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(e){}addPoller(e){}addConfirmCallback(e){}addEditedCallback(e){}addElementsCallback(e){}addInformationResultCallback(e){}addInitCallback(e){}addMakingAdjustmentsCallback(e){}addMandatoryCallback(e){}addMetadataCallback(e){}addSelectionCallback(e){}addStepSpecificStorageCallback(e,t){}addStorageCallback(e){}getCommandDispatcher(){return e=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(e){return[]}getSerializedStep(e,t){}getStepSpecificServices(e){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(e){}markUpdateCompleted(e){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}setCurrentAdjustingStepId(e){}setEditedStatus(e,t){}setInformationResults(e){}setMandatoryFulfilled(e,t){}async setSelectionsAndElements(e,t,A){}toggleDesignConfirmed(){}updateMetadata(e,t){}async updateStorage(e,t){}injectIntoPreviewService(e){return Promise.resolve()}ejectFromPreviewService(){}setWorkflowStateSyncEnabled(e){}}var rA=(c=>(c.SelectFrame="SelectFrame",c.SelectImage="SelectImage",c.Position="Position",c))(rA||{});class cA extends j{constructor(e,t){var A;super(e,t),this.frameService=(A=this.manager.getStepSpecificServices(this.getId()))==null?void 0:A.frameService}selectVariant(e){const t=this.manager.getRegionElements(this.step.stepName);return le.selectVariant(this.step,e.getResource(),t,this.manager,A=>this.setUpdateState(A))}onFrameDataChanged(e){this.frameService&&this.frameService.onFrameDataChanged(t=>{t&&e(t)})}selectImage(e){var A;le.selectImage(this.step,e,this.manager);const t=((A=this.manager.getStepStorage(this.step.stepName))==null?void 0:A.framePatternData)||{};this.manager.updateStorage(this.step.stepName,{framePatternData:{...t,originalAssetKey:e.key}})}async removeBackgroundFromImageSelection(e=!0){var a;const t=await this.getOriginalImageSelection();if(!t)throw new Error("You must supply an image selection before attempting to remove the background.");const A=await v.removeBackgroundFromAsset(t);e&&le.selectImage(this.step,A,this.manager);const n=((a=this.manager.getStepStorage(this.step.stepName))==null?void 0:a.framePatternData)||{};return this.manager.updateStorage(this.step.stepName,{framePatternData:{...n,backgroundRemovedAssetKey:A.key,useOriginalAsset:e}}),A}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(e,t,A,n){return n&&n.length>1&&e===void 0?"SelectFrame":t||A||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}async getOriginalImageSelection(){var t,A;const e=(A=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)==null?void 0:A.originalAssetKey;if(e)return v.getLocalOrFromServer(e)}async getBackgroundRemovedImageSelection(){var t,A;const e=(A=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)==null?void 0:A.backgroundRemovedAssetKey;if(e)return v.getLocalOrFromServer(e)}getUseOriginalImageSelection(){var e,t;return((t=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:t.useOriginalAsset)??!1}setUseOriginalImageSelection(e){var A;const t=((A=this.manager.getStepStorage(this.step.stepName))==null?void 0:A.framePatternData)||{};this.manager.updateStorage(this.step.stepName,{framePatternData:{...t,useOriginalAsset:e}})}}Object.defineProperty(u,"AspectType",{enumerable:!0,get:()=>g.AspectType}),Object.defineProperty(u,"AssetType",{enumerable:!0,get:()=>g.AssetType}),Object.defineProperty(u,"BringForwardCommand",{enumerable:!0,get:()=>g.BringForwardCommand}),Object.defineProperty(u,"BringToBackCommand",{enumerable:!0,get:()=>g.BringToBackCommand}),Object.defineProperty(u,"BringToFrontCommand",{enumerable:!0,get:()=>g.BringToFrontCommand}),Object.defineProperty(u,"CanvasCommand",{enumerable:!0,get:()=>g.CanvasCommand}),Object.defineProperty(u,"CommandContext",{enumerable:!0,get:()=>g.CommandContext}),Object.defineProperty(u,"CreateElementCommand",{enumerable:!0,get:()=>g.CreateElementCommand}),Object.defineProperty(u,"CreateLayoutCommand",{enumerable:!0,get:()=>g.CreateLayoutCommand}),Object.defineProperty(u,"DeleteElementCommand",{enumerable:!0,get:()=>g.DeleteElementCommand}),Object.defineProperty(u,"FontAlignmentCommand",{enumerable:!0,get:()=>g.FontAlignmentCommand}),Object.defineProperty(u,"FontColorCommand",{enumerable:!0,get:()=>g.FontColorCommand}),Object.defineProperty(u,"FontSizeCommand",{enumerable:!0,get:()=>g.FontSizeCommand}),Object.defineProperty(u,"FontSourceCommand",{enumerable:!0,get:()=>g.FontSourceCommand}),Object.defineProperty(u,"GroupCommand",{enumerable:!0,get:()=>g.GroupCommand}),Object.defineProperty(u,"LayoutElementFactory",{enumerable:!0,get:()=>g.LayoutElementFactory}),Object.defineProperty(u,"LayoutElementType",{enumerable:!0,get:()=>g.LayoutElementType}),Object.defineProperty(u,"MoveCommand",{enumerable:!0,get:()=>g.MoveCommand}),Object.defineProperty(u,"ResizeCommand",{enumerable:!0,get:()=>g.ResizeCommand}),Object.defineProperty(u,"RotateCommand",{enumerable:!0,get:()=>g.RotateCommand}),Object.defineProperty(u,"SendBackwardsCommand",{enumerable:!0,get:()=>g.SendBackwardsCommand}),Object.defineProperty(u,"StepAspectType",{enumerable:!0,get:()=>g.StepAspectType}),Object.defineProperty(u,"StepType",{enumerable:!0,get:()=>g.StepType}),Object.defineProperty(u,"TextChangeCommand",{enumerable:!0,get:()=>g.TextChangeCommand}),Object.defineProperty(u,"UnitOfMeasurement",{enumerable:!0,get:()=>g.UnitOfMeasurement}),Object.defineProperty(u,"dataUrlFromExternalUrl",{enumerable:!0,get:()=>g.dataUrlFromExternalUrl}),Object.defineProperty(u,"determineCorrectFontSizeAndLines",{enumerable:!0,get:()=>g.determineCorrectFontSizeAndLines}),Object.defineProperty(u,"findElement",{enumerable:!0,get:()=>g.findElement}),Object.defineProperty(u,"frameDataCache",{enumerable:!0,get:()=>g.frameDataCache}),Object.defineProperty(u,"generate",{enumerable:!0,get:()=>g.generate}),Object.defineProperty(u,"generateSVGWithUnknownColors",{enumerable:!0,get:()=>g.generateSVGWithUnknownColors}),Object.defineProperty(u,"getAttributesFromArrayBuffer",{enumerable:!0,get:()=>g.getAttributesFromArrayBuffer}),Object.defineProperty(u,"getAxisAlignedBoundingBox",{enumerable:!0,get:()=>g.getAxisAlignedBoundingBox}),Object.defineProperty(u,"getFrameData",{enumerable:!0,get:()=>g.getFrameData}),Object.defineProperty(u,"getSvgElement",{enumerable:!0,get:()=>g.getSvgElement}),Object.defineProperty(u,"loadFont",{enumerable:!0,get:()=>g.loadFont}),Object.defineProperty(u,"patternImageDataCache",{enumerable:!0,get:()=>g.patternImageDataCache}),Object.defineProperty(u,"registerFetchImplementation",{enumerable:!0,get:()=>g.registerFetchImplementation}),Object.defineProperty(u,"registerWindowImplementation",{enumerable:!0,get:()=>g.registerWindowImplementation}),Object.defineProperty(u,"rehydrateSerializedLayout",{enumerable:!0,get:()=>g.rehydrateSerializedLayout}),Object.defineProperty(u,"setCanvasModule",{enumerable:!0,get:()=>g.setCanvasModule}),u.ArrayInput=ra,u.AssetNotFoundError=V,u.CollectionProduct=Se,u.ColorOptionGlobalPropertyHandle=_t,u.ConversionDataType=ht,u.ConversionLocation=wt,u.FileUploadGlobalPropertyHandle=Zt,u.FlowExecutionNodeResult=he,u.FlowExecutionResult=iA,u.FlowService=aA,u.FrameService=mt,u.FrameStep=rA,u.FrameStepHandle=cA,u.GlobalPropertyHandle=ye,u.IllustrationStepHandle=Ut,u.InformationMessageType=Be,u.InformationStepHandle=Ot,u.IntegrationProduct=qe,u.IntegrationType=dt,u.LayoutNotFoundError=J,u.MaterialStepHandle=Gt,u.MisconfigurationError=se,u.MockWorkflowManager=Fa,u.ModelStepHandle=vt,u.ObjectInput=Xe,u.ObjectInputType=oA,u.OptionGlobalPropertyHandle=Ke,u.OptionNotFoundError=oe,u.ParseError=q,u.PictureStepHandle=kt,u.ProductCameraRig=Bt,u.ProductCollection=eA,u.ProductWorkflow=Ae,u.PromiseCache=Z,u.PromiseQueue=Ue,u.QuestionStepHandle=bt,u.QueueablePromise=Re,u.ResourceNotFoundError=X,u.ShapeStepHandle=Jt,u.SpiffCommerceClient=sA,u.StakeholderType=ce,u.StepHandle=j,u.TextGlobalPropertyHandle=$t,u.TextInput=sa,u.TextStepHandle=Tt,u.Transform=AA,u.TransformCollection=tA,u.UnhandledBehaviorError=k,u.Variant=K,u.WorkflowExperienceEventType=Vt,u.WorkflowExperienceImpl=we,u.assetService=v,u.createDesign=Kt,u.designService=Fe,u.digitalContentStepService=pt,u.frameStepService=le,u.generateCommands=Wt,u.generateStateFromDesignInputSteps=kn,u.getBoundedOffsets=Qt,u.getWorkflow=Ee,u.getWorkflows=Ze,u.graphQlManager=N,u.illustrationStepService=de,u.materialStepService=Ge,u.modelStepService=ve,u.moduleStepService=Ft,u.optionService=O,u.persistenceService=P,u.pictureStepService=ke,u.questionStepService=be,u.shapeStepService=te,u.shortenUrl=ft,u.spiffCoreConfiguration=W,u.stepAspectValuesToDesignInputSteps=vn,u.textStepService=L,u.toast=Mt,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
3026
+ `,ne=async c=>{var e;for(const t in c.layouts){const A=c.layouts[t].elements.filter(a=>a.type===g.LayoutElementType.Illustration);for(let a=0;a<A.length;++a){const i=A[a];i.src&&i.svg&&(i.cachedObjectURL=await g.svgObjectURL(i.svg))}const n=c.layouts[t].elements.filter(a=>a.type===g.LayoutElementType.Textbox);for(let a=0;a<n.length;++a){const i=n[a];(e=i.fontData)!=null&&e.assetUrl&&await g.loadFont(i.fontData.assetUrl)}}},fa=async(c,e)=>{var n;const t=await N.getShadowGraphqlClient().query({query:Ba(((n=e==null?void 0:e.assets)==null?void 0:n.metadata)||!1),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:c}}),A=t.data.workflows;if(A===void 0||A.length!==c.length)throw new Error(`Unable to read workflows: ${t.errors??"Length mismatch in response"}`);return A.forEach(a=>{a.steps.forEach(i=>{var o,s,r;delete i.data.__typename,(o=i.option)!=null&&o.id&&((s=i.option.defaultVariant)!=null&&s.asset&&v.cacheAsset(i.option.defaultVariant.asset),i.option.colorProfile&&v.cacheAsset(i.option.colorProfile),(r=i.option.variants)==null||r.forEach(l=>{l.asset&&v.cacheAsset(l.asset),l.displayImage&&v.cacheAsset(l.displayImage),l.thumbnail&&v.cacheAsset(l.thumbnail),l.material&&v.cacheMaterial(l.material)}),Z.set({id:i.option.id},Promise.resolve(i.option)))})}),A},Da=async(c,e)=>{const A=(await e).find(n=>n.id===c);if(!A)throw new Error(`Workflow not found: ${c}`);return A},Ze=async(c,e)=>{const t=c.map(o=>Z.get({id:o,options:e})),A=c.filter((o,s)=>t[s]===void 0);if(A.length===0)return Promise.all(t);const n=fa(A,e),a=A.map(o=>Z.set({id:o,options:e},Da(o,n))),i=t.filter(o=>o!==void 0);return await Promise.all(i.concat(a))},Ee=async(c,e)=>(await Ze([c],e))[0],pa=c=>c.sort((e,t)=>e.index-t.index).map(e=>({id:g.generate(),panelId:e.name,name:e.name,index:e.index,createdAt:new Date,updatedAt:new Date,transparentBackground:e.transparentBackground,height:e.height,width:e.width,previewRegion:e.previewRegion,useEditableArea:e.useEditableArea,editableArea:e.editableArea})),$e=(c,e)=>{const t=c.workflowState,A=t?JSON.parse(t):void 0;return A?Object.values(A.layouts).map(n=>n.layout):pa(e.panels)};class sA{constructor(e){this.updateTransactionState=async t=>{try{return N.getShadowGraphqlClient().mutate({...t,mutation:UA})}catch(A){throw console.error(A),new G("Critical - Unable to synchronize workflow state with server.")}},this.initialized=!1,this.options=e,this.options.applicationKey&&wA(this.options.applicationKey)}getAssetManager(){return v}getCurrencyCode(){if(this.currencyCode===void 0)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!hA())throw new Error("Application key required to use Flow Service.");return new aA}async getIntegration(){return(await N.getShadowGraphqlClient().query({query:ha,errorPolicy:"all"})).data.currentIntegration}async authenticateBundleFromLocalStorage(e){var n,a;const t=P.getMap("bundleOwnerIds");if(t!=null&&t.has(e))return Promise.resolve({success:!0,stakeholderType:ce.Owner});const A=P.getMap("bundlePartnerIds")||new Map;if(A.has(e)){const i=A.get(e),s=(P.getMap("partnerCustomerIds")||new Map).get(i);if(s&&await this.authenticateCustomerId(s)){const l=(a=(n=this.customer)==null?void 0:n.bundleStakeholders)==null?void 0:a.find(B=>{var d;return((d=B.bundle)==null?void 0:d.id)===e});if(l)return Promise.resolve({success:!0,stakeholderType:l.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(e){var l,B,d,w,h,C;const t=N.getShadowGraphqlClient(),A=await t.query({query:wa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:e}});if(!A.data.transactions||A.data.transactions.length===0)throw new Error(`Transaction not found: ${e}`);const n=A.data.transactions[0];if(!((B=(l=n.product)==null?void 0:l.partner)==null?void 0:B.id))throw new Error(`Unable to read transaction: ${e}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const i=P.getMap("transactionOwnerIds");if(i!=null&&i.has(e))return Promise.resolve({success:!0,stakeholderType:ce.Owner});const o=P.getMap("transactionCustomerIds");if(o!=null&&o.has(e)){const E=o.get(e);if(E&&await this.authenticateCustomerId(E)){const Q=((w=(d=this.customer)==null?void 0:d.bundleStakeholders)==null?void 0:w.find(F=>{var I,f;return(f=(I=F.bundle)==null?void 0:I.transactions)==null?void 0:f.some(D=>D.id===e)}))||((C=(h=this.customer)==null?void 0:h.stakeholders)==null?void 0:C.find(F=>{var I;return((I=F.transaction)==null?void 0:I.id)===e}));if(Q)return Promise.resolve({success:!0,stakeholderType:Q.type})}}const r=(await t.query({query:Ea,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!r)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:r.overrideTheme,customLogoLink:n.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(e){const t=P.getMap("transactionCustomerIds");t!=null&&t.has(e)&&(t.delete(e),P.setMap("transactionCustomerIds",t))}getStakeholderTypeForTransaction(e){var A,n;const t=(n=(A=this.customer)==null?void 0:A.stakeholders)==null?void 0:n.find(a=>{var i;return((i=a.transaction)==null?void 0:i.id)===e});if(t)return t.type}async getOrCreateCustomer(e){var i;this.customer=void 0;const t=N.getShadowGraphqlClient(),n=(await t.query({query:Ca,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e}})).data.customer;if(!n.id){const s=(i=(await t.mutate({mutation:ua,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:e}}})).data)==null?void 0:i.customerCreate;if(!s)throw new Error("Unable to create customer.");return this.storeCustomer(s),this.customer=s,{customer:s,isAuthenticated:!1}}this.storeCustomer(n);const a=await this.authenticateCustomerId(n.id);return{customer:this.customer||n,isAuthenticated:a}}async authenticateCustomerId(e){var o;const t=N.getShadowGraphqlClient(),A=P.getMap("customerTokens");if(!(A!=null&&A.has(e)))return!1;const n=A.get(e);if(!n)return!1;const i=(o=(await t.mutate({mutation:Qa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data)==null?void 0:o.customerAuthenticate;return i?(this.storeCustomer(i),ct(n),this.customer=i,!0):!1}async generateVerificationCode(e){await N.getShadowGraphqlClient().mutate({mutation:ma,variables:{emailAddress:e}})}async verifyCode(e,t){var a,i;const n=(a=(await N.getShadowGraphqlClient().mutate({mutation:Ia,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e,verificationCode:t}})).data)==null?void 0:a.customerVerifyCode;if(n!=null&&n.loginToken){if(!((i=n.partner)!=null&&i.id))throw new Error(`Unable to find customer: ${e}`);const o=P.getMap("customerTokens")||new Map;return o.set(n.id,n.loginToken),P.setMap("customerTokens",o),this.storeCustomer(n),ct(n.loginToken),this.customer={...n,loginToken:void 0},!0}return!1}async getNewBundle(e,t,A){var s,r,l;const a=(l=(await N.getShadowGraphqlClient().mutate({mutation:zn(((r=(s=A==null?void 0:A.graphql)==null?void 0:s.productCollection)==null?void 0:r.eagerFetchProducts)||!1),variables:{collectionId:e,initialMetadata:t?Object.entries(t).map((B,d)=>({key:B[0],value:B[1]})):void 0},fetchPolicy:"no-cache"})).data)==null?void 0:l.bundleCreate;if(!(a!=null&&a.id))throw new Error("Unable to create bundle");const i=P.getMap("bundlePartnerIds")||new Map;i.set(a.id,a.partner.id),P.setMap("bundlePartnerIds",i);const o=P.getMap("bundleOwnerIds")||new Map;return o.set(a.id,a.bundleOwnerId),P.setMap("bundleOwnerIds",o),new nA(this,a,void 0,void 0,a.bundleOwnerId)}async getExistingBundle(e,t,A,n){var E,m,Q,F,I,f,D,p,y;const a=P.getMap("bundleOwnerIds"),i=a==null?void 0:a.get(e),s=((E=Object.entries(localStorage).find(([S,x])=>S.startsWith("CognitoIdentityServiceProvider")&&S.endsWith("idToken")))==null?void 0:E[0])||"",r=localStorage.getItem(s),l={};r&&(l.Authorization=`Bearer ${r}`);const B={bundleOwnerId:i,...l,...(m=n==null?void 0:n.graphql)==null?void 0:m.additionalHeaders},d=await N.getShadowGraphqlClient().query({query:Jn(((F=(Q=n==null?void 0:n.graphql)==null?void 0:Q.productCollection)==null?void 0:F.eagerFetchProducts)||!1),variables:{id:e},fetchPolicy:"no-cache",context:{headers:B}});if(!((I=d.data)!=null&&I.bundles)||((f=d.data)==null?void 0:f.bundles.length)===0||!((D=d.data)!=null&&D.bundles[0]))throw new Error(`Unable to find bundle: ${e}`);const w=(p=d.data)==null?void 0:p.bundles[0],h=P.getMap("bundlePartnerIds")||new Map;h.set(w.id,w.partner.id),P.setMap("bundlePartnerIds",h);const C=new nA(this,w,t,A,i,{additionalHeaders:(y=n==null?void 0:n.graphql)==null?void 0:y.additionalHeaders});return await C.getInitializationPromise(),C}async getBundleStakeholders(){var a;if(!this.customer)throw new Error("Customer not authenticated.");const e=await N.getShadowGraphqlClient().query({query:On,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!((a=e.data)!=null&&a.customers)||e.data.customers.length===0)throw new Error("Unable to find customer.");const A=e.data.customers[0].bundleStakeholders||[],n=P.getMap("bundlePartnerIds")||new Map;return A.forEach(i=>{var o,s;(o=i.bundle)!=null&&o.id&&((s=i.bundle.partner)!=null&&s.id)&&n.set(i.bundle.id,i.bundle.partner.id)}),P.setMap("bundlePartnerIds",n),A}async getWorkflowExperience(e,t,A,n){var B,d,w,h,C;if(!n)return await this.getWorkflowExperienceDeprecated(e,t,A);const a=async()=>{var m,Q;const E=N.getShadowGraphqlClient();if(n.type==="transaction"){const{transactionId:F,readOnly:I}=n,f=await E.query({query:me,variables:{ids:[F]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!((m=f.data)!=null&&m.transactions)||f.data.transactions.length===0)throw new G("Existing transaction not found.");const D=(Q=f.data)==null?void 0:Q.transactions[0];if(!D.workflowId)throw new G("Existing transaction has no workflow ID.");const p=await Ee(D.workflowId);if(!D.product)throw new G("Failed to load transaction, product not available.");return{transaction:D,workflow:p,readOnly:I}}if(n.type==="integration"||n.type==="external"){const F=async()=>{const p=n.type==="integration"?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},y=await E.mutate({mutation:Et,variables:{...p,workflowId:n.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!y.data||!y.data.transactionCreate)throw new G("Failed to create transaction!");const S=y.data.transactionCreate;if(!S.product)throw new G("Failed to create transaction, product not available.");return S},I=Ee(n.workflowId,n==null?void 0:n.graphql),[f,D]=await Promise.all([F(),I]);return{transaction:f,workflow:D}}throw new G("No workflow ID provided.")},{transaction:i,workflow:o,readOnly:s}=await a();this.currencyCode=(B=i.product.partner)==null?void 0:B.currencyCode;const r={product:i.product,transaction:i,layouts:[],singleVariantsRenderable:(d=n==null?void 0:n.workflowConfiguration)==null?void 0:d.singleVariantsRenderable,stateMutationFunc:s?async()=>{throw new k("State mutation is forbidden in read only mode!")}:async E=>{const Q=(P.getMap("transactionOwnerIds")||new Map).get(i.id)||void 0;return this.updateTransactionState({...E,context:{transactionOwnerId:Q}})},readOnly:s,workflow:o};if(n.type==="transaction"&&i.workflowState){const E=JSON.parse(i.workflowState);r.layouts=Object.values(E.layouts).map(m=>m.layout),await g.rehydrateSerializedLayout(E),await ne(E),r.reloadedState=E}else if(!s&&n.workflowState){const E=JSON.parse(n.workflowState);r.layouts=Object.values(E.layouts).map(m=>m.layout),await g.rehydrateSerializedLayout(E),await ne(E),r.reloadedState=E}else r.layouts=$e(r.transaction,r.workflow);if(r.renderableContextService=new Me(r.layouts),n.previewService?(r.previewService=n.previewService,(w=r.product)!=null&&w.modelUrl&&(r.modelContainer=r.previewService.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))):(r.previewService=A&&A(o),(h=r.product)!=null&&h.modelUrl&&(r.modelContainer=(C=r.previewService)==null?void 0:C.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))),n.type!=="transaction"){const E=P.getMap("transactionOwnerIds")||new Map;E.set(i.id,i.transactionOwnerId),P.setMap("transactionOwnerIds",E)}else r.isReloadedTransaction=!0;this.initialized=!0,this.experienceOptions=r;const l=new we(this,r);return await l.getWorkflowManager().getInitializationPromise(),n.type!=="transaction"&&this.customer&&await l.attachCustomerDetails({email:this.customer.emailAddress}),l}async getWorkflowExperiences(e,t){if(e.length===0)throw new G("No options provided!");const A=N.getShadowGraphqlClient(),n=async f=>{var S,x;if(f.length===0)return[];const D=f.map(Y=>Y.option.transactionId),p=await A.query({query:me,variables:{ids:D},errorPolicy:"all",fetchPolicy:"no-cache"}),y=p.data.transactions;if(y.length!==f.length){const Y=((x=(S=p.errors)==null?void 0:S[0])==null?void 0:x.message)||"Unknown error";throw new G(`Not all transactions were found: ${Y}`)}return y.map((Y,H)=>{var R;return{transaction:Y,workflowId:Y.workflowId,readOnly:((R=f.find(T=>T.option.transactionId===Y.id))==null?void 0:R.option.readOnly)??!1,index:f[H].index}})},a=async f=>{var y,S,x;if(f.length===0)return[];const D=await A.mutate({mutation:HA,variables:{inputs:f.map(Y=>({integrationProductId:Y.option.type==="integration"?Y.option.integrationProductId:void 0,externalIntegrationId:Y.option.type==="external"?Y.option.externalIntegrationId:void 0,externalProductId:Y.option.type==="external"?Y.option.externalProductId:void 0,workflowId:Y.option.workflowId,claim:!0}))},errorPolicy:"all",fetchPolicy:"no-cache"}),p=(y=D.data)==null?void 0:y.transactionCreateMany;if(!p||p.length===0){const Y=((x=(S=D.errors)==null?void 0:S[0])==null?void 0:x.message)||"Unknown error";throw new G(`Failed to create transactions: ${Y}`)}return p.map((Y,H)=>({transaction:Y,workflowId:Y.workflowId,readOnly:!1,index:f[H].index}))},i=e.map((f,D)=>({option:f,index:D})),o=i.filter(f=>f.option.type==="transaction"),s=i.filter(f=>f.option.type==="integration"||f.option.type==="external"),r=it(o,10),l=it(s,10),B=(await Promise.all([...r.map(n),...l.map(a)])).flat(),d=[...new Set(B.map(f=>f.workflowId))],w=await Ze(d,t),h=new Map(w.map(f=>[f.id,f])),C=P.getMap("transactionOwnerIds")||new Map,E=B.map(async f=>{var T;const{transaction:D,workflowId:p,readOnly:y,index:S}=f,x=h.get(p),Y=e[S];!C.get(D.id)&&D.transactionOwnerId&&C.set(D.id,D.transactionOwnerId);const H=C.get(D.id)||void 0,R={product:D.product,transaction:D,layouts:[],singleVariantsRenderable:(T=Y==null?void 0:Y.workflowConfiguration)==null?void 0:T.singleVariantsRenderable,stateMutationFunc:y?async()=>{throw new k("State mutation is forbidden in read only mode!")}:async b=>this.updateTransactionState({...b,context:{transactionOwnerId:H}}),readOnly:y,workflow:x,isReloadedTransaction:Y.type==="transaction"};if(Y.type==="transaction"&&D.workflowState){const b=JSON.parse(D.workflowState);R.layouts=Object.values(b.layouts||{}).map(z=>z.layout),await g.rehydrateSerializedLayout(b),await ne(b),R.reloadedState=b}else if(!y&&Y.workflowState){const b=JSON.parse(Y.workflowState);R.layouts=Object.values(b.layouts||{}).map(z=>z.layout),await g.rehydrateSerializedLayout(b),await ne(b),R.reloadedState=b}else R.layouts=$e(R.transaction,R.workflow);return R.renderableContextService=new Me(R.layouts),R.delayWorkflowStateSync=!0,this.initialized=!0,this.experienceOptions=R,{experienceOptions:R,index:S,options:Y}});P.setMap("transactionOwnerIds",C);const F=(await Promise.all(E)).sort((f,D)=>f.index-D.index).map(async f=>{const{experienceOptions:D,options:p}=f,y=new we(this,D);return await y.getWorkflowManager().getInitializationPromise(),p.type!=="transaction"&&this.customer&&await y.attachCustomerDetails({email:this.customer.emailAddress}),y}),I=await Promise.all(F);return I.forEach(f=>f.getWorkflowManager().setWorkflowStateSyncEnabled(!0)),I}async initFromIntegrationProduct(e){var i;if(e==="")throw new G("No integration product ID provided.");const A=await N.getShadowGraphqlClient().mutate({mutation:Et,variables:{integrationProductId:e,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!A.data||!A.data.transactionCreate)throw new G("Failed to create transaction!");const n=A.data.transactionCreate;if(!n.product)throw new G("Failed to create transaction, product not available.");this.currencyCode=(i=n.product.partner)==null?void 0:i.currencyCode;const a=P.getMap("transactionOwnerIds")||new Map;a.set(n.id,n.transactionOwnerId),P.setMap("transactionOwnerIds",a),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async o=>this.updateTransactionState({...o,context:{transactionOwnerId:n.transactionOwnerId}})},this.initialized=!0}async initFromTransaction(e,t=!1){var o,s,r,l;if(e==="")throw new G("No transaction ID provided.");const A=N.getShadowGraphqlClient(),n=async()=>{var w,h;const d=(w=(await A.query({query:me,variables:{ids:[e]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:w.transactions[0];if(!d)throw new G("Failed to read transaction.");if(!d.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(h=d.product.partner)==null?void 0:h.currencyCode,this.experienceOptions={product:d.product,transaction:d,layouts:[],stateMutationFunc:async()=>{throw new k("State mutation is forbidden in read only mode!")},readOnly:t},this.initialized=!0};if(t)return await n();const a=P.getMap("transactionOwnerIds")||new Map,i=a.get(e);if(i){const d=(o=(await A.query({query:me,variables:{ids:[e]},errorPolicy:"all"})).data)==null?void 0:o.transactions[0];if(!d)throw new G("Failed to read transaction.");if(!d.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(s=d.product.partner)==null?void 0:s.currencyCode,this.experienceOptions={product:d.product,transaction:d,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:i}}),readOnly:t},this.initialized=!0;return}try{const d=(r=(await A.mutate({mutation:RA,variables:{id:e},errorPolicy:"all"})).data)==null?void 0:r.transactionClaim;if(!d)throw new G("Failed to read transaction.");if(!d.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(l=d.product.partner)==null?void 0:l.currencyCode,d.transactionOwnerId&&(a.set(d.id,d.transactionOwnerId),P.setMap("transactionOwnerIds",a)),this.experienceOptions={product:d.product,transaction:d,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:d.transactionOwnerId}}),readOnly:t},this.initialized=!0}catch{throw new G("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(e,t,A){var n,a,i,o;if(!this.initialized||!this.experienceOptions)throw new G("Cannot launch experience: Not initialized.");if(this.experienceOptions.transaction.workflowId){const s=await Ee(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=s,this.experienceOptions.transaction.workflowState){const l=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(l.layouts).map(B=>B.layout),await g.rehydrateSerializedLayout(l),await ne(l),this.experienceOptions.reloadedState=l}this.experienceOptions.previewService=A&&A(s),this.experienceOptions.renderableContextService=new Me(this.experienceOptions.layouts),(n=this.experienceOptions.product)!=null&&n.modelUrl&&(this.experienceOptions.modelContainer=(a=this.experienceOptions.previewService)==null?void 0:a.loadModel({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}));const r=new we(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}if(e){const r=(P.getMap("transactionOwnerIds")||new Map).get(this.experienceOptions.transaction.id),l=N.getShadowGraphqlClient().mutate({mutation:GA,variables:{workflowId:e,id:this.experienceOptions.transaction.id},context:{transactionOwnerId:r}}),B=Ee(e);if(await Promise.all([l,B]),this.experienceOptions.workflow=await B,t){const w=JSON.parse(t);this.experienceOptions.layouts=Object.values(w.layouts).map(h=>h.layout),await g.rehydrateSerializedLayout(w),await ne(w),this.experienceOptions.reloadedState=w}else this.experienceOptions.layouts=$e(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await B),this.experienceOptions.renderableContextService=new Me(this.experienceOptions.layouts),(i=this.experienceOptions.product)!=null&&i.modelUrl&&(this.experienceOptions.modelContainer=(o=this.experienceOptions.previewService)==null?void 0:o.loadModel({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}));const d=new we(this,this.experienceOptions);return await d.getWorkflowManager().getInitializationPromise(),d}throw new G("No workflow ID provided.")}getPreviewService(){var e;return(e=this.experienceOptions)==null?void 0:e.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new G("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new G("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}configureUrls(e,t,A){W.setHubUrl(e),W.setServerUrl(t),W.setServicesApiUrl(A)}storeCustomer(e){const t=P.getMap("partnerCustomerIds")||new Map;t.set(e.partner.id,e.id),P.setMap("partnerCustomerIds",t)}async getIntegrationProductById(e){var a,i;const n=(a=(await N.getShadowGraphqlClient().query({query:kA,variables:{ids:[e]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:a.integrationProducts;if(!n||n.length===0||!((i=n[0])!=null&&i.id))throw new Error("Integration product not found.");return new qe(n[0])}async getIntegrationProductFromExternalIds(e,t){var i;const a=(i=(await N.getShadowGraphqlClient().query({query:bA,variables:{externalProductId:t,externalIntegrationId:e},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:i.integrationProductFromExternalIds;if(!(a!=null&&a.id))throw new Error("Integration product not found.");return new qe(a)}async getIntegrationProduct(e){return e.type==="integration"?this.getIntegrationProductById(e.integrationProductId):this.getIntegrationProductFromExternalIds(e.externalIntegrationId,e.externalProductId)}}class Fa{getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}async reset(){}updateStateWithServer(e){}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(e){}addPoller(e){}addConfirmCallback(e){}addEditedCallback(e){}addElementsCallback(e){}addInformationResultCallback(e){}addInitCallback(e){}addMakingAdjustmentsCallback(e){}addMandatoryCallback(e){}addMetadataCallback(e){}addSelectionCallback(e){}addStepSpecificStorageCallback(e,t){}addStorageCallback(e){}getCommandDispatcher(){return e=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(e){return[]}getSerializedStep(e,t){}getStepSpecificServices(e){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(e){}markUpdateCompleted(e){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}setCurrentAdjustingStepId(e){}setEditedStatus(e,t){}setInformationResults(e){}setMandatoryFulfilled(e,t){}async setSelectionsAndElements(e,t,A){}toggleDesignConfirmed(){}updateMetadata(e,t){}async updateStorage(e,t){}injectIntoPreviewService(e){return Promise.resolve()}ejectFromPreviewService(){}setWorkflowStateSyncEnabled(e){}}var rA=(c=>(c.SelectFrame="SelectFrame",c.SelectImage="SelectImage",c.Position="Position",c))(rA||{});class cA extends j{constructor(e,t){var A;super(e,t),this.frameService=(A=this.manager.getStepSpecificServices(this.getId()))==null?void 0:A.frameService}selectVariant(e){const t=this.manager.getRegionElements(this.step.stepName);return le.selectVariant(this.step,e.getResource(),t,this.manager,A=>this.setUpdateState(A))}onFrameDataChanged(e){this.frameService&&this.frameService.onFrameDataChanged(t=>{t&&e(t)})}selectImage(e,t=!0){var A;if(le.selectImage(this.step,e,this.manager),t){const n=((A=this.manager.getStepStorage(this.step.stepName))==null?void 0:A.framePatternData)||{};this.manager.updateStorage(this.step.stepName,{framePatternData:{...n,originalAssetKey:e.key,backgroundRemovedAssetKey:void 0}})}}async removeBackgroundFromImageSelection(e=!0){var a;const t=await this.getOriginalImageSelection();if(!t)throw new Error("You must supply an image selection before attempting to remove the background.");const A=await v.removeBackgroundFromAsset(t);e&&le.selectImage(this.step,A,this.manager);const n=((a=this.manager.getStepStorage(this.step.stepName))==null?void 0:a.framePatternData)||{};return this.manager.updateStorage(this.step.stepName,{framePatternData:{...n,backgroundRemovedAssetKey:A.key,useOriginalAsset:e}}),A}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(e,t,A,n){return n&&n.length>1&&e===void 0?"SelectFrame":t||A||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}async getOriginalImageSelection(){var t,A;const e=(A=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)==null?void 0:A.originalAssetKey;if(e)return v.getLocalOrFromServer(e)}async getBackgroundRemovedImageSelection(){var t,A;const e=(A=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)==null?void 0:A.backgroundRemovedAssetKey;if(e)return v.getLocalOrFromServer(e)}getUseOriginalImageSelection(){var e,t;return((t=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:t.useOriginalAsset)??!1}setUseOriginalImageSelection(e){var A;const t=((A=this.manager.getStepStorage(this.step.stepName))==null?void 0:A.framePatternData)||{};this.manager.updateStorage(this.step.stepName,{framePatternData:{...t,useOriginalAsset:e}})}}Object.defineProperty(u,"AspectType",{enumerable:!0,get:()=>g.AspectType}),Object.defineProperty(u,"AssetType",{enumerable:!0,get:()=>g.AssetType}),Object.defineProperty(u,"BringForwardCommand",{enumerable:!0,get:()=>g.BringForwardCommand}),Object.defineProperty(u,"BringToBackCommand",{enumerable:!0,get:()=>g.BringToBackCommand}),Object.defineProperty(u,"BringToFrontCommand",{enumerable:!0,get:()=>g.BringToFrontCommand}),Object.defineProperty(u,"CanvasCommand",{enumerable:!0,get:()=>g.CanvasCommand}),Object.defineProperty(u,"CommandContext",{enumerable:!0,get:()=>g.CommandContext}),Object.defineProperty(u,"CreateElementCommand",{enumerable:!0,get:()=>g.CreateElementCommand}),Object.defineProperty(u,"CreateLayoutCommand",{enumerable:!0,get:()=>g.CreateLayoutCommand}),Object.defineProperty(u,"DeleteElementCommand",{enumerable:!0,get:()=>g.DeleteElementCommand}),Object.defineProperty(u,"FontAlignmentCommand",{enumerable:!0,get:()=>g.FontAlignmentCommand}),Object.defineProperty(u,"FontColorCommand",{enumerable:!0,get:()=>g.FontColorCommand}),Object.defineProperty(u,"FontSizeCommand",{enumerable:!0,get:()=>g.FontSizeCommand}),Object.defineProperty(u,"FontSourceCommand",{enumerable:!0,get:()=>g.FontSourceCommand}),Object.defineProperty(u,"GroupCommand",{enumerable:!0,get:()=>g.GroupCommand}),Object.defineProperty(u,"LayoutElementFactory",{enumerable:!0,get:()=>g.LayoutElementFactory}),Object.defineProperty(u,"LayoutElementType",{enumerable:!0,get:()=>g.LayoutElementType}),Object.defineProperty(u,"MoveCommand",{enumerable:!0,get:()=>g.MoveCommand}),Object.defineProperty(u,"ResizeCommand",{enumerable:!0,get:()=>g.ResizeCommand}),Object.defineProperty(u,"RotateCommand",{enumerable:!0,get:()=>g.RotateCommand}),Object.defineProperty(u,"SendBackwardsCommand",{enumerable:!0,get:()=>g.SendBackwardsCommand}),Object.defineProperty(u,"StepAspectType",{enumerable:!0,get:()=>g.StepAspectType}),Object.defineProperty(u,"StepType",{enumerable:!0,get:()=>g.StepType}),Object.defineProperty(u,"TextChangeCommand",{enumerable:!0,get:()=>g.TextChangeCommand}),Object.defineProperty(u,"UnitOfMeasurement",{enumerable:!0,get:()=>g.UnitOfMeasurement}),Object.defineProperty(u,"dataUrlFromExternalUrl",{enumerable:!0,get:()=>g.dataUrlFromExternalUrl}),Object.defineProperty(u,"determineCorrectFontSizeAndLines",{enumerable:!0,get:()=>g.determineCorrectFontSizeAndLines}),Object.defineProperty(u,"findElement",{enumerable:!0,get:()=>g.findElement}),Object.defineProperty(u,"frameDataCache",{enumerable:!0,get:()=>g.frameDataCache}),Object.defineProperty(u,"generate",{enumerable:!0,get:()=>g.generate}),Object.defineProperty(u,"generateSVGWithUnknownColors",{enumerable:!0,get:()=>g.generateSVGWithUnknownColors}),Object.defineProperty(u,"getAttributesFromArrayBuffer",{enumerable:!0,get:()=>g.getAttributesFromArrayBuffer}),Object.defineProperty(u,"getAxisAlignedBoundingBox",{enumerable:!0,get:()=>g.getAxisAlignedBoundingBox}),Object.defineProperty(u,"getFrameData",{enumerable:!0,get:()=>g.getFrameData}),Object.defineProperty(u,"getSvgElement",{enumerable:!0,get:()=>g.getSvgElement}),Object.defineProperty(u,"loadFont",{enumerable:!0,get:()=>g.loadFont}),Object.defineProperty(u,"patternImageDataCache",{enumerable:!0,get:()=>g.patternImageDataCache}),Object.defineProperty(u,"registerFetchImplementation",{enumerable:!0,get:()=>g.registerFetchImplementation}),Object.defineProperty(u,"registerWindowImplementation",{enumerable:!0,get:()=>g.registerWindowImplementation}),Object.defineProperty(u,"rehydrateSerializedLayout",{enumerable:!0,get:()=>g.rehydrateSerializedLayout}),Object.defineProperty(u,"setCanvasModule",{enumerable:!0,get:()=>g.setCanvasModule}),u.ArrayInput=ra,u.AssetNotFoundError=V,u.CollectionProduct=Se,u.ColorOptionGlobalPropertyHandle=_t,u.ConversionDataType=ht,u.ConversionLocation=wt,u.FileUploadGlobalPropertyHandle=Zt,u.FlowExecutionNodeResult=he,u.FlowExecutionResult=iA,u.FlowService=aA,u.FrameService=mt,u.FrameStep=rA,u.FrameStepHandle=cA,u.GlobalPropertyHandle=ye,u.IllustrationStepHandle=Ut,u.InformationMessageType=Be,u.InformationStepHandle=Ot,u.IntegrationProduct=qe,u.IntegrationType=dt,u.LayoutNotFoundError=J,u.MaterialStepHandle=Gt,u.MisconfigurationError=se,u.MockWorkflowManager=Fa,u.ModelStepHandle=vt,u.ObjectInput=Xe,u.ObjectInputType=oA,u.OptionGlobalPropertyHandle=Ke,u.OptionNotFoundError=oe,u.ParseError=q,u.PictureStepHandle=kt,u.ProductCameraRig=Bt,u.ProductCollection=eA,u.ProductWorkflow=Ae,u.PromiseCache=Z,u.PromiseQueue=Ue,u.QuestionStepHandle=bt,u.QueueablePromise=Re,u.ResourceNotFoundError=X,u.ShapeStepHandle=Jt,u.SpiffCommerceClient=sA,u.StakeholderType=ce,u.StepHandle=j,u.TextGlobalPropertyHandle=$t,u.TextInput=sa,u.TextStepHandle=Tt,u.Transform=AA,u.TransformCollection=tA,u.UnhandledBehaviorError=k,u.Variant=K,u.WorkflowExperienceEventType=Vt,u.WorkflowExperienceImpl=we,u.assetService=v,u.createDesign=Kt,u.designService=Fe,u.digitalContentStepService=pt,u.frameStepService=le,u.generateCommands=Wt,u.generateStateFromDesignInputSteps=kn,u.getBoundedOffsets=Qt,u.getWorkflow=Ee,u.getWorkflows=Ze,u.graphQlManager=N,u.illustrationStepService=de,u.materialStepService=Ge,u.modelStepService=ve,u.moduleStepService=Ft,u.optionService=O,u.persistenceService=P,u.pictureStepService=ke,u.questionStepService=be,u.shapeStepService=te,u.shortenUrl=ft,u.spiffCoreConfiguration=W,u.stepAspectValuesToDesignInputSteps=vn,u.textStepService=L,u.toast=Mt,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/core",
3
- "version": "21.9.0-alpha.4",
3
+ "version": "21.9.0-alpha.5",
4
4
  "description": "Core client API for interacting with the Spiff Commerce backend.",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.umd.cjs",