@spiffcommerce/core 15.1.2 → 15.1.4
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 +9 -8
- package/dist/module.js +9 -8
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -579,18 +579,19 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
|
|
|
579
579
|
`;class Rs extends Ps{constructor(t,e){super(t,e),Ys(this,"transaction",this.manager.getTransaction())}selectVariant(){throw new Error("Bulk step does not support variants.")}async setDesignName(t){await Ia.getShadowGraphqlClient().mutate({mutation:ks,variables:{transactionId:this.manager.getTransaction().id,designName:t}});const e=this.manager.getTransaction();this.manager.setTransaction({...e,designName:t})}addVariationRecord(){const t=this.manager.addVariationRecord({transactionId:this.transaction.id,values:[]});return this.manager.setCurrentVariationRecord(t),t}updateBulkIsConnected(t){this.manager.updateStorage(this.getId(),{bulkIsConnected:t})}openBulkSourceUrl(){window.open(this.transaction.bulkSourceUrl,"_blank")}async sendGoogleSheetLinkToEmail(t){await Ia.getShadowGraphqlClient().mutate({mutation:Ns,variables:{id:this.transaction.id,details:{emailAddress:t},type:"Owner"}}),this.openBulkSourceUrl()}deleteVariationRecord(t){this.manager.removeVariationRecord(t)}getAspects(){return this.step.data.aspects}}class Hs extends Ps{constructor(t,e){super(t,e)}async selectVariant(t){if(this.getCurrentVariant()!==t)return gs.selectVariant(this.step,t.getResource(),this.manager.getRegionElements(this.step.stepName)||[],(t=>this.setUpdateState(t)),this.manager)}getColors(){const t=this.manager.getRegionElements(this.step.stepName)||[];if(0!==t.length)try{return Wn(t[0].id,this.manager.getAllLayoutData()).colors}catch(t){console.error(t)}}setColor(t,e){const i=new Map;return i.set(t,e),gs.changeColors(this.step,this.manager.getRegionElements(this.step.stepName),this.manager,(()=>this.manager.getCommandContext().getAllLayouts()),i)}async getColorOption(){return this.step.data.colorOption}getAvailableColors(){return this.step.data.colorPickerEnabled?gs.availableColors(this.step,this.manager):Promise.resolve([])}hasVaryingSelection(){return this.step.data.varySelection}hasVaryingColors(){return this.step.data.varyColors}isColorPickerEnabled(){return this.step.data.colorPickerEnabled}}class Us extends Ps{constructor(t,e){super(t,e)}selectVariant(t){return hs.selectVariant(this.step,t.getResource(),this.manager,(t=>this.setUpdateState(t)))}}class Gs extends Ps{constructor(t,e){super(t,e)}selectVariant(t){return ds.selectVariant(this.step,t.getResource(),this.manager,(t=>this.setUpdateState(t)))}}class Ts extends Ps{constructor(t,e){super(t,e)}selectVariant(t){return ws.selectVariant(this.step,t.getResource(),this.manager,(t=>this.setUpdateState(t)))}}class Os extends Ps{constructor(t,e){super(t,e)}async selectVariant(t){if(!t.getId())throw new Error("Unable to select variant with a null ID");await Bs.selectVariant(this.step,t.getId(),this.manager)}getDisplayType(){return this.step.option?.displayType}}class Js extends Ps{constructor(t,e){super(t,e)}selectVariant(t){const e=t.getResource();return ms.selectVariant(this.step,{fill:e.color,stroke:e.color,variant:e},this.manager.getRegionElements(this.step.stepName)||[],this.manager)}setColor(t){return ms.selectVariant(this.step,t,this.manager.getRegionElements(this.step.stepName)||[],this.manager)}getColors(){return ms.availableColours(this.step)}setCustomColor(t){if("#custom"!==this.getCurrentVariant()?.getColor())throw new Error("Custom colors can only be set on a non-custom variant. Please add a custom variant to the step.");return ms.setCustomColor(t,this.step,this.manager)}getCustomColor(){const t=this.manager.getStepStorage(this.step.stepName)?.colour;if("#custom"!==this.getCurrentVariant()?.getColor())throw new Error("Custom colors can only be set on a non-custom variant. Please add a custom variant to the step.");if(!t)throw new Error("Color not available on step. Set a default on the workflow to fix this.");return t}}class Ls extends Ps{constructor(t,e){super(t,e)}async selectVariant(t){ys.selectVariant(this.step,t.getResource(),this.manager,(t=>{if(t)this.manager.setInformationResults([...this.manager.getInformationResults(),{message:"An issue has occured with test",messageType:Ds.Error,stepID:this.step.stepName}]);else{const t=this.manager.getInformationResults().filter((t=>t.stepID!==this.step.stepName));this.manager.setInformationResults(t)}}),(t=>{}))}getAvailableFillColors(){return this.step.data.colorPickerEnabled?ys.availableFillColors(this.step):[]}async setFillColor(t){const e=this.manager.getRegionElements(this.step.stepName);await ys.changeFillColor(this.step,t,e,this.manager)}getFillColor(){return this.manager.getStepStorage(this.step.stepName)?.color||"#000000"}getAvailableFillImages(){return ys.availableFillImages(this.step)}async setFillImage(t){const e=this.manager.getRegionElements(this.step.stepName);await ys.changeFillImage(this.step,t,e,this.manager)}getFillImage(){return this.manager.getStepStorage(this.step.stepName)?.fillImage}setFullTextCustomization(t){const e=this.manager.getStepStorage(this.step.stepName)?.inputText||"",i=void 0!==this.step.data.replaceableText?this.step.data.replaceableText.replace("{{}}",e):e,n=t?i:this.step.data.defaultText;this.manager.updateStorage(this.step.stepName,{customiseAllText:t,text:n,defaultCleared:!1});return this.setText(n)}setText(t){const e={input:t},i=ys.findLayoutElements(this.manager,this.step),n=ys.filterUnsupportedCharacters(t,i[0]?.fontData);!!this.step.data&&!!this.step.data.maxLength&&n.length>this.step.data.maxLength||(e.input=n);const A=i.length<=0,a=A?{inputText:n,text:n}:{inputText:n};if(this.manager.updateStorage(this.step.stepName,a),this.manager.updateMetadata(this.step.stepName,{text:n}),A)return e;const{command:r,errors:o,helperText:s}=ys.updateInputText(n,i,this.step,this.manager);r&&this.manager.getCommandDispatcher()(r);const c=this.manager.getInformationResults(),l=o[0]?.localizationKey;if(l)this.manager.setInformationResults([...c,{message:`${l} - ${this.step.stepTitle}`,messageType:Ds.Error,stepID:this.step.stepName}]);else{const t=c.filter((t=>t.stepID!==this.step.stepName));this.manager.setInformationResults(t)}return e.helperText=l||s,e.errorText=l,e}getText(){const t=this.step.data.defaultText;return this.manager.getStepStorage(this.step.stepName)?.text||t||""}isReplaceable(){return this.step.data.userCanReplaceText}clearDefaultTextIfNecessary(){if(!this.manager.getStepStorage(this.step.stepName)?.defaultCleared&&this.step.data.deleteDefaultOnFocus){const t=this.setText("");return this.manager.updateStorage(this.step.stepName,{defaultCleared:!0,inputText:""}),t}}hasVaryingText(){return this.step.data.varyText}hasVaryingColor(){return this.step.data.varyColor}hasVaryingSelection(){return this.step.data.varySelection}hasColorPicker(){return this.step.data.colorPickerEnabled}getRegions(){return this.step.data.regions}getCharacterLimit(){return this.step.data.maxLength}getCharactersRemaining(){const t=this.step.data.maxLength;if(void 0===t)return;return t-this.getText().length}}class zs extends Ps{constructor(t,e){super(t,e)}async selectVariant(){}getContent(){return this.step.data.content}}class js{static get(t,e){switch(e.type){case oi.Information:return new zs(t,e);case oi.Question:return new Os(t,e);case oi.Text:return new Ls(t,e);case oi.Illustration:return new Hs(t,e);case oi.Picture:return new Ts(t,e);case oi.Shape:return new Js(t,e);case oi.Material:return new Us(t,e);case oi.Model:return new Gs(t,e);case oi.Frame:return new wl(t,e);case oi.Bulk:return new Rs(t,e);default:throw new ra(`Step type ${e.type} not yet supported in Core SDK`)}}}function Vs(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}const Ks=t.gql`
|
|
580
580
|
fragment CreateDesignTransaction on Transaction {
|
|
581
581
|
id
|
|
582
|
-
designName
|
|
583
582
|
bulk
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
externalDesignProductId
|
|
587
|
-
externalDesignProductVariantId
|
|
583
|
+
bulkEmailAddress
|
|
584
|
+
designName
|
|
588
585
|
externalCartProductId
|
|
589
586
|
externalCartProductVariantId
|
|
587
|
+
externalDesignProductId
|
|
588
|
+
externalDesignProductVariantId
|
|
589
|
+
lastSyncedAt
|
|
590
|
+
previewImageLink
|
|
591
|
+
priceModifierTotal
|
|
592
|
+
variationsCount
|
|
590
593
|
workflowViewerLink
|
|
591
594
|
workflowViewerReadOnlyLink
|
|
592
|
-
lastSyncedAt
|
|
593
|
-
bulkEmailAddress
|
|
594
595
|
}
|
|
595
596
|
`,Ws=t.gql`
|
|
596
597
|
${Ks}
|
|
@@ -1580,5 +1581,5 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
|
|
|
1580
1581
|
}
|
|
1581
1582
|
}
|
|
1582
1583
|
}
|
|
1583
|
-
`),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)))),o=n.filter((t=>void 0!==t));return await Promise.all(o.concat(r))},ol=async(t,e)=>(await rl([t],e))[0],sl=(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 cl{constructor(t){var e;Wc(this,"options",void 0),Wc(this,"initialized",void 0),Wc(this,"currencyCode",void 0),Wc(this,"customer",void 0),Wc(this,"experienceOptions",void 0),Wc(this,"updateTransactionState",(async t=>{try{return Ia.getShadowGraphqlClient().mutate({...t,mutation:Jo})}catch(t){throw console.error(t),new sa("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 Jc}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:gr.Owner})}const i=da.getMap("bundlePartnerIds")||new Map;if(i.has(t)){const e=i.get(t),n=(da.getMap("partnerCustomerIds")||new Map).get(e);if(n){if(await this.authenticateCustomerId(n)){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:_c,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:gr.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 o=(await e.query({query:tl,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!o)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:o.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:el,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!i.id){const i=(await e.mutate({mutation:il,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!i)throw new Error("Unable to create customer.");return this.storeCustomer(i),this.customer=i,{customer:i,isAuthenticated:!1}}this.storeCustomer(i);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:nl,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!A&&(this.storeCustomer(A),Qa(n),this.customer=A,!0)}async generateVerificationCode(t){await Ia.getShadowGraphqlClient().mutate({mutation:Al,variables:{emailAddress:t}})}async verifyCode(t,e){const i=(await Ia.getShadowGraphqlClient().mutate({mutation:al,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),this.storeCustomer(i),Qa(i.loginToken),this.customer={...i,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Ia.getShadowGraphqlClient().mutate({mutation:hc,variables:{collectionId:t},fetchPolicy:"no-cache"})).data?.bundleCreate;if(!e?.id)throw new Error("Unable to create bundle");const i=da.getMap("bundlePartnerIds")||new Map;i.set(e.id,e.partner.id),da.setMap("bundlePartnerIds",i),fa(e.bundleOwnerId);const n=da.getMap("bundleOwnerIds")||new Map;return n.set(e.id,e.bundleOwnerId),da.setMap("bundleOwnerIds",n),new Gc(this,e)}async getExistingBundle(t,e,i){const n=da.getMap("bundleOwnerIds")?.get(t);n&&fa(n);const A=await Ia.getShadowGraphqlClient().query({query:cc,variables:{id:t},fetchPolicy:"no-cache"});if(!A.data?.bundles||0===A.data?.bundles.length||!A.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const a=A.data?.bundles[0],r=da.getMap("bundlePartnerIds")||new Map;r.set(a.id,a.partner.id),da.setMap("bundlePartnerIds",r);const o=new Gc(this,a,e,i);return await o.getInitializationPromise(),o}async getBundleStakeholders(){if(!this.customer)throw new Error("Customer not authenticated.");const t=await Ia.getShadowGraphqlClient().query({query:gc,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&&sn(e.fontData.assetUrl)}}},{transaction:a,workflow:r,readOnly:o}=await(async()=>{const t=Ia.getShadowGraphqlClient();if("transaction"===n.type){const{transactionId:e,readOnly:i}=n,A=await t.query({query:Oo,variables:{ids:[e]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!A.data?.transactions||0===A.data.transactions.length)throw new sa("Existing transaction not found.");const a=A.data?.transactions[0];if(!a.workflowId)throw new sa("Existing transaction has no workflow ID.");const r=await ol(a.workflowId);if(!a.product)throw new sa("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:Uo,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 sa("Failed to create transaction!");const A=i.data.transactionCreate;if(!A.product)throw new sa("Failed to create transaction, product not available.");return A},i=ol(n.workflowId,n?.graphql),[A,a]=await Promise.all([e(),i]);return{transaction:A,workflow:a}}throw new sa("No workflow ID provided.")})();this.currencyCode=a.product.partner?.currencyCode;const s={product:a.product,transaction:a,layouts:[],stateMutationFunc:o?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:o,workflow:r};if("transaction"===n.type&&a.workflowState){const t=JSON.parse(a.workflowState);s.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),s.reloadedState=t}else if(!o&&n.workflowState){const t=JSON.parse(n.workflowState);s.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),s.reloadedState=t}else s.layouts=sl(s.transaction,s.workflow);if(s.renderableContextService=new So(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=i&&i(r),s.product?.modelUrl&&(s.previewService?.initialize({model:s.product.modelUrl,contextService:s.renderableContextService}),s.modelContainer=s.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),s.isReloadedTransaction=!0}this.initialized=!0,this.experienceOptions=s;const c=new rc(this,s);return await c.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await c.attachCustomerDetails({email:this.customer.emailAddress}),c}async getWorkflowExperiences(t,e){if(0===t.length)throw new sa("No options provided!");const i=Ia.getShadowGraphqlClient(),n=t.map(((t,e)=>({option:t,index:e}))),A=n.filter((t=>"transaction"===t.option.type)),a=n.filter((t=>"integration"===t.option.type||"external"===t.option.type)),r=(await Promise.all([(async()=>{if(0===A.length)return[];const t=A.map((t=>t.option.transactionId)),e=await i.query({query:Oo,variables:{ids:t},errorPolicy:"all",fetchPolicy:"no-cache"}),n=e.data.transactions;if(n.length!==A.length){const t=e.errors?.[0]?.message||"Unknown error";throw new sa(`Not all transactions were found: ${t}`)}return n.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:A.find((e=>e.option.transactionId===t.id))?.option.readOnly??!1,index:A[e].index})))})(),(async()=>{if(0===a.length)return[];const t=await i.mutate({mutation:Go,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"}),e=t.data?.transactionCreateMany;if(!e||0===e.length){const e=t.errors?.[0]?.message||"Unknown error";throw new sa(`Failed to create transactions: ${e}`)}return e.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:!1,index:a[e].index})))})()])).flat(),o=[...new Set(r.map((t=>t.workflowId)))],s=await rl(o,e),c=new Map(s.map((t=>[t.id,t]))),l=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&&sn(e.fontData.assetUrl)}}},g=da.getMap("transactionOwnerIds")||new Map,h=r.map((async e=>{const{transaction:i,workflowId:n,readOnly:A,index:a}=e,r=c.get(n),o=t[a];!g.get(i.id)&&i.transactionOwnerId&&g.set(i.id,i.transactionOwnerId);const s=g.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:s}}),readOnly:A,workflow:r,isReloadedTransaction:"transaction"===o.type};if("transaction"===o.type&&i.workflowState){const t=JSON.parse(i.workflowState);h.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await l(t),h.reloadedState=t}else if(!A&&o.workflowState){const t=JSON.parse(o.workflowState);h.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await l(t),h.reloadedState=t}else h.layouts=sl(h.transaction,h.workflow);return h.renderableContextService=new So(h.layouts),this.initialized=!0,this.experienceOptions=h,{experienceOptions:h,index:a,options:o}}));da.setMap("transactionOwnerIds",g);const d=(await Promise.all(h)).sort(((t,e)=>t.index-e.index)).map((async t=>{const{experienceOptions:e,options:i}=t,n=new rc(this,e);return await n.getWorkflowManager().getInitializationPromise(),"transaction"!==i.type&&this.customer&&await n.attachCustomerDetails({email:this.customer.emailAddress}),n}));return await Promise.all(d)}async initFromIntegrationProduct(t){if(""===t)throw new sa("No integration product ID provided.");const e=Ia.getShadowGraphqlClient(),i=await e.mutate({mutation:Uo,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 sa("Failed to create transaction!");const n=i.data.transactionCreate;if(!n.product)throw new sa("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 sa("No transaction ID provided.");const i=Ia.getShadowGraphqlClient();if(e)return await(async()=>{const n=(await i.query({query:Oo,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!n)throw new sa("Failed to read transaction.");if(!n.product)throw new sa("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:Oo,variables:{ids:[t]},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new sa("Failed to read transaction.");if(!n.product)throw new sa("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:To,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!A)throw new sa("Failed to read transaction.");if(!A.product)throw new sa("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 sa("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,i){if(!this.initialized||!this.experienceOptions)throw new sa("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&&sn(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await ol(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 So(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 rc(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const A=Ia.getShadowGraphqlClient().mutate({mutation:Lo,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),a=ol(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=sl(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=i&&i(await a),this.experienceOptions.renderableContextService=new So(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 rc(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}throw new sa("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new sa("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new sa("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}storeCustomer(t){const e=da.getMap("partnerCustomerIds")||new Map;e.set(t.partner.id,t.id),da.setMap("partnerCustomerIds",e)}}function ll(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 gl{constructor(){ll(this,"getProduct",void 0),ll(this,"getCommandContext",void 0),ll(this,"getAllLayoutData",void 0),ll(this,"getMetadata",void 0),ll(this,"getWorkflowMetadata",void 0),ll(this,"getStepStorage",void 0),ll(this,"setModelContainer",void 0),ll(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 hl(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 dl;var ul;(ul=dl||(dl={})).SelectFrame="SelectFrame",ul.SelectImage="SelectImage",ul.Position="Position";class wl extends Ps{constructor(t,e){super(t,e),hl(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return ls.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 ls.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?dl.SelectFrame:e||i||this.getImageData()?dl.Position:dl.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 Bl=t=>{const e=(0,n.useRef)(null),A=(0,n.useRef)(void 0),[a,r]=(0,n.useState)(void 0),{addEvent:o,removeEvent:s,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=>{s(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))}),[s,l.length]),E=(0,n.useCallback)((t=>{o(t);"touch"===t.pointerType&&1===l.length&&(B(new _a({selectedElement:void 0})),u(!0),h(!0))}),[o,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]),jr([" "],(()=>{u(!0),B(new _a({selectedElement:void 0}))}),(()=>u(!1))),jr(["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})};
|
|
1584
|
+
`),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)))),o=n.filter((t=>void 0!==t));return await Promise.all(o.concat(r))},ol=async(t,e)=>(await rl([t],e))[0],sl=(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 cl{constructor(t){var e;Wc(this,"options",void 0),Wc(this,"initialized",void 0),Wc(this,"currencyCode",void 0),Wc(this,"customer",void 0),Wc(this,"experienceOptions",void 0),Wc(this,"updateTransactionState",(async t=>{try{return Ia.getShadowGraphqlClient().mutate({...t,mutation:Jo})}catch(t){throw console.error(t),new sa("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 Jc}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:gr.Owner})}const i=da.getMap("bundlePartnerIds")||new Map;if(i.has(t)){const e=i.get(t),n=(da.getMap("partnerCustomerIds")||new Map).get(e);if(n){if(await this.authenticateCustomerId(n)){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:_c,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:gr.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 o=(await e.query({query:tl,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!o)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:o.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:el,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!i.id){const i=(await e.mutate({mutation:il,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!i)throw new Error("Unable to create customer.");return this.storeCustomer(i),this.customer=i,{customer:i,isAuthenticated:!1}}this.storeCustomer(i);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:nl,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!A&&(this.storeCustomer(A),Qa(n),this.customer=A,!0)}async generateVerificationCode(t){await Ia.getShadowGraphqlClient().mutate({mutation:Al,variables:{emailAddress:t}})}async verifyCode(t,e){const i=(await Ia.getShadowGraphqlClient().mutate({mutation:al,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),this.storeCustomer(i),Qa(i.loginToken),this.customer={...i,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await Ia.getShadowGraphqlClient().mutate({mutation:hc,variables:{collectionId:t},fetchPolicy:"no-cache"})).data?.bundleCreate;if(!e?.id)throw new Error("Unable to create bundle");const i=da.getMap("bundlePartnerIds")||new Map;i.set(e.id,e.partner.id),da.setMap("bundlePartnerIds",i),fa(e.bundleOwnerId);const n=da.getMap("bundleOwnerIds")||new Map;return n.set(e.id,e.bundleOwnerId),da.setMap("bundleOwnerIds",n),new Gc(this,e)}async getExistingBundle(t,e,i){const n=da.getMap("bundleOwnerIds")?.get(t);n&&fa(n);const A=await Ia.getShadowGraphqlClient().query({query:cc,variables:{id:t},fetchPolicy:"no-cache"});if(!A.data?.bundles||0===A.data?.bundles.length||!A.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const a=A.data?.bundles[0],r=da.getMap("bundlePartnerIds")||new Map;r.set(a.id,a.partner.id),da.setMap("bundlePartnerIds",r);const o=new Gc(this,a,e,i);return await o.getInitializationPromise(),o}async getBundleStakeholders(){if(!this.customer)throw new Error("Customer not authenticated.");const t=await Ia.getShadowGraphqlClient().query({query:gc,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!t.data?.customers||0===t.data.customers.length)throw new Error("Unable to find customer.");const e=t.data.customers[0].bundleStakeholders||[],i=da.getMap("bundlePartnerIds")||new Map;return e.forEach((t=>{t.bundle?.id&&t.bundle.partner?.id&&i.set(t.bundle.id,t.bundle.partner.id)})),da.setMap("bundlePartnerIds",i),e}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&&sn(e.fontData.assetUrl)}}},{transaction:a,workflow:r,readOnly:o}=await(async()=>{const t=Ia.getShadowGraphqlClient();if("transaction"===n.type){const{transactionId:e,readOnly:i}=n,A=await t.query({query:Oo,variables:{ids:[e]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!A.data?.transactions||0===A.data.transactions.length)throw new sa("Existing transaction not found.");const a=A.data?.transactions[0];if(!a.workflowId)throw new sa("Existing transaction has no workflow ID.");const r=await ol(a.workflowId);if(!a.product)throw new sa("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:Uo,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 sa("Failed to create transaction!");const A=i.data.transactionCreate;if(!A.product)throw new sa("Failed to create transaction, product not available.");return A},i=ol(n.workflowId,n?.graphql),[A,a]=await Promise.all([e(),i]);return{transaction:A,workflow:a}}throw new sa("No workflow ID provided.")})();this.currencyCode=a.product.partner?.currencyCode;const s={product:a.product,transaction:a,layouts:[],stateMutationFunc:o?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:o,workflow:r};if("transaction"===n.type&&a.workflowState){const t=JSON.parse(a.workflowState);s.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),s.reloadedState=t}else if(!o&&n.workflowState){const t=JSON.parse(n.workflowState);s.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await A(t),s.reloadedState=t}else s.layouts=sl(s.transaction,s.workflow);if(s.renderableContextService=new So(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=i&&i(r),s.product?.modelUrl&&(s.previewService?.initialize({model:s.product.modelUrl,contextService:s.renderableContextService}),s.modelContainer=s.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),s.isReloadedTransaction=!0}this.initialized=!0,this.experienceOptions=s;const c=new rc(this,s);return await c.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await c.attachCustomerDetails({email:this.customer.emailAddress}),c}async getWorkflowExperiences(t,e){if(0===t.length)throw new sa("No options provided!");const i=Ia.getShadowGraphqlClient(),n=t.map(((t,e)=>({option:t,index:e}))),A=n.filter((t=>"transaction"===t.option.type)),a=n.filter((t=>"integration"===t.option.type||"external"===t.option.type)),r=(await Promise.all([(async()=>{if(0===A.length)return[];const t=A.map((t=>t.option.transactionId)),e=await i.query({query:Oo,variables:{ids:t},errorPolicy:"all",fetchPolicy:"no-cache"}),n=e.data.transactions;if(n.length!==A.length){const t=e.errors?.[0]?.message||"Unknown error";throw new sa(`Not all transactions were found: ${t}`)}return n.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:A.find((e=>e.option.transactionId===t.id))?.option.readOnly??!1,index:A[e].index})))})(),(async()=>{if(0===a.length)return[];const t=await i.mutate({mutation:Go,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"}),e=t.data?.transactionCreateMany;if(!e||0===e.length){const e=t.errors?.[0]?.message||"Unknown error";throw new sa(`Failed to create transactions: ${e}`)}return e.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:!1,index:a[e].index})))})()])).flat(),o=[...new Set(r.map((t=>t.workflowId)))],s=await rl(o,e),c=new Map(s.map((t=>[t.id,t]))),l=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&&sn(e.fontData.assetUrl)}}},g=da.getMap("transactionOwnerIds")||new Map,h=r.map((async e=>{const{transaction:i,workflowId:n,readOnly:A,index:a}=e,r=c.get(n),o=t[a];!g.get(i.id)&&i.transactionOwnerId&&g.set(i.id,i.transactionOwnerId);const s=g.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:s}}),readOnly:A,workflow:r,isReloadedTransaction:"transaction"===o.type};if("transaction"===o.type&&i.workflowState){const t=JSON.parse(i.workflowState);h.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await l(t),h.reloadedState=t}else if(!A&&o.workflowState){const t=JSON.parse(o.workflowState);h.layouts=Object.values(t.layouts).map((t=>t.layout)),await Zn(t),await l(t),h.reloadedState=t}else h.layouts=sl(h.transaction,h.workflow);return h.renderableContextService=new So(h.layouts),this.initialized=!0,this.experienceOptions=h,{experienceOptions:h,index:a,options:o}}));da.setMap("transactionOwnerIds",g);const d=(await Promise.all(h)).sort(((t,e)=>t.index-e.index)).map((async t=>{const{experienceOptions:e,options:i}=t,n=new rc(this,e);return await n.getWorkflowManager().getInitializationPromise(),"transaction"!==i.type&&this.customer&&await n.attachCustomerDetails({email:this.customer.emailAddress}),n}));return await Promise.all(d)}async initFromIntegrationProduct(t){if(""===t)throw new sa("No integration product ID provided.");const e=Ia.getShadowGraphqlClient(),i=await e.mutate({mutation:Uo,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 sa("Failed to create transaction!");const n=i.data.transactionCreate;if(!n.product)throw new sa("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 sa("No transaction ID provided.");const i=Ia.getShadowGraphqlClient();if(e)return await(async()=>{const n=(await i.query({query:Oo,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data?.transactions[0];if(!n)throw new sa("Failed to read transaction.");if(!n.product)throw new sa("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:Oo,variables:{ids:[t]},errorPolicy:"all"})).data?.transactions[0];if(!n)throw new sa("Failed to read transaction.");if(!n.product)throw new sa("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:To,variables:{id:t},errorPolicy:"all"})).data?.transactionClaim;if(!A)throw new sa("Failed to read transaction.");if(!A.product)throw new sa("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 sa("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(t,e,i){if(!this.initialized||!this.experienceOptions)throw new sa("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&&sn(e.fontData.assetUrl)}}};if(this.experienceOptions.transaction.workflowId){const t=await ol(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 So(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 rc(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const A=Ia.getShadowGraphqlClient().mutate({mutation:Lo,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),a=ol(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=sl(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=i&&i(await a),this.experienceOptions.renderableContextService=new So(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 rc(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}throw new sa("No workflow ID provided.")}getPreviewService(){return this.experienceOptions?.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new sa("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new sa("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}storeCustomer(t){const e=da.getMap("partnerCustomerIds")||new Map;e.set(t.partner.id,t.id),da.setMap("partnerCustomerIds",e)}}function ll(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 gl{constructor(){ll(this,"getProduct",void 0),ll(this,"getCommandContext",void 0),ll(this,"getAllLayoutData",void 0),ll(this,"getMetadata",void 0),ll(this,"getWorkflowMetadata",void 0),ll(this,"getStepStorage",void 0),ll(this,"setModelContainer",void 0),ll(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 hl(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 dl;var ul;(ul=dl||(dl={})).SelectFrame="SelectFrame",ul.SelectImage="SelectImage",ul.Position="Position";class wl extends Ps{constructor(t,e){super(t,e),hl(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return ls.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 ls.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?dl.SelectFrame:e||i||this.getImageData()?dl.Position:dl.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 Bl=t=>{const e=(0,n.useRef)(null),A=(0,n.useRef)(void 0),[a,r]=(0,n.useState)(void 0),{addEvent:o,removeEvent:s,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=>{s(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))}),[s,l.length]),E=(0,n.useCallback)((t=>{o(t);"touch"===t.pointerType&&1===l.length&&(B(new _a({selectedElement:void 0})),u(!0),h(!0))}),[o,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]),jr([" "],(()=>{u(!0),B(new _a({selectedElement:void 0}))}),(()=>u(!1))),jr(["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})};
|
|
1584
1585
|
//# sourceMappingURL=main.js.map
|
package/dist/module.js
CHANGED
|
@@ -579,18 +579,19 @@ import{CommandContext as t,AssetType as e,BringForwardCommand as A,BringToFrontC
|
|
|
579
579
|
`;class ka extends Na{constructor(t,e){super(t,e),Ra(this,"transaction",this.manager.getTransaction())}selectVariant(){throw new Error("Bulk step does not support variants.")}async setDesignName(t){await ye.getShadowGraphqlClient().mutate({mutation:ba,variables:{transactionId:this.manager.getTransaction().id,designName:t}});const e=this.manager.getTransaction();this.manager.setTransaction({...e,designName:t})}addVariationRecord(){const t=this.manager.addVariationRecord({transactionId:this.transaction.id,values:[]});return this.manager.setCurrentVariationRecord(t),t}updateBulkIsConnected(t){this.manager.updateStorage(this.getId(),{bulkIsConnected:t})}openBulkSourceUrl(){window.open(this.transaction.bulkSourceUrl,"_blank")}async sendGoogleSheetLinkToEmail(t){await ye.getShadowGraphqlClient().mutate({mutation:Ha,variables:{id:this.transaction.id,details:{emailAddress:t},type:"Owner"}}),this.openBulkSourceUrl()}deleteVariationRecord(t){this.manager.removeVariationRecord(t)}getAspects(){return this.step.data.aspects}}class Ua extends Na{constructor(t,e){super(t,e)}async selectVariant(t){if(this.getCurrentVariant()!==t)return Ba.selectVariant(this.step,t.getResource(),this.manager.getRegionElements(this.step.stepName)||[],(t=>this.setUpdateState(t)),this.manager)}getColors(){const t=this.manager.getRegionElements(this.step.stepName)||[];if(0!==t.length)try{return y(t[0].id,this.manager.getAllLayoutData()).colors}catch(t){console.error(t)}}setColor(t,e){const A=new Map;return A.set(t,e),Ba.changeColors(this.step,this.manager.getRegionElements(this.step.stepName),this.manager,(()=>this.manager.getCommandContext().getAllLayouts()),A)}async getColorOption(){return this.step.data.colorOption}getAvailableColors(){return this.step.data.colorPickerEnabled?Ba.availableColors(this.step,this.manager):Promise.resolve([])}hasVaryingSelection(){return this.step.data.varySelection}hasVaryingColors(){return this.step.data.varyColors}isColorPickerEnabled(){return this.step.data.colorPickerEnabled}}class Ga extends Na{constructor(t,e){super(t,e)}selectVariant(t){return da.selectVariant(this.step,t.getResource(),this.manager,(t=>this.setUpdateState(t)))}}class Ja extends Na{constructor(t,e){super(t,e)}selectVariant(t){return wa.selectVariant(this.step,t.getResource(),this.manager,(t=>this.setUpdateState(t)))}}class Ta extends Na{constructor(t,e){super(t,e)}selectVariant(t){return Ea.selectVariant(this.step,t.getResource(),this.manager,(t=>this.setUpdateState(t)))}}class La extends Na{constructor(t,e){super(t,e)}async selectVariant(t){if(!t.getId())throw new Error("Unable to select variant with a null ID");await ua.selectVariant(this.step,t.getId(),this.manager)}getDisplayType(){return this.step.option?.displayType}}class Oa extends Na{constructor(t,e){super(t,e)}selectVariant(t){const e=t.getResource();return Qa.selectVariant(this.step,{fill:e.color,stroke:e.color,variant:e},this.manager.getRegionElements(this.step.stepName)||[],this.manager)}setColor(t){return Qa.selectVariant(this.step,t,this.manager.getRegionElements(this.step.stepName)||[],this.manager)}getColors(){return Qa.availableColours(this.step)}setCustomColor(t){if("#custom"!==this.getCurrentVariant()?.getColor())throw new Error("Custom colors can only be set on a non-custom variant. Please add a custom variant to the step.");return Qa.setCustomColor(t,this.step,this.manager)}getCustomColor(){const t=this.manager.getStepStorage(this.step.stepName)?.colour;if("#custom"!==this.getCurrentVariant()?.getColor())throw new Error("Custom colors can only be set on a non-custom variant. Please add a custom variant to the step.");if(!t)throw new Error("Color not available on step. Set a default on the workflow to fix this.");return t}}class za extends Na{constructor(t,e){super(t,e)}async selectVariant(t){Ia.selectVariant(this.step,t.getResource(),this.manager,(t=>{if(t)this.manager.setInformationResults([...this.manager.getInformationResults(),{message:"An issue has occured with test",messageType:Ma.Error,stepID:this.step.stepName}]);else{const t=this.manager.getInformationResults().filter((t=>t.stepID!==this.step.stepName));this.manager.setInformationResults(t)}}),(t=>{}))}getAvailableFillColors(){return this.step.data.colorPickerEnabled?Ia.availableFillColors(this.step):[]}async setFillColor(t){const e=this.manager.getRegionElements(this.step.stepName);await Ia.changeFillColor(this.step,t,e,this.manager)}getFillColor(){return this.manager.getStepStorage(this.step.stepName)?.color||"#000000"}getAvailableFillImages(){return Ia.availableFillImages(this.step)}async setFillImage(t){const e=this.manager.getRegionElements(this.step.stepName);await Ia.changeFillImage(this.step,t,e,this.manager)}getFillImage(){return this.manager.getStepStorage(this.step.stepName)?.fillImage}setFullTextCustomization(t){const e=this.manager.getStepStorage(this.step.stepName)?.inputText||"",A=void 0!==this.step.data.replaceableText?this.step.data.replaceableText.replace("{{}}",e):e,n=t?A:this.step.data.defaultText;this.manager.updateStorage(this.step.stepName,{customiseAllText:t,text:n,defaultCleared:!1});return this.setText(n)}setText(t){const e={input:t},A=Ia.findLayoutElements(this.manager,this.step),n=Ia.filterUnsupportedCharacters(t,A[0]?.fontData);!!this.step.data&&!!this.step.data.maxLength&&n.length>this.step.data.maxLength||(e.input=n);const a=A.length<=0,i=a?{inputText:n,text:n}:{inputText:n};if(this.manager.updateStorage(this.step.stepName,i),this.manager.updateMetadata(this.step.stepName,{text:n}),a)return e;const{command:o,errors:r,helperText:s}=Ia.updateInputText(n,A,this.step,this.manager);o&&this.manager.getCommandDispatcher()(o);const c=this.manager.getInformationResults(),g=r[0]?.localizationKey;if(g)this.manager.setInformationResults([...c,{message:`${g} - ${this.step.stepTitle}`,messageType:Ma.Error,stepID:this.step.stepName}]);else{const t=c.filter((t=>t.stepID!==this.step.stepName));this.manager.setInformationResults(t)}return e.helperText=g||s,e.errorText=g,e}getText(){const t=this.step.data.defaultText;return this.manager.getStepStorage(this.step.stepName)?.text||t||""}isReplaceable(){return this.step.data.userCanReplaceText}clearDefaultTextIfNecessary(){if(!this.manager.getStepStorage(this.step.stepName)?.defaultCleared&&this.step.data.deleteDefaultOnFocus){const t=this.setText("");return this.manager.updateStorage(this.step.stepName,{defaultCleared:!0,inputText:""}),t}}hasVaryingText(){return this.step.data.varyText}hasVaryingColor(){return this.step.data.varyColor}hasVaryingSelection(){return this.step.data.varySelection}hasColorPicker(){return this.step.data.colorPickerEnabled}getRegions(){return this.step.data.regions}getCharacterLimit(){return this.step.data.maxLength}getCharactersRemaining(){const t=this.step.data.maxLength;if(void 0===t)return;return t-this.getText().length}}class ja extends Na{constructor(t,e){super(t,e)}async selectVariant(){}getContent(){return this.step.data.content}}class Ka{static get(t,e){switch(e.type){case m.Information:return new ja(t,e);case m.Question:return new La(t,e);case m.Text:return new za(t,e);case m.Illustration:return new Ua(t,e);case m.Picture:return new Ta(t,e);case m.Shape:return new Oa(t,e);case m.Material:return new Ga(t,e);case m.Model:return new Ja(t,e);case m.Frame:return new Eo(t,e);case m.Bulk:return new ka(t,e);default:throw new re(`Step type ${e.type} not yet supported in Core SDK`)}}}function Va(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}const Wa=It`
|
|
580
580
|
fragment CreateDesignTransaction on Transaction {
|
|
581
581
|
id
|
|
582
|
-
designName
|
|
583
582
|
bulk
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
externalDesignProductId
|
|
587
|
-
externalDesignProductVariantId
|
|
583
|
+
bulkEmailAddress
|
|
584
|
+
designName
|
|
588
585
|
externalCartProductId
|
|
589
586
|
externalCartProductVariantId
|
|
587
|
+
externalDesignProductId
|
|
588
|
+
externalDesignProductVariantId
|
|
589
|
+
lastSyncedAt
|
|
590
|
+
previewImageLink
|
|
591
|
+
priceModifierTotal
|
|
592
|
+
variationsCount
|
|
590
593
|
workflowViewerLink
|
|
591
594
|
workflowViewerReadOnlyLink
|
|
592
|
-
lastSyncedAt
|
|
593
|
-
bulkEmailAddress
|
|
594
595
|
}
|
|
595
596
|
`,Xa=It`
|
|
596
597
|
${Wa}
|
|
@@ -1580,5 +1581,5 @@ import{CommandContext as t,AssetType as e,BringForwardCommand as A,BringToFrontC
|
|
|
1580
1581
|
}
|
|
1581
1582
|
}
|
|
1582
1583
|
}
|
|
1583
|
-
`),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)})),Ue.set({id:t.option.id},Promise.resolve(t.option)))}))})),a})(n,e),i=n.map((t=>Ue.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))},ro=async(t,e)=>(await oo([t],e))[0],so=(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 co{constructor(t){var e;Wi(this,"options",void 0),Wi(this,"initialized",void 0),Wi(this,"currencyCode",void 0),Wi(this,"customer",void 0),Wi(this,"experienceOptions",void 0),Wi(this,"updateTransactionState",(async t=>{try{return ye.getShadowGraphqlClient().mutate({...t,mutation:On})}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 Li}async authenticateBundleFromLocalStorage(t){const e=we.getMap("bundleOwnerIds");if(e?.has(t)){const A=e.get(t);return me(A),Promise.resolve({success:!0,stakeholderType:BA.Owner})}const A=we.getMap("bundlePartnerIds")||new Map;if(A.has(t)){const e=A.get(t),n=(we.getMap("partnerCustomerIds")||new Map).get(e);if(n){if(await this.authenticateCustomerId(n)){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:_i,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=we.getMap("transactionOwnerIds");if(i?.has(t)){const e=i.get(t);return Qe(e),Promise.resolve({success:!0,stakeholderType:BA.Owner})}const o=we.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:to,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=we.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),we.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:eo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!A.id){const A=(await e.mutate({mutation:Ao,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!A)throw new Error("Unable to create customer.");return this.storeCustomer(A),this.customer=A,{customer:A,isAuthenticated:!1}}this.storeCustomer(A);const n=await this.authenticateCustomerId(A.id);return{customer:this.customer||A,isAuthenticated:n}}async authenticateCustomerId(t){const e=ye.getShadowGraphqlClient(),A=we.getMap("customerTokens");if(!A?.has(t))return!1;const n=A.get(t);if(!n)return!1;const a=(await e.mutate({mutation:no,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!a&&(this.storeCustomer(a),De(n),this.customer=a,!0)}async generateVerificationCode(t){await ye.getShadowGraphqlClient().mutate({mutation:ao,variables:{emailAddress:t}})}async verifyCode(t,e){const A=(await ye.getShadowGraphqlClient().mutate({mutation:io,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=we.getMap("customerTokens")||new Map;return e.set(A.id,A.loginToken),we.setMap("customerTokens",e),this.storeCustomer(A),De(A.loginToken),this.customer={...A,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await ye.getShadowGraphqlClient().mutate({mutation:Bi,variables:{collectionId:t},fetchPolicy:"no-cache"})).data?.bundleCreate;if(!e?.id)throw new Error("Unable to create bundle");const A=we.getMap("bundlePartnerIds")||new Map;A.set(e.id,e.partner.id),we.setMap("bundlePartnerIds",A),me(e.bundleOwnerId);const n=we.getMap("bundleOwnerIds")||new Map;return n.set(e.id,e.bundleOwnerId),we.setMap("bundleOwnerIds",n),new Gi(this,e)}async getExistingBundle(t,e,A){const n=we.getMap("bundleOwnerIds")?.get(t);n&&me(n);const a=await ye.getShadowGraphqlClient().query({query:ci,variables:{id:t},fetchPolicy:"no-cache"});if(!a.data?.bundles||0===a.data?.bundles.length||!a.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const i=a.data?.bundles[0],o=we.getMap("bundlePartnerIds")||new Map;o.set(i.id,i.partner.id),we.setMap("bundlePartnerIds",o);const r=new Gi(this,i,e,A);return await r.getInitializationPromise(),r}async getBundleStakeholders(){if(!this.customer)throw new Error("Customer not authenticated.");const t=await ye.getShadowGraphqlClient().query({query:li,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 wt(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:Ln,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 ro(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:Gn,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=ro(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=(we.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=so(s.transaction,s.workflow);if(s.renderableContextService=new vn(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=we.getMap("transactionOwnerIds")||new Map;t.set(i.id,i.transactionOwnerId),Qe(i.transactionOwnerId||""),we.setMap("transactionOwnerIds",t)}else{const t=(we.getMap("transactionOwnerIds")||new Map).get(i.id);t&&Qe(t),s.isReloadedTransaction=!0}this.initialized=!0,this.experienceOptions=s;const c=new ri(this,s);return await c.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await c.attachCustomerDetails({email:this.customer.emailAddress}),c}async getWorkflowExperiences(t,e){if(0===t.length)throw new ce("No options provided!");const A=ye.getShadowGraphqlClient(),n=t.map(((t,e)=>({option:t,index:e}))),a=n.filter((t=>"transaction"===t.option.type)),i=n.filter((t=>"integration"===t.option.type||"external"===t.option.type)),o=(await Promise.all([(async()=>{if(0===a.length)return[];const t=a.map((t=>t.option.transactionId)),e=await A.query({query:Ln,variables:{ids:t},errorPolicy:"all",fetchPolicy:"no-cache"}),n=e.data.transactions;if(n.length!==a.length){const t=e.errors?.[0]?.message||"Unknown error";throw new ce(`Not all transactions were found: ${t}`)}return n.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:a.find((e=>e.option.transactionId===t.id))?.option.readOnly??!1,index:a[e].index})))})(),(async()=>{if(0===i.length)return[];const t=await A.mutate({mutation:Jn,variables:{inputs:i.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"}),e=t.data?.transactionCreateMany;if(!e||0===e.length){const e=t.errors?.[0]?.message||"Unknown error";throw new ce(`Failed to create transactions: ${e}`)}return e.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:!1,index:i[e].index})))})()])).flat(),r=[...new Set(o.map((t=>t.workflowId)))],s=await oo(r,e),c=new Map(s.map((t=>[t.id,t]))),g=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 wt(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)}}},l=we.getMap("transactionOwnerIds")||new Map,B=o.map((async e=>{const{transaction:A,workflowId:n,readOnly:a,index:i}=e,o=c.get(n),r=t[i];!l.get(A.id)&&A.transactionOwnerId&&l.set(A.id,A.transactionOwnerId);const s=l.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:s}}),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 g(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 g(t),B.reloadedState=t}else B.layouts=so(B.transaction,B.workflow);return B.renderableContextService=new vn(B.layouts),this.initialized=!0,this.experienceOptions=B,{experienceOptions:B,index:i,options:r}}));we.setMap("transactionOwnerIds",l);const d=(await Promise.all(B)).sort(((t,e)=>t.index-e.index)).map((async t=>{const{experienceOptions:e,options:A}=t,n=new ri(this,e);return await n.getWorkflowManager().getInitializationPromise(),"transaction"!==A.type&&this.customer&&await n.attachCustomerDetails({email:this.customer.emailAddress}),n}));return await Promise.all(d)}async initFromIntegrationProduct(t){if(""===t)throw new ce("No integration product ID provided.");const e=ye.getShadowGraphqlClient(),A=await e.mutate({mutation:Gn,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=we.getMap("transactionOwnerIds")||new Map;a.set(n.id,n.transactionOwnerId),Qe(n.transactionOwnerId||""),we.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:Ln,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=we.getMap("transactionOwnerIds")||new Map,a=n.get(t);if(a){Qe(a);const n=(await A.query({query:Ln,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:Tn,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),we.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 wt(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 ro(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 vn(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 ri(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const a=ye.getShadowGraphqlClient().mutate({mutation:zn,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),i=ro(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=so(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await i),this.experienceOptions.renderableContextService=new vn(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 ri(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}storeCustomer(t){const e=we.getMap("partnerCustomerIds")||new Map;e.set(t.partner.id,t.id),we.setMap("partnerCustomerIds",e)}}function go(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 lo{constructor(){go(this,"getProduct",void 0),go(this,"getCommandContext",void 0),go(this,"getAllLayoutData",void 0),go(this,"getMetadata",void 0),go(this,"getWorkflowMetadata",void 0),go(this,"getStepStorage",void 0),go(this,"setModelContainer",void 0),go(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 Bo(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 wo;var ho;(ho=wo||(wo={})).SelectFrame="SelectFrame",ho.SelectImage="SelectImage",ho.Position="Position";class Eo extends Na{constructor(t,e){super(t,e),Bo(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return la.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 la.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?wo.SelectFrame:e||A||this.getImageData()?wo.Position:wo.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 uo=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:d,uiDispatcher:w}=eA(),h=Rt((t=>{const e=t;w(new tA({zoom:Math.max(.1,Math.min(e,d.maxZoom))}))}),[w,d.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&&(w(new tA({selectedElement:void 0})),B(!0),g(!0))}),[i,s.length,w]),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(d.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;w(new tA({selectedElement:void 0,xTranslation:d.xTranslation-e/d.zoom,yTranslation:d.yTranslation-n/d.zoom}))}t.isPrimary&&(A.current={x:t.screenX,y:t.screenY})}),[r,s,c,l,n,h,d.zoom,d.xTranslation,d.yTranslation,w]),Q=Rt((t=>{c&&h(d.zoom-.035*Math.sign(t.deltaY))}),[h,d.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]),KA([" "],(()=>{B(!0),w(new tA({selectedElement:void 0}))}),(()=>B(!1))),KA(["Control"],(()=>g(!0)),(()=>g(!1)));const p=Ut((()=>({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{co as SpiffCommerceClient,t as CommandContext,Ee as spiffCoreConfiguration,qA as PromiseQueue,XA as QueueablePromise,lo as MockWorkflowManager,Ma as InformationMessageType,Na as StepHandle,za as TextStepHandle,Eo as FrameStepHandle,ka as BulkStepHandle,Oa as ShapeStepHandle,ja as InformationStepHandle,Ua as IllustrationStepHandle,Ga as MaterialStepHandle,Ja as ModelStepHandle,Ta as PictureStepHandle,La as QuestionStepHandle,Di as GlobalPropertyHandle,oA as BulkPriceCalculationStrategy,xa as Variant,ri 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,ii as designService,ei as createDesign,Oe as optionService,we as persistenceService,ye as graphQlManager,EA as toast,na as FrameService,ea as getBoundedOffsets,la as frameStepService,wa as modelStepService,da as materialStepService,Qa as shapeStepService,ua as questionStepService,ca as digitalContentStepService,ha as moduleStepService,Ea as pictureStepService,Ia as textStepService,Ba as illustrationStepService,aA as ProductCameraRig,wo as FrameStep,sA as ConversionLocation,gA as ConversionDataType,ro as getWorkflow,oo as getWorkflows,oa as shortenUrl,Ki as ObjectInput,Vi as TextInput,zi as ObjectInputType,bi as ProductCollection,ki as CollectionProduct,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,d as GroupCommand,w as LayoutElementFactory,h as LayoutElementType,E as MoveCommand,u as ResizeCommand,C as RotateCommand,Q as SendBackwardsCommand,BA 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,S as getAxisAlignedBoundingBox,Y as generateSVGWithUnknownColors,v as getAttributesFromArrayBuffer,x as rehydrateSerializedLayout,P as getFrameData,N as getSvgElement,R as loadFontFromDataUrl,H as loadFontFromExternalUrl,b as determineCorrectFontSizeAndLines,k as patternImageDataCache,Sn as generateCommands,U as registerJSDOM,OA as minZoom,Un as AdvancedEditor,uo as TransformWrapper,kn as EditorCore,Ke as useLayouts,eA as useEditorState,jA as useEditorInteraction,KA as useShortcutCombination,Ze as commandReducer,qe as getDefaultState,ze as CommandContextContext,_e as AdvancedEditorStateProvider,$e as AdvancedEditorContext,tA as UICommand,We as EditorSubMenu,uA as ElementEventType,QA as KeyEvent,Vn as gatherVaryingStepAspects};
|
|
1584
|
+
`),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)})),Ue.set({id:t.option.id},Promise.resolve(t.option)))}))})),a})(n,e),i=n.map((t=>Ue.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))},ro=async(t,e)=>(await oo([t],e))[0],so=(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 co{constructor(t){var e;Wi(this,"options",void 0),Wi(this,"initialized",void 0),Wi(this,"currencyCode",void 0),Wi(this,"customer",void 0),Wi(this,"experienceOptions",void 0),Wi(this,"updateTransactionState",(async t=>{try{return ye.getShadowGraphqlClient().mutate({...t,mutation:On})}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 Li}async authenticateBundleFromLocalStorage(t){const e=we.getMap("bundleOwnerIds");if(e?.has(t)){const A=e.get(t);return me(A),Promise.resolve({success:!0,stakeholderType:BA.Owner})}const A=we.getMap("bundlePartnerIds")||new Map;if(A.has(t)){const e=A.get(t),n=(we.getMap("partnerCustomerIds")||new Map).get(e);if(n){if(await this.authenticateCustomerId(n)){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:_i,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=we.getMap("transactionOwnerIds");if(i?.has(t)){const e=i.get(t);return Qe(e),Promise.resolve({success:!0,stakeholderType:BA.Owner})}const o=we.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:to,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=we.getMap("transactionCustomerIds");e?.has(t)&&(e.delete(t),we.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:eo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!A.id){const A=(await e.mutate({mutation:Ao,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data?.customerCreate;if(!A)throw new Error("Unable to create customer.");return this.storeCustomer(A),this.customer=A,{customer:A,isAuthenticated:!1}}this.storeCustomer(A);const n=await this.authenticateCustomerId(A.id);return{customer:this.customer||A,isAuthenticated:n}}async authenticateCustomerId(t){const e=ye.getShadowGraphqlClient(),A=we.getMap("customerTokens");if(!A?.has(t))return!1;const n=A.get(t);if(!n)return!1;const a=(await e.mutate({mutation:no,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data?.customerAuthenticate;return!!a&&(this.storeCustomer(a),De(n),this.customer=a,!0)}async generateVerificationCode(t){await ye.getShadowGraphqlClient().mutate({mutation:ao,variables:{emailAddress:t}})}async verifyCode(t,e){const A=(await ye.getShadowGraphqlClient().mutate({mutation:io,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=we.getMap("customerTokens")||new Map;return e.set(A.id,A.loginToken),we.setMap("customerTokens",e),this.storeCustomer(A),De(A.loginToken),this.customer={...A,loginToken:void 0},!0}return!1}async getNewBundle(t){const e=(await ye.getShadowGraphqlClient().mutate({mutation:Bi,variables:{collectionId:t},fetchPolicy:"no-cache"})).data?.bundleCreate;if(!e?.id)throw new Error("Unable to create bundle");const A=we.getMap("bundlePartnerIds")||new Map;A.set(e.id,e.partner.id),we.setMap("bundlePartnerIds",A),me(e.bundleOwnerId);const n=we.getMap("bundleOwnerIds")||new Map;return n.set(e.id,e.bundleOwnerId),we.setMap("bundleOwnerIds",n),new Gi(this,e)}async getExistingBundle(t,e,A){const n=we.getMap("bundleOwnerIds")?.get(t);n&&me(n);const a=await ye.getShadowGraphqlClient().query({query:ci,variables:{id:t},fetchPolicy:"no-cache"});if(!a.data?.bundles||0===a.data?.bundles.length||!a.data?.bundles[0])throw new Error(`Unable to find bundle: ${t}`);const i=a.data?.bundles[0],o=we.getMap("bundlePartnerIds")||new Map;o.set(i.id,i.partner.id),we.setMap("bundlePartnerIds",o);const r=new Gi(this,i,e,A);return await r.getInitializationPromise(),r}async getBundleStakeholders(){if(!this.customer)throw new Error("Customer not authenticated.");const t=await ye.getShadowGraphqlClient().query({query:li,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!t.data?.customers||0===t.data.customers.length)throw new Error("Unable to find customer.");const e=t.data.customers[0].bundleStakeholders||[],A=we.getMap("bundlePartnerIds")||new Map;return e.forEach((t=>{t.bundle?.id&&t.bundle.partner?.id&&A.set(t.bundle.id,t.bundle.partner.id)})),we.setMap("bundlePartnerIds",A),e}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 wt(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:Ln,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 ro(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:Gn,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=ro(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=(we.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=so(s.transaction,s.workflow);if(s.renderableContextService=new vn(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=we.getMap("transactionOwnerIds")||new Map;t.set(i.id,i.transactionOwnerId),Qe(i.transactionOwnerId||""),we.setMap("transactionOwnerIds",t)}else{const t=(we.getMap("transactionOwnerIds")||new Map).get(i.id);t&&Qe(t),s.isReloadedTransaction=!0}this.initialized=!0,this.experienceOptions=s;const c=new ri(this,s);return await c.getWorkflowManager().getInitializationPromise(),"transaction"!==n.type&&this.customer&&await c.attachCustomerDetails({email:this.customer.emailAddress}),c}async getWorkflowExperiences(t,e){if(0===t.length)throw new ce("No options provided!");const A=ye.getShadowGraphqlClient(),n=t.map(((t,e)=>({option:t,index:e}))),a=n.filter((t=>"transaction"===t.option.type)),i=n.filter((t=>"integration"===t.option.type||"external"===t.option.type)),o=(await Promise.all([(async()=>{if(0===a.length)return[];const t=a.map((t=>t.option.transactionId)),e=await A.query({query:Ln,variables:{ids:t},errorPolicy:"all",fetchPolicy:"no-cache"}),n=e.data.transactions;if(n.length!==a.length){const t=e.errors?.[0]?.message||"Unknown error";throw new ce(`Not all transactions were found: ${t}`)}return n.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:a.find((e=>e.option.transactionId===t.id))?.option.readOnly??!1,index:a[e].index})))})(),(async()=>{if(0===i.length)return[];const t=await A.mutate({mutation:Jn,variables:{inputs:i.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"}),e=t.data?.transactionCreateMany;if(!e||0===e.length){const e=t.errors?.[0]?.message||"Unknown error";throw new ce(`Failed to create transactions: ${e}`)}return e.map(((t,e)=>({transaction:t,workflowId:t.workflowId,readOnly:!1,index:i[e].index})))})()])).flat(),r=[...new Set(o.map((t=>t.workflowId)))],s=await oo(r,e),c=new Map(s.map((t=>[t.id,t]))),g=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 wt(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)}}},l=we.getMap("transactionOwnerIds")||new Map,B=o.map((async e=>{const{transaction:A,workflowId:n,readOnly:a,index:i}=e,o=c.get(n),r=t[i];!l.get(A.id)&&A.transactionOwnerId&&l.set(A.id,A.transactionOwnerId);const s=l.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:s}}),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 g(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 g(t),B.reloadedState=t}else B.layouts=so(B.transaction,B.workflow);return B.renderableContextService=new vn(B.layouts),this.initialized=!0,this.experienceOptions=B,{experienceOptions:B,index:i,options:r}}));we.setMap("transactionOwnerIds",l);const d=(await Promise.all(B)).sort(((t,e)=>t.index-e.index)).map((async t=>{const{experienceOptions:e,options:A}=t,n=new ri(this,e);return await n.getWorkflowManager().getInitializationPromise(),"transaction"!==A.type&&this.customer&&await n.attachCustomerDetails({email:this.customer.emailAddress}),n}));return await Promise.all(d)}async initFromIntegrationProduct(t){if(""===t)throw new ce("No integration product ID provided.");const e=ye.getShadowGraphqlClient(),A=await e.mutate({mutation:Gn,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=we.getMap("transactionOwnerIds")||new Map;a.set(n.id,n.transactionOwnerId),Qe(n.transactionOwnerId||""),we.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:Ln,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=we.getMap("transactionOwnerIds")||new Map,a=n.get(t);if(a){Qe(a);const n=(await A.query({query:Ln,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:Tn,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),we.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 wt(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 ro(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 vn(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 ri(this,this.experienceOptions);return await e.getWorkflowManager().getInitializationPromise(),e}if(t){const a=ye.getShadowGraphqlClient().mutate({mutation:zn,variables:{workflowId:t,id:this.experienceOptions.transaction.id}}),i=ro(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=so(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await i),this.experienceOptions.renderableContextService=new vn(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 ri(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}storeCustomer(t){const e=we.getMap("partnerCustomerIds")||new Map;e.set(t.partner.id,t.id),we.setMap("partnerCustomerIds",e)}}function go(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 lo{constructor(){go(this,"getProduct",void 0),go(this,"getCommandContext",void 0),go(this,"getAllLayoutData",void 0),go(this,"getMetadata",void 0),go(this,"getWorkflowMetadata",void 0),go(this,"getStepStorage",void 0),go(this,"setModelContainer",void 0),go(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 Bo(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 wo;var ho;(ho=wo||(wo={})).SelectFrame="SelectFrame",ho.SelectImage="SelectImage",ho.Position="Position";class Eo extends Na{constructor(t,e){super(t,e),Bo(this,"frameService",this.manager.getStepSpecificServices(this.getId())?.frameService)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return la.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 la.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?wo.SelectFrame:e||A||this.getImageData()?wo.Position:wo.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 uo=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:d,uiDispatcher:w}=eA(),h=Rt((t=>{const e=t;w(new tA({zoom:Math.max(.1,Math.min(e,d.maxZoom))}))}),[w,d.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&&(w(new tA({selectedElement:void 0})),B(!0),g(!0))}),[i,s.length,w]),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(d.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;w(new tA({selectedElement:void 0,xTranslation:d.xTranslation-e/d.zoom,yTranslation:d.yTranslation-n/d.zoom}))}t.isPrimary&&(A.current={x:t.screenX,y:t.screenY})}),[r,s,c,l,n,h,d.zoom,d.xTranslation,d.yTranslation,w]),Q=Rt((t=>{c&&h(d.zoom-.035*Math.sign(t.deltaY))}),[h,d.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]),KA([" "],(()=>{B(!0),w(new tA({selectedElement:void 0}))}),(()=>B(!1))),KA(["Control"],(()=>g(!0)),(()=>g(!1)));const p=Ut((()=>({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{co as SpiffCommerceClient,t as CommandContext,Ee as spiffCoreConfiguration,qA as PromiseQueue,XA as QueueablePromise,lo as MockWorkflowManager,Ma as InformationMessageType,Na as StepHandle,za as TextStepHandle,Eo as FrameStepHandle,ka as BulkStepHandle,Oa as ShapeStepHandle,ja as InformationStepHandle,Ua as IllustrationStepHandle,Ga as MaterialStepHandle,Ja as ModelStepHandle,Ta as PictureStepHandle,La as QuestionStepHandle,Di as GlobalPropertyHandle,oA as BulkPriceCalculationStrategy,xa as Variant,ri 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,ii as designService,ei as createDesign,Oe as optionService,we as persistenceService,ye as graphQlManager,EA as toast,na as FrameService,ea as getBoundedOffsets,la as frameStepService,wa as modelStepService,da as materialStepService,Qa as shapeStepService,ua as questionStepService,ca as digitalContentStepService,ha as moduleStepService,Ea as pictureStepService,Ia as textStepService,Ba as illustrationStepService,aA as ProductCameraRig,wo as FrameStep,sA as ConversionLocation,gA as ConversionDataType,ro as getWorkflow,oo as getWorkflows,oa as shortenUrl,Ki as ObjectInput,Vi as TextInput,zi as ObjectInputType,bi as ProductCollection,ki as CollectionProduct,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,d as GroupCommand,w as LayoutElementFactory,h as LayoutElementType,E as MoveCommand,u as ResizeCommand,C as RotateCommand,Q as SendBackwardsCommand,BA 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,S as getAxisAlignedBoundingBox,Y as generateSVGWithUnknownColors,v as getAttributesFromArrayBuffer,x as rehydrateSerializedLayout,P as getFrameData,N as getSvgElement,R as loadFontFromDataUrl,H as loadFontFromExternalUrl,b as determineCorrectFontSizeAndLines,k as patternImageDataCache,Sn as generateCommands,U as registerJSDOM,OA as minZoom,Un as AdvancedEditor,uo as TransformWrapper,kn as EditorCore,Ke as useLayouts,eA as useEditorState,jA as useEditorInteraction,KA as useShortcutCombination,Ze as commandReducer,qe as getDefaultState,ze as CommandContextContext,_e as AdvancedEditorStateProvider,$e as AdvancedEditorContext,tA as UICommand,We as EditorSubMenu,uA as ElementEventType,QA as KeyEvent,Vn as gatherVaryingStepAspects};
|
|
1584
1585
|
//# sourceMappingURL=module.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1490,7 +1490,7 @@ export class Variant {
|
|
|
1490
1490
|
getThumbnail(): string | undefined;
|
|
1491
1491
|
/**
|
|
1492
1492
|
* @returns The URL for the display image configured on this variant. Can be used for things like size charts.
|
|
1493
|
-
* @deprecated To be removed in a future version
|
|
1493
|
+
* @deprecated To be removed in a future version, Please use getThumbnail() instead
|
|
1494
1494
|
*/
|
|
1495
1495
|
getDisplayImage(): string | undefined;
|
|
1496
1496
|
/**
|