@spiffcommerce/core 12.4.0 → 12.4.2

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
@@ -558,6 +558,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),A=require("react/j
558
558
  mutation CreateBundle($collectionId: String) {
559
559
  bundleCreate(collectionId: $collectionId) {
560
560
  id
561
+ bundleOwnerId
561
562
  metadata {
562
563
  key
563
564
  value
@@ -601,7 +602,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),A=require("react/j
601
602
  id
602
603
  }
603
604
  }
604
- `;function ec(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 Ac{constructor(t,e){ec(this,"client",void 0),ec(this,"id",void 0),ec(this,"name",void 0),ec(this,"metadata",void 0),ec(this,"productCollection",void 0),ec(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}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()}hasGlobalProperties(){throw new Error("Method not implemented.")}getGlobalProperties(){throw new Error("Method not implemented.")}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 Cr.getShadowGraphqlClient().mutate({mutation:Zo,variables:{id:this.id,transactionId:e}}),this.workflowExperiences.push(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 Cr.getShadowGraphqlClient().mutate({mutation:$o,variables:{id:this.id,transactionId:t.getWorkflowManager().getTransaction().id}}),this.workflowExperiences.splice(e,1)}sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t)}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){await Cr.getShadowGraphqlClient().mutate({mutation:_o,variables:{id:this.id,details:t,type:e||ea.Owner}})}async updateStakeholders(t){await Cr.getShadowGraphqlClient().mutate({mutation:tc,variables:{id:this.id,input:t}})}async getAllStakeholders(){const t=await Cr.getShadowGraphqlClient().query({query:Wo,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 updateBundle(){if(!(await Cr.getShadowGraphqlClient().mutate({mutation:qo,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!")}}function ic(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 nc=t.gql`
605
+ `;function ec(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 Ac{constructor(t,e){ec(this,"client",void 0),ec(this,"id",void 0),ec(this,"name",void 0),ec(this,"metadata",void 0),ec(this,"productCollection",void 0),ec(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}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()}hasGlobalProperties(){throw new Error("Method not implemented.")}getGlobalProperties(){throw new Error("Method not implemented.")}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 Cr.getShadowGraphqlClient().mutate({mutation:Zo,variables:{id:this.id,transactionId:e}}),this.workflowExperiences.push(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 Cr.getShadowGraphqlClient().mutate({mutation:$o,variables:{id:this.id,transactionId:t.getWorkflowManager().getTransaction().id}}),this.workflowExperiences.splice(e,1)}sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t)}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){await Cr.getShadowGraphqlClient().mutate({mutation:_o,variables:{id:this.id,details:t,type:e||ea.Owner}})}async updateStakeholders(t){await Cr.getShadowGraphqlClient().mutate({mutation:tc,variables:{id:this.id,input:t}})}async getAllStakeholders(){const t=await Cr.getShadowGraphqlClient().query({query:Wo,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 Cr.getShadowGraphqlClient().mutate({mutation:qo,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!")}}function ic(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 nc=t.gql`
605
606
  fragment RegionFields on Region {
606
607
  width
607
608
  top
@@ -1229,5 +1230,5 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),A=require("react/j
1229
1230
  }
1230
1231
  }
1231
1232
  }
1232
- `,Bc=async t=>{const e=(await Cr.getShadowGraphqlClient().query({query:sc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}})).data.workflow;return e.steps.forEach((t=>{delete t.data.__typename})),e},wc=(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 Ec{constructor(t){var e;ic(this,"options",void 0),ic(this,"initialized",void 0),ic(this,"experienceOptions",void 0),ic(this,"currencyCode",void 0),ic(this,"customer",void 0),ic(this,"updateTransactionState",(async t=>{try{return Cr.getShadowGraphqlClient().mutate({...t,mutation:Ss})}catch(t){throw console.error(t),new nr("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,mr=e)}getAssetManager(){return Sr}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateBundleFromLocalStorage(t){const e=cr.getMap("bundleOwnerIds");if(e?.has(t)){const A=e.get(t);return wr(A),Promise.resolve({success:!0,stakeholderType:ea.Owner})}const A=cr.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=Cr.getShadowGraphqlClient(),A=await e.query({query:oc,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=cr.getMap("transactionOwnerIds");if(r?.has(t)){const e=r.get(t);return ur(e),Promise.resolve({success:!0,stakeholderType:ea.Owner})}const a=cr.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:cc,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=cr.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),cr.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=Cr.getShadowGraphqlClient(),A=(await e.query({query:lc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!A.id){const A=(await e.mutate({mutation:gc,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=Cr.getShadowGraphqlClient(),A=cr.getMap("customerTokens");if(!A?.has(t))return!1;const i=A.get(t);if(!i)return!1;const n=(await e.mutate({mutation:hc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:i}})).data?.customerAuthenticate;return!!n&&(pr(i),this.customer=n,!0)}async generateVerificationCode(t){await Cr.getShadowGraphqlClient().mutate({mutation:dc,variables:{emailAddress:t}})}async verifyCode(t,e){const A=(await Cr.getShadowGraphqlClient().mutate({mutation:uc,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=cr.getMap("customerTokens")||new Map;return e.set(A.id,A.loginToken),cr.setMap("customerTokens",e),pr(A.loginToken),this.customer={...A,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Cr.getShadowGraphqlClient().mutate({mutation:Xo,variables:{collectionId:t}})).data?.bundleCreate;if(!e)throw new Error("Unable to create bundle");wr(e.bundleOwnerId);const A=cr.getMap("bundleOwnerIds")||new Map;return A.set(e.id,e.bundleOwnerId),cr.setMap("bundleOwnerIds",A),new Ac(this,e)}async getExistingBundle(t){const e=await Cr.getShadowGraphqlClient().query({query:Ko,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 A=e.data?.bundles[0],i=cr.getMap("bundleOwnerIds");return i?.has(A.id)&&wr(i.get(A.id)),new Ac(this,A)}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 zn(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&&ii(e.fontData.assetUrl)}}},{transaction:r,workflow:a,readOnly:s}=await(async()=>{const t=Cr.getShadowGraphqlClient();if(await t.resetStore(),"transaction"===i.type){const{transactionId:e,readOnly:A}=i,n=await t.query({query:Fs,variables:{id:e},errorPolicy:"all"});if(!n.data?.transactions||0===n.data.transactions.length)throw new nr("Existing transaction not found.");const r=n.data?.transactions[0];if(!r.workflowId)throw new nr("Existing transaction has no workflow ID.");const a=await Bc(r.workflowId);if(!r.product)throw new nr("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:Ms,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 nr("Failed to create transaction!");const n=A.data.transactionCreate;if(!n.product)throw new nr("Failed to create transaction, product not available.");return n},A=Bc(i.workflowId),[n,r]=await Promise.all([e(),A]);return{transaction:n,workflow:r}}throw new nr("No workflow ID provided.")})();if(this.currencyCode=r.product.partner?.currencyCode,this.experienceOptions={product:r.product,transaction:r,layouts:[],stateMutationFunc:s?async()=>{throw new Ar("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 Vi(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 Vi(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=wc(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=A&&A(a),this.experienceOptions.renderableContextService=new ps(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=cr.getMap("transactionOwnerIds")||new Map;t.set(r.id,r.transactionOwnerId),ur(r.transactionOwnerId||""),cr.setMap("transactionOwnerIds",t)}else{const t=(cr.getMap("transactionOwnerIds")||new Map).get(r.id);t&&ur(t)}this.initialized=!0;const o=new zo(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 nr("No integration product ID provided.");const e=Cr.getShadowGraphqlClient();await e.resetStore();const A=await e.mutate({mutation:Ms,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 nr("Failed to create transaction!");const i=A.data.transactionCreate;if(!i.product)throw new nr("Failed to create transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode;const n=cr.getMap("transactionOwnerIds")||new Map;n.set(i.id,i.transactionOwnerId),ur(i.transactionOwnerId||""),cr.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 nr("No transaction ID provided.");const A=Cr.getShadowGraphqlClient();await A.resetStore();if(e)return await(async()=>{const i=(await A.query({query:Fs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!i)throw new nr("Failed to read transaction.");if(!i.product)throw new nr("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 Ar("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const i=cr.getMap("transactionOwnerIds")||new Map,n=i.get(t);if(n){ur(n);const i=(await A.query({query:Fs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!i)throw new nr("Failed to read transaction.");if(!i.product)throw new nr("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:vs,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!n)throw new nr("Failed to read transaction.");if(!n.product)throw new nr("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,n.transactionOwnerId&&(i.set(n.id,n.transactionOwnerId),ur(n.transactionOwnerId),cr.setMap("transactionOwnerIds",i)),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new nr("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,A){if(!this.initialized||!this.experienceOptions)throw new nr("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 zn(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&&ii(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await Bc(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 Vi(t),await i(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=A&&A(t),this.experienceOptions.renderableContextService=new ps(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 zo(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const n=Cr.getShadowGraphqlClient().mutate({mutation:bs,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),r=Bc(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 Vi(t),await i(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=wc(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await r),this.experienceOptions.renderableContextService=new ps(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 zo(this,this.experienceOptions);return await a.getWorkflowManager().getInitializationPromise(),a}throw new nr("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new nr("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new nr("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}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}class mc{constructor(){pc(this,"getProduct",void 0),pc(this,"getCommandContext",void 0),pc(this,"getAllLayoutData",void 0),pc(this,"getMetadata",void 0),pc(this,"getWorkflowMetadata",void 0),pc(this,"getStepStorage",void 0),pc(this,"setModelContainer",void 0),pc(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 Cc(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 fc;var Qc;(Qc=fc||(fc={})).SelectFrame="SelectFrame",Qc.SelectImage="SelectImage",Qc.Position="Position";class yc extends fo{constructor(t,e){super(t,e),Cc(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return _s.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 _s.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?fc.SelectFrame:e||A||this.getImageData()?fc.Position:fc.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 Dc=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}=kr(),[g,h]=(0,i.useState)(!1),[d,u]=(0,i.useState)(!1),{state:B,uiDispatcher:w}=Vr(),E=(0,i.useCallback)((t=>{const e=t;w(new jr({zoom:Math.max(.1,Math.min(e,B.maxZoom))}))}),[w,B.maxZoom]),p=(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&&(w(new jr({selectedElement:void 0})),u(!0),h(!0))}),[s,l.length,w]),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&&E(B.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;w(new jr({selectedElement:void 0,xTranslation:B.xTranslation-e/B.zoom,yTranslation:B.yTranslation-A/B.zoom}))}t.isPrimary&&(n.current={x:t.screenX,y:t.screenY})}),[c,l,g,d,r,E,B.zoom,B.xTranslation,B.yTranslation,w]),f=(0,i.useCallback)((t=>{g&&E(B.zoom-.035*Math.sign(t.deltaY))}),[E,B.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]),Ra([" "],(()=>{u(!0),w(new jr({selectedElement:void 0}))}),(()=>u(!1))),Ra(["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:p,onPointerCancel:p,onPointerLeave:p,onPointerMove:C,style:Q,children:t.children})};
1233
+ `,Bc=async t=>{const e=(await Cr.getShadowGraphqlClient().query({query:sc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}})).data.workflow;return e.steps.forEach((t=>{delete t.data.__typename})),e},wc=(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 Ec{constructor(t){var e;ic(this,"options",void 0),ic(this,"initialized",void 0),ic(this,"experienceOptions",void 0),ic(this,"currencyCode",void 0),ic(this,"customer",void 0),ic(this,"updateTransactionState",(async t=>{try{return Cr.getShadowGraphqlClient().mutate({...t,mutation:Ss})}catch(t){throw console.error(t),new nr("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,mr=e)}getAssetManager(){return Sr}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateBundleFromLocalStorage(t){const e=cr.getMap("bundleOwnerIds");if(e?.has(t)){const A=e.get(t);return wr(A),Promise.resolve({success:!0,stakeholderType:ea.Owner})}const A=cr.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=Cr.getShadowGraphqlClient(),A=await e.query({query:oc,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=cr.getMap("transactionOwnerIds");if(r?.has(t)){const e=r.get(t);return ur(e),Promise.resolve({success:!0,stakeholderType:ea.Owner})}const a=cr.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:cc,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=cr.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),cr.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=Cr.getShadowGraphqlClient(),A=(await e.query({query:lc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!A.id){const A=(await e.mutate({mutation:gc,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=Cr.getShadowGraphqlClient(),A=cr.getMap("customerTokens");if(!A?.has(t))return!1;const i=A.get(t);if(!i)return!1;const n=(await e.mutate({mutation:hc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:i}})).data?.customerAuthenticate;return!!n&&(pr(i),this.customer=n,!0)}async generateVerificationCode(t){await Cr.getShadowGraphqlClient().mutate({mutation:dc,variables:{emailAddress:t}})}async verifyCode(t,e){const A=(await Cr.getShadowGraphqlClient().mutate({mutation:uc,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=cr.getMap("customerTokens")||new Map;return e.set(A.id,A.loginToken),cr.setMap("customerTokens",e),pr(A.loginToken),this.customer={...A,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Cr.getShadowGraphqlClient().mutate({mutation:Xo,variables:{collectionId:t}})).data?.bundleCreate;if(!e)throw new Error("Unable to create bundle");wr(e.bundleOwnerId);const A=cr.getMap("bundleOwnerIds")||new Map;return A.set(e.id,e.bundleOwnerId),cr.setMap("bundleOwnerIds",A),new Ac(this,e)}async getExistingBundle(t,e){const A=await Cr.getShadowGraphqlClient().query({query:Ko,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=cr.getMap("bundleOwnerIds");n?.has(i.id)&&wr(n.get(i.id));const r=new Ac(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 zn(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&&ii(e.fontData.assetUrl)}}},{transaction:r,workflow:a,readOnly:s}=await(async()=>{const t=Cr.getShadowGraphqlClient();if(await t.resetStore(),"transaction"===i.type){const{transactionId:e,readOnly:A}=i,n=await t.query({query:Fs,variables:{id:e},errorPolicy:"all"});if(!n.data?.transactions||0===n.data.transactions.length)throw new nr("Existing transaction not found.");const r=n.data?.transactions[0];if(!r.workflowId)throw new nr("Existing transaction has no workflow ID.");const a=await Bc(r.workflowId);if(!r.product)throw new nr("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:Ms,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 nr("Failed to create transaction!");const n=A.data.transactionCreate;if(!n.product)throw new nr("Failed to create transaction, product not available.");return n},A=Bc(i.workflowId),[n,r]=await Promise.all([e(),A]);return{transaction:n,workflow:r}}throw new nr("No workflow ID provided.")})();if(this.currencyCode=r.product.partner?.currencyCode,this.experienceOptions={product:r.product,transaction:r,layouts:[],stateMutationFunc:s?async()=>{throw new Ar("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 Vi(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 Vi(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=wc(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=A&&A(a),this.experienceOptions.renderableContextService=new ps(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=cr.getMap("transactionOwnerIds")||new Map;t.set(r.id,r.transactionOwnerId),ur(r.transactionOwnerId||""),cr.setMap("transactionOwnerIds",t)}else{const t=(cr.getMap("transactionOwnerIds")||new Map).get(r.id);t&&ur(t)}this.initialized=!0;const o=new zo(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 nr("No integration product ID provided.");const e=Cr.getShadowGraphqlClient();await e.resetStore();const A=await e.mutate({mutation:Ms,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 nr("Failed to create transaction!");const i=A.data.transactionCreate;if(!i.product)throw new nr("Failed to create transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode;const n=cr.getMap("transactionOwnerIds")||new Map;n.set(i.id,i.transactionOwnerId),ur(i.transactionOwnerId||""),cr.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 nr("No transaction ID provided.");const A=Cr.getShadowGraphqlClient();await A.resetStore();if(e)return await(async()=>{const i=(await A.query({query:Fs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!i)throw new nr("Failed to read transaction.");if(!i.product)throw new nr("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 Ar("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const i=cr.getMap("transactionOwnerIds")||new Map,n=i.get(t);if(n){ur(n);const i=(await A.query({query:Fs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!i)throw new nr("Failed to read transaction.");if(!i.product)throw new nr("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:vs,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!n)throw new nr("Failed to read transaction.");if(!n.product)throw new nr("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,n.transactionOwnerId&&(i.set(n.id,n.transactionOwnerId),ur(n.transactionOwnerId),cr.setMap("transactionOwnerIds",i)),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new nr("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,A){if(!this.initialized||!this.experienceOptions)throw new nr("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 zn(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&&ii(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await Bc(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 Vi(t),await i(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=A&&A(t),this.experienceOptions.renderableContextService=new ps(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 zo(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const n=Cr.getShadowGraphqlClient().mutate({mutation:bs,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),r=Bc(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 Vi(t),await i(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=wc(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await r),this.experienceOptions.renderableContextService=new ps(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 zo(this,this.experienceOptions);return await a.getWorkflowManager().getInitializationPromise(),a}throw new nr("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new nr("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new nr("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}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}class mc{constructor(){pc(this,"getProduct",void 0),pc(this,"getCommandContext",void 0),pc(this,"getAllLayoutData",void 0),pc(this,"getMetadata",void 0),pc(this,"getWorkflowMetadata",void 0),pc(this,"getStepStorage",void 0),pc(this,"setModelContainer",void 0),pc(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 Cc(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 fc;var Qc;(Qc=fc||(fc={})).SelectFrame="SelectFrame",Qc.SelectImage="SelectImage",Qc.Position="Position";class yc extends fo{constructor(t,e){super(t,e),Cc(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return _s.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 _s.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?fc.SelectFrame:e||A||this.getImageData()?fc.Position:fc.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 Dc=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}=kr(),[g,h]=(0,i.useState)(!1),[d,u]=(0,i.useState)(!1),{state:B,uiDispatcher:w}=Vr(),E=(0,i.useCallback)((t=>{const e=t;w(new jr({zoom:Math.max(.1,Math.min(e,B.maxZoom))}))}),[w,B.maxZoom]),p=(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&&(w(new jr({selectedElement:void 0})),u(!0),h(!0))}),[s,l.length,w]),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&&E(B.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;w(new jr({selectedElement:void 0,xTranslation:B.xTranslation-e/B.zoom,yTranslation:B.yTranslation-A/B.zoom}))}t.isPrimary&&(n.current={x:t.screenX,y:t.screenY})}),[c,l,g,d,r,E,B.zoom,B.xTranslation,B.yTranslation,w]),f=(0,i.useCallback)((t=>{g&&E(B.zoom-.035*Math.sign(t.deltaY))}),[E,B.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]),Ra([" "],(()=>{u(!0),w(new jr({selectedElement:void 0}))}),(()=>u(!1))),Ra(["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:p,onPointerCancel:p,onPointerLeave:p,onPointerMove:C,style:Q,children:t.children})};
1233
1234
  //# sourceMappingURL=main.js.map
package/dist/module.js CHANGED
@@ -558,6 +558,7 @@ import{CommandContext as A,AssetType as t,BringForwardCommand as e,BringToFrontC
558
558
  mutation CreateBundle($collectionId: String) {
559
559
  bundleCreate(collectionId: $collectionId) {
560
560
  id
561
+ bundleOwnerId
561
562
  metadata {
562
563
  key
563
564
  value
@@ -601,7 +602,7 @@ import{CommandContext as A,AssetType as t,BringForwardCommand as e,BringToFrontC
601
602
  id
602
603
  }
603
604
  }
604
- `;function ia(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class aa{constructor(A,t){ia(this,"client",void 0),ia(this,"id",void 0),ia(this,"name",void 0),ia(this,"metadata",void 0),ia(this,"productCollection",void 0),ia(this,"workflowExperiences",[]),this.client=A,this.id=t.id,this.name=t.name||"",this.metadata=new Map(t.metadata?.map((A=>[A.key,A.value]))||[]),this.productCollection=t.productCollection}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(A){return this.name=A,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(A){return this.metadata=new Map(A),this.updateBundle()}hasGlobalProperties(){throw new Error("Method not implemented.")}getGlobalProperties(){throw new Error("Method not implemented.")}getTotalSubunits(){return this.workflowExperiences.map((A=>A.getTotalPriceSubunits())).reduce(((A,t)=>A+t),0)}getProductCollection(){return this.productCollection}async addWorkflowExperience(A){const t=A.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((A=>A.getWorkflowManager().getTransaction().id===t)))throw new Error("Unable to add transaction to bundle - Already Exists!");await ft.getShadowGraphqlClient().mutate({mutation:Aa,variables:{id:this.id,transactionId:t}}),this.workflowExperiences.push(A)}async removeWorkflowExperience(A){const t=this.workflowExperiences.indexOf(A);if(!(t>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found!");await ft.getShadowGraphqlClient().mutate({mutation:ta,variables:{id:this.id,transactionId:A.getWorkflowManager().getTransaction().id}}),this.workflowExperiences.splice(t,1)}sortWorkflowExperiences(A){this.workflowExperiences=this.workflowExperiences.sort(A)}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(A,t){await ft.getShadowGraphqlClient().mutate({mutation:ea,variables:{id:this.id,details:A,type:t||ae.Owner}})}async updateStakeholders(A){await ft.getShadowGraphqlClient().mutate({mutation:na,variables:{id:this.id,input:A}})}async getAllStakeholders(){const A=await ft.getShadowGraphqlClient().query({query:Zi,errorPolicy:"all",variables:{id:this.id}});if(!A.data.bundles||0===A.data.bundles.length)throw new Error("Bundle not found!");return A.data.bundles[0].bundleStakeholders||[]}async updateBundle(){if(!(await ft.getShadowGraphqlClient().mutate({mutation:_i,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([A,t])=>({key:A,value:t})))}})).data?.bundleUpdate)throw new Error("Bundle not found!")}}function oa(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}const ra=IA`
605
+ `;function ia(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class aa{constructor(A,t){ia(this,"client",void 0),ia(this,"id",void 0),ia(this,"name",void 0),ia(this,"metadata",void 0),ia(this,"productCollection",void 0),ia(this,"workflowExperiences",[]),this.client=A,this.id=t.id,this.name=t.name||"",this.metadata=new Map(t.metadata?.map((A=>[A.key,A.value]))||[]),this.productCollection=t.productCollection}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(A){return this.name=A,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(A){return this.metadata=new Map(A),this.updateBundle()}hasGlobalProperties(){throw new Error("Method not implemented.")}getGlobalProperties(){throw new Error("Method not implemented.")}getTotalSubunits(){return this.workflowExperiences.map((A=>A.getTotalPriceSubunits())).reduce(((A,t)=>A+t),0)}getProductCollection(){return this.productCollection}async addWorkflowExperience(A){const t=A.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((A=>A.getWorkflowManager().getTransaction().id===t)))throw new Error("Unable to add transaction to bundle - Already Exists!");await ft.getShadowGraphqlClient().mutate({mutation:Aa,variables:{id:this.id,transactionId:t}}),this.workflowExperiences.push(A)}async removeWorkflowExperience(A){const t=this.workflowExperiences.indexOf(A);if(!(t>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found!");await ft.getShadowGraphqlClient().mutate({mutation:ta,variables:{id:this.id,transactionId:A.getWorkflowManager().getTransaction().id}}),this.workflowExperiences.splice(t,1)}sortWorkflowExperiences(A){this.workflowExperiences=this.workflowExperiences.sort(A)}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(A,t){await ft.getShadowGraphqlClient().mutate({mutation:ea,variables:{id:this.id,details:A,type:t||ae.Owner}})}async updateStakeholders(A){await ft.getShadowGraphqlClient().mutate({mutation:na,variables:{id:this.id,input:A}})}async getAllStakeholders(){const A=await ft.getShadowGraphqlClient().query({query:Zi,errorPolicy:"all",variables:{id:this.id}});if(!A.data.bundles||0===A.data.bundles.length)throw new Error("Bundle not found!");return A.data.bundles[0].bundleStakeholders||[]}async reloadWorkflowExperience(A,t){const e=t?e=>t(e,A):void 0,n=await this.client.getWorkflowExperience(void 0,void 0,e,{type:"transaction",transactionId:A}),i=this.workflowExperiences.findIndex((t=>t.getWorkflowManager().getTransaction().id===A));return i>-1?this.workflowExperiences[i]=n:this.workflowExperiences.push(n),n}async updateBundle(){if(!(await ft.getShadowGraphqlClient().mutate({mutation:_i,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([A,t])=>({key:A,value:t})))}})).data?.bundleUpdate)throw new Error("Bundle not found!")}}function oa(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}const ra=IA`
605
606
  ${Mt}
606
607
  ${Yt}
607
608
  ${Pt}
@@ -1229,5 +1230,5 @@ import{CommandContext as A,AssetType as t,BringForwardCommand as e,BringToFrontC
1229
1230
  }
1230
1231
  }
1231
1232
  }
1232
- `,Ea=async A=>{const t=(await ft.getShadowGraphqlClient().query({query:ra,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:A}})).data.workflow;return t.steps.forEach((A=>{delete A.data.__typename})),t},ha=(A,t)=>{const e=A.workflowState,n=e?JSON.parse(e):void 0;return n?Object.values(n.layouts).map((A=>A.layout)):t.panels.sort(((A,t)=>A.index-t.index)).map((A=>({id:F(),panelId:A.name,name:A.name,index:A.index,createdAt:new Date,updatedAt:new Date,transparentBackground:A.transparentBackground,height:A.height,width:A.width,previewRegion:A.previewRegion,useEditableArea:A.useEditableArea,editableArea:A.editableArea})))};class Ca{constructor(A){var t;oa(this,"options",void 0),oa(this,"initialized",void 0),oa(this,"experienceOptions",void 0),oa(this,"currencyCode",void 0),oa(this,"customer",void 0),oa(this,"updateTransactionState",(async A=>{try{return ft.getShadowGraphqlClient().mutate({...A,mutation:Un})}catch(A){throw console.error(A),new st("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=A,this.options.applicationKey&&(t=this.options.applicationKey,It=t)}getAssetManager(){return Ht}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateBundleFromLocalStorage(A){const t=wt.getMap("bundleOwnerIds");if(t?.has(A)){const e=t.get(A);return mt(e),Promise.resolve({success:!0,stakeholderType:ae.Owner})}const e=wt.getMap("bundleCustomerIds");if(e?.has(A)){const t=e.get(A);if(t){if(await this.authenticateCustomerId(t)){const t=this.customer?.bundleStakeholders?.find((t=>t.bundle?.id===A));if(t)return Promise.resolve({success:!0,stakeholderType:t.type})}}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(A){const t=ft.getShadowGraphqlClient(),e=await t.query({query:sa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:A}});if(!e.data.transactions||0===e.data.transactions.length)throw new Error(`Transaction not found: ${A}`);const n=e.data.transactions[0],i=n.product?.partner?.id;if(!i)throw new Error(`Unable to read transaction: ${A}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const a=wt.getMap("transactionOwnerIds");if(a?.has(A)){const t=a.get(A);return Qt(t),Promise.resolve({success:!0,stakeholderType:ae.Owner})}const o=wt.getMap("transactionCustomerIds");if(o?.has(A)){const t=o.get(A);if(t){if(await this.authenticateCustomerId(t)){const t=this.customer?.bundleStakeholders?.find((t=>t.bundle?.transactions?.some((t=>t.id===A))))||this.customer?.stakeholders?.find((t=>t.transaction?.id===A));if(t)return Promise.resolve({success:!0,stakeholderType:t.type})}}}const r=(await t.query({query:ca,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(A){const t=wt.getMap("transactionCustomerIds");t?.has(A)&&(t.delete(A),wt.setMap("transactionCustomerIds",t))}getStakeholderTypeForTransaction(A){const t=this.customer?.stakeholders?.find((t=>t.transaction?.id===A));if(t)return t.type}async getOrCreateCustomer(A){this.customer=void 0;const t=ft.getShadowGraphqlClient(),e=(await t.query({query:ga,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:A}})).data.customer;if(!e.id){const e=(await t.mutate({mutation:la,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:A}}})).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(A){const t=ft.getShadowGraphqlClient(),e=wt.getMap("customerTokens");if(!e?.has(A))return!1;const n=e.get(A);if(!n)return!1;const i=(await t.mutate({mutation:Ba,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!i&&(Dt(n),this.customer=i,!0)}async generateVerificationCode(A){await ft.getShadowGraphqlClient().mutate({mutation:wa,variables:{emailAddress:A}})}async verifyCode(A,t){const e=(await ft.getShadowGraphqlClient().mutate({mutation:da,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:A,verificationCode:t}})).data?.customerVerifyCode;if(e?.loginToken){if(!e.partner?.id)throw new Error(`Unable to find customer: ${A}`);const t=wt.getMap("customerTokens")||new Map;return t.set(e.id,e.loginToken),wt.setMap("customerTokens",t),Dt(e.loginToken),this.customer={...e,loginToken:void 0},!0}return!1}async getNewBundle(A){const t=(await ft.getShadowGraphqlClient().mutate({mutation:$i,variables:{collectionId:A}})).data?.bundleCreate;if(!t)throw new Error("Unable to create bundle");mt(t.bundleOwnerId);const e=wt.getMap("bundleOwnerIds")||new Map;return e.set(t.id,t.bundleOwnerId),wt.setMap("bundleOwnerIds",e),new aa(this,t)}async getExistingBundle(A){const t=await ft.getShadowGraphqlClient().query({query:qi,variables:{id:A}});if(!t.data?.bundles||0===t.data?.bundles.length||!t.data?.bundles[0])throw new Error(`Unable to find bundle: ${A}`);const e=t.data?.bundles[0],n=wt.getMap("bundleOwnerIds");return n?.has(e.id)&&mt(n.get(e.id)),new aa(this,e)}async getWorkflowExperience(A,t,e,n){if(!n)return await this.getWorkflowExperienceDeprecated(A,t,e);const i=async A=>{for(const t in A.layouts){const e=A.layouts[t].elements.filter((A=>A.type===E.Illustration));for(let A=0;A<e.length;++A){const t=e[A];t.src&&t.svg&&(t.cachedObjectURL=await dA(t.svg))}const n=A.layouts[t].elements.filter((A=>A.type===E.Textbox));for(let A=0;A<n.length;++A){const t=n[A];t.fontData?.assetUrl&&U(t.fontData.assetUrl)}}},{transaction:a,workflow:o,readOnly:r}=await(async()=>{const A=ft.getShadowGraphqlClient();if(await A.resetStore(),"transaction"===n.type){const{transactionId:t,readOnly:e}=n,i=await A.query({query:Hn,variables:{id:t},errorPolicy:"all"});if(!i.data?.transactions||0===i.data.transactions.length)throw new st("Existing transaction not found.");const a=i.data?.transactions[0];if(!a.workflowId)throw new st("Existing transaction has no workflow ID.");const o=await Ea(a.workflowId);if(!a.product)throw new st("Failed to load transaction, product not available.");return{transaction:a,workflow:o,readOnly:e}}if("integration"===n.type||"external"===n.type){const t=async()=>{const t="integration"===n.type?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},e=await A.mutate({mutation:Nn,variables:{...t,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 st("Failed to create transaction!");const i=e.data.transactionCreate;if(!i.product)throw new st("Failed to create transaction, product not available.");return i},e=Ea(n.workflowId),[i,a]=await Promise.all([t(),e]);return{transaction:i,workflow:a}}throw new st("No workflow ID provided.")})();if(this.currencyCode=a.product.partner?.currencyCode,this.experienceOptions={product:a.product,transaction:a,layouts:[],stateMutationFunc:r?async()=>{throw new ot("State mutation is forbidden in read only mode!")}:this.updateTransactionState,readOnly:r,workflow:o},"transaction"===n.type&&a.workflowState){const A=JSON.parse(a.workflowState);this.experienceOptions.layouts=Object.values(A.layouts).map((A=>A.layout)),await v(A),await i(A),this.experienceOptions.reloadedState=A}else if(!r&&n.workflowState){const A=JSON.parse(n.workflowState);this.experienceOptions.layouts=Object.values(A.layouts).map((A=>A.layout)),await v(A),await i(A),this.experienceOptions.reloadedState=A}else this.experienceOptions.layouts=ha(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=e&&e(o),this.experienceOptions.renderableContextService=new In(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 A=wt.getMap("transactionOwnerIds")||new Map;A.set(a.id,a.transactionOwnerId),Qt(a.transactionOwnerId||""),wt.setMap("transactionOwnerIds",A)}else{const A=(wt.getMap("transactionOwnerIds")||new Map).get(a.id);A&&Qt(A)}this.initialized=!0;const s=new Wi(this,this.experienceOptions);return await s.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await s.attachCustomerDetails({email:this.customer.emailAddress}),s}async initFromIntegrationProduct(A){if(""===A)throw new st("No integration product ID provided.");const t=ft.getShadowGraphqlClient();await t.resetStore();const e=await t.mutate({mutation:Nn,variables:{integrationProductId:A,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 st("Failed to create transaction!");const n=e.data.transactionCreate;if(!n.product)throw new st("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const i=wt.getMap("transactionOwnerIds")||new Map;i.set(n.id,n.transactionOwnerId),Qt(n.transactionOwnerId||""),wt.setMap("transactionOwnerIds",i),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(A,t=!1){if(""===A)throw new st("No transaction ID provided.");const e=ft.getShadowGraphqlClient();await e.resetStore();if(t)return await(async()=>{const n=(await e.query({query:Hn,variables:{id:A},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new st("Failed to read transaction.");if(!n.product)throw new st("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 ot("State mutation is forbidden in read only mode!")},readOnly:t},this.initialized=!0})();const n=wt.getMap("transactionOwnerIds")||new Map,i=n.get(A);if(i){Qt(i);const n=(await e.query({query:Hn,variables:{id:A},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new st("Failed to read transaction.");if(!n.product)throw new st("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:t},void(this.initialized=!0)}try{const i=(await e.mutate({mutation:Rn,variables:{id:A},errorPolicy:"all"})).data?.transactionClaim;if(!i)throw new st("Failed to read transaction.");if(!i.product)throw new st("Failed to load transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode,i.transactionOwnerId&&(n.set(i.id,i.transactionOwnerId),Qt(i.transactionOwnerId),wt.setMap("transactionOwnerIds",n)),this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:t},this.initialized=!0}catch{throw new st("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(A,t,e){if(!this.initialized||!this.experienceOptions)throw new st("Cannot launch experience: Not initialized.");const n=async A=>{for(const t in A.layouts){const e=A.layouts[t].elements.filter((A=>A.type===E.Illustration));for(let A=0;A<e.length;++A){const t=e[A];t.src&&t.svg&&(t.cachedObjectURL=await dA(t.svg))}const n=A.layouts[t].elements.filter((A=>A.type===E.Textbox));for(let A=0;A<n.length;++A){const t=n[A];t.fontData?.assetUrl&&U(t.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const A=await Ea(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=A,this.experienceOptions.transaction.workflowState){const A=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(A.layouts).map((A=>A.layout)),await v(A),await n(A),this.experienceOptions.reloadedState=A}this.experienceOptions.previewService=e&&e(A),this.experienceOptions.renderableContextService=new In(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 t=new Wi(this,this.experienceOptions);return await t.getWorkflowManager().getInitializationPromise(),t}if(A){const i=ft.getShadowGraphqlClient().mutate({mutation:Pn,variables:{workflowId:A,id:this.experienceOptions.transaction.id}}),a=Ea(A);if(await Promise.all([i,a]),this.experienceOptions.workflow=await a,t){const A=JSON.parse(t);this.experienceOptions.layouts=Object.values(A.layouts).map((A=>A.layout)),await v(A),await n(A),this.experienceOptions.reloadedState=A}else this.experienceOptions.layouts=ha(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=e&&e(await a),this.experienceOptions.renderableContextService=new In(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 Wi(this,this.experienceOptions);return await o.getWorkflowManager().getInitializationPromise(),o}throw new st("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new st("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new st("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function Qa(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class ua{constructor(){Qa(this,"getProduct",void 0),Qa(this,"getCommandContext",void 0),Qa(this,"getAllLayoutData",void 0),Qa(this,"getMetadata",void 0),Qa(this,"getWorkflowMetadata",void 0),Qa(this,"getStepStorage",void 0),Qa(this,"setModelContainer",void 0),Qa(this,"getUpdatesPending",void 0)}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}getVariationRecords(){return[]}async reset(){}updateStateWithServer(A){}addVariationRecord(A){return{recordNumber:0,transactionId:"",values:[]}}getCurrentVariationRecord(){}removeVariationRecord(A){return[]}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(A){}addPoller(A){}addConfirmCallback(A){}addCurrentVariationCallback(A){}addEditedCallback(A){}addElementsCallback(A){}addInformationResultCallback(A){}addInitCallback(A){}addMakingAdjustmentsCallback(A){}addMandatoryCallback(A){}addMetadataCallback(A){}addSelectionCallback(A){}addStepSpecificStorageCallback(A,t){}addStorageCallback(A){}addVariationRecordsCallback(A){}getCommandDispatcher(){return A=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(A){return[]}getSerializedStep(A,t){}getStepSpecificServices(A){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(A){}markUpdateCompleted(A){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}setCurrentAdjustingStepId(A){}setCurrentVariationRecord(A){}setEditedStatus(A,t){}setInformationResults(A){}setMandatoryFulfilled(A,t){}async setSelectionsAndElements(A,t,e){}setVariationRecords(A){}toggleDesignConfirmed(){}updateMetadata(A,t){}async updateStorage(A,t){}}function ma(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}let pa;var Da;(Da=pa||(pa={})).SelectFrame="SelectFrame",Da.SelectImage="SelectImage",Da.Position="Position";class Ia extends yi{constructor(A,t){super(A,t),ma(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(A){const t=this.manager.getRegionElements(this.step.stepName);return ii.selectVariant(this.step,A.getResource(),t,this.manager,(A=>this.setUpdateState(A)))}onFrameDataChanged(A){this.frameService&&this.frameService.onFrameDataChanged((t=>{t&&A(t)}))}selectImage(A){return ii.selectImage(this.step,A,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(A,t,e,n){return n&&n.length>1&&void 0===A?pa.SelectFrame:t||e||this.getImageData()?pa.Position:pa.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 fa=A=>{const t=kA(null),e=kA(void 0),[n,i]=NA(void 0),{addEvent:a,removeEvent:o,updateEvent:r,eventCache:s}=Jt(),[c,g]=NA(!1),[l,B]=NA(!1),{state:w,uiDispatcher:d}=qt(),E=RA((A=>{const t=A;d(new Xt({zoom:Math.max(.1,Math.min(t,w.maxZoom))}))}),[d,w.maxZoom]),h=RA((A=>{o(A),1===s.length&&(e.current=void 0),2===s.length&&i(void 0);"touch"===A.pointerType&&s.length>1&&s.length-1==1&&(B(!1),g(!1))}),[o,s.length]),C=RA((A=>{a(A);"touch"===A.pointerType&&1===s.length&&(d(new Xt({selectedElement:void 0})),B(!0),g(!0))}),[a,s.length,d]),Q=RA((A=>{r(A);const t=1===s.length&&"touch"!==s[0].pointerType,a=2===s.length&&"touch"===s[0].pointerType;if(c&&a){const[A,t]=s,e=Math.abs(A.clientX-t.clientX),a=n;a&&E(w.zoom-.0055*(a-e)),i(e)}if(l&&(t||a)&&A.isPrimary){const t=(e?.current?.x||A.screenX)-A.screenX,n=(e?.current?.y||A.screenY)-A.screenY;d(new Xt({selectedElement:void 0,xTranslation:w.xTranslation-t/w.zoom,yTranslation:w.yTranslation-n/w.zoom}))}A.isPrimary&&(e.current={x:A.screenX,y:A.screenY})}),[r,s,c,l,n,E,w.zoom,w.xTranslation,w.yTranslation,d]),u=RA((A=>{c&&E(w.zoom-.035*Math.sign(A.deltaY))}),[E,w.zoom,c]);UA((()=>{if(!t.current||0===s.length)return;const A=s[0].pointerId,e=t.current.hasPointerCapture(A);l&&!e&&t.current.setPointerCapture(A),!l&&e&&t.current.releasePointerCapture(A)}),[t,l,s]),be([" "],(()=>{B(!0),d(new Xt({selectedElement:void 0}))}),(()=>B(!1))),be(["Control"],(()=>g(!0)),(()=>g(!1)));const m=GA((()=>({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 bA("div",{ref:t,className:"transform-wrapper",onWheel:u,onPointerDown:C,onPointerUp:h,onPointerCancel:h,onPointerLeave:h,onPointerMove:Q,style:m,children:A.children})};export{Ca as SpiffCommerceClient,A as CommandContext,Et as spiffCoreConfiguration,Te as PromiseQueue,Oe as QueueablePromise,ua as MockWorkflowManager,Qi as InformationMessageType,yi as StepHandle,Pi as TextStepHandle,Ia as FrameStepHandle,xi as BulkStepHandle,Ui as ShapeStepHandle,Si as IllustrationStepHandle,vi as MaterialStepHandle,Ni as ModelStepHandle,Ri as PictureStepHandle,Hi as QuestionStepHandle,_t as BulkPriceCalculationStrategy,Ii as Variant,At as OptionNotFoundError,tt as LayoutNotFoundError,et as AssetNotFoundError,nt as ResourceNotFoundError,it as MisconfigurationError,rt as ParseError,ot as UnhandledBehaviorError,Ht as assetService,Ki as designService,Ti as createDesign,kt as optionService,wt as persistenceService,ft as graphQlManager,ce as toast,qn as FrameService,Wn as getBoundedOffsets,ii as frameStepService,ri as modelStepService,oi as materialStepService,li as shapeStepService,gi as questionStepService,ei as digitalContentStepService,si as moduleStepService,ci as pictureStepService,hi as textStepService,ai as illustrationStepService,Zt as ProductCameraRig,pa as FrameStep,te as ConversionLocation,ne as ConversionDataType,Ea as getWorkflow,_n as shortenUrl,t 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,E as LayoutElementType,h as MoveCommand,C as ResizeCommand,Q as RotateCommand,u as SendBackwardsCommand,ae as StakeholderType,m as StepAspectType,p as StepType,D as TextChangeCommand,I as UnitOfMeasurement,f as dataUrlFromExternalUrl,y as findElement,M as frameDataCache,F as generate,Y as getAxisAlignedBoundingBox,x as generateSVGWithUnknownColors,S as getAttributesFromArrayBuffer,v as rehydrateSerializedLayout,N as getFrameData,R as getSvgElement,H as loadFontFromDataUrl,U as loadFontFromExternalUrl,P as determineCorrectFontSizeAndLines,G as patternImageDataCache,pn as generateCommands,k as registerJSDOM,Pe as minZoom,vn as AdvancedEditor,fa as TransformWrapper,Sn as EditorCore,Lt as useLayouts,qt as useEditorState,ke as useEditorInteraction,be as useShortcutCombination,Kt as commandReducer,jt as getDefaultState,bt as CommandContextContext,Wt as AdvancedEditorStateProvider,Vt as AdvancedEditorContext,Xt as UICommand,Tt as EditorSubMenu,ge as ElementEventType,Be as KeyEvent,Jn as gatherVaryingStepAspects};
1233
+ `,Ea=async A=>{const t=(await ft.getShadowGraphqlClient().query({query:ra,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:A}})).data.workflow;return t.steps.forEach((A=>{delete A.data.__typename})),t},ha=(A,t)=>{const e=A.workflowState,n=e?JSON.parse(e):void 0;return n?Object.values(n.layouts).map((A=>A.layout)):t.panels.sort(((A,t)=>A.index-t.index)).map((A=>({id:F(),panelId:A.name,name:A.name,index:A.index,createdAt:new Date,updatedAt:new Date,transparentBackground:A.transparentBackground,height:A.height,width:A.width,previewRegion:A.previewRegion,useEditableArea:A.useEditableArea,editableArea:A.editableArea})))};class Ca{constructor(A){var t;oa(this,"options",void 0),oa(this,"initialized",void 0),oa(this,"experienceOptions",void 0),oa(this,"currencyCode",void 0),oa(this,"customer",void 0),oa(this,"updateTransactionState",(async A=>{try{return ft.getShadowGraphqlClient().mutate({...A,mutation:Un})}catch(A){throw console.error(A),new st("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=A,this.options.applicationKey&&(t=this.options.applicationKey,It=t)}getAssetManager(){return Ht}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateBundleFromLocalStorage(A){const t=wt.getMap("bundleOwnerIds");if(t?.has(A)){const e=t.get(A);return mt(e),Promise.resolve({success:!0,stakeholderType:ae.Owner})}const e=wt.getMap("bundleCustomerIds");if(e?.has(A)){const t=e.get(A);if(t){if(await this.authenticateCustomerId(t)){const t=this.customer?.bundleStakeholders?.find((t=>t.bundle?.id===A));if(t)return Promise.resolve({success:!0,stakeholderType:t.type})}}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(A){const t=ft.getShadowGraphqlClient(),e=await t.query({query:sa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:A}});if(!e.data.transactions||0===e.data.transactions.length)throw new Error(`Transaction not found: ${A}`);const n=e.data.transactions[0],i=n.product?.partner?.id;if(!i)throw new Error(`Unable to read transaction: ${A}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const a=wt.getMap("transactionOwnerIds");if(a?.has(A)){const t=a.get(A);return Qt(t),Promise.resolve({success:!0,stakeholderType:ae.Owner})}const o=wt.getMap("transactionCustomerIds");if(o?.has(A)){const t=o.get(A);if(t){if(await this.authenticateCustomerId(t)){const t=this.customer?.bundleStakeholders?.find((t=>t.bundle?.transactions?.some((t=>t.id===A))))||this.customer?.stakeholders?.find((t=>t.transaction?.id===A));if(t)return Promise.resolve({success:!0,stakeholderType:t.type})}}}const r=(await t.query({query:ca,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(A){const t=wt.getMap("transactionCustomerIds");t?.has(A)&&(t.delete(A),wt.setMap("transactionCustomerIds",t))}getStakeholderTypeForTransaction(A){const t=this.customer?.stakeholders?.find((t=>t.transaction?.id===A));if(t)return t.type}async getOrCreateCustomer(A){this.customer=void 0;const t=ft.getShadowGraphqlClient(),e=(await t.query({query:ga,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:A}})).data.customer;if(!e.id){const e=(await t.mutate({mutation:la,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:A}}})).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(A){const t=ft.getShadowGraphqlClient(),e=wt.getMap("customerTokens");if(!e?.has(A))return!1;const n=e.get(A);if(!n)return!1;const i=(await t.mutate({mutation:Ba,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!i&&(Dt(n),this.customer=i,!0)}async generateVerificationCode(A){await ft.getShadowGraphqlClient().mutate({mutation:wa,variables:{emailAddress:A}})}async verifyCode(A,t){const e=(await ft.getShadowGraphqlClient().mutate({mutation:da,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:A,verificationCode:t}})).data?.customerVerifyCode;if(e?.loginToken){if(!e.partner?.id)throw new Error(`Unable to find customer: ${A}`);const t=wt.getMap("customerTokens")||new Map;return t.set(e.id,e.loginToken),wt.setMap("customerTokens",t),Dt(e.loginToken),this.customer={...e,loginToken:void 0},!0}return!1}async getNewBundle(A){const t=(await ft.getShadowGraphqlClient().mutate({mutation:$i,variables:{collectionId:A}})).data?.bundleCreate;if(!t)throw new Error("Unable to create bundle");mt(t.bundleOwnerId);const e=wt.getMap("bundleOwnerIds")||new Map;return e.set(t.id,t.bundleOwnerId),wt.setMap("bundleOwnerIds",e),new aa(this,t)}async getExistingBundle(A,t){const e=await ft.getShadowGraphqlClient().query({query:qi,variables:{id:A}});if(!e.data?.bundles||0===e.data?.bundles.length||!e.data?.bundles[0])throw new Error(`Unable to find bundle: ${A}`);const n=e.data?.bundles[0],i=wt.getMap("bundleOwnerIds");i?.has(n.id)&&mt(i.get(n.id));const a=new aa(this,n);return n.transactions&&n.transactions.length>0&&await Promise.all(n.transactions.map((async A=>{a.reloadWorkflowExperience(A.id,t)}))),a}async getWorkflowExperience(A,t,e,n){if(!n)return await this.getWorkflowExperienceDeprecated(A,t,e);const i=async A=>{for(const t in A.layouts){const e=A.layouts[t].elements.filter((A=>A.type===E.Illustration));for(let A=0;A<e.length;++A){const t=e[A];t.src&&t.svg&&(t.cachedObjectURL=await dA(t.svg))}const n=A.layouts[t].elements.filter((A=>A.type===E.Textbox));for(let A=0;A<n.length;++A){const t=n[A];t.fontData?.assetUrl&&U(t.fontData.assetUrl)}}},{transaction:a,workflow:o,readOnly:r}=await(async()=>{const A=ft.getShadowGraphqlClient();if(await A.resetStore(),"transaction"===n.type){const{transactionId:t,readOnly:e}=n,i=await A.query({query:Hn,variables:{id:t},errorPolicy:"all"});if(!i.data?.transactions||0===i.data.transactions.length)throw new st("Existing transaction not found.");const a=i.data?.transactions[0];if(!a.workflowId)throw new st("Existing transaction has no workflow ID.");const o=await Ea(a.workflowId);if(!a.product)throw new st("Failed to load transaction, product not available.");return{transaction:a,workflow:o,readOnly:e}}if("integration"===n.type||"external"===n.type){const t=async()=>{const t="integration"===n.type?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},e=await A.mutate({mutation:Nn,variables:{...t,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 st("Failed to create transaction!");const i=e.data.transactionCreate;if(!i.product)throw new st("Failed to create transaction, product not available.");return i},e=Ea(n.workflowId),[i,a]=await Promise.all([t(),e]);return{transaction:i,workflow:a}}throw new st("No workflow ID provided.")})();if(this.currencyCode=a.product.partner?.currencyCode,this.experienceOptions={product:a.product,transaction:a,layouts:[],stateMutationFunc:r?async()=>{throw new ot("State mutation is forbidden in read only mode!")}:this.updateTransactionState,readOnly:r,workflow:o},"transaction"===n.type&&a.workflowState){const A=JSON.parse(a.workflowState);this.experienceOptions.layouts=Object.values(A.layouts).map((A=>A.layout)),await v(A),await i(A),this.experienceOptions.reloadedState=A}else if(!r&&n.workflowState){const A=JSON.parse(n.workflowState);this.experienceOptions.layouts=Object.values(A.layouts).map((A=>A.layout)),await v(A),await i(A),this.experienceOptions.reloadedState=A}else this.experienceOptions.layouts=ha(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=e&&e(o),this.experienceOptions.renderableContextService=new In(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 A=wt.getMap("transactionOwnerIds")||new Map;A.set(a.id,a.transactionOwnerId),Qt(a.transactionOwnerId||""),wt.setMap("transactionOwnerIds",A)}else{const A=(wt.getMap("transactionOwnerIds")||new Map).get(a.id);A&&Qt(A)}this.initialized=!0;const s=new Wi(this,this.experienceOptions);return await s.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await s.attachCustomerDetails({email:this.customer.emailAddress}),s}async initFromIntegrationProduct(A){if(""===A)throw new st("No integration product ID provided.");const t=ft.getShadowGraphqlClient();await t.resetStore();const e=await t.mutate({mutation:Nn,variables:{integrationProductId:A,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 st("Failed to create transaction!");const n=e.data.transactionCreate;if(!n.product)throw new st("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const i=wt.getMap("transactionOwnerIds")||new Map;i.set(n.id,n.transactionOwnerId),Qt(n.transactionOwnerId||""),wt.setMap("transactionOwnerIds",i),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(A,t=!1){if(""===A)throw new st("No transaction ID provided.");const e=ft.getShadowGraphqlClient();await e.resetStore();if(t)return await(async()=>{const n=(await e.query({query:Hn,variables:{id:A},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new st("Failed to read transaction.");if(!n.product)throw new st("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 ot("State mutation is forbidden in read only mode!")},readOnly:t},this.initialized=!0})();const n=wt.getMap("transactionOwnerIds")||new Map,i=n.get(A);if(i){Qt(i);const n=(await e.query({query:Hn,variables:{id:A},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new st("Failed to read transaction.");if(!n.product)throw new st("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:t},void(this.initialized=!0)}try{const i=(await e.mutate({mutation:Rn,variables:{id:A},errorPolicy:"all"})).data?.transactionClaim;if(!i)throw new st("Failed to read transaction.");if(!i.product)throw new st("Failed to load transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode,i.transactionOwnerId&&(n.set(i.id,i.transactionOwnerId),Qt(i.transactionOwnerId),wt.setMap("transactionOwnerIds",n)),this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:t},this.initialized=!0}catch{throw new st("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(A,t,e){if(!this.initialized||!this.experienceOptions)throw new st("Cannot launch experience: Not initialized.");const n=async A=>{for(const t in A.layouts){const e=A.layouts[t].elements.filter((A=>A.type===E.Illustration));for(let A=0;A<e.length;++A){const t=e[A];t.src&&t.svg&&(t.cachedObjectURL=await dA(t.svg))}const n=A.layouts[t].elements.filter((A=>A.type===E.Textbox));for(let A=0;A<n.length;++A){const t=n[A];t.fontData?.assetUrl&&U(t.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const A=await Ea(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=A,this.experienceOptions.transaction.workflowState){const A=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(A.layouts).map((A=>A.layout)),await v(A),await n(A),this.experienceOptions.reloadedState=A}this.experienceOptions.previewService=e&&e(A),this.experienceOptions.renderableContextService=new In(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 t=new Wi(this,this.experienceOptions);return await t.getWorkflowManager().getInitializationPromise(),t}if(A){const i=ft.getShadowGraphqlClient().mutate({mutation:Pn,variables:{workflowId:A,id:this.experienceOptions.transaction.id}}),a=Ea(A);if(await Promise.all([i,a]),this.experienceOptions.workflow=await a,t){const A=JSON.parse(t);this.experienceOptions.layouts=Object.values(A.layouts).map((A=>A.layout)),await v(A),await n(A),this.experienceOptions.reloadedState=A}else this.experienceOptions.layouts=ha(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=e&&e(await a),this.experienceOptions.renderableContextService=new In(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 Wi(this,this.experienceOptions);return await o.getWorkflowManager().getInitializationPromise(),o}throw new st("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new st("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new st("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function Qa(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}class ua{constructor(){Qa(this,"getProduct",void 0),Qa(this,"getCommandContext",void 0),Qa(this,"getAllLayoutData",void 0),Qa(this,"getMetadata",void 0),Qa(this,"getWorkflowMetadata",void 0),Qa(this,"getStepStorage",void 0),Qa(this,"setModelContainer",void 0),Qa(this,"getUpdatesPending",void 0)}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}getVariationRecords(){return[]}async reset(){}updateStateWithServer(A){}addVariationRecord(A){return{recordNumber:0,transactionId:"",values:[]}}getCurrentVariationRecord(){}removeVariationRecord(A){return[]}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(A){}addPoller(A){}addConfirmCallback(A){}addCurrentVariationCallback(A){}addEditedCallback(A){}addElementsCallback(A){}addInformationResultCallback(A){}addInitCallback(A){}addMakingAdjustmentsCallback(A){}addMandatoryCallback(A){}addMetadataCallback(A){}addSelectionCallback(A){}addStepSpecificStorageCallback(A,t){}addStorageCallback(A){}addVariationRecordsCallback(A){}getCommandDispatcher(){return A=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(A){return[]}getSerializedStep(A,t){}getStepSpecificServices(A){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(A){}markUpdateCompleted(A){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}setCurrentAdjustingStepId(A){}setCurrentVariationRecord(A){}setEditedStatus(A,t){}setInformationResults(A){}setMandatoryFulfilled(A,t){}async setSelectionsAndElements(A,t,e){}setVariationRecords(A){}toggleDesignConfirmed(){}updateMetadata(A,t){}async updateStorage(A,t){}}function ma(A,t,e){return(t=function(A){var t=function(A,t){if("object"!=typeof A||null===A)return A;var e=A[Symbol.toPrimitive];if(void 0!==e){var n=e.call(A,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(A)}(A,"string");return"symbol"==typeof t?t:String(t)}(t))in A?Object.defineProperty(A,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):A[t]=e,A}let pa;var Da;(Da=pa||(pa={})).SelectFrame="SelectFrame",Da.SelectImage="SelectImage",Da.Position="Position";class Ia extends yi{constructor(A,t){super(A,t),ma(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(A){const t=this.manager.getRegionElements(this.step.stepName);return ii.selectVariant(this.step,A.getResource(),t,this.manager,(A=>this.setUpdateState(A)))}onFrameDataChanged(A){this.frameService&&this.frameService.onFrameDataChanged((t=>{t&&A(t)}))}selectImage(A){return ii.selectImage(this.step,A,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(A,t,e,n){return n&&n.length>1&&void 0===A?pa.SelectFrame:t||e||this.getImageData()?pa.Position:pa.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 fa=A=>{const t=kA(null),e=kA(void 0),[n,i]=NA(void 0),{addEvent:a,removeEvent:o,updateEvent:r,eventCache:s}=Jt(),[c,g]=NA(!1),[l,B]=NA(!1),{state:w,uiDispatcher:d}=qt(),E=RA((A=>{const t=A;d(new Xt({zoom:Math.max(.1,Math.min(t,w.maxZoom))}))}),[d,w.maxZoom]),h=RA((A=>{o(A),1===s.length&&(e.current=void 0),2===s.length&&i(void 0);"touch"===A.pointerType&&s.length>1&&s.length-1==1&&(B(!1),g(!1))}),[o,s.length]),C=RA((A=>{a(A);"touch"===A.pointerType&&1===s.length&&(d(new Xt({selectedElement:void 0})),B(!0),g(!0))}),[a,s.length,d]),Q=RA((A=>{r(A);const t=1===s.length&&"touch"!==s[0].pointerType,a=2===s.length&&"touch"===s[0].pointerType;if(c&&a){const[A,t]=s,e=Math.abs(A.clientX-t.clientX),a=n;a&&E(w.zoom-.0055*(a-e)),i(e)}if(l&&(t||a)&&A.isPrimary){const t=(e?.current?.x||A.screenX)-A.screenX,n=(e?.current?.y||A.screenY)-A.screenY;d(new Xt({selectedElement:void 0,xTranslation:w.xTranslation-t/w.zoom,yTranslation:w.yTranslation-n/w.zoom}))}A.isPrimary&&(e.current={x:A.screenX,y:A.screenY})}),[r,s,c,l,n,E,w.zoom,w.xTranslation,w.yTranslation,d]),u=RA((A=>{c&&E(w.zoom-.035*Math.sign(A.deltaY))}),[E,w.zoom,c]);UA((()=>{if(!t.current||0===s.length)return;const A=s[0].pointerId,e=t.current.hasPointerCapture(A);l&&!e&&t.current.setPointerCapture(A),!l&&e&&t.current.releasePointerCapture(A)}),[t,l,s]),be([" "],(()=>{B(!0),d(new Xt({selectedElement:void 0}))}),(()=>B(!1))),be(["Control"],(()=>g(!0)),(()=>g(!1)));const m=GA((()=>({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 bA("div",{ref:t,className:"transform-wrapper",onWheel:u,onPointerDown:C,onPointerUp:h,onPointerCancel:h,onPointerLeave:h,onPointerMove:Q,style:m,children:A.children})};export{Ca as SpiffCommerceClient,A as CommandContext,Et as spiffCoreConfiguration,Te as PromiseQueue,Oe as QueueablePromise,ua as MockWorkflowManager,Qi as InformationMessageType,yi as StepHandle,Pi as TextStepHandle,Ia as FrameStepHandle,xi as BulkStepHandle,Ui as ShapeStepHandle,Si as IllustrationStepHandle,vi as MaterialStepHandle,Ni as ModelStepHandle,Ri as PictureStepHandle,Hi as QuestionStepHandle,_t as BulkPriceCalculationStrategy,Ii as Variant,At as OptionNotFoundError,tt as LayoutNotFoundError,et as AssetNotFoundError,nt as ResourceNotFoundError,it as MisconfigurationError,rt as ParseError,ot as UnhandledBehaviorError,Ht as assetService,Ki as designService,Ti as createDesign,kt as optionService,wt as persistenceService,ft as graphQlManager,ce as toast,qn as FrameService,Wn as getBoundedOffsets,ii as frameStepService,ri as modelStepService,oi as materialStepService,li as shapeStepService,gi as questionStepService,ei as digitalContentStepService,si as moduleStepService,ci as pictureStepService,hi as textStepService,ai as illustrationStepService,Zt as ProductCameraRig,pa as FrameStep,te as ConversionLocation,ne as ConversionDataType,Ea as getWorkflow,_n as shortenUrl,t 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,E as LayoutElementType,h as MoveCommand,C as ResizeCommand,Q as RotateCommand,u as SendBackwardsCommand,ae as StakeholderType,m as StepAspectType,p as StepType,D as TextChangeCommand,I as UnitOfMeasurement,f as dataUrlFromExternalUrl,y as findElement,M as frameDataCache,F as generate,Y as getAxisAlignedBoundingBox,x as generateSVGWithUnknownColors,S as getAttributesFromArrayBuffer,v as rehydrateSerializedLayout,N as getFrameData,R as getSvgElement,H as loadFontFromDataUrl,U as loadFontFromExternalUrl,P as determineCorrectFontSizeAndLines,G as patternImageDataCache,pn as generateCommands,k as registerJSDOM,Pe as minZoom,vn as AdvancedEditor,fa as TransformWrapper,Sn as EditorCore,Lt as useLayouts,qt as useEditorState,ke as useEditorInteraction,be as useShortcutCombination,Kt as commandReducer,jt as getDefaultState,bt as CommandContextContext,Wt as AdvancedEditorStateProvider,Vt as AdvancedEditorContext,Xt as UICommand,Tt as EditorSubMenu,ge as ElementEventType,Be as KeyEvent,Jn as gatherVaryingStepAspects};
1233
1234
  //# sourceMappingURL=module.js.map
package/dist/types.d.ts CHANGED
@@ -2053,7 +2053,7 @@ export class SpiffCommerceClient {
2053
2053
  * Retrieves an existing bundle from the API, by id.
2054
2054
  * @returns A bundle to be used for grouping and operating on large amounts of workflow experiences.
2055
2055
  */
2056
- getExistingBundle(bundleId: string): Promise<_Bundle1>;
2056
+ getExistingBundle(bundleId: string, previewServiceConstructor?: (workflow: _Workflow1, transactionId: string) => any): Promise<_Bundle1>;
2057
2057
  /**
2058
2058
  * Creates a new instance of WorkflowExperience. A high level wrapper for workflows.
2059
2059
  * @param workflowId The id of the workflow to be run. Deprecated: Provide options instead.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/core",
3
- "version": "12.4.0",
3
+ "version": "12.4.2",
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",