@spiffcommerce/core 26.4.0 → 26.4.1

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.js CHANGED
@@ -102,7 +102,7 @@
102
102
  ...AssetFields
103
103
  }
104
104
  }
105
- `,qe=async n=>(await F.getShadowGraphqlClient().query({query:Bi,errorPolicy:"all",variables:{keys:n}})).data.assets,ui=async n=>(await F.getShadowGraphqlClient().query({query:hi,errorPolicy:"all",variables:{ids:n}})).data.materials,Ei=async(n,t,e,A,a)=>{var s;return(s=(await F.getShadowGraphqlClient().mutate({mutation:Ci,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:n,type:t,mimeType:e,anonymous:A,temporary:a}})).data)==null?void 0:s.assetCreate};class mi{constructor(){this.cache=new Map,this.bgrmProcessCache=new Map,this.materialCache=new Map,this.loadImageAsFileInfo=async t=>{const e=await t.arrayBuffer(),A=await Ae(e),a=(i,s)=>{const r=atob(i.split(",")[1]),o=[];for(let c=0;c<r.length;c++)o.push(r.charCodeAt(c));return new Blob([new Uint8Array(o)],{type:s})};return{name:t.name.substring(t.name.lastIndexOf("/")+1),blob:a(A.dataUrl,t.type)}}}async getLocalOrFromServer(t){if(this.cache.has(t)){const a=this.cache.get(t);if(!a)throw new L("Failed to get asset from cache!");return a}const A=(async()=>(await qe([t]))[0])();return this.cache.set(t,A),A}async getFromServer(t){const A=(async()=>(await qe([t]))[0])();return this.cache.set(t,A),A}keyFromURL(t){let e;try{e=new URL(t).pathname}catch{e=void 0}return e!==void 0&&e.startsWith("/")&&(e=e.replace("/","")),e==null?void 0:e.split("?")[0]}cacheAsset(t){if(!t.key)throw new L("Asset has no key!");this.cache.has(t.key)||this.cache.set(t.key,Promise.resolve(t))}cacheMaterial(t){if(!t.id)throw new L("Material has no id!");this.materialCache.has(t.id)||this.materialCache.set(t.id,Promise.resolve(t))}async getMaterialLocalOrFromServer(t){if(this.materialCache.has(t))return this.materialCache.get(t);const A=(async()=>(await ui([t]))[0])();return this.materialCache.set(t,A),A}async uploadAssetWithProgress(t,e,A,a,i){const s=await this.dispatchCreateAssetRequest(t,e,a,i);if(!s)throw new Error("Failed to create asset.");return await new Promise((r,o)=>{const c=new XMLHttpRequest;c.open("PUT",s.assetResponse.uploadUrl,!0),c.setRequestHeader("Content-Type",s.mimeType),c.setRequestHeader("Cache-Control","public,max-age=31536000,immutable"),c.upload.onprogress=l=>{l.lengthComputable&&A(l.loaded*100/l.total)},c.onload=()=>{const l=s.assetResponse.asset;Dt.add(s.assetResponse.asset),r(l)},c.onerror=o,c.send(t.blob)}),this.cacheAsset(s.assetResponse.asset),s.assetResponse.asset}async uploadAsset(t,e,A,a){return this.uploadAssetWithProgress(t,e,()=>{},A,a)}async uploadFile(t,e){const A=!(t.type==="image/svg+xml"||t.type==="application/pdf"||t.type==="application/postscript"),a=A?Kt.Image:Kt.Illustration;if(A){const i=await this.loadImageAsFileInfo(t);return await this.uploadAssetWithProgress(i,a,e,!0)}else{const i={name:t.name,blob:new Blob([t],{type:t.type})};return await this.uploadAssetWithProgress(i,a,e,!0)}}async removeBackgroundFromAsset(t){const e=t.key;if(this.bgrmProcessCache.has(e))return this.bgrmProcessCache.get(e);if(q.has(e)){const i=this.getLocalOrFromServer(q.get(e));return this.bgrmProcessCache.set(e,i),i}const a=(async()=>{var s,r;const i=await F.getShadowGraphqlClient().mutate({mutation:wi,fetchPolicy:"no-cache",errorPolicy:"all",variables:{key:e}});if(this.bgrmProcessCache.delete(e),!((r=(s=i.data)==null?void 0:s.assetRemoveBackground)!=null&&r.key))throw new Error("Failed to remove background from image");return Dt.add(i.data.assetRemoveBackground),q.add(e,i.data.assetRemoveBackground.key),this.cache.set(i.data.assetRemoveBackground.key,Promise.resolve(i.data.assetRemoveBackground)),i.data.assetRemoveBackground})();return this.bgrmProcessCache.set(e,a),a}removePersistedAsset(t){Dt.remove(t),q.delete(t),q.deleteForBgRemovedKey(t)}getPersistedAssets(){return Dt.list()}registerPersistedAssetListener(t){Dt.addCallback(t)}unRegisterPersistedAssetListener(t){Dt.removeCallback(t)}async dispatchCreateAssetRequest(t,e,A,a){const i=t.blob.type?t.blob.type:this.guessMIME(t.name),s=await Ei(t.name,e,i,A,a);if(s)return{assetResponse:s,mimeType:i}}guessMIME(t){const e=t.split(".").pop();switch(e){case"glb":return"model/gltf-binary";case"ttf":return"font/ttf";case"mkv":return"video/x-matroska";default:throw new L("Unexpected mimetype: "+e)}}}const bt="persistentAssets",pa=class ut{static add(t){if(!t.fileLink){console.error("Failed to find cdn link on asset, cannot persist!");return}const e=new Map;e.set(t.key||"",t.fileLink);const A=N.getMap(bt);A&&A.forEach((a,i)=>{e.set(i,a)}),N.setMap(bt,e),ut.executeCallbacks()}static remove(t){const e=N.getMap(bt);if(!e)return;const A=Array.from(e.entries()).find(a=>a[0]===t);A&&(e.delete(A[0]),N.setMap(bt,e),ut.executeCallbacks())}static list(){const t=N.getMap(bt);return t?Array.from(t.entries()).map(e=>({assetKey:e[0],src:e[1]})):[]}static addCallback(t){ut.callbacks.push(t)}static removeCallback(t){ut.callbacks=ut.callbacks.filter(e=>e!==t)}static executeCallbacks(){ut.callbacks.forEach(t=>t())}};pa.callbacks=[];let Dt=pa;const jA="bgrmPersistentAssets";class q{static has(t){return q.getMap().has(t)}static get(t){return q.getMap().get(t)}static keys(){return q.getMap().keys()}static values(){return q.getMap().values()}static add(t,e){const A=q.getMap();A.set(t,e),q.setMap(A)}static delete(t){const e=q.getMap();e.delete(t),q.setMap(e)}static deleteForBgRemovedKey(t){const e=q.getMap(),A=Array.from(e.keys()).find(a=>e.get(a)===t);A&&(e.delete(A),q.setMap(e))}static getMap(){return N.getMap(jA)||new Map}static setMap(t){N.setMap(jA,t)}}const G=new mi;class fi{constructor(){this.cache={},this.disabled=!1}get(t){if(this.disabled)return;const e=JSON.stringify(t);return this.cache[e]}set(t,e){if(this.disabled)return e;const A=JSON.stringify(t);return this.cache[A]=e,e}disable(t){this.disabled=t}}const Nt=new fi,Da=p.gql`
105
+ `,qe=async n=>(await F.getShadowGraphqlClient().query({query:Bi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{keys:n}})).data.assets,ui=async n=>(await F.getShadowGraphqlClient().query({query:hi,errorPolicy:"all",variables:{ids:n}})).data.materials,Ei=async(n,t,e,A,a)=>{var s;return(s=(await F.getShadowGraphqlClient().mutate({mutation:Ci,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:n,type:t,mimeType:e,anonymous:A,temporary:a}})).data)==null?void 0:s.assetCreate};class mi{constructor(){this.cache=new Map,this.bgrmProcessCache=new Map,this.materialCache=new Map,this.loadImageAsFileInfo=async t=>{const e=await t.arrayBuffer(),A=await Ae(e),a=(i,s)=>{const r=atob(i.split(",")[1]),o=[];for(let c=0;c<r.length;c++)o.push(r.charCodeAt(c));return new Blob([new Uint8Array(o)],{type:s})};return{name:t.name.substring(t.name.lastIndexOf("/")+1),blob:a(A.dataUrl,t.type)}}}async getLocalOrFromServer(t){if(this.cache.has(t)){const a=this.cache.get(t);if(!a)throw new L("Failed to get asset from cache!");return a}const A=(async()=>(await qe([t]))[0])();return this.cache.set(t,A),A}async getFromServer(t){const A=(async()=>(await qe([t]))[0])();return this.cache.set(t,A),A}keyFromURL(t){let e;try{e=new URL(t).pathname}catch{e=void 0}return e!==void 0&&e.startsWith("/")&&(e=e.replace("/","")),e==null?void 0:e.split("?")[0]}cacheAsset(t){if(!t.key)throw new L("Asset has no key!");this.cache.has(t.key)||this.cache.set(t.key,Promise.resolve(t))}cacheMaterial(t){if(!t.id)throw new L("Material has no id!");this.materialCache.has(t.id)||this.materialCache.set(t.id,Promise.resolve(t))}async getMaterialLocalOrFromServer(t){if(this.materialCache.has(t))return this.materialCache.get(t);const A=(async()=>(await ui([t]))[0])();return this.materialCache.set(t,A),A}async uploadAssetWithProgress(t,e,A,a,i){const s=await this.dispatchCreateAssetRequest(t,e,a,i);if(!s)throw new Error("Failed to create asset.");return await new Promise((r,o)=>{const c=new XMLHttpRequest;c.open("PUT",s.assetResponse.uploadUrl,!0),c.setRequestHeader("Content-Type",s.mimeType),c.setRequestHeader("Cache-Control","public,max-age=31536000,immutable"),c.upload.onprogress=l=>{l.lengthComputable&&A(l.loaded*100/l.total)},c.onload=()=>{const l=s.assetResponse.asset;Dt.add(s.assetResponse.asset),r(l)},c.onerror=o,c.send(t.blob)}),this.cacheAsset(s.assetResponse.asset),s.assetResponse.asset}async uploadAsset(t,e,A,a){return this.uploadAssetWithProgress(t,e,()=>{},A,a)}async uploadFile(t,e){const A=!(t.type==="image/svg+xml"||t.type==="application/pdf"||t.type==="application/postscript"),a=A?Kt.Image:Kt.Illustration;if(A){const i=await this.loadImageAsFileInfo(t);return await this.uploadAssetWithProgress(i,a,e,!0)}else{const i={name:t.name,blob:new Blob([t],{type:t.type})};return await this.uploadAssetWithProgress(i,a,e,!0)}}async removeBackgroundFromAsset(t){const e=t.key;if(this.bgrmProcessCache.has(e))return this.bgrmProcessCache.get(e);if(q.has(e)){const i=this.getLocalOrFromServer(q.get(e));return this.bgrmProcessCache.set(e,i),i}const a=(async()=>{var s,r;const i=await F.getShadowGraphqlClient().mutate({mutation:wi,fetchPolicy:"no-cache",errorPolicy:"all",variables:{key:e}});if(this.bgrmProcessCache.delete(e),!((r=(s=i.data)==null?void 0:s.assetRemoveBackground)!=null&&r.key))throw new Error("Failed to remove background from image");return Dt.add(i.data.assetRemoveBackground),q.add(e,i.data.assetRemoveBackground.key),this.cache.set(i.data.assetRemoveBackground.key,Promise.resolve(i.data.assetRemoveBackground)),i.data.assetRemoveBackground})();return this.bgrmProcessCache.set(e,a),a}removePersistedAsset(t){Dt.remove(t),q.delete(t),q.deleteForBgRemovedKey(t)}getPersistedAssets(){return Dt.list()}registerPersistedAssetListener(t){Dt.addCallback(t)}unRegisterPersistedAssetListener(t){Dt.removeCallback(t)}async dispatchCreateAssetRequest(t,e,A,a){const i=t.blob.type?t.blob.type:this.guessMIME(t.name),s=await Ei(t.name,e,i,A,a);if(s)return{assetResponse:s,mimeType:i}}guessMIME(t){const e=t.split(".").pop();switch(e){case"glb":return"model/gltf-binary";case"ttf":return"font/ttf";case"mkv":return"video/x-matroska";default:throw new L("Unexpected mimetype: "+e)}}}const bt="persistentAssets",pa=class ut{static add(t){if(!t.fileLink){console.error("Failed to find cdn link on asset, cannot persist!");return}const e=new Map;e.set(t.key||"",t.fileLink);const A=N.getMap(bt);A&&A.forEach((a,i)=>{e.set(i,a)}),N.setMap(bt,e),ut.executeCallbacks()}static remove(t){const e=N.getMap(bt);if(!e)return;const A=Array.from(e.entries()).find(a=>a[0]===t);A&&(e.delete(A[0]),N.setMap(bt,e),ut.executeCallbacks())}static list(){const t=N.getMap(bt);return t?Array.from(t.entries()).map(e=>({assetKey:e[0],src:e[1]})):[]}static addCallback(t){ut.callbacks.push(t)}static removeCallback(t){ut.callbacks=ut.callbacks.filter(e=>e!==t)}static executeCallbacks(){ut.callbacks.forEach(t=>t())}};pa.callbacks=[];let Dt=pa;const jA="bgrmPersistentAssets";class q{static has(t){return q.getMap().has(t)}static get(t){return q.getMap().get(t)}static keys(){return q.getMap().keys()}static values(){return q.getMap().values()}static add(t,e){const A=q.getMap();A.set(t,e),q.setMap(A)}static delete(t){const e=q.getMap();e.delete(t),q.setMap(e)}static deleteForBgRemovedKey(t){const e=q.getMap(),A=Array.from(e.keys()).find(a=>e.get(a)===t);A&&(e.delete(A),q.setMap(e))}static getMap(){return N.getMap(jA)||new Map}static setMap(t){N.setMap(jA,t)}}const G=new mi;class fi{constructor(){this.cache={},this.disabled=!1}get(t){if(this.disabled)return;const e=JSON.stringify(t);return this.cache[e]}set(t,e){if(this.disabled)return e;const A=JSON.stringify(t);return this.cache[A]=e,e}disable(t){this.disabled=t}}const Nt=new fi,Da=p.gql`
106
106
  fragment OptionFields on Option {
107
107
  id
108
108
  name
@@ -3353,7 +3353,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
3353
3353
  }
3354
3354
  }
3355
3355
  }
3356
- `,Mo=async(n,t)=>{var a;const e=await F.getShadowGraphqlClient().query({query:Ti(((a=t==null?void 0:t.assets)==null?void 0:a.metadata)||!1),errorPolicy:"all",variables:{ids:n}});if(e.error)throw e.error;if(e.errors)throw e.errors.forEach(i=>console.error(i)),new Error("Unable to read workflows. Consult GraphQL errors.");const A=e.data.workflows;if(A===void 0||A.length!==n.length)throw new Error(`Unable to read workflows: ${e.errors??"Length mismatch in response"}`);return A.forEach(i=>{i.steps.forEach(s=>{var r,o,c;delete s.data.__typename,(r=s.option)!=null&&r.id&&((o=s.option.defaultVariant)!=null&&o.asset&&G.cacheAsset(s.option.defaultVariant.asset),s.option.colorProfile&&G.cacheAsset(s.option.colorProfile),(c=s.option.variants)==null||c.forEach(l=>{l.asset&&G.cacheAsset(l.asset),l.thumbnail&&G.cacheAsset(l.thumbnail),l.material&&G.cacheMaterial(l.material)}),Nt.set({id:s.option.id},Promise.resolve(s.option)))}),i.finalizeStepConfig||(i.finalizeStepConfig={}),i.finalizeStepConfig.termsMarkdown=i.partner.termsMarkdown}),A},So=async(n,t)=>{const A=(await t).find(a=>a.id===n);if(!A)throw new Error(`Workflow not found: ${n}`);return A},bA=async(n,t)=>{const e=n.map(r=>Nt.get({id:r,options:t})),A=n.filter((r,o)=>e[o]===void 0);if(A.length===0)return Promise.all(e);const a=Mo(A,t),i=A.map(r=>Nt.set({id:r,options:t},So(r,a))),s=e.filter(r=>r!==void 0);return await Promise.all(s.concat(i))},xo=async(n,t)=>(await bA([n],t))[0],Yo=n=>n.sort((t,e)=>t.index-e.index).map(t=>({id:H(),panelId:t.name,name:t.name,index:t.index,createdAt:new Date,updatedAt:new Date,transparentBackground:t.transparentBackground,height:t.height,width:t.width,previewRegion:t.previewRegion,useEditableArea:t.useEditableArea,editableArea:t.editableArea})),Po=(n,t)=>{const e=n.workflowState,A=e?JSON.parse(e):void 0;return A?Object.values(A.layouts).map(a=>a.layout):Yo(t.panels)};class vo{constructor(t){this.activeIntegration=void 0,this.updateTransactionState=async e=>{try{return F.getShadowGraphqlClient().mutate({...e,mutation:Si})}catch(A){throw console.error(A),new lt("Critical - Unable to synchronize workflow state with server.")}},this.options=t,this.options.applicationKey&&ai(this.options.applicationKey),console.debug("------------------------"),console.debug("Spiff Commerce Core SDK"),console.debug("Version: 26.4.0"),console.debug(`Application Key Provided: ${!!this.options.applicationKey}`),console.debug("------------------------")}configure(t){dt.setHubUrl(t.hubUrl),dt.setServerUrl(t.serverUrl),dt.setServicesApiUrl(t.servicesApiUrl),this.marketplaceThemeInstallId=t.marketplaceThemeInstallId,this.marketplaceThemeInstallConfigurationId=t.marketplaceThemeInstallConfigurationId,t.bearerAuthenticationToken&&fa(t.bearerAuthenticationToken),this.options.applicationKey&&this.getIntegration()}getAssetManager(){return G}getCurrencyCode(){if(this.currencyCode===void 0)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!ni())throw new Error("Application key required to use Flow Service.");return new Pn}async getIntegration(){if(this.activeIntegration)return this.activeIntegration;if(!this.options.applicationKey)throw new Error("Cannot get current Integration without specifying an Application Key.");return this.activeIntegration=kn(this.options.applicationKey),this.activeIntegration}async canUseAddon(t){var e;try{return((e=(await this.getIntegration()).partner.activeAddons)==null?void 0:e.includes(t))??!1}catch(A){return console.error(A),!1}}async authenticateBundleFromLocalStorage(t){var a,i;const e=N.getMap("bundleOwnerIds");if(e!=null&&e.has(t))return Promise.resolve({success:!0,stakeholderType:Vt.Owner});const A=N.getMap("bundlePartnerIds")||new Map;if(A.has(t)){const s=A.get(t),o=(N.getMap("partnerCustomerIds")||new Map).get(s);if(o&&await this.authenticateCustomerId(o)){const l=(i=(a=this.customer)==null?void 0:a.bundleStakeholders)==null?void 0:i.find(g=>{var d;return((d=g.bundle)==null?void 0:d.id)===t});if(l)return Promise.resolve({success:!0,stakeholderType:l.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){var l,g,d,B,h,C;const e=F.getShadowGraphqlClient(),A=await e.query({query:Ji,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!A.data.transactions||A.data.transactions.length===0)throw new Error(`Transaction not found: ${t}`);const a=A.data.transactions[0];if(!((g=(l=a.product)==null?void 0:l.partner)==null?void 0:g.id))throw new Error(`Unable to read transaction: ${t}`);if(a.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const s=N.getMap("transactionOwnerIds");if(s!=null&&s.has(t))return Promise.resolve({success:!0,stakeholderType:Vt.Owner});const r=N.getMap("transactionCustomerIds");if(r!=null&&r.has(t)){const w=r.get(t);if(w&&await this.authenticateCustomerId(w)){const E=((B=(d=this.customer)==null?void 0:d.bundleStakeholders)==null?void 0:B.find(m=>{var f,Q;return(Q=(f=m.bundle)==null?void 0:f.transactions)==null?void 0:Q.some(D=>D.id===t)}))||((C=(h=this.customer)==null?void 0:h.stakeholders)==null?void 0:C.find(m=>{var f;return((f=m.transaction)==null?void 0:f.id)===t}));if(E)return Promise.resolve({success:!0,stakeholderType:E.type})}}const c=(await e.query({query:Li,errorPolicy:"all",variables:{id:a.workflowId}})).data.workflow;if(!c)throw new Error(`Unable to read workflow: ${a.workflowId}`);return Promise.resolve({success:!1,theme:c.overrideTheme,customLogoLink:a.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=N.getMap("transactionCustomerIds");e!=null&&e.has(t)&&(e.delete(t),N.setMap("transactionCustomerIds",e))}async customerHasBundleTemplates(t){const a=(await F.getShadowGraphqlClient().query({query:ea,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;return a.id?a.hasBundleTemplates??!1:!1}getStakeholderTypeForTransaction(t){var A,a;const e=(a=(A=this.customer)==null?void 0:A.stakeholders)==null?void 0:a.find(i=>{var s;return((s=i.transaction)==null?void 0:s.id)===t});if(e)return e.type}async getOrCreateCustomer(t){var s;this.customer=void 0;const e=F.getShadowGraphqlClient(),a=(await e.query({query:ea,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!a.id){const o=(s=(await e.mutate({mutation:po,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data)==null?void 0:s.customerCreate;if(!o)throw new Error("Unable to create customer.");return this.storeCustomer(o),this.customer=o,{customer:o,isAuthenticated:!1}}this.storeCustomer(a);const i=await this.authenticateCustomerId(a.id);return{customer:this.customer||a,isAuthenticated:i}}getCustomer(){return this.customer}async authenticateCustomerId(t){var r;const e=F.getShadowGraphqlClient(),A=N.getMap("customerTokens");if(!(A!=null&&A.has(t)))return!1;const a=A.get(t);if(!a)return!1;const s=(r=(await e.mutate({mutation:Do,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:a}})).data)==null?void 0:r.customerAuthenticate;return s?(this.storeCustomer(s),zA(a),this.customer=s,!0):!1}async generateVerificationCode(t){await F.getShadowGraphqlClient().mutate({mutation:Io,variables:{emailAddress:t}})}async verifyCode(t,e){var i,s;const a=(i=(await F.getShadowGraphqlClient().mutate({mutation:Fo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data)==null?void 0:i.customerVerifyCode;if(a!=null&&a.loginToken){if(!((s=a.partner)!=null&&s.id))throw new Error(`Unable to find customer: ${t}`);const r=N.getMap("customerTokens")||new Map;return r.set(a.id,a.loginToken),N.setMap("customerTokens",r),this.storeCustomer(a),zA(a.loginToken),this.customer={...a,loginToken:void 0},!0}return!1}async getCustomerMetafields(){var e;if(!((e=this.customer)!=null&&e.id))throw new Error("Customer must be logged in before calling this function.");return(await F.getShadowGraphqlClient().query({query:yo,variables:{id:this.customer.id}})).data.metafields}async getNewBundle(t,e,A){var c,l,g,d,B;const i=(g=(await F.getShadowGraphqlClient().mutate({mutation:Ir(((l=(c=A==null?void 0:A.graphql)==null?void 0:c.productCollection)==null?void 0:l.eagerFetchProducts)||!1),variables:{collectionId:t,initialMetadata:e?Object.entries(e).map((h,C)=>({key:h[0],value:h[1]})):void 0,marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId},fetchPolicy:"no-cache"})).data)==null?void 0:g.bundleCreate;if(!(i!=null&&i.id))throw new Error("Unable to create bundle");const s=N.getMap("bundlePartnerIds")||new Map;s.set(i.id,i.partner.id),N.setMap("bundlePartnerIds",s);const r=N.getMap("bundleOwnerIds")||new Map;r.set(i.id,i.bundleOwnerId),N.setMap("bundleOwnerIds",r);const o=new Oe(this,i,void 0,void 0,i.bundleOwnerId,{eagerFetchProducts:(B=(d=A==null?void 0:A.graphql)==null?void 0:d.productCollection)==null?void 0:B.eagerFetchProducts});return await o.getInitializationPromise(),o}async getExistingBundle(t,e,A,a){var w,u,E,m,f,Q,D,I,y,x,Y;const i=N.getMap("bundleOwnerIds"),s=i==null?void 0:i.get(t),o=((w=Object.entries(localStorage).find(([P,v])=>P.startsWith("CognitoIdentityServiceProvider")&&P.endsWith("idToken")))==null?void 0:w[0])||"",c=localStorage.getItem(o),l={};c&&!fe(c)&&(l.Authorization=`Bearer ${c}`);const g={bundleOwnerId:s,...l,...(u=a==null?void 0:a.graphql)==null?void 0:u.additionalHeaders},d=await F.getShadowGraphqlClient().query({query:fr(((m=(E=a==null?void 0:a.graphql)==null?void 0:E.productCollection)==null?void 0:m.eagerFetchProducts)||!1),variables:{id:t},fetchPolicy:"no-cache",context:{headers:g}});if(!((f=d.data)!=null&&f.bundles)||((Q=d.data)==null?void 0:Q.bundles.length)===0||!((D=d.data)!=null&&D.bundles[0]))throw new Error(`Unable to find bundle: ${t}`);const B=(I=d.data)==null?void 0:I.bundles[0],h=N.getMap("bundlePartnerIds")||new Map;h.set(B.id,B.partner.id),N.setMap("bundlePartnerIds",h);const C=new Oe(this,B,e,A,s,{additionalHeaders:(y=a==null?void 0:a.graphql)==null?void 0:y.additionalHeaders,eagerFetchProducts:(Y=(x=a==null?void 0:a.graphql)==null?void 0:x.productCollection)==null?void 0:Y.eagerFetchProducts,existingGlobalPropertyState:d.data.globalPropertyState});return await C.getInitializationPromise(),C}async duplicateBundle(t,e,A,a){var w,u,E,m,f,Q,D,I;const i=(w=N.getMap("bundleOwnerIds"))==null?void 0:w.get(t),r=((u=Object.entries(localStorage).find(([y,x])=>y.startsWith("CognitoIdentityServiceProvider")&&y.endsWith("idToken")))==null?void 0:u[0])||"",o=localStorage.getItem(r),c={};o&&!fe(o)&&(c.Authorization=`Bearer ${o}`);const l={bundleOwnerId:i,...c,...(E=a==null?void 0:a.graphql)==null?void 0:E.additionalHeaders},d=(Q=(await F.getShadowGraphqlClient().mutate({mutation:Fr(((f=(m=a==null?void 0:a.graphql)==null?void 0:m.productCollection)==null?void 0:f.eagerFetchProducts)||!1),variables:{id:t,template:e,marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId,duplicateTransactions:A},context:{headers:l},fetchPolicy:"no-cache"})).data)==null?void 0:Q.bundleDuplicate;if(!(d!=null&&d.id))throw new Error("Unable to duplicate bundle");const B=N.getMap("bundlePartnerIds")||new Map;B.set(d.id,d.partner.id),N.setMap("bundlePartnerIds",B);const h=N.getMap("bundleOwnerIds")||new Map;h.set(d.id,d.bundleOwnerId),N.setMap("bundleOwnerIds",h);const C=new Oe(this,d,void 0,void 0,d.bundleOwnerId,{eagerFetchProducts:(I=(D=a==null?void 0:a.graphql)==null?void 0:D.productCollection)==null?void 0:I.eagerFetchProducts});return await C.getInitializationPromise(),C}async getBundlesForCustomer(t){var i;if(!((i=this.customer)!=null&&i.id))throw new Error("Customer not authenticated.");const{includeMetadata:e,...A}=t;return(await F.getShadowGraphqlClient().query({query:Rr(e??!1),variables:{...A,id:this.customer.id},fetchPolicy:"no-cache"})).data.customerBundlesFeed}async getBundleStakeholders(){var i;if(!this.customer)throw new Error("Customer not authenticated.");const t=await F.getShadowGraphqlClient().query({query:Qr,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!((i=t.data)!=null&&i.customers)||t.data.customers.length===0)throw new Error("Unable to find customer.");const A=t.data.customers[0].bundleStakeholders||[],a=N.getMap("bundlePartnerIds")||new Map;return A.forEach(s=>{var r,o;(r=s.bundle)!=null&&r.id&&((o=s.bundle.partner)!=null&&o.id)&&a.set(s.bundle.id,s.bundle.partner.id)}),N.setMap("bundlePartnerIds",a),A}async getWorkflowExperience(t,e){if(!t)throw new Error("getWorkflowExperience has been called without an options object! This is not supported.");const A=await this.getWorkflowExperiences([t],t.graphql),a=A[0];return e&&await a.getWorkflowManager().injectIntoPreviewService(e(a.getWorkflowManager().getWorkflow())),A[0]}async getWorkflowExperiences(t,e){if(t.length===0)throw new lt("No options provided!");const A=F.getShadowGraphqlClient(),a=async Q=>{var x,Y,P;if(Q.length===0)return[];const D=Q.map(v=>v.option.transactionId),I=await A.query({query:Mi,variables:{ids:D},errorPolicy:"all",fetchPolicy:"no-cache"}),y=I.data.transactions;if(y.length!==Q.length){const v=((Y=(x=I.errors)==null?void 0:x[0])==null?void 0:Y.message)||"Unknown error";throw new lt(`Not all transactions were found: ${v}`)}return!this.activeIntegration&&((P=y[0].integrationProduct)!=null&&P.integration)&&(this.activeIntegration=Promise.resolve(y[0].integrationProduct.integration)),y.map((v,b)=>{var K;return{transaction:v,workflowId:v.workflowId,readOnly:((K=Q.find(j=>j.option.transactionId===v.id))==null?void 0:K.option.readOnly)??!1,index:Q[b].index}})},i=async Q=>{var y,x,Y;if(Q.length===0)return[];const D=await A.mutate({mutation:yi,variables:{inputs:Q.map(P=>({integrationProductId:P.option.type==="integration"?P.option.integrationProductId:void 0,externalIntegrationId:P.option.type==="external"?P.option.externalIntegrationId:void 0,externalProductId:P.option.type==="external"?P.option.externalProductId:void 0,workflowId:P.option.workflowId,designName:P.option.designName,claim:!0})),marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId},errorPolicy:"all",fetchPolicy:"no-cache"}),I=(y=D.data)==null?void 0:y.transactionCreateMany;if(!I||I.length===0){const P=((Y=(x=D.errors)==null?void 0:x[0])==null?void 0:Y.message)||"Unknown error";throw new lt(`Failed to create transactions: ${P}`)}return I.map((P,v)=>({transaction:P,workflowId:P.workflowId,readOnly:!1,index:Q[v].index}))},s=t.map((Q,D)=>({option:Q,index:D})),r=s.filter(Q=>Q.option.type==="transaction"),o=s.filter(Q=>Q.option.type==="integration"||Q.option.type==="external"),c=GA(r,10),l=GA(o,10),g=(await Promise.all([...c.map(a),...l.map(i)])).flat(),d=[...new Set(g.map(Q=>Q.workflowId))],B=await bA(d,e),h=new Map(B.map(Q=>[Q.id,Q])),C=N.getMap("transactionOwnerIds")||new Map,w=g.map(async Q=>{var K;const{transaction:D,workflowId:I,readOnly:y,index:x}=Q,Y=h.get(I),P=t[x];!C.get(D.id)&&D.transactionOwnerId&&C.set(D.id,D.transactionOwnerId);const v=C.get(D.id)||void 0,b={product:D.product,transaction:D,layouts:[],singleVariantsRenderable:(K=P==null?void 0:P.workflowConfiguration)==null?void 0:K.singleVariantsRenderable,stateMutationFunc:y?async()=>{throw new L("State mutation is forbidden in read only mode!")}:async j=>this.updateTransactionState({...j,context:{transactionOwnerId:v,bundleOwnerId:e==null?void 0:e.bundleOwnerId}}),readOnly:y,workflow:Y,isReloadedTransaction:P.type==="transaction"};if(P.type==="transaction"&&D.workflowState){const j=JSON.parse(D.workflowState);b.layouts=Object.values(j.layouts||{}).map(At=>At.layout),await eA(j),b.reloadedState=j}else if(!y&&P.workflowState){const j=JSON.parse(P.workflowState);b.layouts=Object.values(j.layouts||{}).map(At=>At.layout),await eA(j),b.reloadedState=j}else b.layouts=Po(b.transaction,b.workflow);return b.renderableContextService=new oo(b.layouts),b.delayWorkflowStateSync=!0,{experienceOptions:b,index:x,options:P}}),u=await Promise.all(w);N.setMap("transactionOwnerIds",C);const m=u.sort((Q,D)=>Q.index-D.index).map(async Q=>{const{experienceOptions:D,options:I}=Q,y=new In(this,D);return await y.getWorkflowManager().getInitializationPromise(),I.type!=="transaction"&&this.customer&&await y.attachCustomerDetails({email:this.customer.emailAddress}),y}),f=await Promise.all(m);return f.forEach(Q=>Q.getWorkflowManager().setWorkflowStateSyncEnabled(!0)),f}storeCustomer(t){const e=N.getMap("partnerCustomerIds")||new Map;e.set(t.partner.id,t.id),N.setMap("partnerCustomerIds",e)}async getIntegrationProductById(t){var i,s;const a=(i=(await F.getShadowGraphqlClient().query({query:vi,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:i.integrationProducts;if(!a||a.length===0||!((s=a[0])!=null&&s.id))throw new Error("Integration product not found.");return new rA(a[0])}async getIntegrationProductFromExternalIds(t,e){var s;const i=(s=(await F.getShadowGraphqlClient().query({query:Ni,variables:{externalProductId:e,externalIntegrationId:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:s.integrationProductFromExternalIds;if(!(i!=null&&i.id))throw new Error("Integration product not found.");return new rA(i)}async getIntegrationProduct(t){return t.type==="integration"?this.getIntegrationProductById(t.integrationProductId):this.getIntegrationProductFromExternalIds(t.externalIntegrationId,t.externalProductId)}async getShareActionsForTransaction(t){const A=(N.getMap("transactionOwnerIds")||new Map).get(t)||void 0,a=await F.getShadowGraphqlClient().query({query:Pi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t},context:{transactionOwnerId:A}});if(!a.data.transactions||a.data.transactions.length!==1)throw new Error(`Failed to fetch share actions for transaction: ${t}`);return a.data.transactions[0].transactionShareActions}async placeOrder(t){const e=await F.getShadowGraphqlClient().mutate({mutation:Vi,variables:{orderItems:t}});if(e.errors)throw new Error(e.errors[0].message);if(!e.data)throw new Error("Failed to create order: No order data in response.");return{id:e.data.orderCreate.id,internalId:e.data.orderCreate.internalId}}}const kn=async n=>(await F.getShadowGraphqlClient().query({query:zi,errorPolicy:"all",fetchPolicy:"no-cache",context:{headers:{"x-application-key":n}}})).data.currentIntegration,No=async n=>{const e=await F.getShadowGraphqlClient().query({query:Yi,errorPolicy:"all",fetchPolicy:"network-only",variables:{id:n}});if(e.data.transactions.length!==0)return e.data.transactions[0]},ko=async(n,t)=>{var A;return(A=(await F.getShadowGraphqlClient().query({query:Oi,errorPolicy:"all",variables:{themeConfigurationId:n,themeInstallId:t}})).data)==null?void 0:A.marketplaceThemeInstallConfiguration},Ho=async n=>{var e,A,a;return(a=(A=(e=(await F.getShadowGraphqlClient().query({query:Ki,errorPolicy:"all",variables:{id:n}})).data)==null?void 0:e.bundles)==null?void 0:A[0])==null?void 0:a.marketplaceThemeInstallConfiguration},Ro=async n=>{var e,A,a;return(a=(A=(e=(await F.getShadowGraphqlClient().query({query:ji,errorPolicy:"all",variables:{id:n}})).data)==null?void 0:e.transactions)==null?void 0:A[0])==null?void 0:a.marketplaceThemeInstallConfiguration};class bo{approveTransaction(t){throw new Error("Method not implemented.")}rejectTransaction(t){throw new Error("Method not implemented.")}getClient(){return this.client??{}}getWorkflowExperience(){return{}}setClient(t){this.client=t}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}async reset(){}updateStateWithServer(t){}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,e){}addStorageCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,e){}getStepSpecificServices(t){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(t){}markUpdateCompleted(t){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}getStepSelections(){return{}}setCurrentAdjustingStepId(t){}setEditedStatus(t,e){}setInformationResults(t){}setMandatoryFulfilled(t,e){}async setSelectionsAndElements(t,e,A){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}setWorkflowStateSyncEnabled(t){}async updateTransactionShareActions(){}addValidationCallback(t){}setStepError(t,e,A){}getStepErrors(t){}getValidationErrors(){return{steps:new Map}}async updateTransactionStakeholders(){}getStepTags(t){return[]}}var Hn=(n=>(n.SelectFrame="SelectFrame",n.SelectImage="SelectImage",n.Position="Position",n))(Hn||{});class Rn extends et{constructor(t,e,A){var a;super(t,e,A),this.frameService=(a=this.manager.getStepSpecificServices(this.getId()))==null?void 0:a.frameService}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return ot.selectVariant(this.step,t.getResource(),e,this.manager,A=>this.setUpdateState(A))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged(e=>{e&&t(e)})}async selectImage(t,e=!0,A=!0){var a;if(await ot.selectImage(this.step,t,this.manager,A),e){const i=((a=this.manager.getStepStorage(this.step.stepName))==null?void 0:a.framePatternData)||{};this.manager.updateStorage(this.step.stepName,{framePatternData:{...i,originalAssetKey:t.key,backgroundRemovedAssetKey:void 0,useOriginalAsset:void 0}})}}async canUseBackgroundRemover(){return this.manager.getClient().canUseAddon(Qe.BackgroundRemover)}async canRemoveBackground(){var t,e,A,a;return await this.canUseBackgroundRemover()&&this.hasOriginalImageSelection()&&!!((e=(t=this.frameService)==null?void 0:t.getImageData())!=null&&e.src)&&!((a=(A=this.frameService)==null?void 0:A.getImageData())!=null&&a.svg)}async removeBackgroundFromImageSelection(t=!0){var i;if(!await this.canUseBackgroundRemover())throw new Error("The current Integration does not have access to the Background Remover. Please call canUseBackgroundRemover to ensure you disable this feature when appropriate.");const e=await this.getOriginalImageSelection();if(!e)throw new Error("You must supply an image selection before attempting to remove the background.");const A=await G.removeBackgroundFromAsset(e);t&&await ot.selectImage(this.step,A,this.manager,!1);const a=((i=this.manager.getStepStorage(this.step.stepName))==null?void 0:i.framePatternData)||{};return this.manager.updateStorage(this.step.stepName,{framePatternData:{...a,backgroundRemovedAssetKey:A.key,useOriginalAsset:!t}}),A}changeColors(t){ot.changeColors(this.step,this.manager,t)}getImageData(){if(this.frameService)return this.frameService.getImageData()}async getColorOption(){return this.step.data.colorOption}getAvailableColors(){return this.step.data.colorPickerEnabled?ot.availableColors(this.step,this.manager):Promise.resolve([])}isColorPickerEnabled(){return this.step.data.colorPickerEnabled??!1}async getOriginalImageColors(){const t=this.getImageData();return t!=null&&t.svg?(await st(t.svg)).colors:void 0}getMaxAllowedColors(){return this.step.data.maxColors}getUniqueColorCount(){return ot.getUniqueColorCount(this.step,this.manager)}getCurrentFrameStep(t,e,A,a){return a&&a.length>1&&t===void 0?"SelectFrame":e||A||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}getWhitelistedExtensions(){return[...this.step.data.whitelistedExtensions,...this.step.data.whitelistedExtensions.includes(".jpg")?[".jpeg"]:[]]}async getOriginalImageSelection(){var e,A;const t=(A=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:A.originalAssetKey;if(t)return G.getLocalOrFromServer(t)}async getBackgroundRemovedImageSelection(){var e,A;const t=(A=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:A.backgroundRemovedAssetKey;if(t)return G.getLocalOrFromServer(t)}hasOriginalImageSelection(){var t,e;return!!((e=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)!=null&&e.originalAssetKey)}hasBackgroundRemovedImageSelection(){var t,e;return!!((e=(t=this.getFrameStepStorage())==null?void 0:t.framePatternData)!=null&&e.backgroundRemovedAssetKey)}getUseOriginalImageSelection(){var t,e;return((e=(t=this.getFrameStepStorage())==null?void 0:t.framePatternData)==null?void 0:e.useOriginalAsset)??!1}async setUseOriginalImageSelection(t){var a;const e=((a=this.getFrameStepStorage())==null?void 0:a.framePatternData)||{};if(e.useOriginalAsset===t)return;const A=await this.getOriginalImageSelection();if(!A)throw new Error("You must provide an image selection before calling setUseOriginalImageSelection");if(t)await this.selectImage(A,!1,!1);else{const i=await this.getBackgroundRemovedImageSelection();if(!i)throw new Error("You must call removeBackgroundFromImageSelection before attempting to apply the image.");await this.selectImage(i,!1,!1)}this.manager.updateStorage(this.step.stepName,{framePatternData:{...e,useOriginalAsset:t}})}getFrameStepStorage(){return this.manager.getStepStorage(this.step.stepName)}}const Uo=p.gql`
3356
+ `,Mo=async(n,t)=>{var a;const e=await F.getShadowGraphqlClient().query({query:Ti(((a=t==null?void 0:t.assets)==null?void 0:a.metadata)||!1),errorPolicy:"all",variables:{ids:n}});if(e.error)throw e.error;if(e.errors)throw e.errors.forEach(i=>console.error(i)),new Error("Unable to read workflows. Consult GraphQL errors.");const A=e.data.workflows;if(A===void 0||A.length!==n.length)throw new Error(`Unable to read workflows: ${e.errors??"Length mismatch in response"}`);return A.forEach(i=>{i.steps.forEach(s=>{var r,o,c;delete s.data.__typename,(r=s.option)!=null&&r.id&&((o=s.option.defaultVariant)!=null&&o.asset&&G.cacheAsset(s.option.defaultVariant.asset),s.option.colorProfile&&G.cacheAsset(s.option.colorProfile),(c=s.option.variants)==null||c.forEach(l=>{l.asset&&G.cacheAsset(l.asset),l.thumbnail&&G.cacheAsset(l.thumbnail),l.material&&G.cacheMaterial(l.material)}),Nt.set({id:s.option.id},Promise.resolve(s.option)))}),i.finalizeStepConfig||(i.finalizeStepConfig={}),i.finalizeStepConfig.termsMarkdown=i.partner.termsMarkdown}),A},So=async(n,t)=>{const A=(await t).find(a=>a.id===n);if(!A)throw new Error(`Workflow not found: ${n}`);return A},bA=async(n,t)=>{const e=n.map(r=>Nt.get({id:r,options:t})),A=n.filter((r,o)=>e[o]===void 0);if(A.length===0)return Promise.all(e);const a=Mo(A,t),i=A.map(r=>Nt.set({id:r,options:t},So(r,a))),s=e.filter(r=>r!==void 0);return await Promise.all(s.concat(i))},xo=async(n,t)=>(await bA([n],t))[0],Yo=n=>n.sort((t,e)=>t.index-e.index).map(t=>({id:H(),panelId:t.name,name:t.name,index:t.index,createdAt:new Date,updatedAt:new Date,transparentBackground:t.transparentBackground,height:t.height,width:t.width,previewRegion:t.previewRegion,useEditableArea:t.useEditableArea,editableArea:t.editableArea})),Po=(n,t)=>{const e=n.workflowState,A=e?JSON.parse(e):void 0;return A?Object.values(A.layouts).map(a=>a.layout):Yo(t.panels)};class vo{constructor(t){this.activeIntegration=void 0,this.updateTransactionState=async e=>{try{return F.getShadowGraphqlClient().mutate({...e,mutation:Si})}catch(A){throw console.error(A),new lt("Critical - Unable to synchronize workflow state with server.")}},this.options=t,this.options.applicationKey&&ai(this.options.applicationKey),console.debug("------------------------"),console.debug("Spiff Commerce Core SDK"),console.debug("Version: 26.4.1"),console.debug(`Application Key Provided: ${!!this.options.applicationKey}`),console.debug("------------------------")}configure(t){dt.setHubUrl(t.hubUrl),dt.setServerUrl(t.serverUrl),dt.setServicesApiUrl(t.servicesApiUrl),this.marketplaceThemeInstallId=t.marketplaceThemeInstallId,this.marketplaceThemeInstallConfigurationId=t.marketplaceThemeInstallConfigurationId,t.bearerAuthenticationToken&&fa(t.bearerAuthenticationToken),this.options.applicationKey&&this.getIntegration()}getAssetManager(){return G}getCurrencyCode(){if(this.currencyCode===void 0)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!ni())throw new Error("Application key required to use Flow Service.");return new Pn}async getIntegration(){if(this.activeIntegration)return this.activeIntegration;if(!this.options.applicationKey)throw new Error("Cannot get current Integration without specifying an Application Key.");return this.activeIntegration=kn(this.options.applicationKey),this.activeIntegration}async canUseAddon(t){var e;try{return((e=(await this.getIntegration()).partner.activeAddons)==null?void 0:e.includes(t))??!1}catch(A){return console.error(A),!1}}async authenticateBundleFromLocalStorage(t){var a,i;const e=N.getMap("bundleOwnerIds");if(e!=null&&e.has(t))return Promise.resolve({success:!0,stakeholderType:Vt.Owner});const A=N.getMap("bundlePartnerIds")||new Map;if(A.has(t)){const s=A.get(t),o=(N.getMap("partnerCustomerIds")||new Map).get(s);if(o&&await this.authenticateCustomerId(o)){const l=(i=(a=this.customer)==null?void 0:a.bundleStakeholders)==null?void 0:i.find(g=>{var d;return((d=g.bundle)==null?void 0:d.id)===t});if(l)return Promise.resolve({success:!0,stakeholderType:l.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){var l,g,d,B,h,C;const e=F.getShadowGraphqlClient(),A=await e.query({query:Ji,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!A.data.transactions||A.data.transactions.length===0)throw new Error(`Transaction not found: ${t}`);const a=A.data.transactions[0];if(!((g=(l=a.product)==null?void 0:l.partner)==null?void 0:g.id))throw new Error(`Unable to read transaction: ${t}`);if(a.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const s=N.getMap("transactionOwnerIds");if(s!=null&&s.has(t))return Promise.resolve({success:!0,stakeholderType:Vt.Owner});const r=N.getMap("transactionCustomerIds");if(r!=null&&r.has(t)){const w=r.get(t);if(w&&await this.authenticateCustomerId(w)){const E=((B=(d=this.customer)==null?void 0:d.bundleStakeholders)==null?void 0:B.find(m=>{var f,Q;return(Q=(f=m.bundle)==null?void 0:f.transactions)==null?void 0:Q.some(D=>D.id===t)}))||((C=(h=this.customer)==null?void 0:h.stakeholders)==null?void 0:C.find(m=>{var f;return((f=m.transaction)==null?void 0:f.id)===t}));if(E)return Promise.resolve({success:!0,stakeholderType:E.type})}}const c=(await e.query({query:Li,errorPolicy:"all",variables:{id:a.workflowId}})).data.workflow;if(!c)throw new Error(`Unable to read workflow: ${a.workflowId}`);return Promise.resolve({success:!1,theme:c.overrideTheme,customLogoLink:a.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=N.getMap("transactionCustomerIds");e!=null&&e.has(t)&&(e.delete(t),N.setMap("transactionCustomerIds",e))}async customerHasBundleTemplates(t){const a=(await F.getShadowGraphqlClient().query({query:ea,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;return a.id?a.hasBundleTemplates??!1:!1}getStakeholderTypeForTransaction(t){var A,a;const e=(a=(A=this.customer)==null?void 0:A.stakeholders)==null?void 0:a.find(i=>{var s;return((s=i.transaction)==null?void 0:s.id)===t});if(e)return e.type}async getOrCreateCustomer(t){var s;this.customer=void 0;const e=F.getShadowGraphqlClient(),a=(await e.query({query:ea,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!a.id){const o=(s=(await e.mutate({mutation:po,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data)==null?void 0:s.customerCreate;if(!o)throw new Error("Unable to create customer.");return this.storeCustomer(o),this.customer=o,{customer:o,isAuthenticated:!1}}this.storeCustomer(a);const i=await this.authenticateCustomerId(a.id);return{customer:this.customer||a,isAuthenticated:i}}getCustomer(){return this.customer}async authenticateCustomerId(t){var r;const e=F.getShadowGraphqlClient(),A=N.getMap("customerTokens");if(!(A!=null&&A.has(t)))return!1;const a=A.get(t);if(!a)return!1;const s=(r=(await e.mutate({mutation:Do,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:a}})).data)==null?void 0:r.customerAuthenticate;return s?(this.storeCustomer(s),zA(a),this.customer=s,!0):!1}async generateVerificationCode(t){await F.getShadowGraphqlClient().mutate({mutation:Io,variables:{emailAddress:t}})}async verifyCode(t,e){var i,s;const a=(i=(await F.getShadowGraphqlClient().mutate({mutation:Fo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data)==null?void 0:i.customerVerifyCode;if(a!=null&&a.loginToken){if(!((s=a.partner)!=null&&s.id))throw new Error(`Unable to find customer: ${t}`);const r=N.getMap("customerTokens")||new Map;return r.set(a.id,a.loginToken),N.setMap("customerTokens",r),this.storeCustomer(a),zA(a.loginToken),this.customer={...a,loginToken:void 0},!0}return!1}async getCustomerMetafields(){var e;if(!((e=this.customer)!=null&&e.id))throw new Error("Customer must be logged in before calling this function.");return(await F.getShadowGraphqlClient().query({query:yo,variables:{id:this.customer.id}})).data.metafields}async getNewBundle(t,e,A){var c,l,g,d,B;const i=(g=(await F.getShadowGraphqlClient().mutate({mutation:Ir(((l=(c=A==null?void 0:A.graphql)==null?void 0:c.productCollection)==null?void 0:l.eagerFetchProducts)||!1),variables:{collectionId:t,initialMetadata:e?Object.entries(e).map((h,C)=>({key:h[0],value:h[1]})):void 0,marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId},fetchPolicy:"no-cache"})).data)==null?void 0:g.bundleCreate;if(!(i!=null&&i.id))throw new Error("Unable to create bundle");const s=N.getMap("bundlePartnerIds")||new Map;s.set(i.id,i.partner.id),N.setMap("bundlePartnerIds",s);const r=N.getMap("bundleOwnerIds")||new Map;r.set(i.id,i.bundleOwnerId),N.setMap("bundleOwnerIds",r);const o=new Oe(this,i,void 0,void 0,i.bundleOwnerId,{eagerFetchProducts:(B=(d=A==null?void 0:A.graphql)==null?void 0:d.productCollection)==null?void 0:B.eagerFetchProducts});return await o.getInitializationPromise(),o}async getExistingBundle(t,e,A,a){var w,u,E,m,f,Q,D,I,y,x,Y;const i=N.getMap("bundleOwnerIds"),s=i==null?void 0:i.get(t),o=((w=Object.entries(localStorage).find(([P,v])=>P.startsWith("CognitoIdentityServiceProvider")&&P.endsWith("idToken")))==null?void 0:w[0])||"",c=localStorage.getItem(o),l={};c&&!fe(c)&&(l.Authorization=`Bearer ${c}`);const g={bundleOwnerId:s,...l,...(u=a==null?void 0:a.graphql)==null?void 0:u.additionalHeaders},d=await F.getShadowGraphqlClient().query({query:fr(((m=(E=a==null?void 0:a.graphql)==null?void 0:E.productCollection)==null?void 0:m.eagerFetchProducts)||!1),variables:{id:t},fetchPolicy:"no-cache",context:{headers:g}});if(!((f=d.data)!=null&&f.bundles)||((Q=d.data)==null?void 0:Q.bundles.length)===0||!((D=d.data)!=null&&D.bundles[0]))throw new Error(`Unable to find bundle: ${t}`);const B=(I=d.data)==null?void 0:I.bundles[0],h=N.getMap("bundlePartnerIds")||new Map;h.set(B.id,B.partner.id),N.setMap("bundlePartnerIds",h);const C=new Oe(this,B,e,A,s,{additionalHeaders:(y=a==null?void 0:a.graphql)==null?void 0:y.additionalHeaders,eagerFetchProducts:(Y=(x=a==null?void 0:a.graphql)==null?void 0:x.productCollection)==null?void 0:Y.eagerFetchProducts,existingGlobalPropertyState:d.data.globalPropertyState});return await C.getInitializationPromise(),C}async duplicateBundle(t,e,A,a){var w,u,E,m,f,Q,D,I;const i=(w=N.getMap("bundleOwnerIds"))==null?void 0:w.get(t),r=((u=Object.entries(localStorage).find(([y,x])=>y.startsWith("CognitoIdentityServiceProvider")&&y.endsWith("idToken")))==null?void 0:u[0])||"",o=localStorage.getItem(r),c={};o&&!fe(o)&&(c.Authorization=`Bearer ${o}`);const l={bundleOwnerId:i,...c,...(E=a==null?void 0:a.graphql)==null?void 0:E.additionalHeaders},d=(Q=(await F.getShadowGraphqlClient().mutate({mutation:Fr(((f=(m=a==null?void 0:a.graphql)==null?void 0:m.productCollection)==null?void 0:f.eagerFetchProducts)||!1),variables:{id:t,template:e,marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId,duplicateTransactions:A},context:{headers:l},fetchPolicy:"no-cache"})).data)==null?void 0:Q.bundleDuplicate;if(!(d!=null&&d.id))throw new Error("Unable to duplicate bundle");const B=N.getMap("bundlePartnerIds")||new Map;B.set(d.id,d.partner.id),N.setMap("bundlePartnerIds",B);const h=N.getMap("bundleOwnerIds")||new Map;h.set(d.id,d.bundleOwnerId),N.setMap("bundleOwnerIds",h);const C=new Oe(this,d,void 0,void 0,d.bundleOwnerId,{eagerFetchProducts:(I=(D=a==null?void 0:a.graphql)==null?void 0:D.productCollection)==null?void 0:I.eagerFetchProducts});return await C.getInitializationPromise(),C}async getBundlesForCustomer(t){var i;if(!((i=this.customer)!=null&&i.id))throw new Error("Customer not authenticated.");const{includeMetadata:e,...A}=t;return(await F.getShadowGraphqlClient().query({query:Rr(e??!1),variables:{...A,id:this.customer.id},fetchPolicy:"no-cache"})).data.customerBundlesFeed}async getBundleStakeholders(){var i;if(!this.customer)throw new Error("Customer not authenticated.");const t=await F.getShadowGraphqlClient().query({query:Qr,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!((i=t.data)!=null&&i.customers)||t.data.customers.length===0)throw new Error("Unable to find customer.");const A=t.data.customers[0].bundleStakeholders||[],a=N.getMap("bundlePartnerIds")||new Map;return A.forEach(s=>{var r,o;(r=s.bundle)!=null&&r.id&&((o=s.bundle.partner)!=null&&o.id)&&a.set(s.bundle.id,s.bundle.partner.id)}),N.setMap("bundlePartnerIds",a),A}async getWorkflowExperience(t,e){if(!t)throw new Error("getWorkflowExperience has been called without an options object! This is not supported.");const A=await this.getWorkflowExperiences([t],t.graphql),a=A[0];return e&&await a.getWorkflowManager().injectIntoPreviewService(e(a.getWorkflowManager().getWorkflow())),A[0]}async getWorkflowExperiences(t,e){if(t.length===0)throw new lt("No options provided!");const A=F.getShadowGraphqlClient(),a=async Q=>{var x,Y,P;if(Q.length===0)return[];const D=Q.map(v=>v.option.transactionId),I=await A.query({query:Mi,variables:{ids:D},errorPolicy:"all",fetchPolicy:"no-cache"}),y=I.data.transactions;if(y.length!==Q.length){const v=((Y=(x=I.errors)==null?void 0:x[0])==null?void 0:Y.message)||"Unknown error";throw new lt(`Not all transactions were found: ${v}`)}return!this.activeIntegration&&((P=y[0].integrationProduct)!=null&&P.integration)&&(this.activeIntegration=Promise.resolve(y[0].integrationProduct.integration)),y.map((v,b)=>{var K;return{transaction:v,workflowId:v.workflowId,readOnly:((K=Q.find(j=>j.option.transactionId===v.id))==null?void 0:K.option.readOnly)??!1,index:Q[b].index}})},i=async Q=>{var y,x,Y;if(Q.length===0)return[];const D=await A.mutate({mutation:yi,variables:{inputs:Q.map(P=>({integrationProductId:P.option.type==="integration"?P.option.integrationProductId:void 0,externalIntegrationId:P.option.type==="external"?P.option.externalIntegrationId:void 0,externalProductId:P.option.type==="external"?P.option.externalProductId:void 0,workflowId:P.option.workflowId,designName:P.option.designName,claim:!0})),marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId},errorPolicy:"all",fetchPolicy:"no-cache"}),I=(y=D.data)==null?void 0:y.transactionCreateMany;if(!I||I.length===0){const P=((Y=(x=D.errors)==null?void 0:x[0])==null?void 0:Y.message)||"Unknown error";throw new lt(`Failed to create transactions: ${P}`)}return I.map((P,v)=>({transaction:P,workflowId:P.workflowId,readOnly:!1,index:Q[v].index}))},s=t.map((Q,D)=>({option:Q,index:D})),r=s.filter(Q=>Q.option.type==="transaction"),o=s.filter(Q=>Q.option.type==="integration"||Q.option.type==="external"),c=GA(r,10),l=GA(o,10),g=(await Promise.all([...c.map(a),...l.map(i)])).flat(),d=[...new Set(g.map(Q=>Q.workflowId))],B=await bA(d,e),h=new Map(B.map(Q=>[Q.id,Q])),C=N.getMap("transactionOwnerIds")||new Map,w=g.map(async Q=>{var K;const{transaction:D,workflowId:I,readOnly:y,index:x}=Q,Y=h.get(I),P=t[x];!C.get(D.id)&&D.transactionOwnerId&&C.set(D.id,D.transactionOwnerId);const v=C.get(D.id)||void 0,b={product:D.product,transaction:D,layouts:[],singleVariantsRenderable:(K=P==null?void 0:P.workflowConfiguration)==null?void 0:K.singleVariantsRenderable,stateMutationFunc:y?async()=>{throw new L("State mutation is forbidden in read only mode!")}:async j=>this.updateTransactionState({...j,context:{transactionOwnerId:v,bundleOwnerId:e==null?void 0:e.bundleOwnerId}}),readOnly:y,workflow:Y,isReloadedTransaction:P.type==="transaction"};if(P.type==="transaction"&&D.workflowState){const j=JSON.parse(D.workflowState);b.layouts=Object.values(j.layouts||{}).map(At=>At.layout),await eA(j),b.reloadedState=j}else if(!y&&P.workflowState){const j=JSON.parse(P.workflowState);b.layouts=Object.values(j.layouts||{}).map(At=>At.layout),await eA(j),b.reloadedState=j}else b.layouts=Po(b.transaction,b.workflow);return b.renderableContextService=new oo(b.layouts),b.delayWorkflowStateSync=!0,{experienceOptions:b,index:x,options:P}}),u=await Promise.all(w);N.setMap("transactionOwnerIds",C);const m=u.sort((Q,D)=>Q.index-D.index).map(async Q=>{const{experienceOptions:D,options:I}=Q,y=new In(this,D);return await y.getWorkflowManager().getInitializationPromise(),I.type!=="transaction"&&this.customer&&await y.attachCustomerDetails({email:this.customer.emailAddress}),y}),f=await Promise.all(m);return f.forEach(Q=>Q.getWorkflowManager().setWorkflowStateSyncEnabled(!0)),f}storeCustomer(t){const e=N.getMap("partnerCustomerIds")||new Map;e.set(t.partner.id,t.id),N.setMap("partnerCustomerIds",e)}async getIntegrationProductById(t){var i,s;const a=(i=(await F.getShadowGraphqlClient().query({query:vi,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:i.integrationProducts;if(!a||a.length===0||!((s=a[0])!=null&&s.id))throw new Error("Integration product not found.");return new rA(a[0])}async getIntegrationProductFromExternalIds(t,e){var s;const i=(s=(await F.getShadowGraphqlClient().query({query:Ni,variables:{externalProductId:e,externalIntegrationId:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:s.integrationProductFromExternalIds;if(!(i!=null&&i.id))throw new Error("Integration product not found.");return new rA(i)}async getIntegrationProduct(t){return t.type==="integration"?this.getIntegrationProductById(t.integrationProductId):this.getIntegrationProductFromExternalIds(t.externalIntegrationId,t.externalProductId)}async getShareActionsForTransaction(t){const A=(N.getMap("transactionOwnerIds")||new Map).get(t)||void 0,a=await F.getShadowGraphqlClient().query({query:Pi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t},context:{transactionOwnerId:A}});if(!a.data.transactions||a.data.transactions.length!==1)throw new Error(`Failed to fetch share actions for transaction: ${t}`);return a.data.transactions[0].transactionShareActions}async placeOrder(t){const e=await F.getShadowGraphqlClient().mutate({mutation:Vi,variables:{orderItems:t}});if(e.errors)throw new Error(e.errors[0].message);if(!e.data)throw new Error("Failed to create order: No order data in response.");return{id:e.data.orderCreate.id,internalId:e.data.orderCreate.internalId}}}const kn=async n=>(await F.getShadowGraphqlClient().query({query:zi,errorPolicy:"all",fetchPolicy:"no-cache",context:{headers:{"x-application-key":n}}})).data.currentIntegration,No=async n=>{const e=await F.getShadowGraphqlClient().query({query:Yi,errorPolicy:"all",fetchPolicy:"network-only",variables:{id:n}});if(e.data.transactions.length!==0)return e.data.transactions[0]},ko=async(n,t)=>{var A;return(A=(await F.getShadowGraphqlClient().query({query:Oi,errorPolicy:"all",variables:{themeConfigurationId:n,themeInstallId:t}})).data)==null?void 0:A.marketplaceThemeInstallConfiguration},Ho=async n=>{var e,A,a;return(a=(A=(e=(await F.getShadowGraphqlClient().query({query:Ki,errorPolicy:"all",variables:{id:n}})).data)==null?void 0:e.bundles)==null?void 0:A[0])==null?void 0:a.marketplaceThemeInstallConfiguration},Ro=async n=>{var e,A,a;return(a=(A=(e=(await F.getShadowGraphqlClient().query({query:ji,errorPolicy:"all",variables:{id:n}})).data)==null?void 0:e.transactions)==null?void 0:A[0])==null?void 0:a.marketplaceThemeInstallConfiguration};class bo{approveTransaction(t){throw new Error("Method not implemented.")}rejectTransaction(t){throw new Error("Method not implemented.")}getClient(){return this.client??{}}getWorkflowExperience(){return{}}setClient(t){this.client=t}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}async reset(){}updateStateWithServer(t){}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,e){}addStorageCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,e){}getStepSpecificServices(t){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(t){}markUpdateCompleted(t){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}getStepSelections(){return{}}setCurrentAdjustingStepId(t){}setEditedStatus(t,e){}setInformationResults(t){}setMandatoryFulfilled(t,e){}async setSelectionsAndElements(t,e,A){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}setWorkflowStateSyncEnabled(t){}async updateTransactionShareActions(){}addValidationCallback(t){}setStepError(t,e,A){}getStepErrors(t){}getValidationErrors(){return{steps:new Map}}async updateTransactionStakeholders(){}getStepTags(t){return[]}}var Hn=(n=>(n.SelectFrame="SelectFrame",n.SelectImage="SelectImage",n.Position="Position",n))(Hn||{});class Rn extends et{constructor(t,e,A){var a;super(t,e,A),this.frameService=(a=this.manager.getStepSpecificServices(this.getId()))==null?void 0:a.frameService}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return ot.selectVariant(this.step,t.getResource(),e,this.manager,A=>this.setUpdateState(A))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged(e=>{e&&t(e)})}async selectImage(t,e=!0,A=!0){var a;if(await ot.selectImage(this.step,t,this.manager,A),e){const i=((a=this.manager.getStepStorage(this.step.stepName))==null?void 0:a.framePatternData)||{};this.manager.updateStorage(this.step.stepName,{framePatternData:{...i,originalAssetKey:t.key,backgroundRemovedAssetKey:void 0,useOriginalAsset:void 0}})}}async canUseBackgroundRemover(){return this.manager.getClient().canUseAddon(Qe.BackgroundRemover)}async canRemoveBackground(){var t,e,A,a;return await this.canUseBackgroundRemover()&&this.hasOriginalImageSelection()&&!!((e=(t=this.frameService)==null?void 0:t.getImageData())!=null&&e.src)&&!((a=(A=this.frameService)==null?void 0:A.getImageData())!=null&&a.svg)}async removeBackgroundFromImageSelection(t=!0){var i;if(!await this.canUseBackgroundRemover())throw new Error("The current Integration does not have access to the Background Remover. Please call canUseBackgroundRemover to ensure you disable this feature when appropriate.");const e=await this.getOriginalImageSelection();if(!e)throw new Error("You must supply an image selection before attempting to remove the background.");const A=await G.removeBackgroundFromAsset(e);t&&await ot.selectImage(this.step,A,this.manager,!1);const a=((i=this.manager.getStepStorage(this.step.stepName))==null?void 0:i.framePatternData)||{};return this.manager.updateStorage(this.step.stepName,{framePatternData:{...a,backgroundRemovedAssetKey:A.key,useOriginalAsset:!t}}),A}changeColors(t){ot.changeColors(this.step,this.manager,t)}getImageData(){if(this.frameService)return this.frameService.getImageData()}async getColorOption(){return this.step.data.colorOption}getAvailableColors(){return this.step.data.colorPickerEnabled?ot.availableColors(this.step,this.manager):Promise.resolve([])}isColorPickerEnabled(){return this.step.data.colorPickerEnabled??!1}async getOriginalImageColors(){const t=this.getImageData();return t!=null&&t.svg?(await st(t.svg)).colors:void 0}getMaxAllowedColors(){return this.step.data.maxColors}getUniqueColorCount(){return ot.getUniqueColorCount(this.step,this.manager)}getCurrentFrameStep(t,e,A,a){return a&&a.length>1&&t===void 0?"SelectFrame":e||A||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}getWhitelistedExtensions(){return[...this.step.data.whitelistedExtensions,...this.step.data.whitelistedExtensions.includes(".jpg")?[".jpeg"]:[]]}async getOriginalImageSelection(){var e,A;const t=(A=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:A.originalAssetKey;if(t)return G.getLocalOrFromServer(t)}async getBackgroundRemovedImageSelection(){var e,A;const t=(A=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:A.backgroundRemovedAssetKey;if(t)return G.getLocalOrFromServer(t)}hasOriginalImageSelection(){var t,e;return!!((e=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)!=null&&e.originalAssetKey)}hasBackgroundRemovedImageSelection(){var t,e;return!!((e=(t=this.getFrameStepStorage())==null?void 0:t.framePatternData)!=null&&e.backgroundRemovedAssetKey)}getUseOriginalImageSelection(){var t,e;return((e=(t=this.getFrameStepStorage())==null?void 0:t.framePatternData)==null?void 0:e.useOriginalAsset)??!1}async setUseOriginalImageSelection(t){var a;const e=((a=this.getFrameStepStorage())==null?void 0:a.framePatternData)||{};if(e.useOriginalAsset===t)return;const A=await this.getOriginalImageSelection();if(!A)throw new Error("You must provide an image selection before calling setUseOriginalImageSelection");if(t)await this.selectImage(A,!1,!1);else{const i=await this.getBackgroundRemovedImageSelection();if(!i)throw new Error("You must call removeBackgroundFromImageSelection before attempting to apply the image.");await this.selectImage(i,!1,!1)}this.manager.updateStorage(this.step.stepName,{framePatternData:{...e,useOriginalAsset:t}})}getFrameStepStorage(){return this.manager.getStepStorage(this.step.stepName)}}const Uo=p.gql`
3357
3357
  query GetLoggedInCustomer($email: String!) {
3358
3358
  customer(emailAddress: $email) {
3359
3359
  id