@spiffcommerce/core 14.13.0-alpha.0 → 14.13.0
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 +1 -1
- package/dist/module.js +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1485,5 +1485,5 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
|
|
|
1485
1485
|
}
|
|
1486
1486
|
}
|
|
1487
1487
|
}
|
|
1488
|
-
`),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:e}});var A;const a=n.data.workflows;if(void 0===a||a.length!==e.length)throw new Error(`Unable to read workflows: ${n.errors??"Length mismatch in response"}`);return a.forEach((t=>{t.steps.forEach((t=>{delete t.data.__typename,t.option?.id&&(t.option.defaultVariant?.asset&&ka.cacheAsset(t.option.defaultVariant.asset),t.option.colorProfile&&ka.cacheAsset(t.option.colorProfile),t.option.variants?.forEach((t=>{t.asset&&ka.cacheAsset(t.asset),t.displayImage&&ka.cacheAsset(t.displayImage),t.thumbnail&&ka.cacheAsset(t.thumbnail),t.material&&ka.cacheMaterial(t.material)})),Ha.set({id:t.option.id},Promise.resolve(t.option)))}))})),a})(A,i),r=A.map((t=>Ha.set({id:t,options:i},(async(t,e)=>{const i=(await e).find((e=>e.id===t));if(!i)throw new Error(`Workflow not found: ${t}`);return i})(t,a)))),s=n.filter((t=>void 0!==t));return await Promise.all(s.concat(r))},$c=async(t,e)=>(await Zc([t],e))[0],_c=(t,e)=>{const i=t.workflowState,n=i?JSON.parse(i):void 0;return n?Object.values(n.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 tl{constructor(t){var e;Gc(this,"options",void 0),Gc(this,"initialized",void 0),Gc(this,"currencyCode",void 0),Gc(this,"customer",void 0),Gc(this,"experienceOptions",void 0),Gc(this,"updateTransactionState",(async t=>{try{return Ia.getShadowGraphqlClient().mutate({...t,mutation:Gs})}catch(t){throw console.error(t),new oa("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,ya=e)}getAssetManager(){return ka}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!this.options.applicationKey)throw new Error("Application key required to use Flow Service.");return new Yc}async authenticateBundleFromLocalStorage(t){const e=da.getMap("bundleOwnerIds");if(e?.has(t)){const i=e.get(t);return fa(i),Promise.resolve({success:!0,stakeholderType:cr.Owner})}const i=da.getMap("bundleCustomerIds");if(i?.has(t)){const e=i.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=Ia.getShadowGraphqlClient(),i=await e.query({query:zc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!i.data.transactions||0===i.data.transactions.length)throw new Error(`Transaction not found: ${t}`);const n=i.data.transactions[0],A=n.product?.partner?.id;if(!A)throw new Error(`Unable to read transaction: ${t}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const a=da.getMap("transactionOwnerIds");if(a?.has(t)){const e=a.get(t);return ma(e),Promise.resolve({success:!0,stakeholderType:cr.Owner})}const r=da.getMap("transactionCustomerIds");if(r?.has(t)){const e=r.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:jc,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!s)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:s.overrideTheme,customLogoLink:n.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=da.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),da.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=Ia.getShadowGraphqlClient(),i=(await e.query({query:Vc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!i.id){const i=(await e.mutate({mutation:Kc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!i)throw new Error("Unable to create customer.");return this.customer=i,{customer:i,isAuthenticated:!1}}const n=await this.authenticateCustomerId(i.id);return{customer:this.customer||i,isAuthenticated:n}}async authenticateCustomerId(t){const e=Ia.getShadowGraphqlClient(),i=da.getMap("customerTokens");if(!i?.has(t))return!1;const n=i.get(t);if(!n)return!1;const A=(await e.mutate({mutation:Wc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!A&&(Qa(n),this.customer=A,!0)}async generateVerificationCode(t){await Ia.getShadowGraphqlClient().mutate({mutation:Xc,variables:{emailAddress:t}})}async verifyCode(t,e){const i=(await Ia.getShadowGraphqlClient().mutate({mutation:qc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data?.customerVerifyCode;if(i?.loginToken){if(!i.partner?.id)throw new Error(`Unable to find customer: ${t}`);const e=da.getMap("customerTokens")||new Map;return e.set(i.id,i.loginToken),da.setMap("customerTokens",e),Qa(i.loginToken),this.customer={...i,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Ia.getShadowGraphqlClient().mutate({mutation:rc,variables:{collectionId:t},fetchPolicy:"no-cache"})).data?.bundleCreate;if(!e)throw new Error("Unable to create bundle");fa(e.bundleOwnerId);const i=da.getMap("bundleOwnerIds")||new Map;return i.set(e.id,e.bundleOwnerId),da.setMap("bundleOwnerIds",i),new bc(this,e)}async getExistingBundle(t,e){const i=da.getMap("bundleOwnerIds")?.get(t);i&&fa(i);const n=await Ia.getShadowGraphqlClient().query({query:nc,variables:{id:t},fetchPolicy:"no-cache"});if(!n.data?.bundles||0===n.data?.bundles.length||!n.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const A=n.data?.bundles[0],a=new bc(this,A,e);return await a.getInitializationPromise(),a}async getBundleStakeholders(){if(!this.customer)throw new Error("Customer not authenticated.");const t=await Ia.getShadowGraphqlClient().query({query:ac,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!t.data?.customers||0===t.data.customers.length)throw new Error("Unable to find customer.");return t.data.customers[0].bundleStakeholders||[]}async getWorkflowExperience(t,e,i,n){if(!n)return await this.getWorkflowExperienceDeprecated(t,e,i);const A=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}},{transaction:a,workflow:r,readOnly:s}=await(async()=>{const t=Ia.getShadowGraphqlClient();if("transaction"===n.type){const{transactionId:e,readOnly:i}=n,A=await t.query({query:Us,variables:{ids:[e]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!A.data?.transactions||0===A.data.transactions.length)throw new oa("Existing transaction not found.");const a=A.data?.transactions[0];if(!a.workflowId)throw new oa("Existing transaction has no workflow ID.");const r=await Zc([a.workflowId]);if(!a.product)throw new oa("Failed to load transaction, product not available.");return{transaction:a,workflow:r[0],readOnly:i}}if("integration"===n.type||"external"===n.type){const e=async()=>{const e="integration"===n.type?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},i=await t.mutate({mutation:ks,variables:{...e,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(!i.data||!i.data.transactionCreate)throw new oa("Failed to create transaction!");const A=i.data.transactionCreate;if(!A.product)throw new oa("Failed to create transaction, product not available.");return A},i=Zc([n.workflowId],n?.graphql),[A,[a]]=await Promise.all([e(),i]);return{transaction:A,workflow:a}}throw new oa("No workflow ID provided.")})();this.currencyCode=a.product.partner?.currencyCode;const o={product:a.product,transaction:a,layouts:[],stateMutationFunc:s?async()=>{throw new ra("State mutation is forbidden in read only mode!")}:async t=>{const e=(da.getMap("transactionOwnerIds")||new Map).get(a.id)||void 0;return this.updateTransactionState({...t,context:{transactionOwnerId:e}})},readOnly:s,workflow:r};if("transaction"===n.type&&a.workflowState){const t=JSON.parse(a.workflowState);o.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),o.reloadedState=t}else if(!s&&n.workflowState){const t=JSON.parse(n.workflowState);o.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),o.reloadedState=t}else o.layouts=_c(o.transaction,o.workflow);if(o.renderableContextService=new xs(o.layouts),n.previewService?(o.previewService=n.previewService,o.product?.modelUrl&&(o.modelContainer=o.previewService.loadModel({model:o.product.modelUrl,contextService:o.renderableContextService}))):(o.previewService=i&&i(r),o.product?.modelUrl&&(o.previewService?.initialize({model:o.product.modelUrl,contextService:o.renderableContextService}),o.modelContainer=o.previewService?.getAllModels()[0])),"transaction"!==n.type){const t=da.getMap("transactionOwnerIds")||new Map;t.set(a.id,a.transactionOwnerId),ma(a.transactionOwnerId||""),da.setMap("transactionOwnerIds",t)}else{const t=(da.getMap("transactionOwnerIds")||new Map).get(a.id);t&&ma(t),o.isReloadedTransaction=!0}this.initialized=!0,this.experienceOptions=o;const c=new tc(this,o);return await c.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await c.attachCustomerDetails({email:this.customer.emailAddress}),c}async getWorkflowExperiences(t){if(0===t.length)throw new oa("No options provided!");const e=Ia.getShadowGraphqlClient(),i=t.map(((t,e)=>({option:t,index:e}))),n=i.filter((t=>"transaction"===t.option.type)),A=i.filter((t=>"integration"===t.option.type||"external"===t.option.type)),a=(await Promise.all([(async()=>{if(0===n.length)return[];const t=n.map((t=>t.option.transactionId)),i=await e.query({query:Us,variables:{ids:t},errorPolicy:"all",fetchPolicy:"no-cache"}),A=i.data.transactions;if(A.length!==n.length){const t=i.errors?.[0]?.message||"Unknown error";throw new oa(`Not all transactions were found: ${t}`)}return A.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:n.find((e=>e.option.transactionId===t.id))?.option.readOnly??!1,index:n[e].index})))})(),(async()=>{if(0===A.length)return[];const t=await e.mutate({mutation:Rs,variables:{inputs:A.map((t=>({integrationProductId:"integration"===t.option.type?t.option.integrationProductId:void 0,externalIntegrationId:"external"===t.option.type?t.option.externalIntegrationId:void 0,externalProductId:"external"===t.option.type?t.option.externalProductId:void 0,workflowId:t.option.workflowId,bulk:t.option.bulk,claim:!0})))},errorPolicy:"all",fetchPolicy:"no-cache"}),i=t.data?.transactionCreateMany;if(!i||0===i.length){const e=t.errors?.[0]?.message||"Unknown error";throw new oa(`Failed to create transactions: ${e}`)}return i.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:!1,index:A[e].index})))})()])).flat(),r=[...new Set(a.map((t=>t.workflowId)))],s=await Zc(r),o=new Map(s.map((t=>[t.id,t]))),c=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}},l=da.getMap("transactionOwnerIds")||new Map,g=a.map((async e=>{const{transaction:i,workflowId:n,readOnly:A,index:a}=e,r=o.get(n),s=t[a];!l.get(i.id)&&i.transactionOwnerId&&l.set(i.id,i.transactionOwnerId);const g=l.get(i.id)||void 0,h={product:i.product,transaction:i,layouts:[],stateMutationFunc:A?async()=>{throw new ra("State mutation is forbidden in read only mode!")}:async t=>this.updateTransactionState({...t,context:{transactionOwnerId:g}}),readOnly:A,workflow:r,isReloadedTransaction:"transaction"===s.type};if("transaction"===s.type&&i.workflowState){const t=JSON.parse(i.workflowState);h.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await c(t),h.reloadedState=t}else if(!A&&s.workflowState){const t=JSON.parse(s.workflowState);h.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await c(t),h.reloadedState=t}else h.layouts=_c(h.transaction,h.workflow);return h.renderableContextService=new xs(h.layouts),this.initialized=!0,this.experienceOptions=h,{experienceOptions:h,index:a,options:s}}));da.setMap("transactionOwnerIds",l);const h=(await Promise.all(g)).sort(((t,e)=>t.index-e.index)).map((async t=>{const{experienceOptions:e,options:i}=t,n=new tc(this,e);return await n.getWorkflowManager().getInitializationPromise(),"transaction"!==i.type&&this.customer&&await n.attachCustomerDetails({email:this.customer.emailAddress}),n}));return await Promise.all(h)}async initFromIntegrationProduct(t){if(""===t)throw new oa("No integration product ID provided.");const e=Ia.getShadowGraphqlClient(),i=await e.mutate({mutation:ks,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(!i.data||!i.data.transactionCreate)throw new oa("Failed to create transaction!");const n=i.data.transactionCreate;if(!n.product)throw new oa("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const A=da.getMap("transactionOwnerIds")||new Map;A.set(n.id,n.transactionOwnerId),ma(n.transactionOwnerId||""),da.setMap("transactionOwnerIds",A),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,e=!1){if(""===t)throw new oa("No transaction ID provided.");const i=Ia.getShadowGraphqlClient();if(e)return await(async()=>{const n=(await i.query({query:Us,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!n)throw new oa("Failed to read transaction.");if(!n.product)throw new oa("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async()=>{throw new ra("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const n=da.getMap("transactionOwnerIds")||new Map,A=n.get(t);if(A){ma(A);const n=(await i.query({query:Us,variables:{ids:[t]},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new oa("Failed to read transaction.");if(!n.product)throw new oa("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:e},void(this.initialized=!0)}try{const A=(await i.mutate({mutation:Hs,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!A)throw new oa("Failed to read transaction.");if(!A.product)throw new oa("Failed to load transaction, product not available.");this.currencyCode=A.product.partner?.currencyCode,A.transactionOwnerId&&(n.set(A.id,A.transactionOwnerId),ma(A.transactionOwnerId),da.setMap("transactionOwnerIds",n)),this.experienceOptions={product:A.product,transaction:A,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new oa("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,i){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot launch experience: Not initialized.");const n=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=(await Zc([this.experienceOptions.transaction.workflowId]))[0];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 Zn(t),await n(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=i&&i(t),this.experienceOptions.renderableContextService=new xs(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 tc(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const A=Ia.getShadowGraphqlClient().mutate({mutation:Ts,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),a=Zc([t]);if(await Promise.all([A,a]),this.experienceOptions.workflow=(await a)[0],e){const t=JSON.parse(e);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=_c(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=i&&i((await a)[0]),this.experienceOptions.renderableContextService=new xs(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 r=new tc(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}throw new oa("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function el(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class il{constructor(){el(this,"getProduct",void 0),el(this,"getCommandContext",void 0),el(this,"getAllLayoutData",void 0),el(this,"getMetadata",void 0),el(this,"getWorkflowMetadata",void 0),el(this,"getStepStorage",void 0),el(this,"setModelContainer",void 0),el(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,i){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}}function nl(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}let Al;var al;(al=Al||(Al={})).SelectFrame="SelectFrame",al.SelectImage="SelectImage",al.Position="Position";class rl extends Fo{constructor(t,e){super(t,e),nl(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return oo.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 oo.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,e,i,n){return n&&n.length>1&&void 0===t?Al.SelectFrame:e||i||this.getImageData()?Al.Position:Al.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 sl=t=>{const e=(0,n.useRef)(null),A=(0,n.useRef)(void 0),[a,r]=(0,n.useState)(void 0),{addEvent:s,removeEvent:o,updateEvent:c,eventCache:l}=za(),[g,h]=(0,n.useState)(!1),[d,u]=(0,n.useState)(!1),{state:w,uiDispatcher:B}=tr(),p=(0,n.useCallback)((t=>{const e=t;B(new _a({zoom:Math.max(.1,Math.min(e,w.maxZoom))}))}),[B,w.maxZoom]),m=(0,n.useCallback)((t=>{o(t),1===l.length&&(A.current=void 0),2===l.length&&r(void 0);"touch"===t.pointerType&&l.length>1&&l.length-1==1&&(u(!1),h(!1))}),[o,l.length]),E=(0,n.useCallback)((t=>{s(t);"touch"===t.pointerType&&1===l.length&&(B(new _a({selectedElement:void 0})),u(!0),h(!0))}),[s,l.length,B]),f=(0,n.useCallback)((t=>{c(t);const e=1===l.length&&"touch"!==l[0].pointerType,i=2===l.length&&"touch"===l[0].pointerType;if(g&&i){const[t,e]=l,i=Math.abs(t.clientX-e.clientX),n=a;n&&p(w.zoom-.0055*(n-i)),r(i)}if(d&&(e||i)&&t.isPrimary){const e=(A?.current?.x||t.screenX)-t.screenX,i=(A?.current?.y||t.screenY)-t.screenY;B(new _a({selectedElement:void 0,xTranslation:w.xTranslation-e/w.zoom,yTranslation:w.yTranslation-i/w.zoom}))}t.isPrimary&&(A.current={x:t.screenX,y:t.screenY})}),[c,l,g,d,a,p,w.zoom,w.xTranslation,w.yTranslation,B]),C=(0,n.useCallback)((t=>{g&&p(w.zoom-.035*Math.sign(t.deltaY))}),[p,w.zoom,g]);(0,n.useEffect)((()=>{if(!e.current||0===l.length)return;const t=l[0].pointerId,i=e.current.hasPointerCapture(t);d&&!i&&e.current.setPointerCapture(t),!d&&i&&e.current.releasePointerCapture(t)}),[e,d,l]),Lr([" "],(()=>{u(!0),B(new _a({selectedElement:void 0}))}),(()=>u(!1))),Lr(["Control"],(()=>h(!0)),(()=>h(!1)));const Q=(0,n.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,i.jsx)("div",{ref:e,className:"transform-wrapper",onWheel:C,onPointerDown:E,onPointerUp:m,onPointerCancel:m,onPointerLeave:m,onPointerMove:f,style:Q,children:t.children})};
|
|
1488
|
+
`),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:e}});var A;const a=n.data.workflows;if(void 0===a||a.length!==e.length)throw new Error(`Unable to read workflows: ${n.errors??"Length mismatch in response"}`);return a.forEach((t=>{t.steps.forEach((t=>{delete t.data.__typename,t.option?.id&&(t.option.defaultVariant?.asset&&ka.cacheAsset(t.option.defaultVariant.asset),t.option.colorProfile&&ka.cacheAsset(t.option.colorProfile),t.option.variants?.forEach((t=>{t.asset&&ka.cacheAsset(t.asset),t.displayImage&&ka.cacheAsset(t.displayImage),t.thumbnail&&ka.cacheAsset(t.thumbnail),t.material&&ka.cacheMaterial(t.material)})),Ha.set({id:t.option.id},Promise.resolve(t.option)))}))})),a})(A,i),r=A.map((t=>Ha.set({id:t,options:i},(async(t,e)=>{const i=(await e).find((e=>e.id===t));if(!i)throw new Error(`Workflow not found: ${t}`);return i})(t,a)))),s=n.filter((t=>void 0!==t));return await Promise.all(s.concat(r))},$c=async(t,e)=>(await Zc([t],e))[0],_c=(t,e)=>{const i=t.workflowState,n=i?JSON.parse(i):void 0;return n?Object.values(n.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 tl{constructor(t){var e;Gc(this,"options",void 0),Gc(this,"initialized",void 0),Gc(this,"currencyCode",void 0),Gc(this,"customer",void 0),Gc(this,"experienceOptions",void 0),Gc(this,"updateTransactionState",(async t=>{try{return Ia.getShadowGraphqlClient().mutate({...t,mutation:Gs})}catch(t){throw console.error(t),new oa("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,ya=e)}getAssetManager(){return ka}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!this.options.applicationKey)throw new Error("Application key required to use Flow Service.");return new Yc}async authenticateBundleFromLocalStorage(t){const e=da.getMap("bundleOwnerIds");if(e?.has(t)){const i=e.get(t);return fa(i),Promise.resolve({success:!0,stakeholderType:cr.Owner})}const i=da.getMap("bundleCustomerIds");if(i?.has(t)){const e=i.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=Ia.getShadowGraphqlClient(),i=await e.query({query:zc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!i.data.transactions||0===i.data.transactions.length)throw new Error(`Transaction not found: ${t}`);const n=i.data.transactions[0],A=n.product?.partner?.id;if(!A)throw new Error(`Unable to read transaction: ${t}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const a=da.getMap("transactionOwnerIds");if(a?.has(t)){const e=a.get(t);return ma(e),Promise.resolve({success:!0,stakeholderType:cr.Owner})}const r=da.getMap("transactionCustomerIds");if(r?.has(t)){const e=r.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:jc,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!s)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:s.overrideTheme,customLogoLink:n.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=da.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),da.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=Ia.getShadowGraphqlClient(),i=(await e.query({query:Vc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!i.id){const i=(await e.mutate({mutation:Kc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!i)throw new Error("Unable to create customer.");return this.customer=i,{customer:i,isAuthenticated:!1}}const n=await this.authenticateCustomerId(i.id);return{customer:this.customer||i,isAuthenticated:n}}async authenticateCustomerId(t){const e=Ia.getShadowGraphqlClient(),i=da.getMap("customerTokens");if(!i?.has(t))return!1;const n=i.get(t);if(!n)return!1;const A=(await e.mutate({mutation:Wc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!A&&(Qa(n),this.customer=A,!0)}async generateVerificationCode(t){await Ia.getShadowGraphqlClient().mutate({mutation:Xc,variables:{emailAddress:t}})}async verifyCode(t,e){const i=(await Ia.getShadowGraphqlClient().mutate({mutation:qc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data?.customerVerifyCode;if(i?.loginToken){if(!i.partner?.id)throw new Error(`Unable to find customer: ${t}`);const e=da.getMap("customerTokens")||new Map;return e.set(i.id,i.loginToken),da.setMap("customerTokens",e),Qa(i.loginToken),this.customer={...i,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Ia.getShadowGraphqlClient().mutate({mutation:rc,variables:{collectionId:t},fetchPolicy:"no-cache"})).data?.bundleCreate;if(!e)throw new Error("Unable to create bundle");fa(e.bundleOwnerId);const i=da.getMap("bundleOwnerIds")||new Map;return i.set(e.id,e.bundleOwnerId),da.setMap("bundleOwnerIds",i),new bc(this,e)}async getExistingBundle(t,e){const i=da.getMap("bundleOwnerIds")?.get(t);i&&fa(i);const n=await Ia.getShadowGraphqlClient().query({query:nc,variables:{id:t},fetchPolicy:"no-cache"});if(!n.data?.bundles||0===n.data?.bundles.length||!n.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const A=n.data?.bundles[0],a=new bc(this,A,e);return await a.getInitializationPromise(),a}async getBundleStakeholders(){if(!this.customer)throw new Error("Customer not authenticated.");const t=await Ia.getShadowGraphqlClient().query({query:ac,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!t.data?.customers||0===t.data.customers.length)throw new Error("Unable to find customer.");return t.data.customers[0].bundleStakeholders||[]}async getWorkflowExperience(t,e,i,n){if(!n)return await this.getWorkflowExperienceDeprecated(t,e,i);const A=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}},{transaction:a,workflow:r,readOnly:s}=await(async()=>{const t=Ia.getShadowGraphqlClient();if("transaction"===n.type){const{transactionId:e,readOnly:i}=n,A=await t.query({query:Us,variables:{ids:[e]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!A.data?.transactions||0===A.data.transactions.length)throw new oa("Existing transaction not found.");const a=A.data?.transactions[0];if(!a.workflowId)throw new oa("Existing transaction has no workflow ID.");const r=await $c(a.workflowId);if(!a.product)throw new oa("Failed to load transaction, product not available.");return{transaction:a,workflow:r,readOnly:i}}if("integration"===n.type||"external"===n.type){const e=async()=>{const e="integration"===n.type?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},i=await t.mutate({mutation:ks,variables:{...e,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(!i.data||!i.data.transactionCreate)throw new oa("Failed to create transaction!");const A=i.data.transactionCreate;if(!A.product)throw new oa("Failed to create transaction, product not available.");return A},i=$c(n.workflowId,n?.graphql),[A,a]=await Promise.all([e(),i]);return{transaction:A,workflow:a}}throw new oa("No workflow ID provided.")})();this.currencyCode=a.product.partner?.currencyCode;const o={product:a.product,transaction:a,layouts:[],stateMutationFunc:s?async()=>{throw new ra("State mutation is forbidden in read only mode!")}:async t=>{const e=(da.getMap("transactionOwnerIds")||new Map).get(a.id)||void 0;return this.updateTransactionState({...t,context:{transactionOwnerId:e}})},readOnly:s,workflow:r};if("transaction"===n.type&&a.workflowState){const t=JSON.parse(a.workflowState);o.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),o.reloadedState=t}else if(!s&&n.workflowState){const t=JSON.parse(n.workflowState);o.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),o.reloadedState=t}else o.layouts=_c(o.transaction,o.workflow);if(o.renderableContextService=new xs(o.layouts),n.previewService?(o.previewService=n.previewService,o.product?.modelUrl&&(o.modelContainer=o.previewService.loadModel({model:o.product.modelUrl,contextService:o.renderableContextService}))):(o.previewService=i&&i(r),o.product?.modelUrl&&(o.previewService?.initialize({model:o.product.modelUrl,contextService:o.renderableContextService}),o.modelContainer=o.previewService?.getAllModels()[0])),"transaction"!==n.type){const t=da.getMap("transactionOwnerIds")||new Map;t.set(a.id,a.transactionOwnerId),ma(a.transactionOwnerId||""),da.setMap("transactionOwnerIds",t)}else{const t=(da.getMap("transactionOwnerIds")||new Map).get(a.id);t&&ma(t),o.isReloadedTransaction=!0}this.initialized=!0,this.experienceOptions=o;const c=new tc(this,o);return await c.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await c.attachCustomerDetails({email:this.customer.emailAddress}),c}async getWorkflowExperiences(t){if(0===t.length)throw new oa("No options provided!");const e=Ia.getShadowGraphqlClient(),i=t.map(((t,e)=>({option:t,index:e}))),n=i.filter((t=>"transaction"===t.option.type)),A=i.filter((t=>"integration"===t.option.type||"external"===t.option.type)),a=(await Promise.all([(async()=>{if(0===n.length)return[];const t=n.map((t=>t.option.transactionId)),i=await e.query({query:Us,variables:{ids:t},errorPolicy:"all",fetchPolicy:"no-cache"}),A=i.data.transactions;if(A.length!==n.length){const t=i.errors?.[0]?.message||"Unknown error";throw new oa(`Not all transactions were found: ${t}`)}return A.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:n.find((e=>e.option.transactionId===t.id))?.option.readOnly??!1,index:n[e].index})))})(),(async()=>{if(0===A.length)return[];const t=await e.mutate({mutation:Rs,variables:{inputs:A.map((t=>({integrationProductId:"integration"===t.option.type?t.option.integrationProductId:void 0,externalIntegrationId:"external"===t.option.type?t.option.externalIntegrationId:void 0,externalProductId:"external"===t.option.type?t.option.externalProductId:void 0,workflowId:t.option.workflowId,bulk:t.option.bulk,claim:!0})))},errorPolicy:"all",fetchPolicy:"no-cache"}),i=t.data?.transactionCreateMany;if(!i||0===i.length){const e=t.errors?.[0]?.message||"Unknown error";throw new oa(`Failed to create transactions: ${e}`)}return i.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:!1,index:A[e].index})))})()])).flat(),r=[...new Set(a.map((t=>t.workflowId)))],s=await Zc(r),o=new Map(s.map((t=>[t.id,t]))),c=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}},l=da.getMap("transactionOwnerIds")||new Map,g=a.map((async e=>{const{transaction:i,workflowId:n,readOnly:A,index:a}=e,r=o.get(n),s=t[a];!l.get(i.id)&&i.transactionOwnerId&&l.set(i.id,i.transactionOwnerId);const g=l.get(i.id)||void 0,h={product:i.product,transaction:i,layouts:[],stateMutationFunc:A?async()=>{throw new ra("State mutation is forbidden in read only mode!")}:async t=>this.updateTransactionState({...t,context:{transactionOwnerId:g}}),readOnly:A,workflow:r,isReloadedTransaction:"transaction"===s.type};if("transaction"===s.type&&i.workflowState){const t=JSON.parse(i.workflowState);h.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await c(t),h.reloadedState=t}else if(!A&&s.workflowState){const t=JSON.parse(s.workflowState);h.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await c(t),h.reloadedState=t}else h.layouts=_c(h.transaction,h.workflow);return h.renderableContextService=new xs(h.layouts),this.initialized=!0,this.experienceOptions=h,{experienceOptions:h,index:a,options:s}}));da.setMap("transactionOwnerIds",l);const h=(await Promise.all(g)).sort(((t,e)=>t.index-e.index)).map((async t=>{const{experienceOptions:e,options:i}=t,n=new tc(this,e);return await n.getWorkflowManager().getInitializationPromise(),"transaction"!==i.type&&this.customer&&await n.attachCustomerDetails({email:this.customer.emailAddress}),n}));return await Promise.all(h)}async initFromIntegrationProduct(t){if(""===t)throw new oa("No integration product ID provided.");const e=Ia.getShadowGraphqlClient(),i=await e.mutate({mutation:ks,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(!i.data||!i.data.transactionCreate)throw new oa("Failed to create transaction!");const n=i.data.transactionCreate;if(!n.product)throw new oa("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const A=da.getMap("transactionOwnerIds")||new Map;A.set(n.id,n.transactionOwnerId),ma(n.transactionOwnerId||""),da.setMap("transactionOwnerIds",A),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,e=!1){if(""===t)throw new oa("No transaction ID provided.");const i=Ia.getShadowGraphqlClient();if(e)return await(async()=>{const n=(await i.query({query:Us,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!n)throw new oa("Failed to read transaction.");if(!n.product)throw new oa("Failed to load transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode,this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async()=>{throw new ra("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const n=da.getMap("transactionOwnerIds")||new Map,A=n.get(t);if(A){ma(A);const n=(await i.query({query:Us,variables:{ids:[t]},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new oa("Failed to read transaction.");if(!n.product)throw new oa("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:e},void(this.initialized=!0)}try{const A=(await i.mutate({mutation:Hs,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!A)throw new oa("Failed to read transaction.");if(!A.product)throw new oa("Failed to load transaction, product not available.");this.currencyCode=A.product.partner?.currencyCode,A.transactionOwnerId&&(n.set(A.id,A.transactionOwnerId),ma(A.transactionOwnerId),da.setMap("transactionOwnerIds",n)),this.experienceOptions={product:A.product,transaction:A,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new oa("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,i){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot launch experience: Not initialized.");const n=async t=>{for(const e in t.layouts){const i=t.layouts[e].elements.filter((t=>t.type===ze.Illustration));for(let t=0;t<i.length;++t){const e=i[t];e.src&&e.svg&&(e.cachedObjectURL=await WA(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===ze.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&on(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await $c(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 Zn(t),await n(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=i&&i(t),this.experienceOptions.renderableContextService=new xs(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 tc(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const A=Ia.getShadowGraphqlClient().mutate({mutation:Ts,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),a=$c(t);if(await Promise.all([A,a]),this.experienceOptions.workflow=await a,e){const t=JSON.parse(e);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=_c(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=i&&i(await a),this.experienceOptions.renderableContextService=new xs(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 r=new tc(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}throw new oa("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new oa("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function el(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class il{constructor(){el(this,"getProduct",void 0),el(this,"getCommandContext",void 0),el(this,"getAllLayoutData",void 0),el(this,"getMetadata",void 0),el(this,"getWorkflowMetadata",void 0),el(this,"getStepStorage",void 0),el(this,"setModelContainer",void 0),el(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,i){}setVariationRecords(t){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}}function nl(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;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:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}let Al;var al;(al=Al||(Al={})).SelectFrame="SelectFrame",al.SelectImage="SelectImage",al.Position="Position";class rl extends Fo{constructor(t,e){super(t,e),nl(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return oo.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 oo.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,e,i,n){return n&&n.length>1&&void 0===t?Al.SelectFrame:e||i||this.getImageData()?Al.Position:Al.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 sl=t=>{const e=(0,n.useRef)(null),A=(0,n.useRef)(void 0),[a,r]=(0,n.useState)(void 0),{addEvent:s,removeEvent:o,updateEvent:c,eventCache:l}=za(),[g,h]=(0,n.useState)(!1),[d,u]=(0,n.useState)(!1),{state:w,uiDispatcher:B}=tr(),p=(0,n.useCallback)((t=>{const e=t;B(new _a({zoom:Math.max(.1,Math.min(e,w.maxZoom))}))}),[B,w.maxZoom]),m=(0,n.useCallback)((t=>{o(t),1===l.length&&(A.current=void 0),2===l.length&&r(void 0);"touch"===t.pointerType&&l.length>1&&l.length-1==1&&(u(!1),h(!1))}),[o,l.length]),E=(0,n.useCallback)((t=>{s(t);"touch"===t.pointerType&&1===l.length&&(B(new _a({selectedElement:void 0})),u(!0),h(!0))}),[s,l.length,B]),f=(0,n.useCallback)((t=>{c(t);const e=1===l.length&&"touch"!==l[0].pointerType,i=2===l.length&&"touch"===l[0].pointerType;if(g&&i){const[t,e]=l,i=Math.abs(t.clientX-e.clientX),n=a;n&&p(w.zoom-.0055*(n-i)),r(i)}if(d&&(e||i)&&t.isPrimary){const e=(A?.current?.x||t.screenX)-t.screenX,i=(A?.current?.y||t.screenY)-t.screenY;B(new _a({selectedElement:void 0,xTranslation:w.xTranslation-e/w.zoom,yTranslation:w.yTranslation-i/w.zoom}))}t.isPrimary&&(A.current={x:t.screenX,y:t.screenY})}),[c,l,g,d,a,p,w.zoom,w.xTranslation,w.yTranslation,B]),C=(0,n.useCallback)((t=>{g&&p(w.zoom-.035*Math.sign(t.deltaY))}),[p,w.zoom,g]);(0,n.useEffect)((()=>{if(!e.current||0===l.length)return;const t=l[0].pointerId,i=e.current.hasPointerCapture(t);d&&!i&&e.current.setPointerCapture(t),!d&&i&&e.current.releasePointerCapture(t)}),[e,d,l]),Lr([" "],(()=>{u(!0),B(new _a({selectedElement:void 0}))}),(()=>u(!1))),Lr(["Control"],(()=>h(!0)),(()=>h(!1)));const Q=(0,n.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,i.jsx)("div",{ref:e,className:"transform-wrapper",onWheel:C,onPointerDown:E,onPointerUp:m,onPointerCancel:m,onPointerLeave:m,onPointerMove:f,style:Q,children:t.children})};
|
|
1489
1489
|
//# sourceMappingURL=main.js.map
|
package/dist/module.js
CHANGED
|
@@ -1485,5 +1485,5 @@ import{CommandContext as t,AssetType as e,BringForwardCommand as A,BringToFrontC
|
|
|
1485
1485
|
}
|
|
1486
1486
|
}
|
|
1487
1487
|
}
|
|
1488
|
-
`),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:t}});var n;const a=A.data.workflows;if(void 0===a||a.length!==t.length)throw new Error(`Unable to read workflows: ${A.errors??"Length mismatch in response"}`);return a.forEach((t=>{t.steps.forEach((t=>{delete t.data.__typename,t.option?.id&&(t.option.defaultVariant?.asset&&be.cacheAsset(t.option.defaultVariant.asset),t.option.colorProfile&&be.cacheAsset(t.option.colorProfile),t.option.variants?.forEach((t=>{t.asset&&be.cacheAsset(t.asset),t.displayImage&&be.cacheAsset(t.displayImage),t.thumbnail&&be.cacheAsset(t.thumbnail),t.material&&be.cacheMaterial(t.material)})),ke.set({id:t.option.id},Promise.resolve(t.option)))}))})),a})(n,e),i=n.map((t=>ke.set({id:t,options:e},(async(t,e)=>{const A=(await e).find((e=>e.id===t));if(!A)throw new Error(`Workflow not found: ${t}`);return A})(t,a)))),o=A.filter((t=>void 0!==t));return await Promise.all(o.concat(i))},$i=async(t,e)=>(await Zi([t],e))[0],_i=(t,e)=>{const A=t.workflowState,n=A?JSON.parse(A):void 0;return n?Object.values(n.layouts).map((t=>t.layout)):e.panels.sort(((t,e)=>t.index-e.index)).map((t=>({id:F(),panelId:t.name,name:t.name,index:t.index,createdAt:new Date,updatedAt:new Date,transparentBackground:t.transparentBackground,height:t.height,width:t.width,previewRegion:t.previewRegion,useEditableArea:t.useEditableArea,editableArea:t.editableArea})))};class to{constructor(t){var e;Gi(this,"options",void 0),Gi(this,"initialized",void 0),Gi(this,"currencyCode",void 0),Gi(this,"customer",void 0),Gi(this,"experienceOptions",void 0),Gi(this,"updateTransactionState",(async t=>{try{return ye.getShadowGraphqlClient().mutate({...t,mutation:Tn})}catch(t){throw console.error(t),new ce("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,Ie=e)}getAssetManager(){return be}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!this.options.applicationKey)throw new Error("Application key required to use Flow Service.");return new Ni}async authenticateBundleFromLocalStorage(t){const e=de.getMap("bundleOwnerIds");if(e?.has(t)){const A=e.get(t);return me(A),Promise.resolve({success:!0,stakeholderType:gA.Owner})}const A=de.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=ye.getShadowGraphqlClient(),A=await e.query({query:zi,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 n=A.data.transactions[0],a=n.product?.partner?.id;if(!a)throw new Error(`Unable to read transaction: ${t}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const i=de.getMap("transactionOwnerIds");if(i?.has(t)){const e=i.get(t);return Qe(e),Promise.resolve({success:!0,stakeholderType:gA.Owner})}const o=de.getMap("transactionCustomerIds");if(o?.has(t)){const e=o.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 r=(await e.query({query:ji,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!r)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:r.overrideTheme,customLogoLink:n.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=de.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),de.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=ye.getShadowGraphqlClient(),A=(await e.query({query:Ki,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!A.id){const A=(await e.mutate({mutation:Vi,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 n=await this.authenticateCustomerId(A.id);return{customer:this.customer||A,isAuthenticated:n}}async authenticateCustomerId(t){const e=ye.getShadowGraphqlClient(),A=de.getMap("customerTokens");if(!A?.has(t))return!1;const n=A.get(t);if(!n)return!1;const a=(await e.mutate({mutation:Wi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!a&&(De(n),this.customer=a,!0)}async generateVerificationCode(t){await ye.getShadowGraphqlClient().mutate({mutation:Xi,variables:{emailAddress:t}})}async verifyCode(t,e){const A=(await ye.getShadowGraphqlClient().mutate({mutation:qi,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=de.getMap("customerTokens")||new Map;return e.set(A.id,A.loginToken),de.setMap("customerTokens",e),De(A.loginToken),this.customer={...A,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await ye.getShadowGraphqlClient().mutate({mutation:oi,variables:{collectionId:t},fetchPolicy:"no-cache"})).data?.bundleCreate;if(!e)throw new Error("Unable to create bundle");me(e.bundleOwnerId);const A=de.getMap("bundleOwnerIds")||new Map;return A.set(e.id,e.bundleOwnerId),de.setMap("bundleOwnerIds",A),new vi(this,e)}async getExistingBundle(t,e){const A=de.getMap("bundleOwnerIds")?.get(t);A&&me(A);const n=await ye.getShadowGraphqlClient().query({query:ni,variables:{id:t},fetchPolicy:"no-cache"});if(!n.data?.bundles||0===n.data?.bundles.length||!n.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const a=n.data?.bundles[0],i=new vi(this,a,e);return await i.getInitializationPromise(),i}async getBundleStakeholders(){if(!this.customer)throw new Error("Customer not authenticated.");const t=await ye.getShadowGraphqlClient().query({query:ii,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!t.data?.customers||0===t.data.customers.length)throw new Error("Unable to find customer.");return t.data.customers[0].bundleStakeholders||[]}async getWorkflowExperience(t,e,A,n){if(!n)return await this.getWorkflowExperienceDeprecated(t,e,A);const a=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===h.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await dt(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===h.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&H(e.fontData.assetUrl)}}},{transaction:i,workflow:o,readOnly:r}=await(async()=>{const t=ye.getShadowGraphqlClient();if("transaction"===n.type){const{transactionId:e,readOnly:A}=n,a=await t.query({query:Jn,variables:{ids:[e]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!a.data?.transactions||0===a.data.transactions.length)throw new ce("Existing transaction not found.");const i=a.data?.transactions[0];if(!i.workflowId)throw new ce("Existing transaction has no workflow ID.");const o=await Zi([i.workflowId]);if(!i.product)throw new ce("Failed to load transaction, product not available.");return{transaction:i,workflow:o[0],readOnly:A}}if("integration"===n.type||"external"===n.type){const e=async()=>{const e="integration"===n.type?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},A=await t.mutate({mutation:Un,variables:{...e,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(!A.data||!A.data.transactionCreate)throw new ce("Failed to create transaction!");const a=A.data.transactionCreate;if(!a.product)throw new ce("Failed to create transaction, product not available.");return a},A=Zi([n.workflowId],n?.graphql),[a,[i]]=await Promise.all([e(),A]);return{transaction:a,workflow:i}}throw new ce("No workflow ID provided.")})();this.currencyCode=i.product.partner?.currencyCode;const s={product:i.product,transaction:i,layouts:[],stateMutationFunc:r?async()=>{throw new re("State mutation is forbidden in read only mode!")}:async t=>{const e=(de.getMap("transactionOwnerIds")||new Map).get(i.id)||void 0;return this.updateTransactionState({...t,context:{transactionOwnerId:e}})},readOnly:r,workflow:o};if("transaction"===n.type&&i.workflowState){const t=JSON.parse(i.workflowState);s.layouts=Object.values(t.layouts).map((t=>t.layout)),await x(t),await a(t),s.reloadedState=t}else if(!r&&n.workflowState){const t=JSON.parse(n.workflowState);s.layouts=Object.values(t.layouts).map((t=>t.layout)),await x(t),await a(t),s.reloadedState=t}else s.layouts=_i(s.transaction,s.workflow);if(s.renderableContextService=new Yn(s.layouts),n.previewService?(s.previewService=n.previewService,s.product?.modelUrl&&(s.modelContainer=s.previewService.loadModel({model:s.product.modelUrl,contextService:s.renderableContextService}))):(s.previewService=A&&A(o),s.product?.modelUrl&&(s.previewService?.initialize({model:s.product.modelUrl,contextService:s.renderableContextService}),s.modelContainer=s.previewService?.getAllModels()[0])),"transaction"!==n.type){const t=de.getMap("transactionOwnerIds")||new Map;t.set(i.id,i.transactionOwnerId),Qe(i.transactionOwnerId||""),de.setMap("transactionOwnerIds",t)}else{const t=(de.getMap("transactionOwnerIds")||new Map).get(i.id);t&&Qe(t),s.isReloadedTransaction=!0}this.initialized=!0,this.experienceOptions=s;const c=new ei(this,s);return await c.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await c.attachCustomerDetails({email:this.customer.emailAddress}),c}async getWorkflowExperiences(t){if(0===t.length)throw new ce("No options provided!");const e=ye.getShadowGraphqlClient(),A=t.map(((t,e)=>({option:t,index:e}))),n=A.filter((t=>"transaction"===t.option.type)),a=A.filter((t=>"integration"===t.option.type||"external"===t.option.type)),i=(await Promise.all([(async()=>{if(0===n.length)return[];const t=n.map((t=>t.option.transactionId)),A=await e.query({query:Jn,variables:{ids:t},errorPolicy:"all",fetchPolicy:"no-cache"}),a=A.data.transactions;if(a.length!==n.length){const t=A.errors?.[0]?.message||"Unknown error";throw new ce(`Not all transactions were found: ${t}`)}return a.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:n.find((e=>e.option.transactionId===t.id))?.option.readOnly??!1,index:n[e].index})))})(),(async()=>{if(0===a.length)return[];const t=await e.mutate({mutation:kn,variables:{inputs:a.map((t=>({integrationProductId:"integration"===t.option.type?t.option.integrationProductId:void 0,externalIntegrationId:"external"===t.option.type?t.option.externalIntegrationId:void 0,externalProductId:"external"===t.option.type?t.option.externalProductId:void 0,workflowId:t.option.workflowId,bulk:t.option.bulk,claim:!0})))},errorPolicy:"all",fetchPolicy:"no-cache"}),A=t.data?.transactionCreateMany;if(!A||0===A.length){const e=t.errors?.[0]?.message||"Unknown error";throw new ce(`Failed to create transactions: ${e}`)}return A.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:!1,index:a[e].index})))})()])).flat(),o=[...new Set(i.map((t=>t.workflowId)))],r=await Zi(o),s=new Map(r.map((t=>[t.id,t]))),c=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===h.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await dt(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===h.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&H(e.fontData.assetUrl)}}},g=de.getMap("transactionOwnerIds")||new Map,l=i.map((async e=>{const{transaction:A,workflowId:n,readOnly:a,index:i}=e,o=s.get(n),r=t[i];!g.get(A.id)&&A.transactionOwnerId&&g.set(A.id,A.transactionOwnerId);const l=g.get(A.id)||void 0,B={product:A.product,transaction:A,layouts:[],stateMutationFunc:a?async()=>{throw new re("State mutation is forbidden in read only mode!")}:async t=>this.updateTransactionState({...t,context:{transactionOwnerId:l}}),readOnly:a,workflow:o,isReloadedTransaction:"transaction"===r.type};if("transaction"===r.type&&A.workflowState){const t=JSON.parse(A.workflowState);B.layouts=Object.values(t.layouts).map((t=>t.layout)),await x(t),await c(t),B.reloadedState=t}else if(!a&&r.workflowState){const t=JSON.parse(r.workflowState);B.layouts=Object.values(t.layouts).map((t=>t.layout)),await x(t),await c(t),B.reloadedState=t}else B.layouts=_i(B.transaction,B.workflow);return B.renderableContextService=new Yn(B.layouts),this.initialized=!0,this.experienceOptions=B,{experienceOptions:B,index:i,options:r}}));de.setMap("transactionOwnerIds",g);const B=(await Promise.all(l)).sort(((t,e)=>t.index-e.index)).map((async t=>{const{experienceOptions:e,options:A}=t,n=new ei(this,e);return await n.getWorkflowManager().getInitializationPromise(),"transaction"!==A.type&&this.customer&&await n.attachCustomerDetails({email:this.customer.emailAddress}),n}));return await Promise.all(B)}async initFromIntegrationProduct(t){if(""===t)throw new ce("No integration product ID provided.");const e=ye.getShadowGraphqlClient(),A=await e.mutate({mutation:Un,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 ce("Failed to create transaction!");const n=A.data.transactionCreate;if(!n.product)throw new ce("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const a=de.getMap("transactionOwnerIds")||new Map;a.set(n.id,n.transactionOwnerId),Qe(n.transactionOwnerId||""),de.setMap("transactionOwnerIds",a),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,e=!1){if(""===t)throw new ce("No transaction ID provided.");const A=ye.getShadowGraphqlClient();if(e)return await(async()=>{const n=(await A.query({query:Jn,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!n)throw new ce("Failed to read transaction.");if(!n.product)throw new ce("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 re("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const n=de.getMap("transactionOwnerIds")||new Map,a=n.get(t);if(a){Qe(a);const n=(await A.query({query:Jn,variables:{ids:[t]},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new ce("Failed to read transaction.");if(!n.product)throw new ce("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:e},void(this.initialized=!0)}try{const a=(await A.mutate({mutation:Gn,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!a)throw new ce("Failed to read transaction.");if(!a.product)throw new ce("Failed to load transaction, product not available.");this.currencyCode=a.product.partner?.currencyCode,a.transactionOwnerId&&(n.set(a.id,a.transactionOwnerId),Qe(a.transactionOwnerId),de.setMap("transactionOwnerIds",n)),this.experienceOptions={product:a.product,transaction:a,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new ce("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,A){if(!this.initialized||!this.experienceOptions)throw new ce("Cannot launch experience: Not initialized.");const n=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===h.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await dt(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===h.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&H(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=(await Zi([this.experienceOptions.transaction.workflowId]))[0];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 x(t),await n(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=A&&A(t),this.experienceOptions.renderableContextService=new Yn(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 ei(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const a=ye.getShadowGraphqlClient().mutate({mutation:Ln,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),i=Zi([t]);if(await Promise.all([a,i]),this.experienceOptions.workflow=(await i)[0],e){const t=JSON.parse(e);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await x(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=_i(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A((await i)[0]),this.experienceOptions.renderableContextService=new Yn(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 ei(this,this.experienceOptions);return await o.getWorkflowManager().getInitializationPromise(),o}throw new ce("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new ce("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new ce("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function eo(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 n=A.call(t,e||"default");if("object"!=typeof n)return n;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 Ao{constructor(){eo(this,"getProduct",void 0),eo(this,"getCommandContext",void 0),eo(this,"getAllLayoutData",void 0),eo(this,"getMetadata",void 0),eo(this,"getWorkflowMetadata",void 0),eo(this,"getStepStorage",void 0),eo(this,"setModelContainer",void 0),eo(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){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}}function no(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 n=A.call(t,e||"default");if("object"!=typeof n)return n;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 ao;var io;(io=ao||(ao={})).SelectFrame="SelectFrame",io.SelectImage="SelectImage",io.Position="Position";class oo extends Pa{constructor(t,e){super(t,e),no(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return ga.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 ga.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,e,A,n){return n&&n.length>1&&void 0===t?ao.SelectFrame:e||A||this.getImageData()?ao.Position:ao.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 ro=t=>{const e=Gt(null),A=Gt(void 0),[n,a]=Nt(void 0),{addEvent:i,removeEvent:o,updateEvent:r,eventCache:s}=je(),[c,g]=Nt(!1),[l,B]=Nt(!1),{state:w,uiDispatcher:d}=eA(),h=Rt((t=>{const e=t;d(new tA({zoom:Math.max(.1,Math.min(e,w.maxZoom))}))}),[d,w.maxZoom]),E=Rt((t=>{o(t),1===s.length&&(A.current=void 0),2===s.length&&a(void 0);"touch"===t.pointerType&&s.length>1&&s.length-1==1&&(B(!1),g(!1))}),[o,s.length]),u=Rt((t=>{i(t);"touch"===t.pointerType&&1===s.length&&(d(new tA({selectedElement:void 0})),B(!0),g(!0))}),[i,s.length,d]),C=Rt((t=>{r(t);const e=1===s.length&&"touch"!==s[0].pointerType,i=2===s.length&&"touch"===s[0].pointerType;if(c&&i){const[t,e]=s,A=Math.abs(t.clientX-e.clientX),i=n;i&&h(w.zoom-.0055*(i-A)),a(A)}if(l&&(e||i)&&t.isPrimary){const e=(A?.current?.x||t.screenX)-t.screenX,n=(A?.current?.y||t.screenY)-t.screenY;d(new tA({selectedElement:void 0,xTranslation:w.xTranslation-e/w.zoom,yTranslation:w.yTranslation-n/w.zoom}))}t.isPrimary&&(A.current={x:t.screenX,y:t.screenY})}),[r,s,c,l,n,h,w.zoom,w.xTranslation,w.yTranslation,d]),Q=Rt((t=>{c&&h(w.zoom-.035*Math.sign(t.deltaY))}),[h,w.zoom,c]);bt((()=>{if(!e.current||0===s.length)return;const t=s[0].pointerId,A=e.current.hasPointerCapture(t);l&&!A&&e.current.setPointerCapture(t),!l&&A&&e.current.releasePointerCapture(t)}),[e,l,s]),zA([" "],(()=>{B(!0),d(new tA({selectedElement:void 0}))}),(()=>B(!1))),zA(["Control"],(()=>g(!0)),(()=>g(!1)));const p=kt((()=>({cursor:l&&0===s.length?"grab":l&&1===s.length?"grabbing":c?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[l,c,s]);return Jt("div",{ref:e,className:"transform-wrapper",onWheel:Q,onPointerDown:u,onPointerUp:E,onPointerCancel:E,onPointerLeave:E,onPointerMove:C,style:p,children:t.children})};export{to as SpiffCommerceClient,t as CommandContext,Ee as spiffCoreConfiguration,WA as PromiseQueue,VA as QueueablePromise,Ao as MockWorkflowManager,ya as InformationMessageType,Pa as StepHandle,Oa as TextStepHandle,oo as FrameStepHandle,ba as BulkStepHandle,La as ShapeStepHandle,Ua as IllustrationStepHandle,ka as MaterialStepHandle,Ga as ModelStepHandle,Ja as PictureStepHandle,Ta as QuestionStepHandle,aA as BulkPriceCalculationStrategy,va as Variant,ei as WorkflowExperienceImpl,ee as OptionNotFoundError,Ae as LayoutNotFoundError,ne as AssetNotFoundError,ae as ResourceNotFoundError,ie as MisconfigurationError,se as ParseError,re as UnhandledBehaviorError,be as assetService,_a as designService,qa as createDesign,Oe as optionService,de as persistenceService,ye as graphQlManager,dA as toast,Aa as FrameService,ta as getBoundedOffsets,ga as frameStepService,wa as modelStepService,Ba as materialStepService,Ca as shapeStepService,Ea as questionStepService,sa as digitalContentStepService,da as moduleStepService,ha as pictureStepService,Da as textStepService,la as illustrationStepService,AA as ProductCameraRig,ao as FrameStep,oA as ConversionLocation,sA as ConversionDataType,$i as getWorkflow,Zi as getWorkflows,ia as shortenUrl,Ui as ObjectInput,ki as TextInput,Hi as ObjectInputType,e as AssetType,A as BringForwardCommand,n as BringToFrontCommand,a as BringToBackCommand,i as CanvasCommand,o as CreateElementCommand,r as CreateLayoutCommand,s as DeleteElementCommand,c as FontAlignmentCommand,g as FontColorCommand,l as FontSizeCommand,B as FontSourceCommand,w as GroupCommand,d as LayoutElementFactory,h as LayoutElementType,E as MoveCommand,u as ResizeCommand,C as RotateCommand,Q as SendBackwardsCommand,gA as StakeholderType,p as StepAspectType,m as StepType,f as TextChangeCommand,D as UnitOfMeasurement,I as dataUrlFromExternalUrl,y as findElement,M as frameDataCache,F as generate,Y as getAxisAlignedBoundingBox,S as generateSVGWithUnknownColors,v as getAttributesFromArrayBuffer,x as rehydrateSerializedLayout,P as getFrameData,N as getSvgElement,R as loadFontFromDataUrl,H as loadFontFromExternalUrl,b as determineCorrectFontSizeAndLines,U as patternImageDataCache,Mn as generateCommands,k as registerJSDOM,TA as minZoom,bn as AdvancedEditor,ro as TransformWrapper,Hn as EditorCore,Ke as useLayouts,eA as useEditorState,OA as useEditorInteraction,zA as useShortcutCombination,Ze as commandReducer,qe as getDefaultState,ze as CommandContextContext,_e as AdvancedEditorStateProvider,$e as AdvancedEditorContext,tA as UICommand,We as EditorSubMenu,hA as ElementEventType,uA as KeyEvent,Kn as gatherVaryingStepAspects};
|
|
1488
|
+
`),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:t}});var n;const a=A.data.workflows;if(void 0===a||a.length!==t.length)throw new Error(`Unable to read workflows: ${A.errors??"Length mismatch in response"}`);return a.forEach((t=>{t.steps.forEach((t=>{delete t.data.__typename,t.option?.id&&(t.option.defaultVariant?.asset&&be.cacheAsset(t.option.defaultVariant.asset),t.option.colorProfile&&be.cacheAsset(t.option.colorProfile),t.option.variants?.forEach((t=>{t.asset&&be.cacheAsset(t.asset),t.displayImage&&be.cacheAsset(t.displayImage),t.thumbnail&&be.cacheAsset(t.thumbnail),t.material&&be.cacheMaterial(t.material)})),ke.set({id:t.option.id},Promise.resolve(t.option)))}))})),a})(n,e),i=n.map((t=>ke.set({id:t,options:e},(async(t,e)=>{const A=(await e).find((e=>e.id===t));if(!A)throw new Error(`Workflow not found: ${t}`);return A})(t,a)))),o=A.filter((t=>void 0!==t));return await Promise.all(o.concat(i))},$i=async(t,e)=>(await Zi([t],e))[0],_i=(t,e)=>{const A=t.workflowState,n=A?JSON.parse(A):void 0;return n?Object.values(n.layouts).map((t=>t.layout)):e.panels.sort(((t,e)=>t.index-e.index)).map((t=>({id:F(),panelId:t.name,name:t.name,index:t.index,createdAt:new Date,updatedAt:new Date,transparentBackground:t.transparentBackground,height:t.height,width:t.width,previewRegion:t.previewRegion,useEditableArea:t.useEditableArea,editableArea:t.editableArea})))};class to{constructor(t){var e;Gi(this,"options",void 0),Gi(this,"initialized",void 0),Gi(this,"currencyCode",void 0),Gi(this,"customer",void 0),Gi(this,"experienceOptions",void 0),Gi(this,"updateTransactionState",(async t=>{try{return ye.getShadowGraphqlClient().mutate({...t,mutation:Tn})}catch(t){throw console.error(t),new ce("Critical - Unable to synchronize workflow state with server.")}})),this.initialized=!1,this.options=t,this.options.applicationKey&&(e=this.options.applicationKey,Ie=e)}getAssetManager(){return be}getCurrencyCode(){if(void 0===this.currencyCode)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!this.options.applicationKey)throw new Error("Application key required to use Flow Service.");return new Ni}async authenticateBundleFromLocalStorage(t){const e=de.getMap("bundleOwnerIds");if(e?.has(t)){const A=e.get(t);return me(A),Promise.resolve({success:!0,stakeholderType:gA.Owner})}const A=de.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=ye.getShadowGraphqlClient(),A=await e.query({query:zi,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 n=A.data.transactions[0],a=n.product?.partner?.id;if(!a)throw new Error(`Unable to read transaction: ${t}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const i=de.getMap("transactionOwnerIds");if(i?.has(t)){const e=i.get(t);return Qe(e),Promise.resolve({success:!0,stakeholderType:gA.Owner})}const o=de.getMap("transactionCustomerIds");if(o?.has(t)){const e=o.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 r=(await e.query({query:ji,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!r)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:r.overrideTheme,customLogoLink:n.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=de.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),de.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=ye.getShadowGraphqlClient(),A=(await e.query({query:Ki,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!A.id){const A=(await e.mutate({mutation:Vi,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 n=await this.authenticateCustomerId(A.id);return{customer:this.customer||A,isAuthenticated:n}}async authenticateCustomerId(t){const e=ye.getShadowGraphqlClient(),A=de.getMap("customerTokens");if(!A?.has(t))return!1;const n=A.get(t);if(!n)return!1;const a=(await e.mutate({mutation:Wi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!a&&(De(n),this.customer=a,!0)}async generateVerificationCode(t){await ye.getShadowGraphqlClient().mutate({mutation:Xi,variables:{emailAddress:t}})}async verifyCode(t,e){const A=(await ye.getShadowGraphqlClient().mutate({mutation:qi,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=de.getMap("customerTokens")||new Map;return e.set(A.id,A.loginToken),de.setMap("customerTokens",e),De(A.loginToken),this.customer={...A,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await ye.getShadowGraphqlClient().mutate({mutation:oi,variables:{collectionId:t},fetchPolicy:"no-cache"})).data?.bundleCreate;if(!e)throw new Error("Unable to create bundle");me(e.bundleOwnerId);const A=de.getMap("bundleOwnerIds")||new Map;return A.set(e.id,e.bundleOwnerId),de.setMap("bundleOwnerIds",A),new vi(this,e)}async getExistingBundle(t,e){const A=de.getMap("bundleOwnerIds")?.get(t);A&&me(A);const n=await ye.getShadowGraphqlClient().query({query:ni,variables:{id:t},fetchPolicy:"no-cache"});if(!n.data?.bundles||0===n.data?.bundles.length||!n.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const a=n.data?.bundles[0],i=new vi(this,a,e);return await i.getInitializationPromise(),i}async getBundleStakeholders(){if(!this.customer)throw new Error("Customer not authenticated.");const t=await ye.getShadowGraphqlClient().query({query:ii,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!t.data?.customers||0===t.data.customers.length)throw new Error("Unable to find customer.");return t.data.customers[0].bundleStakeholders||[]}async getWorkflowExperience(t,e,A,n){if(!n)return await this.getWorkflowExperienceDeprecated(t,e,A);const a=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===h.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await dt(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===h.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&H(e.fontData.assetUrl)}}},{transaction:i,workflow:o,readOnly:r}=await(async()=>{const t=ye.getShadowGraphqlClient();if("transaction"===n.type){const{transactionId:e,readOnly:A}=n,a=await t.query({query:Jn,variables:{ids:[e]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!a.data?.transactions||0===a.data.transactions.length)throw new ce("Existing transaction not found.");const i=a.data?.transactions[0];if(!i.workflowId)throw new ce("Existing transaction has no workflow ID.");const o=await $i(i.workflowId);if(!i.product)throw new ce("Failed to load transaction, product not available.");return{transaction:i,workflow:o,readOnly:A}}if("integration"===n.type||"external"===n.type){const e=async()=>{const e="integration"===n.type?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},A=await t.mutate({mutation:Un,variables:{...e,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(!A.data||!A.data.transactionCreate)throw new ce("Failed to create transaction!");const a=A.data.transactionCreate;if(!a.product)throw new ce("Failed to create transaction, product not available.");return a},A=$i(n.workflowId,n?.graphql),[a,i]=await Promise.all([e(),A]);return{transaction:a,workflow:i}}throw new ce("No workflow ID provided.")})();this.currencyCode=i.product.partner?.currencyCode;const s={product:i.product,transaction:i,layouts:[],stateMutationFunc:r?async()=>{throw new re("State mutation is forbidden in read only mode!")}:async t=>{const e=(de.getMap("transactionOwnerIds")||new Map).get(i.id)||void 0;return this.updateTransactionState({...t,context:{transactionOwnerId:e}})},readOnly:r,workflow:o};if("transaction"===n.type&&i.workflowState){const t=JSON.parse(i.workflowState);s.layouts=Object.values(t.layouts).map((t=>t.layout)),await x(t),await a(t),s.reloadedState=t}else if(!r&&n.workflowState){const t=JSON.parse(n.workflowState);s.layouts=Object.values(t.layouts).map((t=>t.layout)),await x(t),await a(t),s.reloadedState=t}else s.layouts=_i(s.transaction,s.workflow);if(s.renderableContextService=new Yn(s.layouts),n.previewService?(s.previewService=n.previewService,s.product?.modelUrl&&(s.modelContainer=s.previewService.loadModel({model:s.product.modelUrl,contextService:s.renderableContextService}))):(s.previewService=A&&A(o),s.product?.modelUrl&&(s.previewService?.initialize({model:s.product.modelUrl,contextService:s.renderableContextService}),s.modelContainer=s.previewService?.getAllModels()[0])),"transaction"!==n.type){const t=de.getMap("transactionOwnerIds")||new Map;t.set(i.id,i.transactionOwnerId),Qe(i.transactionOwnerId||""),de.setMap("transactionOwnerIds",t)}else{const t=(de.getMap("transactionOwnerIds")||new Map).get(i.id);t&&Qe(t),s.isReloadedTransaction=!0}this.initialized=!0,this.experienceOptions=s;const c=new ei(this,s);return await c.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await c.attachCustomerDetails({email:this.customer.emailAddress}),c}async getWorkflowExperiences(t){if(0===t.length)throw new ce("No options provided!");const e=ye.getShadowGraphqlClient(),A=t.map(((t,e)=>({option:t,index:e}))),n=A.filter((t=>"transaction"===t.option.type)),a=A.filter((t=>"integration"===t.option.type||"external"===t.option.type)),i=(await Promise.all([(async()=>{if(0===n.length)return[];const t=n.map((t=>t.option.transactionId)),A=await e.query({query:Jn,variables:{ids:t},errorPolicy:"all",fetchPolicy:"no-cache"}),a=A.data.transactions;if(a.length!==n.length){const t=A.errors?.[0]?.message||"Unknown error";throw new ce(`Not all transactions were found: ${t}`)}return a.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:n.find((e=>e.option.transactionId===t.id))?.option.readOnly??!1,index:n[e].index})))})(),(async()=>{if(0===a.length)return[];const t=await e.mutate({mutation:kn,variables:{inputs:a.map((t=>({integrationProductId:"integration"===t.option.type?t.option.integrationProductId:void 0,externalIntegrationId:"external"===t.option.type?t.option.externalIntegrationId:void 0,externalProductId:"external"===t.option.type?t.option.externalProductId:void 0,workflowId:t.option.workflowId,bulk:t.option.bulk,claim:!0})))},errorPolicy:"all",fetchPolicy:"no-cache"}),A=t.data?.transactionCreateMany;if(!A||0===A.length){const e=t.errors?.[0]?.message||"Unknown error";throw new ce(`Failed to create transactions: ${e}`)}return A.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:!1,index:a[e].index})))})()])).flat(),o=[...new Set(i.map((t=>t.workflowId)))],r=await Zi(o),s=new Map(r.map((t=>[t.id,t]))),c=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===h.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await dt(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===h.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&H(e.fontData.assetUrl)}}},g=de.getMap("transactionOwnerIds")||new Map,l=i.map((async e=>{const{transaction:A,workflowId:n,readOnly:a,index:i}=e,o=s.get(n),r=t[i];!g.get(A.id)&&A.transactionOwnerId&&g.set(A.id,A.transactionOwnerId);const l=g.get(A.id)||void 0,B={product:A.product,transaction:A,layouts:[],stateMutationFunc:a?async()=>{throw new re("State mutation is forbidden in read only mode!")}:async t=>this.updateTransactionState({...t,context:{transactionOwnerId:l}}),readOnly:a,workflow:o,isReloadedTransaction:"transaction"===r.type};if("transaction"===r.type&&A.workflowState){const t=JSON.parse(A.workflowState);B.layouts=Object.values(t.layouts).map((t=>t.layout)),await x(t),await c(t),B.reloadedState=t}else if(!a&&r.workflowState){const t=JSON.parse(r.workflowState);B.layouts=Object.values(t.layouts).map((t=>t.layout)),await x(t),await c(t),B.reloadedState=t}else B.layouts=_i(B.transaction,B.workflow);return B.renderableContextService=new Yn(B.layouts),this.initialized=!0,this.experienceOptions=B,{experienceOptions:B,index:i,options:r}}));de.setMap("transactionOwnerIds",g);const B=(await Promise.all(l)).sort(((t,e)=>t.index-e.index)).map((async t=>{const{experienceOptions:e,options:A}=t,n=new ei(this,e);return await n.getWorkflowManager().getInitializationPromise(),"transaction"!==A.type&&this.customer&&await n.attachCustomerDetails({email:this.customer.emailAddress}),n}));return await Promise.all(B)}async initFromIntegrationProduct(t){if(""===t)throw new ce("No integration product ID provided.");const e=ye.getShadowGraphqlClient(),A=await e.mutate({mutation:Un,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 ce("Failed to create transaction!");const n=A.data.transactionCreate;if(!n.product)throw new ce("Failed to create transaction, product not available.");this.currencyCode=n.product.partner?.currencyCode;const a=de.getMap("transactionOwnerIds")||new Map;a.set(n.id,n.transactionOwnerId),Qe(n.transactionOwnerId||""),de.setMap("transactionOwnerIds",a),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:this.updateTransactionState},this.initialized=!0}async initFromTransaction(t,e=!1){if(""===t)throw new ce("No transaction ID provided.");const A=ye.getShadowGraphqlClient();if(e)return await(async()=>{const n=(await A.query({query:Jn,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!n)throw new ce("Failed to read transaction.");if(!n.product)throw new ce("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 re("State mutation is forbidden in read only mode!")},readOnly:e},this.initialized=!0})();const n=de.getMap("transactionOwnerIds")||new Map,a=n.get(t);if(a){Qe(a);const n=(await A.query({query:Jn,variables:{ids:[t]},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new ce("Failed to read transaction.");if(!n.product)throw new ce("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:e},void(this.initialized=!0)}try{const a=(await A.mutate({mutation:Gn,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!a)throw new ce("Failed to read transaction.");if(!a.product)throw new ce("Failed to load transaction, product not available.");this.currencyCode=a.product.partner?.currencyCode,a.transactionOwnerId&&(n.set(a.id,a.transactionOwnerId),Qe(a.transactionOwnerId),de.setMap("transactionOwnerIds",n)),this.experienceOptions={product:a.product,transaction:a,layouts:[],stateMutationFunc:this.updateTransactionState,readOnly:e},this.initialized=!0}catch{throw new ce("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,A){if(!this.initialized||!this.experienceOptions)throw new ce("Cannot launch experience: Not initialized.");const n=async t=>{for(const e in t.layouts){const A=t.layouts[e].elements.filter((t=>t.type===h.Illustration));for(let t=0;t<A.length;++t){const e=A[t];e.src&&e.svg&&(e.cachedObjectURL=await dt(e.svg))}const n=t.layouts[e].elements.filter((t=>t.type===h.Textbox));for(let t=0;t<n.length;++t){const e=n[t];e.fontData?.assetUrl&&H(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await $i(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 x(t),await n(t),this.experienceOptions.reloadedState=t}this.experienceOptions.previewService=A&&A(t),this.experienceOptions.renderableContextService=new Yn(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 ei(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const a=ye.getShadowGraphqlClient().mutate({mutation:Ln,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),i=$i(t);if(await Promise.all([a,i]),this.experienceOptions.workflow=await i,e){const t=JSON.parse(e);this.experienceOptions.layouts=Object.values(t.layouts).map((t=>t.layout)),await x(t),await n(t),this.experienceOptions.reloadedState=t}else this.experienceOptions.layouts=_i(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await i),this.experienceOptions.renderableContextService=new Yn(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 ei(this,this.experienceOptions);return await o.getWorkflowManager().getInitializationPromise(),o}throw new ce("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new ce("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new ce("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}}function eo(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 n=A.call(t,e||"default");if("object"!=typeof n)return n;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 Ao{constructor(){eo(this,"getProduct",void 0),eo(this,"getCommandContext",void 0),eo(this,"getAllLayoutData",void 0),eo(this,"getMetadata",void 0),eo(this,"getWorkflowMetadata",void 0),eo(this,"getStepStorage",void 0),eo(this,"setModelContainer",void 0),eo(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){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}}function no(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 n=A.call(t,e||"default");if("object"!=typeof n)return n;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 ao;var io;(io=ao||(ao={})).SelectFrame="SelectFrame",io.SelectImage="SelectImage",io.Position="Position";class oo extends Pa{constructor(t,e){super(t,e),no(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return ga.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 ga.selectImage(this.step,t,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(t,e,A,n){return n&&n.length>1&&void 0===t?ao.SelectFrame:e||A||this.getImageData()?ao.Position:ao.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 ro=t=>{const e=Gt(null),A=Gt(void 0),[n,a]=Nt(void 0),{addEvent:i,removeEvent:o,updateEvent:r,eventCache:s}=je(),[c,g]=Nt(!1),[l,B]=Nt(!1),{state:w,uiDispatcher:d}=eA(),h=Rt((t=>{const e=t;d(new tA({zoom:Math.max(.1,Math.min(e,w.maxZoom))}))}),[d,w.maxZoom]),E=Rt((t=>{o(t),1===s.length&&(A.current=void 0),2===s.length&&a(void 0);"touch"===t.pointerType&&s.length>1&&s.length-1==1&&(B(!1),g(!1))}),[o,s.length]),u=Rt((t=>{i(t);"touch"===t.pointerType&&1===s.length&&(d(new tA({selectedElement:void 0})),B(!0),g(!0))}),[i,s.length,d]),C=Rt((t=>{r(t);const e=1===s.length&&"touch"!==s[0].pointerType,i=2===s.length&&"touch"===s[0].pointerType;if(c&&i){const[t,e]=s,A=Math.abs(t.clientX-e.clientX),i=n;i&&h(w.zoom-.0055*(i-A)),a(A)}if(l&&(e||i)&&t.isPrimary){const e=(A?.current?.x||t.screenX)-t.screenX,n=(A?.current?.y||t.screenY)-t.screenY;d(new tA({selectedElement:void 0,xTranslation:w.xTranslation-e/w.zoom,yTranslation:w.yTranslation-n/w.zoom}))}t.isPrimary&&(A.current={x:t.screenX,y:t.screenY})}),[r,s,c,l,n,h,w.zoom,w.xTranslation,w.yTranslation,d]),Q=Rt((t=>{c&&h(w.zoom-.035*Math.sign(t.deltaY))}),[h,w.zoom,c]);bt((()=>{if(!e.current||0===s.length)return;const t=s[0].pointerId,A=e.current.hasPointerCapture(t);l&&!A&&e.current.setPointerCapture(t),!l&&A&&e.current.releasePointerCapture(t)}),[e,l,s]),zA([" "],(()=>{B(!0),d(new tA({selectedElement:void 0}))}),(()=>B(!1))),zA(["Control"],(()=>g(!0)),(()=>g(!1)));const p=kt((()=>({cursor:l&&0===s.length?"grab":l&&1===s.length?"grabbing":c?"zoom-in":void 0,width:"100%",height:"100%",overflow:"clip"})),[l,c,s]);return Jt("div",{ref:e,className:"transform-wrapper",onWheel:Q,onPointerDown:u,onPointerUp:E,onPointerCancel:E,onPointerLeave:E,onPointerMove:C,style:p,children:t.children})};export{to as SpiffCommerceClient,t as CommandContext,Ee as spiffCoreConfiguration,WA as PromiseQueue,VA as QueueablePromise,Ao as MockWorkflowManager,ya as InformationMessageType,Pa as StepHandle,Oa as TextStepHandle,oo as FrameStepHandle,ba as BulkStepHandle,La as ShapeStepHandle,Ua as IllustrationStepHandle,ka as MaterialStepHandle,Ga as ModelStepHandle,Ja as PictureStepHandle,Ta as QuestionStepHandle,aA as BulkPriceCalculationStrategy,va as Variant,ei as WorkflowExperienceImpl,ee as OptionNotFoundError,Ae as LayoutNotFoundError,ne as AssetNotFoundError,ae as ResourceNotFoundError,ie as MisconfigurationError,se as ParseError,re as UnhandledBehaviorError,be as assetService,_a as designService,qa as createDesign,Oe as optionService,de as persistenceService,ye as graphQlManager,dA as toast,Aa as FrameService,ta as getBoundedOffsets,ga as frameStepService,wa as modelStepService,Ba as materialStepService,Ca as shapeStepService,Ea as questionStepService,sa as digitalContentStepService,da as moduleStepService,ha as pictureStepService,Da as textStepService,la as illustrationStepService,AA as ProductCameraRig,ao as FrameStep,oA as ConversionLocation,sA as ConversionDataType,$i as getWorkflow,Zi as getWorkflows,ia as shortenUrl,Ui as ObjectInput,ki as TextInput,Hi as ObjectInputType,e as AssetType,A as BringForwardCommand,n as BringToFrontCommand,a as BringToBackCommand,i as CanvasCommand,o as CreateElementCommand,r as CreateLayoutCommand,s as DeleteElementCommand,c as FontAlignmentCommand,g as FontColorCommand,l as FontSizeCommand,B as FontSourceCommand,w as GroupCommand,d as LayoutElementFactory,h as LayoutElementType,E as MoveCommand,u as ResizeCommand,C as RotateCommand,Q as SendBackwardsCommand,gA as StakeholderType,p as StepAspectType,m as StepType,f as TextChangeCommand,D as UnitOfMeasurement,I as dataUrlFromExternalUrl,y as findElement,M as frameDataCache,F as generate,Y as getAxisAlignedBoundingBox,S as generateSVGWithUnknownColors,v as getAttributesFromArrayBuffer,x as rehydrateSerializedLayout,P as getFrameData,N as getSvgElement,R as loadFontFromDataUrl,H as loadFontFromExternalUrl,b as determineCorrectFontSizeAndLines,U as patternImageDataCache,Mn as generateCommands,k as registerJSDOM,TA as minZoom,bn as AdvancedEditor,ro as TransformWrapper,Hn as EditorCore,Ke as useLayouts,eA as useEditorState,OA as useEditorInteraction,zA as useShortcutCombination,Ze as commandReducer,qe as getDefaultState,ze as CommandContextContext,_e as AdvancedEditorStateProvider,$e as AdvancedEditorContext,tA as UICommand,We as EditorSubMenu,hA as ElementEventType,uA as KeyEvent,Kn as gatherVaryingStepAspects};
|
|
1489
1489
|
//# sourceMappingURL=module.js.map
|