@spiffcommerce/core 12.9.0 → 12.9.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/main.js CHANGED
@@ -657,7 +657,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),A=require("react/j
657
657
  }
658
658
  }
659
659
  }
660
- `;function hc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class dc{constructor(t){hc(this,"bundleId",void 0),hc(this,"globalPropertyState",void 0),this.bundleId=t,this.getOrCreateGlobalPropertyState().then((t=>this.globalPropertyState=t))}getGlobalPropertyState(){return this.globalPropertyState}getAspect(t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=this.globalPropertyState.aspects.find((e=>e.name===t));if(e)return e.value}setAspect(t,e){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const A=this.globalPropertyState.aspects.find((e=>e.name===t));return A?A.value=e:this.globalPropertyState.aspects.push({name:t,value:e}),this.updateGlobalPropertyState()}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await Qr.getShadowGraphqlClient().mutate({mutation:lc,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects}});if(!t.data?.globalPropertyStateUpdate)throw new Error("Unable to update global property state");this.globalPropertyState=t.data.globalPropertyStateUpdate}async getOrCreateGlobalPropertyState(){const t=await Qr.getShadowGraphqlClient().query({query:gc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const e=await Qr.getShadowGraphqlClient().mutate({mutation:cc,variables:{bundleId:this.bundleId}});if(e.data?.globalPropertyStateCreate&&e.data.globalPropertyStateCreate.id)return e.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}function uc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class wc{constructor(t,e){uc(this,"client",void 0),uc(this,"id",void 0),uc(this,"name",void 0),uc(this,"metadata",void 0),uc(this,"productCollection",void 0),uc(this,"globalConfigurations",void 0),uc(this,"globalPropertyStateManager",void 0),uc(this,"workflowExperiences",[]),this.client=t,this.id=e.id,this.name=e.name||"",this.metadata=new Map(e.metadata?.map((t=>[t.key,t.value]))||[]),this.productCollection=e.productCollection,this.globalConfigurations=this.resolveGlobalProperties(),this.globalPropertyStateManager=new dc(this.id)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(t){return this.name=t,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(t){return this.metadata=new Map(t),this.updateBundle()}setNameAndMetadata(t,e){return this.name=t,this.metadata=new Map(e),this.updateBundle()}async hasGlobalProperties(){const t=await this.globalConfigurations;return t.length>0&&t.some((t=>t.aspects.length>0))}async getGlobalProperties(){const t=await this.globalConfigurations;if(0===t.length)return[];return(await Promise.all(t.map((t=>Promise.all(t.aspects.map((async t=>{switch(t.type){case tA.FileUpload:return new sc(this,t);case tA.Option:return new oc(this,t,t.entityId?await kr.getOption(t.entityId):void 0)}}))))))).flat()}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,e)=>t+e),0)}getProductCollection(){return this.productCollection}async addWorkflowExperience(t){const e=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===e)))throw new Error("Unable to add transaction to bundle - Already Exists!");await Qr.getShadowGraphqlClient().mutate({mutation:_o,variables:{id:this.id,transactionId:e}}),this.workflowExperiences.push(t);const A=await this.getGlobalProperties();await Promise.all(A.map((e=>e.applyGlobalState([t]))))}async removeWorkflowExperience(t){const e=this.workflowExperiences.indexOf(t);if(!(e>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found!");await Qr.getShadowGraphqlClient().mutate({mutation:tc,variables:{id:this.id,transactionId:t.getWorkflowManager().getTransaction().id}}),this.workflowExperiences.splice(e,1)}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await Qr.getShadowGraphqlClient().mutate({mutation:nc,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){await Qr.getShadowGraphqlClient().mutate({mutation:ec,variables:{id:this.id,details:t,type:e||ia.Owner}})}async updateStakeholders(t){await Qr.getShadowGraphqlClient().mutate({mutation:Ac,variables:{id:this.id,input:t}})}async getAllStakeholders(){const t=await Qr.getShadowGraphqlClient().query({query:qo,errorPolicy:"all",variables:{id:this.id}});if(!t.data.bundles||0===t.data.bundles.length)throw new Error("Bundle not found!");return t.data.bundles[0].bundleStakeholders||[]}async reloadWorkflowExperience(t,e){const A=e?A=>e(A,t):void 0,i=await this.client.getWorkflowExperience(void 0,void 0,A,{type:"transaction",transactionId:t}),n=this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t));return n>-1?this.workflowExperiences[n]=i:this.workflowExperiences.push(i),i}async updateBundle(){if(!(await Qr.getShadowGraphqlClient().mutate({mutation:$o,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e})))}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async resolveGlobalProperties(){const t=this.productCollection;if(!t)return Promise.resolve([]);const e=new Set;t.products.forEach((t=>t.workflows?.forEach((t=>e.add(t.workflowName)))));const A=await Qr.getShadowGraphqlClient().query({query:ic,errorPolicy:"all",variables:{ids:Array.from(e)}}),i=new Map;return A.data.workflows?.forEach((t=>{t.globalPropertyConfiguration&&i.set(t.globalPropertyConfiguration.id,t.globalPropertyConfiguration)})),Object.values(i)}}function Bc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const pc=t.gql`
660
+ `;function hc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class dc{constructor(t){hc(this,"bundleId",void 0),hc(this,"globalPropertyState",void 0),this.bundleId=t,this.getOrCreateGlobalPropertyState().then((t=>this.globalPropertyState=t))}getGlobalPropertyState(){return this.globalPropertyState}getAspect(t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=this.globalPropertyState.aspects.find((e=>e.name===t));if(e)return e.value}setAspect(t,e){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const A=this.globalPropertyState.aspects.find((e=>e.name===t));return A?A.value=e:this.globalPropertyState.aspects.push({name:t,value:e}),this.updateGlobalPropertyState()}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await Qr.getShadowGraphqlClient().mutate({mutation:lc,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects}});if(!t.data?.globalPropertyStateUpdate)throw new Error("Unable to update global property state");this.globalPropertyState=t.data.globalPropertyStateUpdate}async getOrCreateGlobalPropertyState(){const t=await Qr.getShadowGraphqlClient().query({query:gc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const e=await Qr.getShadowGraphqlClient().mutate({mutation:cc,variables:{bundleId:this.bundleId}});if(e.data?.globalPropertyStateCreate&&e.data.globalPropertyStateCreate.id)return e.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}function uc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class wc{constructor(t,e){uc(this,"client",void 0),uc(this,"id",void 0),uc(this,"name",void 0),uc(this,"metadata",void 0),uc(this,"productCollection",void 0),uc(this,"globalConfigurations",void 0),uc(this,"globalPropertyStateManager",void 0),uc(this,"workflowExperiences",[]),this.client=t,this.id=e.id,this.name=e.name||"",this.metadata=new Map(e.metadata?.map((t=>[t.key,t.value]))||[]),this.productCollection=e.productCollection,this.globalConfigurations=this.resolveGlobalProperties(),this.globalPropertyStateManager=new dc(this.id),e.transactions&&e.transactions.length>0&&(this.workflowExperiences=e.transactions.map((()=>{})))}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(t){return this.name=t,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(t){return this.metadata=new Map(t),this.updateBundle()}setNameAndMetadata(t,e){return this.name=t,this.metadata=new Map(e),this.updateBundle()}async hasGlobalProperties(){const t=await this.globalConfigurations;return t.length>0&&t.some((t=>t.aspects.length>0))}async getGlobalProperties(){const t=await this.globalConfigurations;if(0===t.length)return[];return(await Promise.all(t.map((t=>Promise.all(t.aspects.map((async t=>{switch(t.type){case tA.FileUpload:return new sc(this,t);case tA.Option:return new oc(this,t,t.entityId?await kr.getOption(t.entityId):void 0)}}))))))).flat()}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,e)=>t+e),0)}getProductCollection(){return this.productCollection}async addWorkflowExperience(t){const e=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===e)))throw new Error("Unable to add transaction to bundle - Already Exists!");await Qr.getShadowGraphqlClient().mutate({mutation:_o,variables:{id:this.id,transactionId:e}}),this.workflowExperiences.push(t);const A=await this.getGlobalProperties();await Promise.all(A.map((e=>e.applyGlobalState([t]))))}async removeWorkflowExperience(t){const e=this.workflowExperiences.indexOf(t);if(!(e>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found!");await Qr.getShadowGraphqlClient().mutate({mutation:tc,variables:{id:this.id,transactionId:t.getWorkflowManager().getTransaction().id}}),this.workflowExperiences.splice(e,1)}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await Qr.getShadowGraphqlClient().mutate({mutation:nc,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){await Qr.getShadowGraphqlClient().mutate({mutation:ec,variables:{id:this.id,details:t,type:e||ia.Owner}})}async updateStakeholders(t){await Qr.getShadowGraphqlClient().mutate({mutation:Ac,variables:{id:this.id,input:t}})}async getAllStakeholders(){const t=await Qr.getShadowGraphqlClient().query({query:qo,errorPolicy:"all",variables:{id:this.id}});if(!t.data.bundles||0===t.data.bundles.length)throw new Error("Bundle not found!");return t.data.bundles[0].bundleStakeholders||[]}async reloadWorkflowExperience(t,e,A){const i=e?A=>e(A,t):void 0,n=await this.client.getWorkflowExperience(void 0,void 0,i,{type:"transaction",transactionId:t}),r=A??this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t));return r>-1?this.workflowExperiences[r]=n:this.workflowExperiences.push(n),n}async updateBundle(){if(!(await Qr.getShadowGraphqlClient().mutate({mutation:$o,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e})))}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async resolveGlobalProperties(){const t=this.productCollection;if(!t)return Promise.resolve([]);const e=new Set;t.products.forEach((t=>t.workflows?.forEach((t=>e.add(t.workflowName)))));const A=await Qr.getShadowGraphqlClient().query({query:ic,errorPolicy:"all",variables:{ids:Array.from(e)}}),i=new Map;return A.data.workflows?.forEach((t=>{t.globalPropertyConfiguration&&i.set(t.globalPropertyConfiguration.id,t.globalPropertyConfiguration)})),Object.values(i)}}function Bc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const pc=t.gql`
661
661
  fragment RegionFields on Region {
662
662
  width
663
663
  top
@@ -1282,5 +1282,5 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),A=require("react/j
1282
1282
  }
1283
1283
  }
1284
1284
  }
1285
- `,vc=async t=>{const e=(await Qr.getShadowGraphqlClient().query({query:Cc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}})).data.workflow;return e.steps.forEach((t=>{delete t.data.__typename})),e},Fc=(t,e)=>{const A=t.workflowState,i=A?JSON.parse(A):void 0;return i?Object.values(i.layouts).map((t=>t.layout)):e.panels.sort(((t,e)=>t.index-e.index)).map((t=>({id:Te(),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})))};class Sc{constructor(t){var e;Bc(this,"options",void 0),Bc(this,"initialized",void 0),Bc(this,"experienceOptions",void 0),Bc(this,"currencyCode",void 0),Bc(this,"customer",void 0),Bc(this,"updateTransactionState",(async t=>{try{return Qr.getShadowGraphqlClient().mutate({...t,mutation:Ys})}catch(t){throw console.error(t),new ar("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,fr=e)}getAssetManager(){return Yr}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateBundleFromLocalStorage(t){const e=gr.getMap("bundleOwnerIds");if(e?.has(t)){const A=e.get(t);return Er(A),Promise.resolve({success:!0,stakeholderType:ia.Owner})}const A=gr.getMap("bundleCustomerIds");if(A?.has(t)){const e=A.get(t);if(e){if(await this.authenticateCustomerId(e)){const e=this.customer?.bundleStakeholders?.find((e=>e.bundle?.id===t));if(e)return Promise.resolve({success:!0,stakeholderType:e.type})}}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){const e=Qr.getShadowGraphqlClient(),A=await e.query({query:fc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!A.data.transactions||0===A.data.transactions.length)throw new Error(`Transaction not found: ${t}`);const i=A.data.transactions[0],n=i.product?.partner?.id;if(!n)throw new Error(`Unable to read transaction: ${t}`);if(i.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const r=gr.getMap("transactionOwnerIds");if(r?.has(t)){const e=r.get(t);return Br(e),Promise.resolve({success:!0,stakeholderType:ia.Owner})}const a=gr.getMap("transactionCustomerIds");if(a?.has(t)){const e=a.get(t);if(e){if(await this.authenticateCustomerId(e)){const e=this.customer?.bundleStakeholders?.find((e=>e.bundle?.transactions?.some((e=>e.id===t))))||this.customer?.stakeholders?.find((e=>e.transaction?.id===t));if(e)return Promise.resolve({success:!0,stakeholderType:e.type})}}}const s=(await e.query({query:Qc,errorPolicy:"all",variables:{id:i.workflowId}})).data.workflow;if(!s)throw new Error(`Unable to read workflow: ${i.workflowId}`);return Promise.resolve({success:!1,theme:s.overrideTheme,customLogoLink:i.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=gr.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),gr.setMap("transactionCustomerIds",e))}getStakeholderTypeForTransaction(t){const e=this.customer?.stakeholders?.find((e=>e.transaction?.id===t));if(e)return e.type}async getOrCreateCustomer(t){this.customer=void 0;const e=Qr.getShadowGraphqlClient(),A=(await e.query({query:yc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!A.id){const A=(await e.mutate({mutation:Dc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!A)throw new Error("Unable to create customer.");return this.customer=A,{customer:A,isAuthenticated:!1}}const i=await this.authenticateCustomerId(A.id);return{customer:this.customer||A,isAuthenticated:i}}async authenticateCustomerId(t){const e=Qr.getShadowGraphqlClient(),A=gr.getMap("customerTokens");if(!A?.has(t))return!1;const i=A.get(t);if(!i)return!1;const n=(await e.mutate({mutation:Ic,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:i}})).data?.customerAuthenticate;return!!n&&(Cr(i),this.customer=n,!0)}async generateVerificationCode(t){await Qr.getShadowGraphqlClient().mutate({mutation:xc,variables:{emailAddress:t}})}async verifyCode(t,e){const A=(await Qr.getShadowGraphqlClient().mutate({mutation:Mc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data?.customerVerifyCode;if(A?.loginToken){if(!A.partner?.id)throw new Error(`Unable to find customer: ${t}`);const e=gr.getMap("customerTokens")||new Map;return e.set(A.id,A.loginToken),gr.setMap("customerTokens",e),Cr(A.loginToken),this.customer={...A,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Qr.getShadowGraphqlClient().mutate({mutation:Zo,variables:{collectionId:t}})).data?.bundleCreate;if(!e)throw new Error("Unable to create bundle");Er(e.bundleOwnerId);const A=gr.getMap("bundleOwnerIds")||new Map;return A.set(e.id,e.bundleOwnerId),gr.setMap("bundleOwnerIds",A),new wc(this,e)}async getExistingBundle(t,e){const A=await Qr.getShadowGraphqlClient().query({query:Xo,variables:{id:t}});if(!A.data?.bundles||0===A.data?.bundles.length||!A.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const i=A.data?.bundles[0],n=gr.getMap("bundleOwnerIds");n?.has(i.id)&&Er(n.get(i.id));const r=new wc(this,i);return i.transactions&&i.transactions.length>0&&await Promise.all(i.transactions.map((async t=>{r.reloadWorkflowExperience(t.id,e)}))),r}async getWorkflowExperience(t,e,A,i){if(!i)return await this.getWorkflowExperienceDeprecated(t,e,A);const n=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await Vn(e.svg))}const i=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<i.length;++t){const e=i[t];e.fontData?.assetUrl&&ri(e.fontData.assetUrl)}}},{transaction:r,workflow:a,readOnly:s}=await(async()=>{const t=Qr.getShadowGraphqlClient();if("transaction"===i.type){const{transactionId:e,readOnly:A}=i,n=await t.query({query:bs,variables:{id:e},errorPolicy:"all",fetchPolicy:"no-cache"});if(!n.data?.transactions||0===n.data.transactions.length)throw new ar("Existing transaction not found.");const r=n.data?.transactions[0];if(!r.workflowId)throw new ar("Existing transaction has no workflow ID.");const a=await vc(r.workflowId);if(!r.product)throw new ar("Failed to load transaction, product not available.");return{transaction:r,workflow:a,readOnly:A}}if("integration"===i.type||"external"===i.type){const e=async()=>{const e="integration"===i.type?{integrationProductId:i.integrationProductId}:{externalIntegrationId:i.externalIntegrationId,externalProductId:i.externalProductId},A=await t.mutate({mutation:Fs,variables:{...e,bulk:i.bulk,workflowId:i.workflowId,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 ar("Failed to create transaction!");const n=A.data.transactionCreate;if(!n.product)throw new ar("Failed to create transaction, product not available.");return n},A=vc(i.workflowId),[n,r]=await Promise.all([e(),A]);return{transaction:n,workflow:r}}throw new ar("No workflow ID provided.")})();if(this.currencyCode=r.product.partner?.currencyCode,this.experienceOptions={product:r.product,transaction:r,layouts:[],stateMutationFunc:s?async()=>{throw new nr("State mutation is forbidden in read only mode!")}:this.updateTransactionState,readOnly:s,workflow:a},"transaction"===i.type&&r.workflowState){const t=JSON.parse(r.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await n(t),this.experienceOptions.reloadedState=t}else if(!s&&i.workflowState){const t=JSON.parse(i.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Fc(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=A&&A(a),this.experienceOptions.renderableContextService=new Cs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]),"transaction"!==i.type){const t=gr.getMap("transactionOwnerIds")||new Map;t.set(r.id,r.transactionOwnerId),Br(r.transactionOwnerId||""),gr.setMap("transactionOwnerIds",t)}else{const t=(gr.getMap("transactionOwnerIds")||new Map).get(r.id);t&&Br(t)}this.initialized=!0;const o=new Vo(this,this.experienceOptions);return await o.getWorkflowManager().getInitializationPromise(),"transaction"!==i.type&&this.customer&&await o.attachCustomerDetails({email:this.customer.emailAddress}),o}async initFromIntegrationProduct(t){if(""===t)throw new ar("No integration product ID provided.");const e=Qr.getShadowGraphqlClient(),A=await e.mutate({mutation:Fs,variables:{integrationProductId:t,bulk:this.options.bulk||!1,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 ar("Failed to create transaction!");const i=A.data.transactionCreate;if(!i.product)throw new ar("Failed to create transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode;const n=gr.getMap("transactionOwnerIds")||new Map;n.set(i.id,i.transactionOwnerId),Br(i.transactionOwnerId||""),gr.setMap("transactionOwnerIds",n),this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,e=!1){if(""===t)throw new ar("No transaction ID provided.");const A=Qr.getShadowGraphqlClient();if(e)return await(async()=>{const i=(await A.query({query:bs,variables:{id:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!i)throw new ar("Failed to read transaction.");if(!i.product)throw new ar("Failed to load transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode,this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:async()=>{throw new nr("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const i=gr.getMap("transactionOwnerIds")||new Map,n=i.get(t);if(n){Br(n);const i=(await A.query({query:bs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!i)throw new ar("Failed to read transaction.");if(!i.product)throw new ar("Failed to load transaction, product not available.");return this.currencyCode=i.product.partner?.currencyCode,this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},void(this.initialized=!0)}try{const n=(await A.mutate({mutation:Ss,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!n)throw new ar("Failed to read transaction.");if(!n.product)throw new ar("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,n.transactionOwnerId&&(i.set(n.id,n.transactionOwnerId),Br(n.transactionOwnerId),gr.setMap("transactionOwnerIds",i)),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new ar("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,A){if(!this.initialized||!this.experienceOptions)throw new ar("Cannot launch experience: Not initialized.");const i=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await Vn(e.svg))}const i=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<i.length;++t){const e=i[t];e.fontData?.assetUrl&&ri(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await vc(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=t,this.experienceOptions.transaction.workflowState){const t=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await i(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=A&&A(t),this.experienceOptions.renderableContextService=new Cs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const e=new Vo(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const n=Qr.getShadowGraphqlClient().mutate({mutation:Ps,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),r=vc(t);if(await Promise.all([n,r]),this.experienceOptions.workflow=await r,e){const t=JSON.parse(e);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await i(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Fc(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await r),this.experienceOptions.renderableContextService=new Cs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const a=new Vo(this,this.experienceOptions);return await a.getWorkflowManager().getInitializationPromise(),a}throw new ar("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new ar("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new ar("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function bc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Yc{constructor(){bc(this,"getProduct",void 0),bc(this,"getCommandContext",void 0),bc(this,"getAllLayoutData",void 0),bc(this,"getMetadata",void 0),bc(this,"getWorkflowMetadata",void 0),bc(this,"getStepStorage",void 0),bc(this,"setModelContainer",void 0),bc(this,"getUpdatesPending",void 0)}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}getVariationRecords(){return[]}async reset(){}updateStateWithServer(t){}addVariationRecord(t){return{recordNumber:0,transactionId:"",values:[]}}getCurrentVariationRecord(){}removeVariationRecord(t){return[]}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addCurrentVariationCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,e){}addStorageCallback(t){}addVariationRecordsCallback(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{}}setCurrentAdjustingStepId(t){}setCurrentVariationRecord(t){}setEditedStatus(t,e){}setInformationResults(t){}setMandatoryFulfilled(t,e){}async setSelectionsAndElements(t,e,A){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}}function Pc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}let Nc;var Rc;(Rc=Nc||(Nc={})).SelectFrame="SelectFrame",Rc.SelectImage="SelectImage",Rc.Position="Position";class kc extends yo{constructor(t,e){super(t,e),Pc(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return eo.selectVariant(this.step,t.getResource(),e,this.manager,(t=>this.setUpdateState(t)))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged((e=>{e&&t(e)}))}selectImage(t){return eo.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,e,A,i){return i&&i.length>1&&void 0===t?Nc.SelectFrame:e||A||this.getImageData()?Nc.Position:Nc.SelectImage}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}hasVaryingUpload(){return this.step.data.varyUpload}hasVaryingSelection(){return this.step.data.varySelection}}const Hc=t=>{const e=(0,i.useRef)(null),n=(0,i.useRef)(void 0),[r,a]=(0,i.useState)(void 0),{addEvent:s,removeEvent:o,updateEvent:c,eventCache:l}=Ur(),[g,h]=(0,i.useState)(!1),[d,u]=(0,i.useState)(!1),{state:w,uiDispatcher:B}=Wr(),p=(0,i.useCallback)((t=>{const e=t;B(new Kr({zoom:Math.max(.1,Math.min(e,w.maxZoom))}))}),[B,w.maxZoom]),E=(0,i.useCallback)((t=>{o(t),1===l.length&&(n.current=void 0),2===l.length&&a(void 0);"touch"===t.pointerType&&l.length>1&&l.length-1==1&&(u(!1),h(!1))}),[o,l.length]),m=(0,i.useCallback)((t=>{s(t);"touch"===t.pointerType&&1===l.length&&(B(new Kr({selectedElement:void 0})),u(!0),h(!0))}),[s,l.length,B]),C=(0,i.useCallback)((t=>{c(t);const e=1===l.length&&"touch"!==l[0].pointerType,A=2===l.length&&"touch"===l[0].pointerType;if(g&&A){const[t,e]=l,A=Math.abs(t.clientX-e.clientX),i=r;i&&p(w.zoom-.0055*(i-A)),a(A)}if(d&&(e||A)&&t.isPrimary){const e=(n?.current?.x||t.screenX)-t.screenX,A=(n?.current?.y||t.screenY)-t.screenY;B(new Kr({selectedElement:void 0,xTranslation:w.xTranslation-e/w.zoom,yTranslation:w.yTranslation-A/w.zoom}))}t.isPrimary&&(n.current={x:t.screenX,y:t.screenY})}),[c,l,g,d,r,p,w.zoom,w.xTranslation,w.yTranslation,B]),f=(0,i.useCallback)((t=>{g&&p(w.zoom-.035*Math.sign(t.deltaY))}),[p,w.zoom,g]);(0,i.useEffect)((()=>{if(!e.current||0===l.length)return;const t=l[0].pointerId,A=e.current.hasPointerCapture(t);d&&!A&&e.current.setPointerCapture(t),!d&&A&&e.current.releasePointerCapture(t)}),[e,d,l]),Ha([" "],(()=>{u(!0),B(new Kr({selectedElement:void 0}))}),(()=>u(!1))),Ha(["Control"],(()=>h(!0)),(()=>h(!1)));const Q=(0,i.useMemo)((()=>({cursor:d&&0===l.length?"grab":d&&1===l.length?"grabbing":g?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[d,g,l]);return(0,A.jsx)("div",{ref:e,className:"transform-wrapper",onWheel:f,onPointerDown:m,onPointerUp:E,onPointerCancel:E,onPointerLeave:E,onPointerMove:C,style:Q,children:t.children})};
1285
+ `,vc=async t=>{const e=(await Qr.getShadowGraphqlClient().query({query:Cc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}})).data.workflow;return e.steps.forEach((t=>{delete t.data.__typename})),e},Fc=(t,e)=>{const A=t.workflowState,i=A?JSON.parse(A):void 0;return i?Object.values(i.layouts).map((t=>t.layout)):e.panels.sort(((t,e)=>t.index-e.index)).map((t=>({id:Te(),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})))};class Sc{constructor(t){var e;Bc(this,"options",void 0),Bc(this,"initialized",void 0),Bc(this,"experienceOptions",void 0),Bc(this,"currencyCode",void 0),Bc(this,"customer",void 0),Bc(this,"updateTransactionState",(async t=>{try{return Qr.getShadowGraphqlClient().mutate({...t,mutation:Ys})}catch(t){throw console.error(t),new ar("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,fr=e)}getAssetManager(){return Yr}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateBundleFromLocalStorage(t){const e=gr.getMap("bundleOwnerIds");if(e?.has(t)){const A=e.get(t);return Er(A),Promise.resolve({success:!0,stakeholderType:ia.Owner})}const A=gr.getMap("bundleCustomerIds");if(A?.has(t)){const e=A.get(t);if(e){if(await this.authenticateCustomerId(e)){const e=this.customer?.bundleStakeholders?.find((e=>e.bundle?.id===t));if(e)return Promise.resolve({success:!0,stakeholderType:e.type})}}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){const e=Qr.getShadowGraphqlClient(),A=await e.query({query:fc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!A.data.transactions||0===A.data.transactions.length)throw new Error(`Transaction not found: ${t}`);const i=A.data.transactions[0],n=i.product?.partner?.id;if(!n)throw new Error(`Unable to read transaction: ${t}`);if(i.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const r=gr.getMap("transactionOwnerIds");if(r?.has(t)){const e=r.get(t);return Br(e),Promise.resolve({success:!0,stakeholderType:ia.Owner})}const a=gr.getMap("transactionCustomerIds");if(a?.has(t)){const e=a.get(t);if(e){if(await this.authenticateCustomerId(e)){const e=this.customer?.bundleStakeholders?.find((e=>e.bundle?.transactions?.some((e=>e.id===t))))||this.customer?.stakeholders?.find((e=>e.transaction?.id===t));if(e)return Promise.resolve({success:!0,stakeholderType:e.type})}}}const s=(await e.query({query:Qc,errorPolicy:"all",variables:{id:i.workflowId}})).data.workflow;if(!s)throw new Error(`Unable to read workflow: ${i.workflowId}`);return Promise.resolve({success:!1,theme:s.overrideTheme,customLogoLink:i.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=gr.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),gr.setMap("transactionCustomerIds",e))}getStakeholderTypeForTransaction(t){const e=this.customer?.stakeholders?.find((e=>e.transaction?.id===t));if(e)return e.type}async getOrCreateCustomer(t){this.customer=void 0;const e=Qr.getShadowGraphqlClient(),A=(await e.query({query:yc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!A.id){const A=(await e.mutate({mutation:Dc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!A)throw new Error("Unable to create customer.");return this.customer=A,{customer:A,isAuthenticated:!1}}const i=await this.authenticateCustomerId(A.id);return{customer:this.customer||A,isAuthenticated:i}}async authenticateCustomerId(t){const e=Qr.getShadowGraphqlClient(),A=gr.getMap("customerTokens");if(!A?.has(t))return!1;const i=A.get(t);if(!i)return!1;const n=(await e.mutate({mutation:Ic,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:i}})).data?.customerAuthenticate;return!!n&&(Cr(i),this.customer=n,!0)}async generateVerificationCode(t){await Qr.getShadowGraphqlClient().mutate({mutation:xc,variables:{emailAddress:t}})}async verifyCode(t,e){const A=(await Qr.getShadowGraphqlClient().mutate({mutation:Mc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data?.customerVerifyCode;if(A?.loginToken){if(!A.partner?.id)throw new Error(`Unable to find customer: ${t}`);const e=gr.getMap("customerTokens")||new Map;return e.set(A.id,A.loginToken),gr.setMap("customerTokens",e),Cr(A.loginToken),this.customer={...A,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Qr.getShadowGraphqlClient().mutate({mutation:Zo,variables:{collectionId:t}})).data?.bundleCreate;if(!e)throw new Error("Unable to create bundle");Er(e.bundleOwnerId);const A=gr.getMap("bundleOwnerIds")||new Map;return A.set(e.id,e.bundleOwnerId),gr.setMap("bundleOwnerIds",A),new wc(this,e)}async getExistingBundle(t,e){const A=await Qr.getShadowGraphqlClient().query({query:Xo,variables:{id:t}});if(!A.data?.bundles||0===A.data?.bundles.length||!A.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const i=A.data?.bundles[0],n=gr.getMap("bundleOwnerIds");n?.has(i.id)&&Er(n.get(i.id));const r=new wc(this,i);return i.transactions&&i.transactions.length>0&&await Promise.all(i.transactions.map((async(t,A)=>{r.reloadWorkflowExperience(t.id,e,A)}))),r}async getWorkflowExperience(t,e,A,i){if(!i)return await this.getWorkflowExperienceDeprecated(t,e,A);const n=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await Vn(e.svg))}const i=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<i.length;++t){const e=i[t];e.fontData?.assetUrl&&ri(e.fontData.assetUrl)}}},{transaction:r,workflow:a,readOnly:s}=await(async()=>{const t=Qr.getShadowGraphqlClient();if("transaction"===i.type){const{transactionId:e,readOnly:A}=i,n=await t.query({query:bs,variables:{id:e},errorPolicy:"all",fetchPolicy:"no-cache"});if(!n.data?.transactions||0===n.data.transactions.length)throw new ar("Existing transaction not found.");const r=n.data?.transactions[0];if(!r.workflowId)throw new ar("Existing transaction has no workflow ID.");const a=await vc(r.workflowId);if(!r.product)throw new ar("Failed to load transaction, product not available.");return{transaction:r,workflow:a,readOnly:A}}if("integration"===i.type||"external"===i.type){const e=async()=>{const e="integration"===i.type?{integrationProductId:i.integrationProductId}:{externalIntegrationId:i.externalIntegrationId,externalProductId:i.externalProductId},A=await t.mutate({mutation:Fs,variables:{...e,bulk:i.bulk,workflowId:i.workflowId,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 ar("Failed to create transaction!");const n=A.data.transactionCreate;if(!n.product)throw new ar("Failed to create transaction, product not available.");return n},A=vc(i.workflowId),[n,r]=await Promise.all([e(),A]);return{transaction:n,workflow:r}}throw new ar("No workflow ID provided.")})();if(this.currencyCode=r.product.partner?.currencyCode,this.experienceOptions={product:r.product,transaction:r,layouts:[],stateMutationFunc:s?async()=>{throw new nr("State mutation is forbidden in read only mode!")}:this.updateTransactionState,readOnly:s,workflow:a},"transaction"===i.type&&r.workflowState){const t=JSON.parse(r.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await n(t),this.experienceOptions.reloadedState=t}else if(!s&&i.workflowState){const t=JSON.parse(i.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Fc(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=A&&A(a),this.experienceOptions.renderableContextService=new Cs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]),"transaction"!==i.type){const t=gr.getMap("transactionOwnerIds")||new Map;t.set(r.id,r.transactionOwnerId),Br(r.transactionOwnerId||""),gr.setMap("transactionOwnerIds",t)}else{const t=(gr.getMap("transactionOwnerIds")||new Map).get(r.id);t&&Br(t)}this.initialized=!0;const o=new Vo(this,this.experienceOptions);return await o.getWorkflowManager().getInitializationPromise(),"transaction"!==i.type&&this.customer&&await o.attachCustomerDetails({email:this.customer.emailAddress}),o}async initFromIntegrationProduct(t){if(""===t)throw new ar("No integration product ID provided.");const e=Qr.getShadowGraphqlClient(),A=await e.mutate({mutation:Fs,variables:{integrationProductId:t,bulk:this.options.bulk||!1,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 ar("Failed to create transaction!");const i=A.data.transactionCreate;if(!i.product)throw new ar("Failed to create transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode;const n=gr.getMap("transactionOwnerIds")||new Map;n.set(i.id,i.transactionOwnerId),Br(i.transactionOwnerId||""),gr.setMap("transactionOwnerIds",n),this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,e=!1){if(""===t)throw new ar("No transaction ID provided.");const A=Qr.getShadowGraphqlClient();if(e)return await(async()=>{const i=(await A.query({query:bs,variables:{id:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!i)throw new ar("Failed to read transaction.");if(!i.product)throw new ar("Failed to load transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode,this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:async()=>{throw new nr("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const i=gr.getMap("transactionOwnerIds")||new Map,n=i.get(t);if(n){Br(n);const i=(await A.query({query:bs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!i)throw new ar("Failed to read transaction.");if(!i.product)throw new ar("Failed to load transaction, product not available.");return this.currencyCode=i.product.partner?.currencyCode,this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},void(this.initialized=!0)}try{const n=(await A.mutate({mutation:Ss,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!n)throw new ar("Failed to read transaction.");if(!n.product)throw new ar("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,n.transactionOwnerId&&(i.set(n.id,n.transactionOwnerId),Br(n.transactionOwnerId),gr.setMap("transactionOwnerIds",i)),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new ar("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,A){if(!this.initialized||!this.experienceOptions)throw new ar("Cannot launch experience: Not initialized.");const i=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await Vn(e.svg))}const i=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<i.length;++t){const e=i[t];e.fontData?.assetUrl&&ri(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await vc(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=t,this.experienceOptions.transaction.workflowState){const t=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await i(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=A&&A(t),this.experienceOptions.renderableContextService=new Cs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const e=new Vo(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const n=Qr.getShadowGraphqlClient().mutate({mutation:Ps,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),r=vc(t);if(await Promise.all([n,r]),this.experienceOptions.workflow=await r,e){const t=JSON.parse(e);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Wi(t),await i(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Fc(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await r),this.experienceOptions.renderableContextService=new Cs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const a=new Vo(this,this.experienceOptions);return await a.getWorkflowManager().getInitializationPromise(),a}throw new ar("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new ar("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new ar("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function bc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Yc{constructor(){bc(this,"getProduct",void 0),bc(this,"getCommandContext",void 0),bc(this,"getAllLayoutData",void 0),bc(this,"getMetadata",void 0),bc(this,"getWorkflowMetadata",void 0),bc(this,"getStepStorage",void 0),bc(this,"setModelContainer",void 0),bc(this,"getUpdatesPending",void 0)}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}getVariationRecords(){return[]}async reset(){}updateStateWithServer(t){}addVariationRecord(t){return{recordNumber:0,transactionId:"",values:[]}}getCurrentVariationRecord(){}removeVariationRecord(t){return[]}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addCurrentVariationCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,e){}addStorageCallback(t){}addVariationRecordsCallback(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{}}setCurrentAdjustingStepId(t){}setCurrentVariationRecord(t){}setEditedStatus(t,e){}setInformationResults(t){}setMandatoryFulfilled(t,e){}async setSelectionsAndElements(t,e,A){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}}function Pc(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var i=A.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}let Nc;var Rc;(Rc=Nc||(Nc={})).SelectFrame="SelectFrame",Rc.SelectImage="SelectImage",Rc.Position="Position";class kc extends yo{constructor(t,e){super(t,e),Pc(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return eo.selectVariant(this.step,t.getResource(),e,this.manager,(t=>this.setUpdateState(t)))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged((e=>{e&&t(e)}))}selectImage(t){return eo.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,e,A,i){return i&&i.length>1&&void 0===t?Nc.SelectFrame:e||A||this.getImageData()?Nc.Position:Nc.SelectImage}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}hasVaryingUpload(){return this.step.data.varyUpload}hasVaryingSelection(){return this.step.data.varySelection}}const Hc=t=>{const e=(0,i.useRef)(null),n=(0,i.useRef)(void 0),[r,a]=(0,i.useState)(void 0),{addEvent:s,removeEvent:o,updateEvent:c,eventCache:l}=Ur(),[g,h]=(0,i.useState)(!1),[d,u]=(0,i.useState)(!1),{state:w,uiDispatcher:B}=Wr(),p=(0,i.useCallback)((t=>{const e=t;B(new Kr({zoom:Math.max(.1,Math.min(e,w.maxZoom))}))}),[B,w.maxZoom]),E=(0,i.useCallback)((t=>{o(t),1===l.length&&(n.current=void 0),2===l.length&&a(void 0);"touch"===t.pointerType&&l.length>1&&l.length-1==1&&(u(!1),h(!1))}),[o,l.length]),m=(0,i.useCallback)((t=>{s(t);"touch"===t.pointerType&&1===l.length&&(B(new Kr({selectedElement:void 0})),u(!0),h(!0))}),[s,l.length,B]),C=(0,i.useCallback)((t=>{c(t);const e=1===l.length&&"touch"!==l[0].pointerType,A=2===l.length&&"touch"===l[0].pointerType;if(g&&A){const[t,e]=l,A=Math.abs(t.clientX-e.clientX),i=r;i&&p(w.zoom-.0055*(i-A)),a(A)}if(d&&(e||A)&&t.isPrimary){const e=(n?.current?.x||t.screenX)-t.screenX,A=(n?.current?.y||t.screenY)-t.screenY;B(new Kr({selectedElement:void 0,xTranslation:w.xTranslation-e/w.zoom,yTranslation:w.yTranslation-A/w.zoom}))}t.isPrimary&&(n.current={x:t.screenX,y:t.screenY})}),[c,l,g,d,r,p,w.zoom,w.xTranslation,w.yTranslation,B]),f=(0,i.useCallback)((t=>{g&&p(w.zoom-.035*Math.sign(t.deltaY))}),[p,w.zoom,g]);(0,i.useEffect)((()=>{if(!e.current||0===l.length)return;const t=l[0].pointerId,A=e.current.hasPointerCapture(t);d&&!A&&e.current.setPointerCapture(t),!d&&A&&e.current.releasePointerCapture(t)}),[e,d,l]),Ha([" "],(()=>{u(!0),B(new Kr({selectedElement:void 0}))}),(()=>u(!1))),Ha(["Control"],(()=>h(!0)),(()=>h(!1)));const Q=(0,i.useMemo)((()=>({cursor:d&&0===l.length?"grab":d&&1===l.length?"grabbing":g?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[d,g,l]);return(0,A.jsx)("div",{ref:e,className:"transform-wrapper",onWheel:f,onPointerDown:m,onPointerUp:E,onPointerCancel:E,onPointerLeave:E,onPointerMove:C,style:Q,children:t.children})};
1286
1286
  //# sourceMappingURL=main.js.map
package/dist/module.js CHANGED
@@ -657,7 +657,7 @@ import{CommandContext as t,AssetType as A,BringForwardCommand as e,BringToFrontC
657
657
  }
658
658
  }
659
659
  }
660
- `;function da(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class ha{constructor(t){da(this,"bundleId",void 0),da(this,"globalPropertyState",void 0),this.bundleId=t,this.getOrCreateGlobalPropertyState().then((t=>this.globalPropertyState=t))}getGlobalPropertyState(){return this.globalPropertyState}getAspect(t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const A=this.globalPropertyState.aspects.find((A=>A.name===t));if(A)return A.value}setAspect(t,A){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=this.globalPropertyState.aspects.find((A=>A.name===t));return e?e.value=A:this.globalPropertyState.aspects.push({name:t,value:A}),this.updateGlobalPropertyState()}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await yA.getShadowGraphqlClient().mutate({mutation:Ba,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects}});if(!t.data?.globalPropertyStateUpdate)throw new Error("Unable to update global property state");this.globalPropertyState=t.data.globalPropertyStateUpdate}async getOrCreateGlobalPropertyState(){const t=await yA.getShadowGraphqlClient().query({query:wa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const A=await yA.getShadowGraphqlClient().mutate({mutation:la,variables:{bundleId:this.bundleId}});if(A.data?.globalPropertyStateCreate&&A.data.globalPropertyStateCreate.id)return A.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}function Ea(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class Ca{constructor(t,A){Ea(this,"client",void 0),Ea(this,"id",void 0),Ea(this,"name",void 0),Ea(this,"metadata",void 0),Ea(this,"productCollection",void 0),Ea(this,"globalConfigurations",void 0),Ea(this,"globalPropertyStateManager",void 0),Ea(this,"workflowExperiences",[]),this.client=t,this.id=A.id,this.name=A.name||"",this.metadata=new Map(A.metadata?.map((t=>[t.key,t.value]))||[]),this.productCollection=A.productCollection,this.globalConfigurations=this.resolveGlobalProperties(),this.globalPropertyStateManager=new ha(this.id)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(t){return this.name=t,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(t){return this.metadata=new Map(t),this.updateBundle()}setNameAndMetadata(t,A){return this.name=t,this.metadata=new Map(A),this.updateBundle()}async hasGlobalProperties(){const t=await this.globalConfigurations;return t.length>0&&t.some((t=>t.aspects.length>0))}async getGlobalProperties(){const t=await this.globalConfigurations;if(0===t.length)return[];return(await Promise.all(t.map((t=>Promise.all(t.aspects.map((async t=>{switch(t.type){case It.FileUpload:return new ca(this,t);case It.Option:return new ga(this,t,t.entityId?await bA.getOption(t.entityId):void 0)}}))))))).flat()}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,A)=>t+A),0)}getProductCollection(){return this.productCollection}async addWorkflowExperience(t){const A=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===A)))throw new Error("Unable to add transaction to bundle - Already Exists!");await yA.getShadowGraphqlClient().mutate({mutation:Aa,variables:{id:this.id,transactionId:A}}),this.workflowExperiences.push(t);const e=await this.getGlobalProperties();await Promise.all(e.map((A=>A.applyGlobalState([t]))))}async removeWorkflowExperience(t){const A=this.workflowExperiences.indexOf(t);if(!(A>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found!");await yA.getShadowGraphqlClient().mutate({mutation:ea,variables:{id:this.id,transactionId:t.getWorkflowManager().getTransaction().id}}),this.workflowExperiences.splice(A,1)}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await yA.getShadowGraphqlClient().mutate({mutation:oa,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,A){await yA.getShadowGraphqlClient().mutate({mutation:na,variables:{id:this.id,details:t,type:A||oe.Owner}})}async updateStakeholders(t){await yA.getShadowGraphqlClient().mutate({mutation:ia,variables:{id:this.id,input:t}})}async getAllStakeholders(){const t=await yA.getShadowGraphqlClient().query({query:$i,errorPolicy:"all",variables:{id:this.id}});if(!t.data.bundles||0===t.data.bundles.length)throw new Error("Bundle not found!");return t.data.bundles[0].bundleStakeholders||[]}async reloadWorkflowExperience(t,A){const e=A?e=>A(e,t):void 0,n=await this.client.getWorkflowExperience(void 0,void 0,e,{type:"transaction",transactionId:t}),i=this.workflowExperiences.findIndex((A=>A.getWorkflowManager().getTransaction().id===t));return i>-1?this.workflowExperiences[i]=n:this.workflowExperiences.push(n),n}async updateBundle(){if(!(await yA.getShadowGraphqlClient().mutate({mutation:ta,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,A])=>({key:t,value:A})))}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async resolveGlobalProperties(){const t=this.productCollection;if(!t)return Promise.resolve([]);const A=new Set;t.products.forEach((t=>t.workflows?.forEach((t=>A.add(t.workflowName)))));const e=await yA.getShadowGraphqlClient().query({query:aa,errorPolicy:"all",variables:{ids:Array.from(A)}}),n=new Map;return e.data.workflows?.forEach((t=>{t.globalPropertyConfiguration&&n.set(t.globalPropertyConfiguration.id,t.globalPropertyConfiguration)})),Object.values(n)}}function Qa(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const ua=ft`
660
+ `;function da(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class ha{constructor(t){da(this,"bundleId",void 0),da(this,"globalPropertyState",void 0),this.bundleId=t,this.getOrCreateGlobalPropertyState().then((t=>this.globalPropertyState=t))}getGlobalPropertyState(){return this.globalPropertyState}getAspect(t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const A=this.globalPropertyState.aspects.find((A=>A.name===t));if(A)return A.value}setAspect(t,A){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=this.globalPropertyState.aspects.find((A=>A.name===t));return e?e.value=A:this.globalPropertyState.aspects.push({name:t,value:A}),this.updateGlobalPropertyState()}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await yA.getShadowGraphqlClient().mutate({mutation:Ba,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects}});if(!t.data?.globalPropertyStateUpdate)throw new Error("Unable to update global property state");this.globalPropertyState=t.data.globalPropertyStateUpdate}async getOrCreateGlobalPropertyState(){const t=await yA.getShadowGraphqlClient().query({query:wa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const A=await yA.getShadowGraphqlClient().mutate({mutation:la,variables:{bundleId:this.bundleId}});if(A.data?.globalPropertyStateCreate&&A.data.globalPropertyStateCreate.id)return A.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}function Ea(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class Ca{constructor(t,A){Ea(this,"client",void 0),Ea(this,"id",void 0),Ea(this,"name",void 0),Ea(this,"metadata",void 0),Ea(this,"productCollection",void 0),Ea(this,"globalConfigurations",void 0),Ea(this,"globalPropertyStateManager",void 0),Ea(this,"workflowExperiences",[]),this.client=t,this.id=A.id,this.name=A.name||"",this.metadata=new Map(A.metadata?.map((t=>[t.key,t.value]))||[]),this.productCollection=A.productCollection,this.globalConfigurations=this.resolveGlobalProperties(),this.globalPropertyStateManager=new ha(this.id),A.transactions&&A.transactions.length>0&&(this.workflowExperiences=A.transactions.map((()=>{})))}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(t){return this.name=t,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(t){return this.metadata=new Map(t),this.updateBundle()}setNameAndMetadata(t,A){return this.name=t,this.metadata=new Map(A),this.updateBundle()}async hasGlobalProperties(){const t=await this.globalConfigurations;return t.length>0&&t.some((t=>t.aspects.length>0))}async getGlobalProperties(){const t=await this.globalConfigurations;if(0===t.length)return[];return(await Promise.all(t.map((t=>Promise.all(t.aspects.map((async t=>{switch(t.type){case It.FileUpload:return new ca(this,t);case It.Option:return new ga(this,t,t.entityId?await bA.getOption(t.entityId):void 0)}}))))))).flat()}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,A)=>t+A),0)}getProductCollection(){return this.productCollection}async addWorkflowExperience(t){const A=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===A)))throw new Error("Unable to add transaction to bundle - Already Exists!");await yA.getShadowGraphqlClient().mutate({mutation:Aa,variables:{id:this.id,transactionId:A}}),this.workflowExperiences.push(t);const e=await this.getGlobalProperties();await Promise.all(e.map((A=>A.applyGlobalState([t]))))}async removeWorkflowExperience(t){const A=this.workflowExperiences.indexOf(t);if(!(A>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found!");await yA.getShadowGraphqlClient().mutate({mutation:ea,variables:{id:this.id,transactionId:t.getWorkflowManager().getTransaction().id}}),this.workflowExperiences.splice(A,1)}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await yA.getShadowGraphqlClient().mutate({mutation:oa,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,A){await yA.getShadowGraphqlClient().mutate({mutation:na,variables:{id:this.id,details:t,type:A||oe.Owner}})}async updateStakeholders(t){await yA.getShadowGraphqlClient().mutate({mutation:ia,variables:{id:this.id,input:t}})}async getAllStakeholders(){const t=await yA.getShadowGraphqlClient().query({query:$i,errorPolicy:"all",variables:{id:this.id}});if(!t.data.bundles||0===t.data.bundles.length)throw new Error("Bundle not found!");return t.data.bundles[0].bundleStakeholders||[]}async reloadWorkflowExperience(t,A,e){const n=A?e=>A(e,t):void 0,i=await this.client.getWorkflowExperience(void 0,void 0,n,{type:"transaction",transactionId:t}),a=e??this.workflowExperiences.findIndex((A=>A.getWorkflowManager().getTransaction().id===t));return a>-1?this.workflowExperiences[a]=i:this.workflowExperiences.push(i),i}async updateBundle(){if(!(await yA.getShadowGraphqlClient().mutate({mutation:ta,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,A])=>({key:t,value:A})))}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async resolveGlobalProperties(){const t=this.productCollection;if(!t)return Promise.resolve([]);const A=new Set;t.products.forEach((t=>t.workflows?.forEach((t=>A.add(t.workflowName)))));const e=await yA.getShadowGraphqlClient().query({query:aa,errorPolicy:"all",variables:{ids:Array.from(A)}}),n=new Map;return e.data.workflows?.forEach((t=>{t.globalPropertyConfiguration&&n.set(t.globalPropertyConfiguration.id,t.globalPropertyConfiguration)})),Object.values(n)}}function Qa(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}const ua=ft`
661
661
  ${FA}
662
662
  ${SA}
663
663
  ${GA}
@@ -1282,5 +1282,5 @@ import{CommandContext as t,AssetType as A,BringForwardCommand as e,BringToFrontC
1282
1282
  }
1283
1283
  }
1284
1284
  }
1285
- `,Fa=async t=>{const A=(await yA.getShadowGraphqlClient().query({query:ua,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}})).data.workflow;return A.steps.forEach((t=>{delete t.data.__typename})),A},Ya=(t,A)=>{const e=t.workflowState,n=e?JSON.parse(e):void 0;return n?Object.values(n.layouts).map((t=>t.layout)):A.panels.sort(((t,A)=>t.index-A.index)).map((t=>({id:F(),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})))};class Sa{constructor(t){var A;Qa(this,"options",void 0),Qa(this,"initialized",void 0),Qa(this,"experienceOptions",void 0),Qa(this,"currencyCode",void 0),Qa(this,"customer",void 0),Qa(this,"updateTransactionState",(async t=>{try{return yA.getShadowGraphqlClient().mutate({...t,mutation:Un})}catch(t){throw console.error(t),new cA("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(A=this.options.applicationKey,fA=A)}getAssetManager(){return HA}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateBundleFromLocalStorage(t){const A=dA.getMap("bundleOwnerIds");if(A?.has(t)){const e=A.get(t);return mA(e),Promise.resolve({success:!0,stakeholderType:oe.Owner})}const e=dA.getMap("bundleCustomerIds");if(e?.has(t)){const A=e.get(t);if(A){if(await this.authenticateCustomerId(A)){const A=this.customer?.bundleStakeholders?.find((A=>A.bundle?.id===t));if(A)return Promise.resolve({success:!0,stakeholderType:A.type})}}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){const A=yA.getShadowGraphqlClient(),e=await A.query({query:pa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!e.data.transactions||0===e.data.transactions.length)throw new Error(`Transaction not found: ${t}`);const n=e.data.transactions[0],i=n.product?.partner?.id;if(!i)throw new Error(`Unable to read transaction: ${t}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const a=dA.getMap("transactionOwnerIds");if(a?.has(t)){const A=a.get(t);return uA(A),Promise.resolve({success:!0,stakeholderType:oe.Owner})}const o=dA.getMap("transactionCustomerIds");if(o?.has(t)){const A=o.get(t);if(A){if(await this.authenticateCustomerId(A)){const A=this.customer?.bundleStakeholders?.find((A=>A.bundle?.transactions?.some((A=>A.id===t))))||this.customer?.stakeholders?.find((A=>A.transaction?.id===t));if(A)return Promise.resolve({success:!0,stakeholderType:A.type})}}}const r=(await A.query({query:ma,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(t){const A=dA.getMap("transactionCustomerIds");A?.has(t)&&(A.delete(t),dA.setMap("transactionCustomerIds",A))}getStakeholderTypeForTransaction(t){const A=this.customer?.stakeholders?.find((A=>A.transaction?.id===t));if(A)return A.type}async getOrCreateCustomer(t){this.customer=void 0;const A=yA.getShadowGraphqlClient(),e=(await A.query({query:Da,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!e.id){const e=(await A.mutate({mutation:Ia,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!e)throw new Error("Unable to create customer.");return this.customer=e,{customer:e,isAuthenticated:!1}}const n=await this.authenticateCustomerId(e.id);return{customer:this.customer||e,isAuthenticated:n}}async authenticateCustomerId(t){const A=yA.getShadowGraphqlClient(),e=dA.getMap("customerTokens");if(!e?.has(t))return!1;const n=e.get(t);if(!n)return!1;const i=(await A.mutate({mutation:fa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!i&&(IA(n),this.customer=i,!0)}async generateVerificationCode(t){await yA.getShadowGraphqlClient().mutate({mutation:ya,variables:{emailAddress:t}})}async verifyCode(t,A){const e=(await yA.getShadowGraphqlClient().mutate({mutation:Ma,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:A}})).data?.customerVerifyCode;if(e?.loginToken){if(!e.partner?.id)throw new Error(`Unable to find customer: ${t}`);const A=dA.getMap("customerTokens")||new Map;return A.set(e.id,e.loginToken),dA.setMap("customerTokens",A),IA(e.loginToken),this.customer={...e,loginToken:void 0},!0}return!1}async getNewBundle(t){const A=(await yA.getShadowGraphqlClient().mutate({mutation:_i,variables:{collectionId:t}})).data?.bundleCreate;if(!A)throw new Error("Unable to create bundle");mA(A.bundleOwnerId);const e=dA.getMap("bundleOwnerIds")||new Map;return e.set(A.id,A.bundleOwnerId),dA.setMap("bundleOwnerIds",e),new Ca(this,A)}async getExistingBundle(t,A){const e=await yA.getShadowGraphqlClient().query({query:Zi,variables:{id:t}});if(!e.data?.bundles||0===e.data?.bundles.length||!e.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const n=e.data?.bundles[0],i=dA.getMap("bundleOwnerIds");i?.has(n.id)&&mA(i.get(n.id));const a=new Ca(this,n);return n.transactions&&n.transactions.length>0&&await Promise.all(n.transactions.map((async t=>{a.reloadWorkflowExperience(t.id,A)}))),a}async getWorkflowExperience(t,A,e,n){if(!n)return await this.getWorkflowExperienceDeprecated(t,A,e);const i=async t=>{for(const A in t.layouts){const e=t.layouts[A].elements.filter((t=>t.type===h.Illustration));for(let t=0;t<e.length;++t){const A=e[t];A.src&&A.svg&&(A.cachedObjectURL=await dt(A.svg))}const n=t.layouts[A].elements.filter((t=>t.type===h.Textbox));for(let t=0;t<n.length;++t){const A=n[t];A.fontData?.assetUrl&&H(A.fontData.assetUrl)}}},{transaction:a,workflow:o,readOnly:r}=await(async()=>{const t=yA.getShadowGraphqlClient();if("transaction"===n.type){const{transactionId:A,readOnly:e}=n,i=await t.query({query:Hn,variables:{id:A},errorPolicy:"all",fetchPolicy:"no-cache"});if(!i.data?.transactions||0===i.data.transactions.length)throw new cA("Existing transaction not found.");const a=i.data?.transactions[0];if(!a.workflowId)throw new cA("Existing transaction has no workflow ID.");const o=await Fa(a.workflowId);if(!a.product)throw new cA("Failed to load transaction, product not available.");return{transaction:a,workflow:o,readOnly:e}}if("integration"===n.type||"external"===n.type){const A=async()=>{const A="integration"===n.type?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},e=await t.mutate({mutation:Rn,variables:{...A,bulk:n.bulk,workflowId:n.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!e.data||!e.data.transactionCreate)throw new cA("Failed to create transaction!");const i=e.data.transactionCreate;if(!i.product)throw new cA("Failed to create transaction, product not available.");return i},e=Fa(n.workflowId),[i,a]=await Promise.all([A(),e]);return{transaction:i,workflow:a}}throw new cA("No workflow ID provided.")})();if(this.currencyCode=a.product.partner?.currencyCode,this.experienceOptions={product:a.product,transaction:a,layouts:[],stateMutationFunc:r?async()=>{throw new rA("State mutation is forbidden in read only mode!")}:this.updateTransactionState,readOnly:r,workflow:o},"transaction"===n.type&&a.workflowState){const t=JSON.parse(a.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await v(t),await i(t),this.experienceOptions.reloadedState=t}else if(!r&&n.workflowState){const t=JSON.parse(n.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await v(t),await i(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Ya(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=e&&e(o),this.experienceOptions.renderableContextService=new fn(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]),"transaction"!==n.type){const t=dA.getMap("transactionOwnerIds")||new Map;t.set(a.id,a.transactionOwnerId),uA(a.transactionOwnerId||""),dA.setMap("transactionOwnerIds",t)}else{const t=(dA.getMap("transactionOwnerIds")||new Map).get(a.id);t&&uA(t)}this.initialized=!0;const s=new Xi(this,this.experienceOptions);return await s.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await s.attachCustomerDetails({email:this.customer.emailAddress}),s}async initFromIntegrationProduct(t){if(""===t)throw new cA("No integration product ID provided.");const A=yA.getShadowGraphqlClient(),e=await A.mutate({mutation:Rn,variables:{integrationProductId:t,bulk:this.options.bulk||!1,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!e.data||!e.data.transactionCreate)throw new cA("Failed to create transaction!");const n=e.data.transactionCreate;if(!n.product)throw new cA("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const i=dA.getMap("transactionOwnerIds")||new Map;i.set(n.id,n.transactionOwnerId),uA(n.transactionOwnerId||""),dA.setMap("transactionOwnerIds",i),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,A=!1){if(""===t)throw new cA("No transaction ID provided.");const e=yA.getShadowGraphqlClient();if(A)return await(async()=>{const n=(await e.query({query:Hn,variables:{id:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!n)throw new cA("Failed to read transaction.");if(!n.product)throw new cA("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async()=>{throw new rA("State mutation is forbidden in read only mode!")},readOnly:A},this.initialized=!0})();const n=dA.getMap("transactionOwnerIds")||new Map,i=n.get(t);if(i){uA(i);const n=(await e.query({query:Hn,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new cA("Failed to read transaction.");if(!n.product)throw new cA("Failed to load transaction, product not available.");return this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:A},void(this.initialized=!0)}try{const i=(await e.mutate({mutation:Pn,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!i)throw new cA("Failed to read transaction.");if(!i.product)throw new cA("Failed to load transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode,i.transactionOwnerId&&(n.set(i.id,i.transactionOwnerId),uA(i.transactionOwnerId),dA.setMap("transactionOwnerIds",n)),this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:A},this.initialized=!0}catch{throw new cA("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,A,e){if(!this.initialized||!this.experienceOptions)throw new cA("Cannot launch experience: Not initialized.");const n=async t=>{for(const A in t.layouts){const e=t.layouts[A].elements.filter((t=>t.type===h.Illustration));for(let t=0;t<e.length;++t){const A=e[t];A.src&&A.svg&&(A.cachedObjectURL=await dt(A.svg))}const n=t.layouts[A].elements.filter((t=>t.type===h.Textbox));for(let t=0;t<n.length;++t){const A=n[t];A.fontData?.assetUrl&&H(A.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await Fa(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=t,this.experienceOptions.transaction.workflowState){const t=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await v(t),await n(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=e&&e(t),this.experienceOptions.renderableContextService=new fn(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const A=new Xi(this,this.experienceOptions);return await A.getWorkflowManager().getInitializationPromise(),A}if(t){const i=yA.getShadowGraphqlClient().mutate({mutation:Gn,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),a=Fa(t);if(await Promise.all([i,a]),this.experienceOptions.workflow=await a,A){const t=JSON.parse(A);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await v(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Ya(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=e&&e(await a),this.experienceOptions.renderableContextService=new fn(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const o=new Xi(this,this.experienceOptions);return await o.getWorkflowManager().getInitializationPromise(),o}throw new cA("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new cA("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new cA("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function xa(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class va{constructor(){xa(this,"getProduct",void 0),xa(this,"getCommandContext",void 0),xa(this,"getAllLayoutData",void 0),xa(this,"getMetadata",void 0),xa(this,"getWorkflowMetadata",void 0),xa(this,"getStepStorage",void 0),xa(this,"setModelContainer",void 0),xa(this,"getUpdatesPending",void 0)}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}getVariationRecords(){return[]}async reset(){}updateStateWithServer(t){}addVariationRecord(t){return{recordNumber:0,transactionId:"",values:[]}}getCurrentVariationRecord(){}removeVariationRecord(t){return[]}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addCurrentVariationCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,A){}addStorageCallback(t){}addVariationRecordsCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,A){}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{}}setCurrentAdjustingStepId(t){}setCurrentVariationRecord(t){}setEditedStatus(t,A){}setInformationResults(t){}setMandatoryFulfilled(t,A){}async setSelectionsAndElements(t,A,e){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,A){}async updateStorage(t,A){}}function Na(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}let Ra;var Pa;(Pa=Ra||(Ra={})).SelectFrame="SelectFrame",Pa.SelectImage="SelectImage",Pa.Position="Position";class Ha extends Mi{constructor(t,A){super(t,A),Na(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const A=this.manager.getRegionElements(this.step.stepName);return ai.selectVariant(this.step,t.getResource(),A,this.manager,(t=>this.setUpdateState(t)))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged((A=>{A&&t(A)}))}selectImage(t){return ai.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,A,e,n){return n&&n.length>1&&void 0===t?Ra.SelectFrame:A||e||this.getImageData()?Ra.Position:Ra.SelectImage}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}hasVaryingUpload(){return this.step.data.varyUpload}hasVaryingSelection(){return this.step.data.varySelection}}const Ua=t=>{const A=bt(null),e=bt(void 0),[n,i]=Rt(void 0),{addEvent:a,removeEvent:o,updateEvent:r,eventCache:s}=LA(),[c,g]=Rt(!1),[l,B]=Rt(!1),{state:w,uiDispatcher:d}=ZA(),h=Pt((t=>{const A=t;d(new qA({zoom:Math.max(.1,Math.min(A,w.maxZoom))}))}),[d,w.maxZoom]),E=Pt((t=>{o(t),1===s.length&&(e.current=void 0),2===s.length&&i(void 0);"touch"===t.pointerType&&s.length>1&&s.length-1==1&&(B(!1),g(!1))}),[o,s.length]),C=Pt((t=>{a(t);"touch"===t.pointerType&&1===s.length&&(d(new qA({selectedElement:void 0})),B(!0),g(!0))}),[a,s.length,d]),Q=Pt((t=>{r(t);const A=1===s.length&&"touch"!==s[0].pointerType,a=2===s.length&&"touch"===s[0].pointerType;if(c&&a){const[t,A]=s,e=Math.abs(t.clientX-A.clientX),a=n;a&&h(w.zoom-.0055*(a-e)),i(e)}if(l&&(A||a)&&t.isPrimary){const A=(e?.current?.x||t.screenX)-t.screenX,n=(e?.current?.y||t.screenY)-t.screenY;d(new qA({selectedElement:void 0,xTranslation:w.xTranslation-A/w.zoom,yTranslation:w.yTranslation-n/w.zoom}))}t.isPrimary&&(e.current={x:t.screenX,y:t.screenY})}),[r,s,c,l,n,h,w.zoom,w.xTranslation,w.yTranslation,d]),u=Pt((t=>{c&&h(w.zoom-.035*Math.sign(t.deltaY))}),[h,w.zoom,c]);Ut((()=>{if(!A.current||0===s.length)return;const t=s[0].pointerId,e=A.current.hasPointerCapture(t);l&&!e&&A.current.setPointerCapture(t),!l&&e&&A.current.releasePointerCapture(t)}),[A,l,s]),Je([" "],(()=>{B(!0),d(new qA({selectedElement:void 0}))}),(()=>B(!1))),Je(["Control"],(()=>g(!0)),(()=>g(!1)));const p=kt((()=>({cursor:l&&0===s.length?"grab":l&&1===s.length?"grabbing":c?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[l,c,s]);return Jt("div",{ref:A,className:"transform-wrapper",onWheel:u,onPointerDown:C,onPointerUp:E,onPointerCancel:E,onPointerLeave:E,onPointerMove:Q,style:p,children:t.children})};export{Sa as SpiffCommerceClient,t as CommandContext,EA as spiffCoreConfiguration,ze as PromiseQueue,Te as QueueablePromise,va as MockWorkflowManager,ui as InformationMessageType,Mi as StepHandle,Gi as TextStepHandle,Ha as FrameStepHandle,xi as BulkStepHandle,Ui as ShapeStepHandle,vi as IllustrationStepHandle,Ni as MaterialStepHandle,Ri as ModelStepHandle,Pi as PictureStepHandle,Hi as QuestionStepHandle,te as BulkPriceCalculationStrategy,fi as Variant,AA as OptionNotFoundError,eA as LayoutNotFoundError,nA as AssetNotFoundError,iA as ResourceNotFoundError,aA as MisconfigurationError,sA as ParseError,rA as UnhandledBehaviorError,HA as assetService,Vi as designService,zi as createDesign,bA as optionService,dA as persistenceService,yA as graphQlManager,ge as toast,Zn as FrameService,Xn as getBoundedOffsets,ai as frameStepService,si as modelStepService,ri as materialStepService,Bi as shapeStepService,li as questionStepService,ni as digitalContentStepService,ci as moduleStepService,gi as pictureStepService,Ci as textStepService,oi as illustrationStepService,$A as ProductCameraRig,Ra as FrameStep,ee as ConversionLocation,ie as ConversionDataType,Fa as getWorkflow,ti as shortenUrl,A as AssetType,e as BringForwardCommand,n as BringToFrontCommand,i as BringToBackCommand,a as CanvasCommand,o as CreateElementCommand,r as CreateLayoutCommand,s as DeleteElementCommand,c as FontAlignmentCommand,g as FontColorCommand,l as FontSizeCommand,B as FontSourceCommand,w as GroupCommand,d as LayoutElementFactory,h as LayoutElementType,E as MoveCommand,C as ResizeCommand,Q as RotateCommand,u as SendBackwardsCommand,oe as StakeholderType,p as StepAspectType,m as StepType,D as TextChangeCommand,I as UnitOfMeasurement,f as dataUrlFromExternalUrl,y as findElement,M as frameDataCache,F as generate,Y as getAxisAlignedBoundingBox,S as generateSVGWithUnknownColors,x as getAttributesFromArrayBuffer,v as rehydrateSerializedLayout,N as getFrameData,R as getSvgElement,P as loadFontFromDataUrl,H as loadFontFromExternalUrl,U as determineCorrectFontSizeAndLines,G as patternImageDataCache,Dn as generateCommands,k as registerJSDOM,Ge as minZoom,Nn as AdvancedEditor,Ua as TransformWrapper,vn as EditorCore,OA as useLayouts,ZA as useEditorState,be as useEditorInteraction,Je as useShortcutCombination,VA as commandReducer,KA as getDefaultState,JA as CommandContextContext,XA as AdvancedEditorStateProvider,WA as AdvancedEditorContext,qA as UICommand,zA as EditorSubMenu,le as ElementEventType,we as KeyEvent,Ln as gatherVaryingStepAspects};
1285
+ `,Fa=async t=>{const A=(await yA.getShadowGraphqlClient().query({query:ua,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}})).data.workflow;return A.steps.forEach((t=>{delete t.data.__typename})),A},Ya=(t,A)=>{const e=t.workflowState,n=e?JSON.parse(e):void 0;return n?Object.values(n.layouts).map((t=>t.layout)):A.panels.sort(((t,A)=>t.index-A.index)).map((t=>({id:F(),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})))};class Sa{constructor(t){var A;Qa(this,"options",void 0),Qa(this,"initialized",void 0),Qa(this,"experienceOptions",void 0),Qa(this,"currencyCode",void 0),Qa(this,"customer",void 0),Qa(this,"updateTransactionState",(async t=>{try{return yA.getShadowGraphqlClient().mutate({...t,mutation:Un})}catch(t){throw console.error(t),new cA("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(A=this.options.applicationKey,fA=A)}getAssetManager(){return HA}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateBundleFromLocalStorage(t){const A=dA.getMap("bundleOwnerIds");if(A?.has(t)){const e=A.get(t);return mA(e),Promise.resolve({success:!0,stakeholderType:oe.Owner})}const e=dA.getMap("bundleCustomerIds");if(e?.has(t)){const A=e.get(t);if(A){if(await this.authenticateCustomerId(A)){const A=this.customer?.bundleStakeholders?.find((A=>A.bundle?.id===t));if(A)return Promise.resolve({success:!0,stakeholderType:A.type})}}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){const A=yA.getShadowGraphqlClient(),e=await A.query({query:pa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!e.data.transactions||0===e.data.transactions.length)throw new Error(`Transaction not found: ${t}`);const n=e.data.transactions[0],i=n.product?.partner?.id;if(!i)throw new Error(`Unable to read transaction: ${t}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const a=dA.getMap("transactionOwnerIds");if(a?.has(t)){const A=a.get(t);return uA(A),Promise.resolve({success:!0,stakeholderType:oe.Owner})}const o=dA.getMap("transactionCustomerIds");if(o?.has(t)){const A=o.get(t);if(A){if(await this.authenticateCustomerId(A)){const A=this.customer?.bundleStakeholders?.find((A=>A.bundle?.transactions?.some((A=>A.id===t))))||this.customer?.stakeholders?.find((A=>A.transaction?.id===t));if(A)return Promise.resolve({success:!0,stakeholderType:A.type})}}}const r=(await A.query({query:ma,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(t){const A=dA.getMap("transactionCustomerIds");A?.has(t)&&(A.delete(t),dA.setMap("transactionCustomerIds",A))}getStakeholderTypeForTransaction(t){const A=this.customer?.stakeholders?.find((A=>A.transaction?.id===t));if(A)return A.type}async getOrCreateCustomer(t){this.customer=void 0;const A=yA.getShadowGraphqlClient(),e=(await A.query({query:Da,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!e.id){const e=(await A.mutate({mutation:Ia,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!e)throw new Error("Unable to create customer.");return this.customer=e,{customer:e,isAuthenticated:!1}}const n=await this.authenticateCustomerId(e.id);return{customer:this.customer||e,isAuthenticated:n}}async authenticateCustomerId(t){const A=yA.getShadowGraphqlClient(),e=dA.getMap("customerTokens");if(!e?.has(t))return!1;const n=e.get(t);if(!n)return!1;const i=(await A.mutate({mutation:fa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!i&&(IA(n),this.customer=i,!0)}async generateVerificationCode(t){await yA.getShadowGraphqlClient().mutate({mutation:ya,variables:{emailAddress:t}})}async verifyCode(t,A){const e=(await yA.getShadowGraphqlClient().mutate({mutation:Ma,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:A}})).data?.customerVerifyCode;if(e?.loginToken){if(!e.partner?.id)throw new Error(`Unable to find customer: ${t}`);const A=dA.getMap("customerTokens")||new Map;return A.set(e.id,e.loginToken),dA.setMap("customerTokens",A),IA(e.loginToken),this.customer={...e,loginToken:void 0},!0}return!1}async getNewBundle(t){const A=(await yA.getShadowGraphqlClient().mutate({mutation:_i,variables:{collectionId:t}})).data?.bundleCreate;if(!A)throw new Error("Unable to create bundle");mA(A.bundleOwnerId);const e=dA.getMap("bundleOwnerIds")||new Map;return e.set(A.id,A.bundleOwnerId),dA.setMap("bundleOwnerIds",e),new Ca(this,A)}async getExistingBundle(t,A){const e=await yA.getShadowGraphqlClient().query({query:Zi,variables:{id:t}});if(!e.data?.bundles||0===e.data?.bundles.length||!e.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const n=e.data?.bundles[0],i=dA.getMap("bundleOwnerIds");i?.has(n.id)&&mA(i.get(n.id));const a=new Ca(this,n);return n.transactions&&n.transactions.length>0&&await Promise.all(n.transactions.map((async(t,e)=>{a.reloadWorkflowExperience(t.id,A,e)}))),a}async getWorkflowExperience(t,A,e,n){if(!n)return await this.getWorkflowExperienceDeprecated(t,A,e);const i=async t=>{for(const A in t.layouts){const e=t.layouts[A].elements.filter((t=>t.type===h.Illustration));for(let t=0;t<e.length;++t){const A=e[t];A.src&&A.svg&&(A.cachedObjectURL=await dt(A.svg))}const n=t.layouts[A].elements.filter((t=>t.type===h.Textbox));for(let t=0;t<n.length;++t){const A=n[t];A.fontData?.assetUrl&&H(A.fontData.assetUrl)}}},{transaction:a,workflow:o,readOnly:r}=await(async()=>{const t=yA.getShadowGraphqlClient();if("transaction"===n.type){const{transactionId:A,readOnly:e}=n,i=await t.query({query:Hn,variables:{id:A},errorPolicy:"all",fetchPolicy:"no-cache"});if(!i.data?.transactions||0===i.data.transactions.length)throw new cA("Existing transaction not found.");const a=i.data?.transactions[0];if(!a.workflowId)throw new cA("Existing transaction has no workflow ID.");const o=await Fa(a.workflowId);if(!a.product)throw new cA("Failed to load transaction, product not available.");return{transaction:a,workflow:o,readOnly:e}}if("integration"===n.type||"external"===n.type){const A=async()=>{const A="integration"===n.type?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},e=await t.mutate({mutation:Rn,variables:{...A,bulk:n.bulk,workflowId:n.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!e.data||!e.data.transactionCreate)throw new cA("Failed to create transaction!");const i=e.data.transactionCreate;if(!i.product)throw new cA("Failed to create transaction, product not available.");return i},e=Fa(n.workflowId),[i,a]=await Promise.all([A(),e]);return{transaction:i,workflow:a}}throw new cA("No workflow ID provided.")})();if(this.currencyCode=a.product.partner?.currencyCode,this.experienceOptions={product:a.product,transaction:a,layouts:[],stateMutationFunc:r?async()=>{throw new rA("State mutation is forbidden in read only mode!")}:this.updateTransactionState,readOnly:r,workflow:o},"transaction"===n.type&&a.workflowState){const t=JSON.parse(a.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await v(t),await i(t),this.experienceOptions.reloadedState=t}else if(!r&&n.workflowState){const t=JSON.parse(n.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await v(t),await i(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Ya(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=e&&e(o),this.experienceOptions.renderableContextService=new fn(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]),"transaction"!==n.type){const t=dA.getMap("transactionOwnerIds")||new Map;t.set(a.id,a.transactionOwnerId),uA(a.transactionOwnerId||""),dA.setMap("transactionOwnerIds",t)}else{const t=(dA.getMap("transactionOwnerIds")||new Map).get(a.id);t&&uA(t)}this.initialized=!0;const s=new Xi(this,this.experienceOptions);return await s.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await s.attachCustomerDetails({email:this.customer.emailAddress}),s}async initFromIntegrationProduct(t){if(""===t)throw new cA("No integration product ID provided.");const A=yA.getShadowGraphqlClient(),e=await A.mutate({mutation:Rn,variables:{integrationProductId:t,bulk:this.options.bulk||!1,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!e.data||!e.data.transactionCreate)throw new cA("Failed to create transaction!");const n=e.data.transactionCreate;if(!n.product)throw new cA("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const i=dA.getMap("transactionOwnerIds")||new Map;i.set(n.id,n.transactionOwnerId),uA(n.transactionOwnerId||""),dA.setMap("transactionOwnerIds",i),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,A=!1){if(""===t)throw new cA("No transaction ID provided.");const e=yA.getShadowGraphqlClient();if(A)return await(async()=>{const n=(await e.query({query:Hn,variables:{id:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!n)throw new cA("Failed to read transaction.");if(!n.product)throw new cA("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async()=>{throw new rA("State mutation is forbidden in read only mode!")},readOnly:A},this.initialized=!0})();const n=dA.getMap("transactionOwnerIds")||new Map,i=n.get(t);if(i){uA(i);const n=(await e.query({query:Hn,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new cA("Failed to read transaction.");if(!n.product)throw new cA("Failed to load transaction, product not available.");return this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:A},void(this.initialized=!0)}try{const i=(await e.mutate({mutation:Pn,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!i)throw new cA("Failed to read transaction.");if(!i.product)throw new cA("Failed to load transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode,i.transactionOwnerId&&(n.set(i.id,i.transactionOwnerId),uA(i.transactionOwnerId),dA.setMap("transactionOwnerIds",n)),this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:A},this.initialized=!0}catch{throw new cA("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,A,e){if(!this.initialized||!this.experienceOptions)throw new cA("Cannot launch experience: Not initialized.");const n=async t=>{for(const A in t.layouts){const e=t.layouts[A].elements.filter((t=>t.type===h.Illustration));for(let t=0;t<e.length;++t){const A=e[t];A.src&&A.svg&&(A.cachedObjectURL=await dt(A.svg))}const n=t.layouts[A].elements.filter((t=>t.type===h.Textbox));for(let t=0;t<n.length;++t){const A=n[t];A.fontData?.assetUrl&&H(A.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await Fa(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=t,this.experienceOptions.transaction.workflowState){const t=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await v(t),await n(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=e&&e(t),this.experienceOptions.renderableContextService=new fn(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const A=new Xi(this,this.experienceOptions);return await A.getWorkflowManager().getInitializationPromise(),A}if(t){const i=yA.getShadowGraphqlClient().mutate({mutation:Gn,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),a=Fa(t);if(await Promise.all([i,a]),this.experienceOptions.workflow=await a,A){const t=JSON.parse(A);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await v(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=Ya(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=e&&e(await a),this.experienceOptions.renderableContextService=new fn(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&(this.experienceOptions.previewService?.initialize({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}),this.experienceOptions.modelContainer=this.experienceOptions.previewService?.getAllModels()[0]);const o=new Xi(this,this.experienceOptions);return await o.getWorkflowManager().getInitializationPromise(),o}throw new cA("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new cA("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new cA("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function xa(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}class va{constructor(){xa(this,"getProduct",void 0),xa(this,"getCommandContext",void 0),xa(this,"getAllLayoutData",void 0),xa(this,"getMetadata",void 0),xa(this,"getWorkflowMetadata",void 0),xa(this,"getStepStorage",void 0),xa(this,"setModelContainer",void 0),xa(this,"getUpdatesPending",void 0)}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}getVariationRecords(){return[]}async reset(){}updateStateWithServer(t){}addVariationRecord(t){return{recordNumber:0,transactionId:"",values:[]}}getCurrentVariationRecord(){}removeVariationRecord(t){return[]}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addCurrentVariationCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,A){}addStorageCallback(t){}addVariationRecordsCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,A){}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{}}setCurrentAdjustingStepId(t){}setCurrentVariationRecord(t){}setEditedStatus(t,A){}setInformationResults(t){}setMandatoryFulfilled(t,A){}async setSelectionsAndElements(t,A,e){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,A){}async updateStorage(t,A){}}function Na(t,A,e){return(A=function(t){var A=function(t,A){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,A||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===A?String:Number)(t)}(t,"string");return"symbol"==typeof A?A:String(A)}(A))in t?Object.defineProperty(t,A,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[A]=e,t}let Ra;var Pa;(Pa=Ra||(Ra={})).SelectFrame="SelectFrame",Pa.SelectImage="SelectImage",Pa.Position="Position";class Ha extends Mi{constructor(t,A){super(t,A),Na(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const A=this.manager.getRegionElements(this.step.stepName);return ai.selectVariant(this.step,t.getResource(),A,this.manager,(t=>this.setUpdateState(t)))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged((A=>{A&&t(A)}))}selectImage(t){return ai.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,A,e,n){return n&&n.length>1&&void 0===t?Ra.SelectFrame:A||e||this.getImageData()?Ra.Position:Ra.SelectImage}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}hasVaryingUpload(){return this.step.data.varyUpload}hasVaryingSelection(){return this.step.data.varySelection}}const Ua=t=>{const A=bt(null),e=bt(void 0),[n,i]=Rt(void 0),{addEvent:a,removeEvent:o,updateEvent:r,eventCache:s}=LA(),[c,g]=Rt(!1),[l,B]=Rt(!1),{state:w,uiDispatcher:d}=ZA(),h=Pt((t=>{const A=t;d(new qA({zoom:Math.max(.1,Math.min(A,w.maxZoom))}))}),[d,w.maxZoom]),E=Pt((t=>{o(t),1===s.length&&(e.current=void 0),2===s.length&&i(void 0);"touch"===t.pointerType&&s.length>1&&s.length-1==1&&(B(!1),g(!1))}),[o,s.length]),C=Pt((t=>{a(t);"touch"===t.pointerType&&1===s.length&&(d(new qA({selectedElement:void 0})),B(!0),g(!0))}),[a,s.length,d]),Q=Pt((t=>{r(t);const A=1===s.length&&"touch"!==s[0].pointerType,a=2===s.length&&"touch"===s[0].pointerType;if(c&&a){const[t,A]=s,e=Math.abs(t.clientX-A.clientX),a=n;a&&h(w.zoom-.0055*(a-e)),i(e)}if(l&&(A||a)&&t.isPrimary){const A=(e?.current?.x||t.screenX)-t.screenX,n=(e?.current?.y||t.screenY)-t.screenY;d(new qA({selectedElement:void 0,xTranslation:w.xTranslation-A/w.zoom,yTranslation:w.yTranslation-n/w.zoom}))}t.isPrimary&&(e.current={x:t.screenX,y:t.screenY})}),[r,s,c,l,n,h,w.zoom,w.xTranslation,w.yTranslation,d]),u=Pt((t=>{c&&h(w.zoom-.035*Math.sign(t.deltaY))}),[h,w.zoom,c]);Ut((()=>{if(!A.current||0===s.length)return;const t=s[0].pointerId,e=A.current.hasPointerCapture(t);l&&!e&&A.current.setPointerCapture(t),!l&&e&&A.current.releasePointerCapture(t)}),[A,l,s]),Je([" "],(()=>{B(!0),d(new qA({selectedElement:void 0}))}),(()=>B(!1))),Je(["Control"],(()=>g(!0)),(()=>g(!1)));const p=kt((()=>({cursor:l&&0===s.length?"grab":l&&1===s.length?"grabbing":c?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[l,c,s]);return Jt("div",{ref:A,className:"transform-wrapper",onWheel:u,onPointerDown:C,onPointerUp:E,onPointerCancel:E,onPointerLeave:E,onPointerMove:Q,style:p,children:t.children})};export{Sa as SpiffCommerceClient,t as CommandContext,EA as spiffCoreConfiguration,ze as PromiseQueue,Te as QueueablePromise,va as MockWorkflowManager,ui as InformationMessageType,Mi as StepHandle,Gi as TextStepHandle,Ha as FrameStepHandle,xi as BulkStepHandle,Ui as ShapeStepHandle,vi as IllustrationStepHandle,Ni as MaterialStepHandle,Ri as ModelStepHandle,Pi as PictureStepHandle,Hi as QuestionStepHandle,te as BulkPriceCalculationStrategy,fi as Variant,AA as OptionNotFoundError,eA as LayoutNotFoundError,nA as AssetNotFoundError,iA as ResourceNotFoundError,aA as MisconfigurationError,sA as ParseError,rA as UnhandledBehaviorError,HA as assetService,Vi as designService,zi as createDesign,bA as optionService,dA as persistenceService,yA as graphQlManager,ge as toast,Zn as FrameService,Xn as getBoundedOffsets,ai as frameStepService,si as modelStepService,ri as materialStepService,Bi as shapeStepService,li as questionStepService,ni as digitalContentStepService,ci as moduleStepService,gi as pictureStepService,Ci as textStepService,oi as illustrationStepService,$A as ProductCameraRig,Ra as FrameStep,ee as ConversionLocation,ie as ConversionDataType,Fa as getWorkflow,ti as shortenUrl,A as AssetType,e as BringForwardCommand,n as BringToFrontCommand,i as BringToBackCommand,a as CanvasCommand,o as CreateElementCommand,r as CreateLayoutCommand,s as DeleteElementCommand,c as FontAlignmentCommand,g as FontColorCommand,l as FontSizeCommand,B as FontSourceCommand,w as GroupCommand,d as LayoutElementFactory,h as LayoutElementType,E as MoveCommand,C as ResizeCommand,Q as RotateCommand,u as SendBackwardsCommand,oe as StakeholderType,p as StepAspectType,m as StepType,D as TextChangeCommand,I as UnitOfMeasurement,f as dataUrlFromExternalUrl,y as findElement,M as frameDataCache,F as generate,Y as getAxisAlignedBoundingBox,S as generateSVGWithUnknownColors,x as getAttributesFromArrayBuffer,v as rehydrateSerializedLayout,N as getFrameData,R as getSvgElement,P as loadFontFromDataUrl,H as loadFontFromExternalUrl,U as determineCorrectFontSizeAndLines,G as patternImageDataCache,Dn as generateCommands,k as registerJSDOM,Ge as minZoom,Nn as AdvancedEditor,Ua as TransformWrapper,vn as EditorCore,OA as useLayouts,ZA as useEditorState,be as useEditorInteraction,Je as useShortcutCombination,VA as commandReducer,KA as getDefaultState,JA as CommandContextContext,XA as AdvancedEditorStateProvider,WA as AdvancedEditorContext,qA as UICommand,zA as EditorSubMenu,le as ElementEventType,we as KeyEvent,Ln as gatherVaryingStepAspects};
1286
1286
  //# sourceMappingURL=module.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/core",
3
- "version": "12.9.0",
3
+ "version": "12.9.1",
4
4
  "description": "Core client API for interacting with the Spiff Commerce backend.",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/main.js",