@spiffcommerce/core 18.5.0-alpha.0 → 18.5.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9664,7 +9664,7 @@ class Ei {
|
|
|
9664
9664
|
return (await N.getShadowGraphqlClient().query({
|
|
9665
9665
|
query: ii,
|
|
9666
9666
|
errorPolicy: "all"
|
|
9667
|
-
})).data;
|
|
9667
|
+
})).data.currentIntegration;
|
|
9668
9668
|
}
|
|
9669
9669
|
// TODO: Authentication functions should probably be moved to a separate class.
|
|
9670
9670
|
/**
|
package/dist/index.umd.cjs
CHANGED
|
@@ -2892,4 +2892,4 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
2892
2892
|
}
|
|
2893
2893
|
}
|
|
2894
2894
|
}
|
|
2895
|
-
`,ee=async g=>{var e;for(const A in g.layouts){const t=g.layouts[A].elements.filter(a=>a.type===c.LayoutElementType.Illustration);for(let a=0;a<t.length;++a){const i=t[a];i.src&&i.svg&&(i.cachedObjectURL=await c.svgObjectURL(i.svg))}const n=g.layouts[A].elements.filter(a=>a.type===c.LayoutElementType.Textbox);for(let a=0;a<n.length;++a){const i=n[a];(e=i.fontData)!=null&&e.assetUrl&&await c.loadFont(i.fontData.assetUrl)}}},ca=async(g,e)=>{var n;const A=await x.getShadowGraphqlClient().query({query:ea(((n=e==null?void 0:e.assets)==null?void 0:n.metadata)||!1),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:g}}),t=A.data.workflows;if(t===void 0||t.length!==g.length)throw new Error(`Unable to read workflows: ${A.errors??"Length mismatch in response"}`);return t.forEach(a=>{a.steps.forEach(i=>{var o,s,r;delete i.data.__typename,(o=i.option)!=null&&o.id&&((s=i.option.defaultVariant)!=null&&s.asset&&J.cacheAsset(i.option.defaultVariant.asset),i.option.colorProfile&&J.cacheAsset(i.option.colorProfile),(r=i.option.variants)==null||r.forEach(l=>{l.asset&&J.cacheAsset(l.asset),l.displayImage&&J.cacheAsset(l.displayImage),l.thumbnail&&J.cacheAsset(l.thumbnail),l.material&&J.cacheMaterial(l.material)}),q.set({id:i.option.id},Promise.resolve(i.option)))})}),t},ga=async(g,e)=>{const t=(await e).find(n=>n.id===g);if(!t)throw new Error(`Workflow not found: ${g}`);return t},je=async(g,e)=>{const A=g.map(o=>q.get({id:o,options:e})),t=g.filter((o,s)=>A[s]===void 0);if(t.length===0)return Promise.all(A);const n=ca(t,e),a=t.map(o=>q.set({id:o,options:e},ga(o,n))),i=A.filter(o=>o!==void 0);return await Promise.all(i.concat(a))},de=async(g,e)=>(await je([g],e))[0],la=g=>g.sort((e,A)=>e.index-A.index).map(e=>({id:c.generate(),panelId:e.name,name:e.name,index:e.index,createdAt:new Date,updatedAt:new Date,transparentBackground:e.transparentBackground,height:e.height,width:e.width,previewRegion:e.previewRegion,useEditableArea:e.useEditableArea,editableArea:e.editableArea})),Ke=(g,e)=>{const A=g.workflowState,t=A?JSON.parse(A):void 0;return t?Object.values(t.layouts).map(n=>n.layout):la(e.panels)};class $A{constructor(e){this.updateTransactionState=async A=>{try{return x.getShadowGraphqlClient().mutate({...A,mutation:pt})}catch(t){throw console.error(t),new G("Critical - Unable to synchronize workflow state with server.")}},this.initialized=!1,this.options=e,this.options.applicationKey&&it(this.options.applicationKey)}getAssetManager(){return J}getCurrencyCode(){if(this.currencyCode===void 0)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 XA}async getIntegration(){return(await x.getShadowGraphqlClient().query({query:ta,errorPolicy:"all"})).data}async authenticateBundleFromLocalStorage(e){var n,a;const A=P.getMap("bundleOwnerIds");if(A!=null&&A.has(e))return Promise.resolve({success:!0,stakeholderType:oe.Owner});const t=P.getMap("bundlePartnerIds")||new Map;if(t.has(e)){const i=t.get(e),s=(P.getMap("partnerCustomerIds")||new Map).get(i);if(s&&await this.authenticateCustomerId(s)){const l=(a=(n=this.customer)==null?void 0:n.bundleStakeholders)==null?void 0:a.find(d=>{var B;return((B=d.bundle)==null?void 0:B.id)===e});if(l)return Promise.resolve({success:!0,stakeholderType:l.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(e){var l,d,B,w,E,C;const A=x.getShadowGraphqlClient(),t=await A.query({query:Aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:e}});if(!t.data.transactions||t.data.transactions.length===0)throw new Error(`Transaction not found: ${e}`);const n=t.data.transactions[0];if(!((d=(l=n.product)==null?void 0:l.partner)==null?void 0:d.id))throw new Error(`Unable to read transaction: ${e}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const i=P.getMap("transactionOwnerIds");if(i!=null&&i.has(e))return Promise.resolve({success:!0,stakeholderType:oe.Owner});const o=P.getMap("transactionCustomerIds");if(o!=null&&o.has(e)){const h=o.get(e);if(h&&await this.authenticateCustomerId(h)){const m=((w=(B=this.customer)==null?void 0:B.bundleStakeholders)==null?void 0:w.find(F=>{var I,f;return(f=(I=F.bundle)==null?void 0:I.transactions)==null?void 0:f.some(D=>D.id===e)}))||((C=(E=this.customer)==null?void 0:E.stakeholders)==null?void 0:C.find(F=>{var I;return((I=F.transaction)==null?void 0:I.id)===e}));if(m)return Promise.resolve({success:!0,stakeholderType:m.type})}}const r=(await A.query({query:na,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(e){const A=P.getMap("transactionCustomerIds");A!=null&&A.has(e)&&(A.delete(e),P.setMap("transactionCustomerIds",A))}getStakeholderTypeForTransaction(e){var t,n;const A=(n=(t=this.customer)==null?void 0:t.stakeholders)==null?void 0:n.find(a=>{var i;return((i=a.transaction)==null?void 0:i.id)===e});if(A)return A.type}async getOrCreateCustomer(e){var i;this.customer=void 0;const A=x.getShadowGraphqlClient(),n=(await A.query({query:aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e}})).data.customer;if(!n.id){const s=(i=(await A.mutate({mutation:ia,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:e}}})).data)==null?void 0:i.customerCreate;if(!s)throw new Error("Unable to create customer.");return this.storeCustomer(s),this.customer=s,{customer:s,isAuthenticated:!1}}this.storeCustomer(n);const a=await this.authenticateCustomerId(n.id);return{customer:this.customer||n,isAuthenticated:a}}async authenticateCustomerId(e){var o;const A=x.getShadowGraphqlClient(),t=P.getMap("customerTokens");if(!(t!=null&&t.has(e)))return!1;const n=t.get(e);if(!n)return!1;const i=(o=(await A.mutate({mutation:oa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data)==null?void 0:o.customerAuthenticate;return i?(this.storeCustomer(i),nA(n),this.customer=i,!0):!1}async generateVerificationCode(e){await x.getShadowGraphqlClient().mutate({mutation:sa,variables:{emailAddress:e}})}async verifyCode(e,A){var a,i;const n=(a=(await x.getShadowGraphqlClient().mutate({mutation:ra,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e,verificationCode:A}})).data)==null?void 0:a.customerVerifyCode;if(n!=null&&n.loginToken){if(!((i=n.partner)!=null&&i.id))throw new Error(`Unable to find customer: ${e}`);const o=P.getMap("customerTokens")||new Map;return o.set(n.id,n.loginToken),P.setMap("customerTokens",o),this.storeCustomer(n),nA(n.loginToken),this.customer={...n,loginToken:void 0},!0}return!1}async getNewBundle(e,A){var o;const n=(o=(await x.getShadowGraphqlClient().mutate({mutation:Pn,variables:{collectionId:e,initialMetadata:A?Object.entries(A).map((s,r)=>({key:s[0],value:s[1]})):void 0},fetchPolicy:"no-cache"})).data)==null?void 0:o.bundleCreate;if(!(n!=null&&n.id))throw new Error("Unable to create bundle");const a=P.getMap("bundlePartnerIds")||new Map;a.set(n.id,n.partner.id),P.setMap("bundlePartnerIds",a);const i=P.getMap("bundleOwnerIds")||new Map;return i.set(n.id,n.bundleOwnerId),P.setMap("bundleOwnerIds",i),new WA(this,n,void 0,void 0,n.bundleOwnerId)}async getExistingBundle(e,A,t){var l,d,B,w;const n=P.getMap("bundleOwnerIds"),a=n==null?void 0:n.get(e),i=await x.getShadowGraphqlClient().query({query:Sn,variables:{id:e},fetchPolicy:"no-cache",context:{bundleOwnerId:a}});if(!((l=i.data)!=null&&l.bundles)||((d=i.data)==null?void 0:d.bundles.length)===0||!((B=i.data)!=null&&B.bundles[0]))throw new Error(`Unable to find bundle: ${e}`);const o=(w=i.data)==null?void 0:w.bundles[0],s=P.getMap("bundlePartnerIds")||new Map;s.set(o.id,o.partner.id),P.setMap("bundlePartnerIds",s);const r=new WA(this,o,A,t,a);return await r.getInitializationPromise(),r}async getBundleStakeholders(){var a;if(!this.customer)throw new Error("Customer not authenticated.");const e=await x.getShadowGraphqlClient().query({query:yn,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!((a=e.data)!=null&&a.customers)||e.data.customers.length===0)throw new Error("Unable to find customer.");const t=e.data.customers[0].bundleStakeholders||[],n=P.getMap("bundlePartnerIds")||new Map;return t.forEach(i=>{var o,s;(o=i.bundle)!=null&&o.id&&((s=i.bundle.partner)!=null&&s.id)&&n.set(i.bundle.id,i.bundle.partner.id)}),P.setMap("bundlePartnerIds",n),t}async getWorkflowExperience(e,A,t,n){var d,B,w,E,C;if(!n)return await this.getWorkflowExperienceDeprecated(e,A,t);const a=async()=>{var u,m;const h=x.getShadowGraphqlClient();if(n.type==="transaction"){const{transactionId:F,readOnly:I}=n,f=await h.query({query:Qe,variables:{ids:[F]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!((u=f.data)!=null&&u.transactions)||f.data.transactions.length===0)throw new G("Existing transaction not found.");const D=(m=f.data)==null?void 0:m.transactions[0];if(!D.workflowId)throw new G("Existing transaction has no workflow ID.");const p=await de(D.workflowId);if(!D.product)throw new G("Failed to load transaction, product not available.");return{transaction:D,workflow:p,readOnly:I}}if(n.type==="integration"||n.type==="external"){const F=async()=>{const p=n.type==="integration"?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},S=await h.mutate({mutation:lA,variables:{...p,workflowId:n.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!S.data||!S.data.transactionCreate)throw new G("Failed to create transaction!");const Y=S.data.transactionCreate;if(!Y.product)throw new G("Failed to create transaction, product not available.");return Y},I=de(n.workflowId,n==null?void 0:n.graphql),[f,D]=await Promise.all([F(),I]);return{transaction:f,workflow:D}}throw new G("No workflow ID provided.")},{transaction:i,workflow:o,readOnly:s}=await a();this.currencyCode=(d=i.product.partner)==null?void 0:d.currencyCode;const r={product:i.product,transaction:i,layouts:[],singleVariantsRenderable:(B=n==null?void 0:n.workflowConfiguration)==null?void 0:B.singleVariantsRenderable,stateMutationFunc:s?async()=>{throw new v("State mutation is forbidden in read only mode!")}:async h=>{const m=(P.getMap("transactionOwnerIds")||new Map).get(i.id)||void 0;return this.updateTransactionState({...h,context:{transactionOwnerId:m}})},readOnly:s,workflow:o};if(n.type==="transaction"&&i.workflowState){const h=JSON.parse(i.workflowState);r.layouts=Object.values(h.layouts).map(u=>u.layout),await c.rehydrateSerializedLayout(h),await ee(h),r.reloadedState=h}else if(!s&&n.workflowState){const h=JSON.parse(n.workflowState);r.layouts=Object.values(h.layouts).map(u=>u.layout),await c.rehydrateSerializedLayout(h),await ee(h),r.reloadedState=h}else r.layouts=Ke(r.transaction,r.workflow);if(r.renderableContextService=new Fe(r.layouts),n.previewService?(r.previewService=n.previewService,(w=r.product)!=null&&w.modelUrl&&(r.modelContainer=r.previewService.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))):(r.previewService=t&&t(o),(E=r.product)!=null&&E.modelUrl&&(r.modelContainer=(C=r.previewService)==null?void 0:C.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))),n.type!=="transaction"){const h=P.getMap("transactionOwnerIds")||new Map;h.set(i.id,i.transactionOwnerId),P.setMap("transactionOwnerIds",h)}else r.isReloadedTransaction=!0;this.initialized=!0,this.experienceOptions=r;const l=new le(this,r);return await l.getWorkflowManager().getInitializationPromise(),n.type!=="transaction"&&this.customer&&await l.attachCustomerDetails({email:this.customer.emailAddress}),l}async getWorkflowExperiences(e,A){if(e.length===0)throw new G("No options provided!");const t=x.getShadowGraphqlClient(),n=async f=>{var Y,N;if(f.length===0)return[];const D=f.map(y=>y.option.transactionId),p=await t.query({query:Qe,variables:{ids:D},errorPolicy:"all",fetchPolicy:"no-cache"}),S=p.data.transactions;if(S.length!==f.length){const y=((N=(Y=p.errors)==null?void 0:Y[0])==null?void 0:N.message)||"Unknown error";throw new G(`Not all transactions were found: ${y}`)}return S.map((y,H)=>{var R;return{transaction:y,workflowId:y.workflowId,readOnly:((R=f.find(T=>T.option.transactionId===y.id))==null?void 0:R.option.readOnly)??!1,index:f[H].index}})},a=async f=>{var S,Y,N;if(f.length===0)return[];const D=await t.mutate({mutation:ft,variables:{inputs:f.map(y=>({integrationProductId:y.option.type==="integration"?y.option.integrationProductId:void 0,externalIntegrationId:y.option.type==="external"?y.option.externalIntegrationId:void 0,externalProductId:y.option.type==="external"?y.option.externalProductId:void 0,workflowId:y.option.workflowId,claim:!0}))},errorPolicy:"all",fetchPolicy:"no-cache"}),p=(S=D.data)==null?void 0:S.transactionCreateMany;if(!p||p.length===0){const y=((N=(Y=D.errors)==null?void 0:Y[0])==null?void 0:N.message)||"Unknown error";throw new G(`Failed to create transactions: ${y}`)}return p.map((y,H)=>({transaction:y,workflowId:y.workflowId,readOnly:!1,index:f[H].index}))},i=e.map((f,D)=>({option:f,index:D})),o=i.filter(f=>f.option.type==="transaction"),s=i.filter(f=>f.option.type==="integration"||f.option.type==="external"),r=_e(o,10),l=_e(s,10),d=(await Promise.all([...r.map(n),...l.map(a)])).flat(),B=[...new Set(d.map(f=>f.workflowId))],w=await je(B,A),E=new Map(w.map(f=>[f.id,f])),C=P.getMap("transactionOwnerIds")||new Map,h=d.map(async f=>{var T;const{transaction:D,workflowId:p,readOnly:S,index:Y}=f,N=E.get(p),y=e[Y];!C.get(D.id)&&D.transactionOwnerId&&C.set(D.id,D.transactionOwnerId);const H=C.get(D.id)||void 0,R={product:D.product,transaction:D,layouts:[],singleVariantsRenderable:(T=y==null?void 0:y.workflowConfiguration)==null?void 0:T.singleVariantsRenderable,stateMutationFunc:S?async()=>{throw new v("State mutation is forbidden in read only mode!")}:async k=>this.updateTransactionState({...k,context:{transactionOwnerId:H}}),readOnly:S,workflow:N,isReloadedTransaction:y.type==="transaction"};if(y.type==="transaction"&&D.workflowState){const k=JSON.parse(D.workflowState);R.layouts=Object.values(k.layouts).map(z=>z.layout),await c.rehydrateSerializedLayout(k),await ee(k),R.reloadedState=k}else if(!S&&y.workflowState){const k=JSON.parse(y.workflowState);R.layouts=Object.values(k.layouts).map(z=>z.layout),await c.rehydrateSerializedLayout(k),await ee(k),R.reloadedState=k}else R.layouts=Ke(R.transaction,R.workflow);return R.renderableContextService=new Fe(R.layouts),R.delayWorkflowStateSync=!0,this.initialized=!0,this.experienceOptions=R,{experienceOptions:R,index:Y,options:y}});P.setMap("transactionOwnerIds",C);const F=(await Promise.all(h)).sort((f,D)=>f.index-D.index).map(async f=>{const{experienceOptions:D,options:p}=f,S=new le(this,D);return await S.getWorkflowManager().getInitializationPromise(),p.type!=="transaction"&&this.customer&&await S.attachCustomerDetails({email:this.customer.emailAddress}),S}),I=await Promise.all(F);return I.forEach(f=>f.getWorkflowManager().setWorkflowStateSyncEnabled(!0)),I}async initFromIntegrationProduct(e){var i;if(e==="")throw new G("No integration product ID provided.");const t=await x.getShadowGraphqlClient().mutate({mutation:lA,variables:{integrationProductId:e,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!t.data||!t.data.transactionCreate)throw new G("Failed to create transaction!");const n=t.data.transactionCreate;if(!n.product)throw new G("Failed to create transaction, product not available.");this.currencyCode=(i=n.product.partner)==null?void 0:i.currencyCode;const a=P.getMap("transactionOwnerIds")||new Map;a.set(n.id,n.transactionOwnerId),P.setMap("transactionOwnerIds",a),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async o=>this.updateTransactionState({...o,context:{transactionOwnerId:n.transactionOwnerId}})},this.initialized=!0}async initFromTransaction(e,A=!1){var o,s,r,l;if(e==="")throw new G("No transaction ID provided.");const t=x.getShadowGraphqlClient(),n=async()=>{var w,E;const B=(w=(await t.query({query:Qe,variables:{ids:[e]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:w.transactions[0];if(!B)throw new G("Failed to read transaction.");if(!B.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(E=B.product.partner)==null?void 0:E.currencyCode,this.experienceOptions={product:B.product,transaction:B,layouts:[],stateMutationFunc:async()=>{throw new v("State mutation is forbidden in read only mode!")},readOnly:A},this.initialized=!0};if(A)return await n();const a=P.getMap("transactionOwnerIds")||new Map,i=a.get(e);if(i){const B=(o=(await t.query({query:Qe,variables:{ids:[e]},errorPolicy:"all"})).data)==null?void 0:o.transactions[0];if(!B)throw new G("Failed to read transaction.");if(!B.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(s=B.product.partner)==null?void 0:s.currencyCode,this.experienceOptions={product:B.product,transaction:B,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:i}}),readOnly:A},this.initialized=!0;return}try{const B=(r=(await t.mutate({mutation:Dt,variables:{id:e},errorPolicy:"all"})).data)==null?void 0:r.transactionClaim;if(!B)throw new G("Failed to read transaction.");if(!B.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(l=B.product.partner)==null?void 0:l.currencyCode,B.transactionOwnerId&&(a.set(B.id,B.transactionOwnerId),P.setMap("transactionOwnerIds",a)),this.experienceOptions={product:B.product,transaction:B,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:B.transactionOwnerId}}),readOnly:A},this.initialized=!0}catch{throw new G("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(e,A,t){var n,a,i,o;if(!this.initialized||!this.experienceOptions)throw new G("Cannot launch experience: Not initialized.");if(this.experienceOptions.transaction.workflowId){const s=await de(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=s,this.experienceOptions.transaction.workflowState){const l=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(l.layouts).map(d=>d.layout),await c.rehydrateSerializedLayout(l),await ee(l),this.experienceOptions.reloadedState=l}this.experienceOptions.previewService=t&&t(s),this.experienceOptions.renderableContextService=new Fe(this.experienceOptions.layouts),(n=this.experienceOptions.product)!=null&&n.modelUrl&&(this.experienceOptions.modelContainer=(a=this.experienceOptions.previewService)==null?void 0:a.loadModel({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}));const r=new le(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}if(e){const r=(P.getMap("transactionOwnerIds")||new Map).get(this.experienceOptions.transaction.id),l=x.getShadowGraphqlClient().mutate({mutation:Ft,variables:{workflowId:e,id:this.experienceOptions.transaction.id},context:{transactionOwnerId:r}}),d=de(e);if(await Promise.all([l,d]),this.experienceOptions.workflow=await d,A){const w=JSON.parse(A);this.experienceOptions.layouts=Object.values(w.layouts).map(E=>E.layout),await c.rehydrateSerializedLayout(w),await ee(w),this.experienceOptions.reloadedState=w}else this.experienceOptions.layouts=Ke(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=t&&t(await d),this.experienceOptions.renderableContextService=new Fe(this.experienceOptions.layouts),(i=this.experienceOptions.product)!=null&&i.modelUrl&&(this.experienceOptions.modelContainer=(o=this.experienceOptions.previewService)==null?void 0:o.loadModel({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}));const B=new le(this,this.experienceOptions);return await B.getWorkflowManager().getInitializationPromise(),B}throw new G("No workflow ID provided.")}getPreviewService(){var e;return(e=this.experienceOptions)==null?void 0:e.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new G("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new G("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}storeCustomer(e){const A=P.getMap("partnerCustomerIds")||new Map;A.set(e.partner.id,e.id),P.setMap("partnerCustomerIds",A)}}class Ba{getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}async reset(){}updateStateWithServer(e){}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(e){}addPoller(e){}addConfirmCallback(e){}addEditedCallback(e){}addElementsCallback(e){}addInformationResultCallback(e){}addInitCallback(e){}addMakingAdjustmentsCallback(e){}addMandatoryCallback(e){}addMetadataCallback(e){}addSelectionCallback(e){}addStepSpecificStorageCallback(e,A){}addStorageCallback(e){}getCommandDispatcher(){return e=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(e){return[]}getSerializedStep(e,A){}getStepSpecificServices(e){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(e){}markUpdateCompleted(e){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}setCurrentAdjustingStepId(e){}setEditedStatus(e,A){}setInformationResults(e){}setMandatoryFulfilled(e,A){}async setSelectionsAndElements(e,A,t){}toggleDesignConfirmed(){}updateMetadata(e,A){}async updateStorage(e,A){}injectIntoPreviewService(e){return Promise.resolve()}ejectFromPreviewService(){}setWorkflowStateSyncEnabled(e){}}var _A=(g=>(g.SelectFrame="SelectFrame",g.SelectImage="SelectImage",g.Position="Position",g))(_A||{});class et extends j{constructor(e,A){var t;super(e,A),this.frameService=(t=this.manager.getStepSpecificServices(this.getId()))==null?void 0:t.frameService}selectVariant(e){const A=this.manager.getRegionElements(this.step.stepName);return ue.selectVariant(this.step,e.getResource(),A,this.manager,t=>this.setUpdateState(t))}onFrameDataChanged(e){this.frameService&&this.frameService.onFrameDataChanged(A=>{A&&e(A)})}selectImage(e){return ue.selectImage(this.step,e,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(e,A,t,n){return n&&n.length>1&&e===void 0?"SelectFrame":A||t||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}}Object.defineProperty(Q,"AssetType",{enumerable:!0,get:()=>c.AssetType}),Object.defineProperty(Q,"BringForwardCommand",{enumerable:!0,get:()=>c.BringForwardCommand}),Object.defineProperty(Q,"BringToBackCommand",{enumerable:!0,get:()=>c.BringToBackCommand}),Object.defineProperty(Q,"BringToFrontCommand",{enumerable:!0,get:()=>c.BringToFrontCommand}),Object.defineProperty(Q,"CanvasCommand",{enumerable:!0,get:()=>c.CanvasCommand}),Object.defineProperty(Q,"CommandContext",{enumerable:!0,get:()=>c.CommandContext}),Object.defineProperty(Q,"CreateElementCommand",{enumerable:!0,get:()=>c.CreateElementCommand}),Object.defineProperty(Q,"CreateLayoutCommand",{enumerable:!0,get:()=>c.CreateLayoutCommand}),Object.defineProperty(Q,"DeleteElementCommand",{enumerable:!0,get:()=>c.DeleteElementCommand}),Object.defineProperty(Q,"FontAlignmentCommand",{enumerable:!0,get:()=>c.FontAlignmentCommand}),Object.defineProperty(Q,"FontColorCommand",{enumerable:!0,get:()=>c.FontColorCommand}),Object.defineProperty(Q,"FontSizeCommand",{enumerable:!0,get:()=>c.FontSizeCommand}),Object.defineProperty(Q,"FontSourceCommand",{enumerable:!0,get:()=>c.FontSourceCommand}),Object.defineProperty(Q,"GroupCommand",{enumerable:!0,get:()=>c.GroupCommand}),Object.defineProperty(Q,"LayoutElementFactory",{enumerable:!0,get:()=>c.LayoutElementFactory}),Object.defineProperty(Q,"LayoutElementType",{enumerable:!0,get:()=>c.LayoutElementType}),Object.defineProperty(Q,"MoveCommand",{enumerable:!0,get:()=>c.MoveCommand}),Object.defineProperty(Q,"ResizeCommand",{enumerable:!0,get:()=>c.ResizeCommand}),Object.defineProperty(Q,"RotateCommand",{enumerable:!0,get:()=>c.RotateCommand}),Object.defineProperty(Q,"SendBackwardsCommand",{enumerable:!0,get:()=>c.SendBackwardsCommand}),Object.defineProperty(Q,"StepAspectType",{enumerable:!0,get:()=>c.StepAspectType}),Object.defineProperty(Q,"StepType",{enumerable:!0,get:()=>c.StepType}),Object.defineProperty(Q,"TextChangeCommand",{enumerable:!0,get:()=>c.TextChangeCommand}),Object.defineProperty(Q,"UnitOfMeasurement",{enumerable:!0,get:()=>c.UnitOfMeasurement}),Object.defineProperty(Q,"dataUrlFromExternalUrl",{enumerable:!0,get:()=>c.dataUrlFromExternalUrl}),Object.defineProperty(Q,"determineCorrectFontSizeAndLines",{enumerable:!0,get:()=>c.determineCorrectFontSizeAndLines}),Object.defineProperty(Q,"findElement",{enumerable:!0,get:()=>c.findElement}),Object.defineProperty(Q,"frameDataCache",{enumerable:!0,get:()=>c.frameDataCache}),Object.defineProperty(Q,"generate",{enumerable:!0,get:()=>c.generate}),Object.defineProperty(Q,"generateSVGWithUnknownColors",{enumerable:!0,get:()=>c.generateSVGWithUnknownColors}),Object.defineProperty(Q,"getAttributesFromArrayBuffer",{enumerable:!0,get:()=>c.getAttributesFromArrayBuffer}),Object.defineProperty(Q,"getAxisAlignedBoundingBox",{enumerable:!0,get:()=>c.getAxisAlignedBoundingBox}),Object.defineProperty(Q,"getFrameData",{enumerable:!0,get:()=>c.getFrameData}),Object.defineProperty(Q,"getSvgElement",{enumerable:!0,get:()=>c.getSvgElement}),Object.defineProperty(Q,"loadFont",{enumerable:!0,get:()=>c.loadFont}),Object.defineProperty(Q,"patternImageDataCache",{enumerable:!0,get:()=>c.patternImageDataCache}),Object.defineProperty(Q,"registerFetchImplementation",{enumerable:!0,get:()=>c.registerFetchImplementation}),Object.defineProperty(Q,"registerWindowImplementation",{enumerable:!0,get:()=>c.registerWindowImplementation}),Object.defineProperty(Q,"rehydrateSerializedLayout",{enumerable:!0,get:()=>c.rehydrateSerializedLayout}),Object.defineProperty(Q,"setCanvasModule",{enumerable:!0,get:()=>c.setCanvasModule}),Q.AssetNotFoundError=V,Q.CollectionProduct=jA,Q.ConversionDataType=gA,Q.ConversionLocation=cA,Q.FlowExecutionNodeResult=Be,Q.FlowExecutionResult=qA,Q.FlowService=XA,Q.FrameService=wA,Q.FrameStep=_A,Q.FrameStepHandle=et,Q.GlobalPropertyHandle=Me,Q.IllustrationStepHandle=yA,Q.InformationMessageType=ge,Q.InformationStepHandle=GA,Q.IntegrationType=sA,Q.LayoutNotFoundError=b,Q.MaterialStepHandle=PA,Q.MisconfigurationError=ne,Q.MockWorkflowManager=Ba,Q.ModelStepHandle=NA,Q.ObjectInput=ze,Q.ObjectInputType=ZA,Q.OptionNotFoundError=te,Q.ParseError=X,Q.PictureStepHandle=xA,Q.ProductCameraRig=rA,Q.ProductCollection=zA,Q.ProductWorkflow=Oe,Q.PromiseCache=q,Q.PromiseQueue=xe,Q.QuestionStepHandle=HA,Q.QueueablePromise=Ne,Q.ResourceNotFoundError=W,Q.ShapeStepHandle=RA,Q.SpiffCommerceClient=$A,Q.StakeholderType=oe,Q.StepHandle=j,Q.TextStepHandle=UA,Q.Transform=VA,Q.TransformCollection=KA,Q.UnhandledBehaviorError=v,Q.Variant=K,Q.WorkflowExperienceImpl=le,Q.assetService=J,Q.createDesign=JA,Q.designService=pe,Q.digitalContentStepService=QA,Q.frameStepService=ue,Q.generateCommands=TA,Q.generateStateFromDesignInputSteps=pn,Q.getBoundedOffsets=dA,Q.getWorkflow=de,Q.getWorkflows=je,Q.graphQlManager=x,Q.illustrationStepService=ce,Q.materialStepService=He,Q.modelStepService=Re,Q.moduleStepService=mA,Q.optionService=L,Q.persistenceService=P,Q.pictureStepService=Ue,Q.questionStepService=Ge,Q.shapeStepService=_,Q.shortenUrl=hA,Q.spiffCoreConfiguration=ae,Q.stepAspectValuesToDesignInputSteps=Dn,Q.textStepService=O,Q.toast=uA,Object.defineProperty(Q,Symbol.toStringTag,{value:"Module"})});
|
|
2895
|
+
`,ee=async g=>{var e;for(const A in g.layouts){const t=g.layouts[A].elements.filter(a=>a.type===c.LayoutElementType.Illustration);for(let a=0;a<t.length;++a){const i=t[a];i.src&&i.svg&&(i.cachedObjectURL=await c.svgObjectURL(i.svg))}const n=g.layouts[A].elements.filter(a=>a.type===c.LayoutElementType.Textbox);for(let a=0;a<n.length;++a){const i=n[a];(e=i.fontData)!=null&&e.assetUrl&&await c.loadFont(i.fontData.assetUrl)}}},ca=async(g,e)=>{var n;const A=await x.getShadowGraphqlClient().query({query:ea(((n=e==null?void 0:e.assets)==null?void 0:n.metadata)||!1),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:g}}),t=A.data.workflows;if(t===void 0||t.length!==g.length)throw new Error(`Unable to read workflows: ${A.errors??"Length mismatch in response"}`);return t.forEach(a=>{a.steps.forEach(i=>{var o,s,r;delete i.data.__typename,(o=i.option)!=null&&o.id&&((s=i.option.defaultVariant)!=null&&s.asset&&J.cacheAsset(i.option.defaultVariant.asset),i.option.colorProfile&&J.cacheAsset(i.option.colorProfile),(r=i.option.variants)==null||r.forEach(l=>{l.asset&&J.cacheAsset(l.asset),l.displayImage&&J.cacheAsset(l.displayImage),l.thumbnail&&J.cacheAsset(l.thumbnail),l.material&&J.cacheMaterial(l.material)}),q.set({id:i.option.id},Promise.resolve(i.option)))})}),t},ga=async(g,e)=>{const t=(await e).find(n=>n.id===g);if(!t)throw new Error(`Workflow not found: ${g}`);return t},je=async(g,e)=>{const A=g.map(o=>q.get({id:o,options:e})),t=g.filter((o,s)=>A[s]===void 0);if(t.length===0)return Promise.all(A);const n=ca(t,e),a=t.map(o=>q.set({id:o,options:e},ga(o,n))),i=A.filter(o=>o!==void 0);return await Promise.all(i.concat(a))},de=async(g,e)=>(await je([g],e))[0],la=g=>g.sort((e,A)=>e.index-A.index).map(e=>({id:c.generate(),panelId:e.name,name:e.name,index:e.index,createdAt:new Date,updatedAt:new Date,transparentBackground:e.transparentBackground,height:e.height,width:e.width,previewRegion:e.previewRegion,useEditableArea:e.useEditableArea,editableArea:e.editableArea})),Ke=(g,e)=>{const A=g.workflowState,t=A?JSON.parse(A):void 0;return t?Object.values(t.layouts).map(n=>n.layout):la(e.panels)};class $A{constructor(e){this.updateTransactionState=async A=>{try{return x.getShadowGraphqlClient().mutate({...A,mutation:pt})}catch(t){throw console.error(t),new G("Critical - Unable to synchronize workflow state with server.")}},this.initialized=!1,this.options=e,this.options.applicationKey&&it(this.options.applicationKey)}getAssetManager(){return J}getCurrencyCode(){if(this.currencyCode===void 0)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 XA}async getIntegration(){return(await x.getShadowGraphqlClient().query({query:ta,errorPolicy:"all"})).data.currentIntegration}async authenticateBundleFromLocalStorage(e){var n,a;const A=P.getMap("bundleOwnerIds");if(A!=null&&A.has(e))return Promise.resolve({success:!0,stakeholderType:oe.Owner});const t=P.getMap("bundlePartnerIds")||new Map;if(t.has(e)){const i=t.get(e),s=(P.getMap("partnerCustomerIds")||new Map).get(i);if(s&&await this.authenticateCustomerId(s)){const l=(a=(n=this.customer)==null?void 0:n.bundleStakeholders)==null?void 0:a.find(d=>{var B;return((B=d.bundle)==null?void 0:B.id)===e});if(l)return Promise.resolve({success:!0,stakeholderType:l.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(e){var l,d,B,w,E,C;const A=x.getShadowGraphqlClient(),t=await A.query({query:Aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:e}});if(!t.data.transactions||t.data.transactions.length===0)throw new Error(`Transaction not found: ${e}`);const n=t.data.transactions[0];if(!((d=(l=n.product)==null?void 0:l.partner)==null?void 0:d.id))throw new Error(`Unable to read transaction: ${e}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const i=P.getMap("transactionOwnerIds");if(i!=null&&i.has(e))return Promise.resolve({success:!0,stakeholderType:oe.Owner});const o=P.getMap("transactionCustomerIds");if(o!=null&&o.has(e)){const h=o.get(e);if(h&&await this.authenticateCustomerId(h)){const m=((w=(B=this.customer)==null?void 0:B.bundleStakeholders)==null?void 0:w.find(F=>{var I,f;return(f=(I=F.bundle)==null?void 0:I.transactions)==null?void 0:f.some(D=>D.id===e)}))||((C=(E=this.customer)==null?void 0:E.stakeholders)==null?void 0:C.find(F=>{var I;return((I=F.transaction)==null?void 0:I.id)===e}));if(m)return Promise.resolve({success:!0,stakeholderType:m.type})}}const r=(await A.query({query:na,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(e){const A=P.getMap("transactionCustomerIds");A!=null&&A.has(e)&&(A.delete(e),P.setMap("transactionCustomerIds",A))}getStakeholderTypeForTransaction(e){var t,n;const A=(n=(t=this.customer)==null?void 0:t.stakeholders)==null?void 0:n.find(a=>{var i;return((i=a.transaction)==null?void 0:i.id)===e});if(A)return A.type}async getOrCreateCustomer(e){var i;this.customer=void 0;const A=x.getShadowGraphqlClient(),n=(await A.query({query:aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e}})).data.customer;if(!n.id){const s=(i=(await A.mutate({mutation:ia,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:e}}})).data)==null?void 0:i.customerCreate;if(!s)throw new Error("Unable to create customer.");return this.storeCustomer(s),this.customer=s,{customer:s,isAuthenticated:!1}}this.storeCustomer(n);const a=await this.authenticateCustomerId(n.id);return{customer:this.customer||n,isAuthenticated:a}}async authenticateCustomerId(e){var o;const A=x.getShadowGraphqlClient(),t=P.getMap("customerTokens");if(!(t!=null&&t.has(e)))return!1;const n=t.get(e);if(!n)return!1;const i=(o=(await A.mutate({mutation:oa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data)==null?void 0:o.customerAuthenticate;return i?(this.storeCustomer(i),nA(n),this.customer=i,!0):!1}async generateVerificationCode(e){await x.getShadowGraphqlClient().mutate({mutation:sa,variables:{emailAddress:e}})}async verifyCode(e,A){var a,i;const n=(a=(await x.getShadowGraphqlClient().mutate({mutation:ra,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e,verificationCode:A}})).data)==null?void 0:a.customerVerifyCode;if(n!=null&&n.loginToken){if(!((i=n.partner)!=null&&i.id))throw new Error(`Unable to find customer: ${e}`);const o=P.getMap("customerTokens")||new Map;return o.set(n.id,n.loginToken),P.setMap("customerTokens",o),this.storeCustomer(n),nA(n.loginToken),this.customer={...n,loginToken:void 0},!0}return!1}async getNewBundle(e,A){var o;const n=(o=(await x.getShadowGraphqlClient().mutate({mutation:Pn,variables:{collectionId:e,initialMetadata:A?Object.entries(A).map((s,r)=>({key:s[0],value:s[1]})):void 0},fetchPolicy:"no-cache"})).data)==null?void 0:o.bundleCreate;if(!(n!=null&&n.id))throw new Error("Unable to create bundle");const a=P.getMap("bundlePartnerIds")||new Map;a.set(n.id,n.partner.id),P.setMap("bundlePartnerIds",a);const i=P.getMap("bundleOwnerIds")||new Map;return i.set(n.id,n.bundleOwnerId),P.setMap("bundleOwnerIds",i),new WA(this,n,void 0,void 0,n.bundleOwnerId)}async getExistingBundle(e,A,t){var l,d,B,w;const n=P.getMap("bundleOwnerIds"),a=n==null?void 0:n.get(e),i=await x.getShadowGraphqlClient().query({query:Sn,variables:{id:e},fetchPolicy:"no-cache",context:{bundleOwnerId:a}});if(!((l=i.data)!=null&&l.bundles)||((d=i.data)==null?void 0:d.bundles.length)===0||!((B=i.data)!=null&&B.bundles[0]))throw new Error(`Unable to find bundle: ${e}`);const o=(w=i.data)==null?void 0:w.bundles[0],s=P.getMap("bundlePartnerIds")||new Map;s.set(o.id,o.partner.id),P.setMap("bundlePartnerIds",s);const r=new WA(this,o,A,t,a);return await r.getInitializationPromise(),r}async getBundleStakeholders(){var a;if(!this.customer)throw new Error("Customer not authenticated.");const e=await x.getShadowGraphqlClient().query({query:yn,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!((a=e.data)!=null&&a.customers)||e.data.customers.length===0)throw new Error("Unable to find customer.");const t=e.data.customers[0].bundleStakeholders||[],n=P.getMap("bundlePartnerIds")||new Map;return t.forEach(i=>{var o,s;(o=i.bundle)!=null&&o.id&&((s=i.bundle.partner)!=null&&s.id)&&n.set(i.bundle.id,i.bundle.partner.id)}),P.setMap("bundlePartnerIds",n),t}async getWorkflowExperience(e,A,t,n){var d,B,w,E,C;if(!n)return await this.getWorkflowExperienceDeprecated(e,A,t);const a=async()=>{var u,m;const h=x.getShadowGraphqlClient();if(n.type==="transaction"){const{transactionId:F,readOnly:I}=n,f=await h.query({query:Qe,variables:{ids:[F]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!((u=f.data)!=null&&u.transactions)||f.data.transactions.length===0)throw new G("Existing transaction not found.");const D=(m=f.data)==null?void 0:m.transactions[0];if(!D.workflowId)throw new G("Existing transaction has no workflow ID.");const p=await de(D.workflowId);if(!D.product)throw new G("Failed to load transaction, product not available.");return{transaction:D,workflow:p,readOnly:I}}if(n.type==="integration"||n.type==="external"){const F=async()=>{const p=n.type==="integration"?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},S=await h.mutate({mutation:lA,variables:{...p,workflowId:n.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!S.data||!S.data.transactionCreate)throw new G("Failed to create transaction!");const Y=S.data.transactionCreate;if(!Y.product)throw new G("Failed to create transaction, product not available.");return Y},I=de(n.workflowId,n==null?void 0:n.graphql),[f,D]=await Promise.all([F(),I]);return{transaction:f,workflow:D}}throw new G("No workflow ID provided.")},{transaction:i,workflow:o,readOnly:s}=await a();this.currencyCode=(d=i.product.partner)==null?void 0:d.currencyCode;const r={product:i.product,transaction:i,layouts:[],singleVariantsRenderable:(B=n==null?void 0:n.workflowConfiguration)==null?void 0:B.singleVariantsRenderable,stateMutationFunc:s?async()=>{throw new v("State mutation is forbidden in read only mode!")}:async h=>{const m=(P.getMap("transactionOwnerIds")||new Map).get(i.id)||void 0;return this.updateTransactionState({...h,context:{transactionOwnerId:m}})},readOnly:s,workflow:o};if(n.type==="transaction"&&i.workflowState){const h=JSON.parse(i.workflowState);r.layouts=Object.values(h.layouts).map(u=>u.layout),await c.rehydrateSerializedLayout(h),await ee(h),r.reloadedState=h}else if(!s&&n.workflowState){const h=JSON.parse(n.workflowState);r.layouts=Object.values(h.layouts).map(u=>u.layout),await c.rehydrateSerializedLayout(h),await ee(h),r.reloadedState=h}else r.layouts=Ke(r.transaction,r.workflow);if(r.renderableContextService=new Fe(r.layouts),n.previewService?(r.previewService=n.previewService,(w=r.product)!=null&&w.modelUrl&&(r.modelContainer=r.previewService.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))):(r.previewService=t&&t(o),(E=r.product)!=null&&E.modelUrl&&(r.modelContainer=(C=r.previewService)==null?void 0:C.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))),n.type!=="transaction"){const h=P.getMap("transactionOwnerIds")||new Map;h.set(i.id,i.transactionOwnerId),P.setMap("transactionOwnerIds",h)}else r.isReloadedTransaction=!0;this.initialized=!0,this.experienceOptions=r;const l=new le(this,r);return await l.getWorkflowManager().getInitializationPromise(),n.type!=="transaction"&&this.customer&&await l.attachCustomerDetails({email:this.customer.emailAddress}),l}async getWorkflowExperiences(e,A){if(e.length===0)throw new G("No options provided!");const t=x.getShadowGraphqlClient(),n=async f=>{var Y,N;if(f.length===0)return[];const D=f.map(y=>y.option.transactionId),p=await t.query({query:Qe,variables:{ids:D},errorPolicy:"all",fetchPolicy:"no-cache"}),S=p.data.transactions;if(S.length!==f.length){const y=((N=(Y=p.errors)==null?void 0:Y[0])==null?void 0:N.message)||"Unknown error";throw new G(`Not all transactions were found: ${y}`)}return S.map((y,H)=>{var R;return{transaction:y,workflowId:y.workflowId,readOnly:((R=f.find(T=>T.option.transactionId===y.id))==null?void 0:R.option.readOnly)??!1,index:f[H].index}})},a=async f=>{var S,Y,N;if(f.length===0)return[];const D=await t.mutate({mutation:ft,variables:{inputs:f.map(y=>({integrationProductId:y.option.type==="integration"?y.option.integrationProductId:void 0,externalIntegrationId:y.option.type==="external"?y.option.externalIntegrationId:void 0,externalProductId:y.option.type==="external"?y.option.externalProductId:void 0,workflowId:y.option.workflowId,claim:!0}))},errorPolicy:"all",fetchPolicy:"no-cache"}),p=(S=D.data)==null?void 0:S.transactionCreateMany;if(!p||p.length===0){const y=((N=(Y=D.errors)==null?void 0:Y[0])==null?void 0:N.message)||"Unknown error";throw new G(`Failed to create transactions: ${y}`)}return p.map((y,H)=>({transaction:y,workflowId:y.workflowId,readOnly:!1,index:f[H].index}))},i=e.map((f,D)=>({option:f,index:D})),o=i.filter(f=>f.option.type==="transaction"),s=i.filter(f=>f.option.type==="integration"||f.option.type==="external"),r=_e(o,10),l=_e(s,10),d=(await Promise.all([...r.map(n),...l.map(a)])).flat(),B=[...new Set(d.map(f=>f.workflowId))],w=await je(B,A),E=new Map(w.map(f=>[f.id,f])),C=P.getMap("transactionOwnerIds")||new Map,h=d.map(async f=>{var T;const{transaction:D,workflowId:p,readOnly:S,index:Y}=f,N=E.get(p),y=e[Y];!C.get(D.id)&&D.transactionOwnerId&&C.set(D.id,D.transactionOwnerId);const H=C.get(D.id)||void 0,R={product:D.product,transaction:D,layouts:[],singleVariantsRenderable:(T=y==null?void 0:y.workflowConfiguration)==null?void 0:T.singleVariantsRenderable,stateMutationFunc:S?async()=>{throw new v("State mutation is forbidden in read only mode!")}:async k=>this.updateTransactionState({...k,context:{transactionOwnerId:H}}),readOnly:S,workflow:N,isReloadedTransaction:y.type==="transaction"};if(y.type==="transaction"&&D.workflowState){const k=JSON.parse(D.workflowState);R.layouts=Object.values(k.layouts).map(z=>z.layout),await c.rehydrateSerializedLayout(k),await ee(k),R.reloadedState=k}else if(!S&&y.workflowState){const k=JSON.parse(y.workflowState);R.layouts=Object.values(k.layouts).map(z=>z.layout),await c.rehydrateSerializedLayout(k),await ee(k),R.reloadedState=k}else R.layouts=Ke(R.transaction,R.workflow);return R.renderableContextService=new Fe(R.layouts),R.delayWorkflowStateSync=!0,this.initialized=!0,this.experienceOptions=R,{experienceOptions:R,index:Y,options:y}});P.setMap("transactionOwnerIds",C);const F=(await Promise.all(h)).sort((f,D)=>f.index-D.index).map(async f=>{const{experienceOptions:D,options:p}=f,S=new le(this,D);return await S.getWorkflowManager().getInitializationPromise(),p.type!=="transaction"&&this.customer&&await S.attachCustomerDetails({email:this.customer.emailAddress}),S}),I=await Promise.all(F);return I.forEach(f=>f.getWorkflowManager().setWorkflowStateSyncEnabled(!0)),I}async initFromIntegrationProduct(e){var i;if(e==="")throw new G("No integration product ID provided.");const t=await x.getShadowGraphqlClient().mutate({mutation:lA,variables:{integrationProductId:e,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!t.data||!t.data.transactionCreate)throw new G("Failed to create transaction!");const n=t.data.transactionCreate;if(!n.product)throw new G("Failed to create transaction, product not available.");this.currencyCode=(i=n.product.partner)==null?void 0:i.currencyCode;const a=P.getMap("transactionOwnerIds")||new Map;a.set(n.id,n.transactionOwnerId),P.setMap("transactionOwnerIds",a),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async o=>this.updateTransactionState({...o,context:{transactionOwnerId:n.transactionOwnerId}})},this.initialized=!0}async initFromTransaction(e,A=!1){var o,s,r,l;if(e==="")throw new G("No transaction ID provided.");const t=x.getShadowGraphqlClient(),n=async()=>{var w,E;const B=(w=(await t.query({query:Qe,variables:{ids:[e]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:w.transactions[0];if(!B)throw new G("Failed to read transaction.");if(!B.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(E=B.product.partner)==null?void 0:E.currencyCode,this.experienceOptions={product:B.product,transaction:B,layouts:[],stateMutationFunc:async()=>{throw new v("State mutation is forbidden in read only mode!")},readOnly:A},this.initialized=!0};if(A)return await n();const a=P.getMap("transactionOwnerIds")||new Map,i=a.get(e);if(i){const B=(o=(await t.query({query:Qe,variables:{ids:[e]},errorPolicy:"all"})).data)==null?void 0:o.transactions[0];if(!B)throw new G("Failed to read transaction.");if(!B.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(s=B.product.partner)==null?void 0:s.currencyCode,this.experienceOptions={product:B.product,transaction:B,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:i}}),readOnly:A},this.initialized=!0;return}try{const B=(r=(await t.mutate({mutation:Dt,variables:{id:e},errorPolicy:"all"})).data)==null?void 0:r.transactionClaim;if(!B)throw new G("Failed to read transaction.");if(!B.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(l=B.product.partner)==null?void 0:l.currencyCode,B.transactionOwnerId&&(a.set(B.id,B.transactionOwnerId),P.setMap("transactionOwnerIds",a)),this.experienceOptions={product:B.product,transaction:B,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:B.transactionOwnerId}}),readOnly:A},this.initialized=!0}catch{throw new G("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(e,A,t){var n,a,i,o;if(!this.initialized||!this.experienceOptions)throw new G("Cannot launch experience: Not initialized.");if(this.experienceOptions.transaction.workflowId){const s=await de(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=s,this.experienceOptions.transaction.workflowState){const l=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(l.layouts).map(d=>d.layout),await c.rehydrateSerializedLayout(l),await ee(l),this.experienceOptions.reloadedState=l}this.experienceOptions.previewService=t&&t(s),this.experienceOptions.renderableContextService=new Fe(this.experienceOptions.layouts),(n=this.experienceOptions.product)!=null&&n.modelUrl&&(this.experienceOptions.modelContainer=(a=this.experienceOptions.previewService)==null?void 0:a.loadModel({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}));const r=new le(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}if(e){const r=(P.getMap("transactionOwnerIds")||new Map).get(this.experienceOptions.transaction.id),l=x.getShadowGraphqlClient().mutate({mutation:Ft,variables:{workflowId:e,id:this.experienceOptions.transaction.id},context:{transactionOwnerId:r}}),d=de(e);if(await Promise.all([l,d]),this.experienceOptions.workflow=await d,A){const w=JSON.parse(A);this.experienceOptions.layouts=Object.values(w.layouts).map(E=>E.layout),await c.rehydrateSerializedLayout(w),await ee(w),this.experienceOptions.reloadedState=w}else this.experienceOptions.layouts=Ke(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=t&&t(await d),this.experienceOptions.renderableContextService=new Fe(this.experienceOptions.layouts),(i=this.experienceOptions.product)!=null&&i.modelUrl&&(this.experienceOptions.modelContainer=(o=this.experienceOptions.previewService)==null?void 0:o.loadModel({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}));const B=new le(this,this.experienceOptions);return await B.getWorkflowManager().getInitializationPromise(),B}throw new G("No workflow ID provided.")}getPreviewService(){var e;return(e=this.experienceOptions)==null?void 0:e.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new G("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new G("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}storeCustomer(e){const A=P.getMap("partnerCustomerIds")||new Map;A.set(e.partner.id,e.id),P.setMap("partnerCustomerIds",A)}}class Ba{getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}async reset(){}updateStateWithServer(e){}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(e){}addPoller(e){}addConfirmCallback(e){}addEditedCallback(e){}addElementsCallback(e){}addInformationResultCallback(e){}addInitCallback(e){}addMakingAdjustmentsCallback(e){}addMandatoryCallback(e){}addMetadataCallback(e){}addSelectionCallback(e){}addStepSpecificStorageCallback(e,A){}addStorageCallback(e){}getCommandDispatcher(){return e=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(e){return[]}getSerializedStep(e,A){}getStepSpecificServices(e){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(e){}markUpdateCompleted(e){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}setCurrentAdjustingStepId(e){}setEditedStatus(e,A){}setInformationResults(e){}setMandatoryFulfilled(e,A){}async setSelectionsAndElements(e,A,t){}toggleDesignConfirmed(){}updateMetadata(e,A){}async updateStorage(e,A){}injectIntoPreviewService(e){return Promise.resolve()}ejectFromPreviewService(){}setWorkflowStateSyncEnabled(e){}}var _A=(g=>(g.SelectFrame="SelectFrame",g.SelectImage="SelectImage",g.Position="Position",g))(_A||{});class et extends j{constructor(e,A){var t;super(e,A),this.frameService=(t=this.manager.getStepSpecificServices(this.getId()))==null?void 0:t.frameService}selectVariant(e){const A=this.manager.getRegionElements(this.step.stepName);return ue.selectVariant(this.step,e.getResource(),A,this.manager,t=>this.setUpdateState(t))}onFrameDataChanged(e){this.frameService&&this.frameService.onFrameDataChanged(A=>{A&&e(A)})}selectImage(e){return ue.selectImage(this.step,e,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(e,A,t,n){return n&&n.length>1&&e===void 0?"SelectFrame":A||t||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}}Object.defineProperty(Q,"AssetType",{enumerable:!0,get:()=>c.AssetType}),Object.defineProperty(Q,"BringForwardCommand",{enumerable:!0,get:()=>c.BringForwardCommand}),Object.defineProperty(Q,"BringToBackCommand",{enumerable:!0,get:()=>c.BringToBackCommand}),Object.defineProperty(Q,"BringToFrontCommand",{enumerable:!0,get:()=>c.BringToFrontCommand}),Object.defineProperty(Q,"CanvasCommand",{enumerable:!0,get:()=>c.CanvasCommand}),Object.defineProperty(Q,"CommandContext",{enumerable:!0,get:()=>c.CommandContext}),Object.defineProperty(Q,"CreateElementCommand",{enumerable:!0,get:()=>c.CreateElementCommand}),Object.defineProperty(Q,"CreateLayoutCommand",{enumerable:!0,get:()=>c.CreateLayoutCommand}),Object.defineProperty(Q,"DeleteElementCommand",{enumerable:!0,get:()=>c.DeleteElementCommand}),Object.defineProperty(Q,"FontAlignmentCommand",{enumerable:!0,get:()=>c.FontAlignmentCommand}),Object.defineProperty(Q,"FontColorCommand",{enumerable:!0,get:()=>c.FontColorCommand}),Object.defineProperty(Q,"FontSizeCommand",{enumerable:!0,get:()=>c.FontSizeCommand}),Object.defineProperty(Q,"FontSourceCommand",{enumerable:!0,get:()=>c.FontSourceCommand}),Object.defineProperty(Q,"GroupCommand",{enumerable:!0,get:()=>c.GroupCommand}),Object.defineProperty(Q,"LayoutElementFactory",{enumerable:!0,get:()=>c.LayoutElementFactory}),Object.defineProperty(Q,"LayoutElementType",{enumerable:!0,get:()=>c.LayoutElementType}),Object.defineProperty(Q,"MoveCommand",{enumerable:!0,get:()=>c.MoveCommand}),Object.defineProperty(Q,"ResizeCommand",{enumerable:!0,get:()=>c.ResizeCommand}),Object.defineProperty(Q,"RotateCommand",{enumerable:!0,get:()=>c.RotateCommand}),Object.defineProperty(Q,"SendBackwardsCommand",{enumerable:!0,get:()=>c.SendBackwardsCommand}),Object.defineProperty(Q,"StepAspectType",{enumerable:!0,get:()=>c.StepAspectType}),Object.defineProperty(Q,"StepType",{enumerable:!0,get:()=>c.StepType}),Object.defineProperty(Q,"TextChangeCommand",{enumerable:!0,get:()=>c.TextChangeCommand}),Object.defineProperty(Q,"UnitOfMeasurement",{enumerable:!0,get:()=>c.UnitOfMeasurement}),Object.defineProperty(Q,"dataUrlFromExternalUrl",{enumerable:!0,get:()=>c.dataUrlFromExternalUrl}),Object.defineProperty(Q,"determineCorrectFontSizeAndLines",{enumerable:!0,get:()=>c.determineCorrectFontSizeAndLines}),Object.defineProperty(Q,"findElement",{enumerable:!0,get:()=>c.findElement}),Object.defineProperty(Q,"frameDataCache",{enumerable:!0,get:()=>c.frameDataCache}),Object.defineProperty(Q,"generate",{enumerable:!0,get:()=>c.generate}),Object.defineProperty(Q,"generateSVGWithUnknownColors",{enumerable:!0,get:()=>c.generateSVGWithUnknownColors}),Object.defineProperty(Q,"getAttributesFromArrayBuffer",{enumerable:!0,get:()=>c.getAttributesFromArrayBuffer}),Object.defineProperty(Q,"getAxisAlignedBoundingBox",{enumerable:!0,get:()=>c.getAxisAlignedBoundingBox}),Object.defineProperty(Q,"getFrameData",{enumerable:!0,get:()=>c.getFrameData}),Object.defineProperty(Q,"getSvgElement",{enumerable:!0,get:()=>c.getSvgElement}),Object.defineProperty(Q,"loadFont",{enumerable:!0,get:()=>c.loadFont}),Object.defineProperty(Q,"patternImageDataCache",{enumerable:!0,get:()=>c.patternImageDataCache}),Object.defineProperty(Q,"registerFetchImplementation",{enumerable:!0,get:()=>c.registerFetchImplementation}),Object.defineProperty(Q,"registerWindowImplementation",{enumerable:!0,get:()=>c.registerWindowImplementation}),Object.defineProperty(Q,"rehydrateSerializedLayout",{enumerable:!0,get:()=>c.rehydrateSerializedLayout}),Object.defineProperty(Q,"setCanvasModule",{enumerable:!0,get:()=>c.setCanvasModule}),Q.AssetNotFoundError=V,Q.CollectionProduct=jA,Q.ConversionDataType=gA,Q.ConversionLocation=cA,Q.FlowExecutionNodeResult=Be,Q.FlowExecutionResult=qA,Q.FlowService=XA,Q.FrameService=wA,Q.FrameStep=_A,Q.FrameStepHandle=et,Q.GlobalPropertyHandle=Me,Q.IllustrationStepHandle=yA,Q.InformationMessageType=ge,Q.InformationStepHandle=GA,Q.IntegrationType=sA,Q.LayoutNotFoundError=b,Q.MaterialStepHandle=PA,Q.MisconfigurationError=ne,Q.MockWorkflowManager=Ba,Q.ModelStepHandle=NA,Q.ObjectInput=ze,Q.ObjectInputType=ZA,Q.OptionNotFoundError=te,Q.ParseError=X,Q.PictureStepHandle=xA,Q.ProductCameraRig=rA,Q.ProductCollection=zA,Q.ProductWorkflow=Oe,Q.PromiseCache=q,Q.PromiseQueue=xe,Q.QuestionStepHandle=HA,Q.QueueablePromise=Ne,Q.ResourceNotFoundError=W,Q.ShapeStepHandle=RA,Q.SpiffCommerceClient=$A,Q.StakeholderType=oe,Q.StepHandle=j,Q.TextStepHandle=UA,Q.Transform=VA,Q.TransformCollection=KA,Q.UnhandledBehaviorError=v,Q.Variant=K,Q.WorkflowExperienceImpl=le,Q.assetService=J,Q.createDesign=JA,Q.designService=pe,Q.digitalContentStepService=QA,Q.frameStepService=ue,Q.generateCommands=TA,Q.generateStateFromDesignInputSteps=pn,Q.getBoundedOffsets=dA,Q.getWorkflow=de,Q.getWorkflows=je,Q.graphQlManager=x,Q.illustrationStepService=ce,Q.materialStepService=He,Q.modelStepService=Re,Q.moduleStepService=mA,Q.optionService=L,Q.persistenceService=P,Q.pictureStepService=Ue,Q.questionStepService=Ge,Q.shapeStepService=_,Q.shortenUrl=hA,Q.spiffCoreConfiguration=ae,Q.stepAspectValuesToDesignInputSteps=Dn,Q.textStepService=O,Q.toast=uA,Object.defineProperty(Q,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED