@spiffcommerce/core 11.1.0 → 11.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1099,5 +1099,5 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),A=require("react/j
1099
1099
  }
1100
1100
  }
1101
1101
  }
1102
- `,tc=async t=>{const e=(await Er.getShadowGraphqlClient().query({query:Vo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}})).data.workflow;return e.steps.forEach((t=>{delete t.data.__typename})),e},ec=(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:Ge(),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 Ac{constructor(t){var e;Jo(this,"options",void 0),Jo(this,"initialized",void 0),Jo(this,"experienceOptions",void 0),Jo(this,"currencyCode",void 0),Jo(this,"customer",void 0),Jo(this,"updateTransactionState",(async t=>{try{return Er.getShadowGraphqlClient().mutate({...t,mutation:Ms})}catch(t){throw console.error(t),new ir("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,wr=e)}getAssetManager(){return Mr}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateTransactionFromLocalStorage(t){const e=Er.getShadowGraphqlClient(),A=await e.query({query:Ko,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=or.getMap("transactionOwnerIds");if(r?.has(t)){const e=r.get(t);return dr(e),Promise.resolve({success:!0,stakeholderType:$r.Owner})}const a=or.getMap("transactionCustomerIds");if(a?.has(t)){const e=a.get(t);if(e){if(await this.authenticateCustomerId(e)){const e=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:Wo,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=or.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),or.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=Er.getShadowGraphqlClient(),A=(await e.query({query:Xo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!A.id){const A=(await e.mutate({mutation:qo,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=Er.getShadowGraphqlClient(),A=or.getMap("customerTokens");if(!A?.has(t))return!1;const i=A.get(t);if(!i)return!1;const n=(await e.mutate({mutation:Zo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:i}})).data?.customerAuthenticate;return!!n&&(Br(i),this.customer=n,!0)}async generateVerificationCode(t){await Er.getShadowGraphqlClient().mutate({mutation:$o,variables:{emailAddress:t}})}async verifyCode(t,e){const A=await Er.getShadowGraphqlClient().mutate({mutation:_o,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}});if(A.data?.customerVerifyCode.loginToken){if(!A.data.customerVerifyCode.partner?.id)throw new Error(`Unable to find customer: ${t}`);const e=or.getMap("customerTokens")||new Map;return e.set(A.data.customerVerifyCode.id,A.data.customerVerifyCode.loginToken),or.setMap("customerTokens",e),Br(A.data.customerVerifyCode.loginToken),this.customer={...A.data.customerVerifyCode,loginToken:void 0},!0}return!1}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===Le.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await Ln(e.svg))}const i=t.layouts[e].elements.filter((t=>t.type===Le.Textbox));for(let t=0;t<i.length;++t){const e=i[t];e.fontData?.assetUrl&&Ai(e.fontData.assetUrl)}}},{transaction:r,workflow:a,readOnly:s}=await(async()=>{const t=Er.getShadowGraphqlClient();if(await t.resetStore(),"transaction"===i.type){const{transactionId:e,readOnly:A}=i,n=await t.query({query:xs,variables:{id:e},errorPolicy:"all"});if(!n.data?.transactions||0===n.data.transactions.length)throw new ir("Existing transaction not found.");const r=n.data?.transactions[0];if(!r.workflowId)throw new ir("Existing transaction has no workflow ID.");const a=await tc(r.workflowId);if(!r.product)throw new ir("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:Ds,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 ir("Failed to create transaction!");const n=A.data.transactionCreate;if(!n.product)throw new ir("Failed to create transaction, product not available.");return n},A=tc(i.workflowId),[n,r]=await Promise.all([e(),A]);return{transaction:n,workflow:r}}throw new ir("No workflow ID provided.")})();if(this.currencyCode=r.product.partner?.currencyCode,this.experienceOptions={product:r.product,transaction:r,layouts:[],stateMutationFunc:s?async()=>{throw new er("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 ji(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 ji(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=ec(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=A&&A(a),this.experienceOptions.renderableContextService=new Bs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService),"transaction"!==i.type){const t=or.getMap("transactionOwnerIds")||new Map;t.set(r.id,r.transactionOwnerId),dr(r.transactionOwnerId||""),or.setMap("transactionOwnerIds",t)}this.initialized=!0;const o=new Oo(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 ir("No integration product ID provided.");const e=Er.getShadowGraphqlClient();await e.resetStore();const A=await e.mutate({mutation:Ds,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 ir("Failed to create transaction!");const i=A.data.transactionCreate;if(!i.product)throw new ir("Failed to create transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode;const n=or.getMap("transactionOwnerIds")||new Map;n.set(i.id,i.transactionOwnerId),dr(i.transactionOwnerId||""),or.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 ir("No transaction ID provided.");const A=Er.getShadowGraphqlClient();await A.resetStore();if(e)return await(async()=>{const i=(await A.query({query:xs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!i)throw new ir("Failed to read transaction.");if(!i.product)throw new ir("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 er("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const i=or.getMap("transactionOwnerIds")||new Map,n=i.get(t);if(n){dr(n);const i=(await A.query({query:xs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!i)throw new ir("Failed to read transaction.");if(!i.product)throw new ir("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:Is,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!n)throw new ir("Failed to read transaction.");if(!n.product)throw new ir("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,n.transactionOwnerId&&(i.set(n.id,n.transactionOwnerId),dr(n.transactionOwnerId),or.setMap("transactionOwnerIds",i)),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new ir("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,A){if(!this.initialized||!this.experienceOptions)throw new ir("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===Le.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await Ln(e.svg))}const i=t.layouts[e].elements.filter((t=>t.type===Le.Textbox));for(let t=0;t<i.length;++t){const e=i[t];e.fontData?.assetUrl&&Ai(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await tc(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 ji(t),await i(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=A&&A(t),this.experienceOptions.renderableContextService=new Bs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService);const e=new Oo(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const n=Er.getShadowGraphqlClient().mutate({mutation:vs,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),r=tc(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 ji(t),await i(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=ec(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await r),this.experienceOptions.renderableContextService=new Bs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService);const a=new Oo(this,this.experienceOptions);return await a.getWorkflowManager().getInitializationPromise(),a}throw new ir("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new ir("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new ir("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}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}class nc{constructor(){ic(this,"getProduct",void 0),ic(this,"getCommandContext",void 0),ic(this,"getAllLayoutData",void 0),ic(this,"getMetadata",void 0),ic(this,"getWorkflowMetadata",void 0),ic(this,"getStepStorage",void 0),ic(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(){}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 rc(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 ac;var sc;(sc=ac||(ac={})).SelectFrame="SelectFrame",sc.SelectImage="SelectImage",sc.Position="Position";class oc extends po{constructor(t,e){super(t,e),rc(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return qs.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 qs.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?ac.SelectFrame:e||A||this.getImageData()?ac.Position:ac.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 cc=t=>{const e=(0,i.useRef)(null);let n=(0,i.useRef)(void 0);const[r,a]=(0,i.useState)(void 0),{addEvent:s,removeEvent:o,updateEvent:c,eventCache:l}=Pr(),[g,h]=(0,i.useState)(!1),[d,u]=(0,i.useState)(!1),{state:B,uiDispatcher:w}=Lr(),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))}),[e,l]),m=(0,i.useCallback)((t=>{s(t);"touch"===t.pointerType&&1===l.length&&(w(new Jr({selectedElement:void 0})),u(!0),h(!0))}),[e,d,l]),C=(0,i.useCallback)((t=>{c(t),t.isPrimary&&(n.current={x:t.screenX,y:t.screenY});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}))}}),[B.xTranslation,B.yTranslation,B.zoom,d,g,E,l,n,r]),f=(0,i.useCallback)((t=>{g&&E(B.zoom-.035*Math.sign(t.deltaY))}),[B,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]),ba([" "],(()=>{u(!0),w(new Jr({selectedElement:void 0}))}),(()=>u(!1))),ba(["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})};
1102
+ `,tc=async t=>{const e=(await Er.getShadowGraphqlClient().query({query:Vo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}})).data.workflow;return e.steps.forEach((t=>{delete t.data.__typename})),e},ec=(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:Ge(),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 Ac{constructor(t){var e;Jo(this,"options",void 0),Jo(this,"initialized",void 0),Jo(this,"experienceOptions",void 0),Jo(this,"currencyCode",void 0),Jo(this,"customer",void 0),Jo(this,"updateTransactionState",(async t=>{try{return Er.getShadowGraphqlClient().mutate({...t,mutation:Ms})}catch(t){throw console.error(t),new ir("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,wr=e)}getAssetManager(){return Mr}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateTransactionFromLocalStorage(t){const e=Er.getShadowGraphqlClient(),A=await e.query({query:Ko,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=or.getMap("transactionOwnerIds");if(r?.has(t)){const e=r.get(t);return dr(e),Promise.resolve({success:!0,stakeholderType:$r.Owner})}const a=or.getMap("transactionCustomerIds");if(a?.has(t)){const e=a.get(t);if(e){if(await this.authenticateCustomerId(e)){const e=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:Wo,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=or.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),or.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=Er.getShadowGraphqlClient(),A=(await e.query({query:Xo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!A.id){const A=(await e.mutate({mutation:qo,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=Er.getShadowGraphqlClient(),A=or.getMap("customerTokens");if(!A?.has(t))return!1;const i=A.get(t);if(!i)return!1;const n=(await e.mutate({mutation:Zo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:i}})).data?.customerAuthenticate;return!!n&&(Br(i),this.customer=n,!0)}async generateVerificationCode(t){await Er.getShadowGraphqlClient().mutate({mutation:$o,variables:{emailAddress:t}})}async verifyCode(t,e){const A=await Er.getShadowGraphqlClient().mutate({mutation:_o,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}});if(A.data?.customerVerifyCode.loginToken){if(!A.data.customerVerifyCode.partner?.id)throw new Error(`Unable to find customer: ${t}`);const e=or.getMap("customerTokens")||new Map;return e.set(A.data.customerVerifyCode.id,A.data.customerVerifyCode.loginToken),or.setMap("customerTokens",e),Br(A.data.customerVerifyCode.loginToken),this.customer={...A.data.customerVerifyCode,loginToken:void 0},!0}return!1}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===Le.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await Ln(e.svg))}const i=t.layouts[e].elements.filter((t=>t.type===Le.Textbox));for(let t=0;t<i.length;++t){const e=i[t];e.fontData?.assetUrl&&Ai(e.fontData.assetUrl)}}},{transaction:r,workflow:a,readOnly:s}=await(async()=>{const t=Er.getShadowGraphqlClient();if(await t.resetStore(),"transaction"===i.type){const{transactionId:e,readOnly:A}=i,n=await t.query({query:xs,variables:{id:e},errorPolicy:"all"});if(!n.data?.transactions||0===n.data.transactions.length)throw new ir("Existing transaction not found.");const r=n.data?.transactions[0];if(!r.workflowId)throw new ir("Existing transaction has no workflow ID.");const a=await tc(r.workflowId);if(!r.product)throw new ir("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:Ds,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 ir("Failed to create transaction!");const n=A.data.transactionCreate;if(!n.product)throw new ir("Failed to create transaction, product not available.");return n},A=tc(i.workflowId),[n,r]=await Promise.all([e(),A]);return{transaction:n,workflow:r}}throw new ir("No workflow ID provided.")})();if(this.currencyCode=r.product.partner?.currencyCode,this.experienceOptions={product:r.product,transaction:r,layouts:[],stateMutationFunc:s?async()=>{throw new er("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 ji(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 ji(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=ec(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=A&&A(a),this.experienceOptions.renderableContextService=new Bs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService),"transaction"!==i.type){const t=or.getMap("transactionOwnerIds")||new Map;t.set(r.id,r.transactionOwnerId),dr(r.transactionOwnerId||""),or.setMap("transactionOwnerIds",t)}this.initialized=!0;const o=new Oo(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 ir("No integration product ID provided.");const e=Er.getShadowGraphqlClient();await e.resetStore();const A=await e.mutate({mutation:Ds,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 ir("Failed to create transaction!");const i=A.data.transactionCreate;if(!i.product)throw new ir("Failed to create transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode;const n=or.getMap("transactionOwnerIds")||new Map;n.set(i.id,i.transactionOwnerId),dr(i.transactionOwnerId||""),or.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 ir("No transaction ID provided.");const A=Er.getShadowGraphqlClient();await A.resetStore();if(e)return await(async()=>{const i=(await A.query({query:xs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!i)throw new ir("Failed to read transaction.");if(!i.product)throw new ir("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 er("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const i=or.getMap("transactionOwnerIds")||new Map,n=i.get(t);if(n){dr(n);const i=(await A.query({query:xs,variables:{id:t},errorPolicy:"all"})).data?.transactions[0];if(!i)throw new ir("Failed to read transaction.");if(!i.product)throw new ir("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:Is,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!n)throw new ir("Failed to read transaction.");if(!n.product)throw new ir("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,n.transactionOwnerId&&(i.set(n.id,n.transactionOwnerId),dr(n.transactionOwnerId),or.setMap("transactionOwnerIds",i)),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new ir("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,A){if(!this.initialized||!this.experienceOptions)throw new ir("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===Le.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await Ln(e.svg))}const i=t.layouts[e].elements.filter((t=>t.type===Le.Textbox));for(let t=0;t<i.length;++t){const e=i[t];e.fontData?.assetUrl&&Ai(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await tc(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 ji(t),await i(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=A&&A(t),this.experienceOptions.renderableContextService=new Bs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService);const e=new Oo(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const n=Er.getShadowGraphqlClient().mutate({mutation:vs,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),r=tc(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 ji(t),await i(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=ec(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await r),this.experienceOptions.renderableContextService=new Bs(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService);const a=new Oo(this,this.experienceOptions);return await a.getWorkflowManager().getInitializationPromise(),a}throw new ir("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new ir("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new ir("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}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}class nc{constructor(){ic(this,"getProduct",void 0),ic(this,"getCommandContext",void 0),ic(this,"getAllLayoutData",void 0),ic(this,"getMetadata",void 0),ic(this,"getWorkflowMetadata",void 0),ic(this,"getStepStorage",void 0),ic(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(){}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 rc(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 ac;var sc;(sc=ac||(ac={})).SelectFrame="SelectFrame",sc.SelectImage="SelectImage",sc.Position="Position";class oc extends po{constructor(t,e){super(t,e),rc(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return qs.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 qs.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?ac.SelectFrame:e||A||this.getImageData()?ac.Position:ac.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 cc=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}=Pr(),[g,h]=(0,i.useState)(!1),[d,u]=(0,i.useState)(!1),{state:B,uiDispatcher:w}=Lr(),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]),ba([" "],(()=>{u(!0),w(new Jr({selectedElement:void 0}))}),(()=>u(!1))),ba(["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})};
1103
1103
  //# sourceMappingURL=main.js.map
package/dist/module.js CHANGED
@@ -1099,5 +1099,5 @@ import{CommandContext as A,AssetType as t,BringForwardCommand as e,BringToFrontC
1099
1099
  }
1100
1100
  }
1101
1101
  }
1102
- `,ta=async A=>{const t=(await mt.getShadowGraphqlClient().query({query:Vi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:A}})).data.workflow;return t.steps.forEach((A=>{delete A.data.__typename})),t},ea=(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 na{constructor(A){var t;Ki(this,"options",void 0),Ki(this,"initialized",void 0),Ki(this,"experienceOptions",void 0),Ki(this,"currencyCode",void 0),Ki(this,"customer",void 0),Ki(this,"updateTransactionState",(async A=>{try{return mt.getShadowGraphqlClient().mutate({...A,mutation:Nn})}catch(A){throw console.error(A),new rt("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=A,this.options.applicationKey&&(t=this.options.applicationKey,Dt=t)}getAssetManager(){return vt}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateTransactionFromLocalStorage(A){const t=mt.getShadowGraphqlClient(),e=await t.query({query:Wi,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=lt.getMap("transactionOwnerIds");if(a?.has(A)){const t=a.get(A);return Qt(t),Promise.resolve({success:!0,stakeholderType:ee.Owner})}const o=lt.getMap("transactionCustomerIds");if(o?.has(A)){const t=o.get(A);if(t){if(await this.authenticateCustomerId(t)){const t=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:Xi,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=lt.getMap("transactionCustomerIds");t?.has(A)&&(t.delete(A),lt.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=mt.getShadowGraphqlClient(),e=(await t.query({query:qi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:A}})).data.customer;if(!e.id){const e=(await t.mutate({mutation:Zi,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=mt.getShadowGraphqlClient(),e=lt.getMap("customerTokens");if(!e?.has(A))return!1;const n=e.get(A);if(!n)return!1;const i=(await t.mutate({mutation:$i,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!i&&(ut(n),this.customer=i,!0)}async generateVerificationCode(A){await mt.getShadowGraphqlClient().mutate({mutation:_i,variables:{emailAddress:A}})}async verifyCode(A,t){const e=await mt.getShadowGraphqlClient().mutate({mutation:Aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:A,verificationCode:t}});if(e.data?.customerVerifyCode.loginToken){if(!e.data.customerVerifyCode.partner?.id)throw new Error(`Unable to find customer: ${A}`);const t=lt.getMap("customerTokens")||new Map;return t.set(e.data.customerVerifyCode.id,e.data.customerVerifyCode.loginToken),lt.setMap("customerTokens",t),ut(e.data.customerVerifyCode.loginToken),this.customer={...e.data.customerVerifyCode,loginToken:void 0},!0}return!1}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=mt.getShadowGraphqlClient();if(await A.resetStore(),"transaction"===n.type){const{transactionId:t,readOnly:e}=n,i=await A.query({query:vn,variables:{id:t},errorPolicy:"all"});if(!i.data?.transactions||0===i.data.transactions.length)throw new rt("Existing transaction not found.");const a=i.data?.transactions[0];if(!a.workflowId)throw new rt("Existing transaction has no workflow ID.");const o=await ta(a.workflowId);if(!a.product)throw new rt("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:xn,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 rt("Failed to create transaction!");const i=e.data.transactionCreate;if(!i.product)throw new rt("Failed to create transaction, product not available.");return i},e=ta(n.workflowId),[i,a]=await Promise.all([t(),e]);return{transaction:i,workflow:a}}throw new rt("No workflow ID provided.")})();if(this.currencyCode=a.product.partner?.currencyCode,this.experienceOptions={product:a.product,transaction:a,layouts:[],stateMutationFunc:r?async()=>{throw new at("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=ea(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=e&&e(o),this.experienceOptions.renderableContextService=new Dn(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService),"transaction"!==n.type){const A=lt.getMap("transactionOwnerIds")||new Map;A.set(a.id,a.transactionOwnerId),Qt(a.transactionOwnerId||""),lt.setMap("transactionOwnerIds",A)}this.initialized=!0;const s=new ji(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 rt("No integration product ID provided.");const t=mt.getShadowGraphqlClient();await t.resetStore();const e=await t.mutate({mutation:xn,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 rt("Failed to create transaction!");const n=e.data.transactionCreate;if(!n.product)throw new rt("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const i=lt.getMap("transactionOwnerIds")||new Map;i.set(n.id,n.transactionOwnerId),Qt(n.transactionOwnerId||""),lt.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 rt("No transaction ID provided.");const e=mt.getShadowGraphqlClient();await e.resetStore();if(t)return await(async()=>{const n=(await e.query({query:vn,variables:{id:A},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new rt("Failed to read transaction.");if(!n.product)throw new rt("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 at("State mutation is forbidden in read only mode!")},readOnly:t},this.initialized=!0})();const n=lt.getMap("transactionOwnerIds")||new Map,i=n.get(A);if(i){Qt(i);const n=(await e.query({query:vn,variables:{id:A},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new rt("Failed to read transaction.");if(!n.product)throw new rt("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:Sn,variables:{id:A},errorPolicy:"all"})).data?.transactionClaim;if(!i)throw new rt("Failed to read transaction.");if(!i.product)throw new rt("Failed to load transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode,i.transactionOwnerId&&(n.set(i.id,i.transactionOwnerId),Qt(i.transactionOwnerId),lt.setMap("transactionOwnerIds",n)),this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:t},this.initialized=!0}catch{throw new rt("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(A,t,e){if(!this.initialized||!this.experienceOptions)throw new rt("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 ta(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 Dn(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService);const t=new ji(this,this.experienceOptions);return await t.getWorkflowManager().getInitializationPromise(),t}if(A){const i=mt.getShadowGraphqlClient().mutate({mutation:Rn,variables:{workflowId:A,id:this.experienceOptions.transaction.id}}),a=ta(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=ea(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=e&&e(await a),this.experienceOptions.renderableContextService=new Dn(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService);const o=new ji(this,this.experienceOptions);return await o.getWorkflowManager().getInitializationPromise(),o}throw new rt("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new rt("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new rt("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}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(){ia(this,"getProduct",void 0),ia(this,"getCommandContext",void 0),ia(this,"getAllLayoutData",void 0),ia(this,"getMetadata",void 0),ia(this,"getWorkflowMetadata",void 0),ia(this,"getStepStorage",void 0),ia(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(){}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 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}let ra;var sa;(sa=ra||(ra={})).SelectFrame="SelectFrame",sa.SelectImage="SelectImage",sa.Position="Position";class ca extends pi{constructor(A,t){super(A,t),oa(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(A){const t=this.manager.getRegionElements(this.step.stepName);return ti.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 ti.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?ra.SelectFrame:t||e||this.getImageData()?ra.Position:ra.SelectImage}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}hasVaryingUpload(){return this.step.data.varyUpload}hasVaryingSelection(){return this.step.data.varySelection}}const ga=A=>{const t=kA(null);let e=kA(void 0);const[n,i]=NA(void 0),{addEvent:a,removeEvent:o,updateEvent:r,eventCache:s}=Gt(),[c,g]=NA(!1),[B,l]=NA(!1),{state:w,uiDispatcher:d}=Vt(),E=RA((A=>{const t=A;d(new Kt({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&&(l(!1),g(!1))}),[t,s]),Q=RA((A=>{a(A);"touch"===A.pointerType&&1===s.length&&(d(new Kt({selectedElement:void 0})),l(!0),g(!0))}),[t,B,s]),C=RA((A=>{r(A),A.isPrimary&&(e.current={x:A.screenX,y:A.screenY});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(B&&(t||a)&&A.isPrimary){const t=(e?.current?.x||A.screenX)-A.screenX,n=(e?.current?.y||A.screenY)-A.screenY;d(new Kt({selectedElement:void 0,xTranslation:w.xTranslation-t/w.zoom,yTranslation:w.yTranslation-n/w.zoom}))}}),[w.xTranslation,w.yTranslation,w.zoom,B,c,E,s,e,n]),u=RA((A=>{c&&E(w.zoom-.035*Math.sign(A.deltaY))}),[w,c]);UA((()=>{if(!t.current||0===s.length)return;const A=s[0].pointerId,e=t.current.hasPointerCapture(A);B&&!e&&t.current.setPointerCapture(A),!B&&e&&t.current.releasePointerCapture(A)}),[t,B,s]),Pe([" "],(()=>{l(!0),d(new Kt({selectedElement:void 0}))}),(()=>l(!1))),Pe(["Control"],(()=>g(!0)),(()=>g(!1)));const D=GA((()=>({cursor:B&&0===s.length?"grab":B&&1===s.length?"grabbing":c?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[B,c,s]);return bA("div",{ref:t,className:"transform-wrapper",onWheel:u,onPointerDown:Q,onPointerUp:h,onPointerCancel:h,onPointerLeave:h,onPointerMove:C,style:D,children:A.children})};export{na as SpiffCommerceClient,A as CommandContext,dt as spiffCoreConfiguration,Je as PromiseQueue,be as QueueablePromise,aa as MockWorkflowManager,Ei as InformationMessageType,pi as StepHandle,Ri as TextStepHandle,ca as FrameStepHandle,Mi as BulkStepHandle,Ni as ShapeStepHandle,Fi as IllustrationStepHandle,Yi as MaterialStepHandle,xi as ModelStepHandle,Si as PictureStepHandle,vi as QuestionStepHandle,qt as BulkPriceCalculationStrategy,Di as Variant,_A as OptionNotFoundError,At as LayoutNotFoundError,tt as AssetNotFoundError,et as ResourceNotFoundError,nt as MisconfigurationError,ot as ParseError,at as UnhandledBehaviorError,vt as assetService,Ti as designService,Ji as createDesign,Ut as optionService,lt as persistenceService,mt as graphQlManager,oe as toast,Vn as FrameService,jn as getBoundedOffsets,ti as frameStepService,ii as modelStepService,ni as materialStepService,si as shapeStepService,ri as questionStepService,_n as digitalContentStepService,ai as moduleStepService,oi as pictureStepService,wi as textStepService,ei as illustrationStepService,Wt as ProductCameraRig,ra as FrameStep,$t as ConversionLocation,Ae as ConversionDataType,ta as getWorkflow,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,B as FontSizeCommand,l as FontSourceCommand,w as GroupCommand,d as LayoutElementFactory,E as LayoutElementType,h as MoveCommand,Q as ResizeCommand,C as RotateCommand,u as SendBackwardsCommand,ee as StakeholderType,D as StepAspectType,m as StepType,p 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,Cn as generateCommands,k as registerJSDOM,Re as minZoom,Yn as AdvancedEditor,ga as TransformWrapper,Fn as EditorCore,kt as useLayouts,Vt as useEditorState,Ue as useEditorInteraction,Pe as useShortcutCombination,Tt as commandReducer,Ot as getDefaultState,Pt as CommandContextContext,jt as AdvancedEditorStateProvider,zt as AdvancedEditorContext,Kt as UICommand,Jt as EditorSubMenu,re as ElementEventType,ce as KeyEvent,Gn as gatherVaryingStepAspects};
1102
+ `,ta=async A=>{const t=(await mt.getShadowGraphqlClient().query({query:Vi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:A}})).data.workflow;return t.steps.forEach((A=>{delete A.data.__typename})),t},ea=(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 na{constructor(A){var t;Ki(this,"options",void 0),Ki(this,"initialized",void 0),Ki(this,"experienceOptions",void 0),Ki(this,"currencyCode",void 0),Ki(this,"customer",void 0),Ki(this,"updateTransactionState",(async A=>{try{return mt.getShadowGraphqlClient().mutate({...A,mutation:Nn})}catch(A){throw console.error(A),new rt("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=A,this.options.applicationKey&&(t=this.options.applicationKey,Dt=t)}getAssetManager(){return vt}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}async authenticateTransactionFromLocalStorage(A){const t=mt.getShadowGraphqlClient(),e=await t.query({query:Wi,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=lt.getMap("transactionOwnerIds");if(a?.has(A)){const t=a.get(A);return Qt(t),Promise.resolve({success:!0,stakeholderType:ee.Owner})}const o=lt.getMap("transactionCustomerIds");if(o?.has(A)){const t=o.get(A);if(t){if(await this.authenticateCustomerId(t)){const t=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:Xi,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=lt.getMap("transactionCustomerIds");t?.has(A)&&(t.delete(A),lt.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=mt.getShadowGraphqlClient(),e=(await t.query({query:qi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:A}})).data.customer;if(!e.id){const e=(await t.mutate({mutation:Zi,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=mt.getShadowGraphqlClient(),e=lt.getMap("customerTokens");if(!e?.has(A))return!1;const n=e.get(A);if(!n)return!1;const i=(await t.mutate({mutation:$i,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!i&&(ut(n),this.customer=i,!0)}async generateVerificationCode(A){await mt.getShadowGraphqlClient().mutate({mutation:_i,variables:{emailAddress:A}})}async verifyCode(A,t){const e=await mt.getShadowGraphqlClient().mutate({mutation:Aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:A,verificationCode:t}});if(e.data?.customerVerifyCode.loginToken){if(!e.data.customerVerifyCode.partner?.id)throw new Error(`Unable to find customer: ${A}`);const t=lt.getMap("customerTokens")||new Map;return t.set(e.data.customerVerifyCode.id,e.data.customerVerifyCode.loginToken),lt.setMap("customerTokens",t),ut(e.data.customerVerifyCode.loginToken),this.customer={...e.data.customerVerifyCode,loginToken:void 0},!0}return!1}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=mt.getShadowGraphqlClient();if(await A.resetStore(),"transaction"===n.type){const{transactionId:t,readOnly:e}=n,i=await A.query({query:vn,variables:{id:t},errorPolicy:"all"});if(!i.data?.transactions||0===i.data.transactions.length)throw new rt("Existing transaction not found.");const a=i.data?.transactions[0];if(!a.workflowId)throw new rt("Existing transaction has no workflow ID.");const o=await ta(a.workflowId);if(!a.product)throw new rt("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:xn,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 rt("Failed to create transaction!");const i=e.data.transactionCreate;if(!i.product)throw new rt("Failed to create transaction, product not available.");return i},e=ta(n.workflowId),[i,a]=await Promise.all([t(),e]);return{transaction:i,workflow:a}}throw new rt("No workflow ID provided.")})();if(this.currencyCode=a.product.partner?.currencyCode,this.experienceOptions={product:a.product,transaction:a,layouts:[],stateMutationFunc:r?async()=>{throw new at("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=ea(this.experienceOptions.transaction,this.experienceOptions.workflow);if(this.experienceOptions.previewService=e&&e(o),this.experienceOptions.renderableContextService=new Dn(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService),"transaction"!==n.type){const A=lt.getMap("transactionOwnerIds")||new Map;A.set(a.id,a.transactionOwnerId),Qt(a.transactionOwnerId||""),lt.setMap("transactionOwnerIds",A)}this.initialized=!0;const s=new ji(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 rt("No integration product ID provided.");const t=mt.getShadowGraphqlClient();await t.resetStore();const e=await t.mutate({mutation:xn,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 rt("Failed to create transaction!");const n=e.data.transactionCreate;if(!n.product)throw new rt("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const i=lt.getMap("transactionOwnerIds")||new Map;i.set(n.id,n.transactionOwnerId),Qt(n.transactionOwnerId||""),lt.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 rt("No transaction ID provided.");const e=mt.getShadowGraphqlClient();await e.resetStore();if(t)return await(async()=>{const n=(await e.query({query:vn,variables:{id:A},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new rt("Failed to read transaction.");if(!n.product)throw new rt("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 at("State mutation is forbidden in read only mode!")},readOnly:t},this.initialized=!0})();const n=lt.getMap("transactionOwnerIds")||new Map,i=n.get(A);if(i){Qt(i);const n=(await e.query({query:vn,variables:{id:A},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new rt("Failed to read transaction.");if(!n.product)throw new rt("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:Sn,variables:{id:A},errorPolicy:"all"})).data?.transactionClaim;if(!i)throw new rt("Failed to read transaction.");if(!i.product)throw new rt("Failed to load transaction, product not available.");this.currencyCode=i.product.partner?.currencyCode,i.transactionOwnerId&&(n.set(i.id,i.transactionOwnerId),Qt(i.transactionOwnerId),lt.setMap("transactionOwnerIds",n)),this.experienceOptions={product:i.product,transaction:i,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:t},this.initialized=!0}catch{throw new rt("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(A,t,e){if(!this.initialized||!this.experienceOptions)throw new rt("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 ta(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 Dn(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService);const t=new ji(this,this.experienceOptions);return await t.getWorkflowManager().getInitializationPromise(),t}if(A){const i=mt.getShadowGraphqlClient().mutate({mutation:Rn,variables:{workflowId:A,id:this.experienceOptions.transaction.id}}),a=ta(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=ea(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=e&&e(await a),this.experienceOptions.renderableContextService=new Dn(this.experienceOptions.layouts),this.experienceOptions.product?.modelUrl&&this.experienceOptions.previewService?.initialize(this.experienceOptions.product.modelUrl,this.experienceOptions.renderableContextService);const o=new ji(this,this.experienceOptions);return await o.getWorkflowManager().getInitializationPromise(),o}throw new rt("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new rt("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new rt("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}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(){ia(this,"getProduct",void 0),ia(this,"getCommandContext",void 0),ia(this,"getAllLayoutData",void 0),ia(this,"getMetadata",void 0),ia(this,"getWorkflowMetadata",void 0),ia(this,"getStepStorage",void 0),ia(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(){}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 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}let ra;var sa;(sa=ra||(ra={})).SelectFrame="SelectFrame",sa.SelectImage="SelectImage",sa.Position="Position";class ca extends pi{constructor(A,t){super(A,t),oa(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(A){const t=this.manager.getRegionElements(this.step.stepName);return ti.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 ti.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?ra.SelectFrame:t||e||this.getImageData()?ra.Position:ra.SelectImage}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}hasVaryingUpload(){return this.step.data.varyUpload}hasVaryingSelection(){return this.step.data.varySelection}}const ga=A=>{const t=kA(null),e=kA(void 0),[n,i]=NA(void 0),{addEvent:a,removeEvent:o,updateEvent:r,eventCache:s}=Gt(),[c,g]=NA(!1),[B,l]=NA(!1),{state:w,uiDispatcher:d}=Vt(),E=RA((A=>{const t=A;d(new Kt({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&&(l(!1),g(!1))}),[o,s.length]),Q=RA((A=>{a(A);"touch"===A.pointerType&&1===s.length&&(d(new Kt({selectedElement:void 0})),l(!0),g(!0))}),[a,s.length,d]),C=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(B&&(t||a)&&A.isPrimary){const t=(e?.current?.x||A.screenX)-A.screenX,n=(e?.current?.y||A.screenY)-A.screenY;d(new Kt({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,B,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);B&&!e&&t.current.setPointerCapture(A),!B&&e&&t.current.releasePointerCapture(A)}),[t,B,s]),Pe([" "],(()=>{l(!0),d(new Kt({selectedElement:void 0}))}),(()=>l(!1))),Pe(["Control"],(()=>g(!0)),(()=>g(!1)));const D=GA((()=>({cursor:B&&0===s.length?"grab":B&&1===s.length?"grabbing":c?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[B,c,s]);return bA("div",{ref:t,className:"transform-wrapper",onWheel:u,onPointerDown:Q,onPointerUp:h,onPointerCancel:h,onPointerLeave:h,onPointerMove:C,style:D,children:A.children})};export{na as SpiffCommerceClient,A as CommandContext,dt as spiffCoreConfiguration,Je as PromiseQueue,be as QueueablePromise,aa as MockWorkflowManager,Ei as InformationMessageType,pi as StepHandle,Ri as TextStepHandle,ca as FrameStepHandle,Mi as BulkStepHandle,Ni as ShapeStepHandle,Fi as IllustrationStepHandle,Yi as MaterialStepHandle,xi as ModelStepHandle,Si as PictureStepHandle,vi as QuestionStepHandle,qt as BulkPriceCalculationStrategy,Di as Variant,_A as OptionNotFoundError,At as LayoutNotFoundError,tt as AssetNotFoundError,et as ResourceNotFoundError,nt as MisconfigurationError,ot as ParseError,at as UnhandledBehaviorError,vt as assetService,Ti as designService,Ji as createDesign,Ut as optionService,lt as persistenceService,mt as graphQlManager,oe as toast,Vn as FrameService,jn as getBoundedOffsets,ti as frameStepService,ii as modelStepService,ni as materialStepService,si as shapeStepService,ri as questionStepService,_n as digitalContentStepService,ai as moduleStepService,oi as pictureStepService,wi as textStepService,ei as illustrationStepService,Wt as ProductCameraRig,ra as FrameStep,$t as ConversionLocation,Ae as ConversionDataType,ta as getWorkflow,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,B as FontSizeCommand,l as FontSourceCommand,w as GroupCommand,d as LayoutElementFactory,E as LayoutElementType,h as MoveCommand,Q as ResizeCommand,C as RotateCommand,u as SendBackwardsCommand,ee as StakeholderType,D as StepAspectType,m as StepType,p 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,Cn as generateCommands,k as registerJSDOM,Re as minZoom,Yn as AdvancedEditor,ga as TransformWrapper,Fn as EditorCore,kt as useLayouts,Vt as useEditorState,Ue as useEditorInteraction,Pe as useShortcutCombination,Tt as commandReducer,Ot as getDefaultState,Pt as CommandContextContext,jt as AdvancedEditorStateProvider,zt as AdvancedEditorContext,Kt as UICommand,Jt as EditorSubMenu,re as ElementEventType,ce as KeyEvent,Gn as gatherVaryingStepAspects};
1103
1103
  //# sourceMappingURL=module.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/core",
3
- "version": "11.1.0",
3
+ "version": "11.1.1",
4
4
  "description": "Core client API for interacting with the Spiff Commerce backend.",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/main.js",