@spiffcommerce/core 21.9.1-5 → 21.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +190 -188
- package/dist/index.umd.cjs +3 -3
- package/package.json +1 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(u,M){typeof exports=="object"&&typeof module<"u"?M(exports,require("@apollo/client/core"),require("@spiffcommerce/papyrus"),require("@apollo/client/link/context"),require("@apollo/client/link/error"),require("pith"),require("lodash.debounce"),require("lodash.isequal"),require("lodash.clonedeep"),require("qrcode"),require("unicode-default-word-boundary"),require("svg-path-bbox"),require("lodash.chunk")):typeof define=="function"&&define.amd?define(["exports","@apollo/client/core","@spiffcommerce/papyrus","@apollo/client/link/context","@apollo/client/link/error","pith","lodash.debounce","lodash.isequal","lodash.clonedeep","qrcode","unicode-default-word-boundary","svg-path-bbox","lodash.chunk"],M):(u=typeof globalThis<"u"?globalThis:u||self,M(u.Core={},u.core,u.papyrus,u.context,u.error,u.pith,u.debounce,u.isEqual,u.cloneDeep,u.qrcode,u.unicodeDefaultWordBoundary,u.svgPathBbox,u.chunk))})(this,function(u,M,l,lA,dA,At,nt,at,ae,it,Ye,Pe,ot){"use strict";class st extends Error{constructor(e){super(e),this.name=this.constructor.name}}class ie extends st{constructor(e){super(`ConfigurationError - ${e}`)}}class oe extends ie{constructor(e){super(`Option not Configured: ${e.stepTitle}`),this.optionId=(e==null?void 0:e.optionId)||"N/A"}}class J extends ie{constructor(e){super(`Panel not Found: ${e.panelId}`),this.panelId=(e==null?void 0:e.panelId)||"N/A"}}class V extends ie{constructor(e){super(`Asset not found for variant: ${e.name}`),this.variant=e}}class X extends ie{constructor(e){super(`Resource not found for asset: ${e.name}`),this.asset=e}}class se extends ie{constructor(e,t){super(`Workflow Misconfiguration: ${e.stepName} - ${t}`),this.step=e}}class ue extends st{constructor(e){super(`ImplementationError - ${e}`)}}class k extends ue{constructor(e){super(`Unhandled Behavior Encountered: ${e}`)}}class q extends ue{constructor(e){super(`Parsing Error: ${e}`)}}class G extends ue{constructor(e){super(`Client Error: ${e}`)}}class Qe extends ue{constructor(e){super(`Resource Generation Failed: ${e}`)}}class BA{get(e){return localStorage.getItem(e)||void 0}set(e,t){localStorage.setItem(e,t)}remove(e){localStorage.removeItem(e)}getMap(e){const t=this.get(e);if(t)return new Map(JSON.parse(t))}setMap(e,t){const A=JSON.stringify([...t.entries()]);this.set(e,A)}}class rt{constructor(){this.storage=new Map}get(e){return this.storage.get(e)||void 0}set(e,t){this.storage.set(e,t)}remove(e){this.storage.delete(e)}getMap(e){const t=this.get(e);if(t)return new Map(JSON.parse(t))}setMap(e,t){const A=JSON.stringify([...t.entries()]);this.set(e,A)}}const P=(()=>{try{return localStorage?new BA:new rt}catch{return console.warn("Local storage was unavilable due to browser security settings. Using in-memory storage instead."),new rt}})();class wA{constructor(){this.defaultServerUrl="https://api.spiff.com.au",this.defaultServicesApiUrl="https://services.spiff.com.au",this.defaultHubUrl="https://hub.spiff.com.au",this.serverUrl=this.defaultServerUrl,this.servicesApiUrl=this.defaultServicesApiUrl,this.hubUrl=this.defaultHubUrl,this.serverUrlCallbacks=[]}getServerUrl(){return this.serverUrl}getServicesApiUrl(){return this.servicesApiUrl}getHubUrl(){return this.hubUrl}setServerUrl(e){this.serverUrl=e,this.serverUrlCallbacks.forEach(t=>t())}setServicesApiUrl(e){this.servicesApiUrl=e}setHubUrl(e){this.hubUrl=e}addServerUrlCallback(e){this.serverUrlCallbacks.push(e)}}const W=new wA;let ct;const gt=c=>{ct=c};let xe;const hA=c=>{xe=c},EA=()=>xe,CA=()=>new Promise(c=>{const e=W.getHubUrl(),t=A=>{A.origin===e&&(window.removeEventListener("message",t),c(A.data))};window.parent!==window&&(window.addEventListener("message",t,!1),window.parent.postMessage("ready",e))}),uA=async()=>{const c={applicationKey:xe,customerToken:ct};return typeof window<"u"&&(window.location.href.includes("/workflows/product/")||window.location.href.includes("hub=true"))?{...await CA(),...c}:c};class QA{constructor(){this.shadowGraphqlClient=this.constructShadowGraphqlClient(),W.addServerUrlCallback(()=>{this.shadowGraphqlClient=this.constructShadowGraphqlClient()})}getShadowGraphqlClient(){return
|
|
1
|
+
(function(u,M){typeof exports=="object"&&typeof module<"u"?M(exports,require("@apollo/client/core"),require("@spiffcommerce/papyrus"),require("@apollo/client/link/context"),require("@apollo/client/link/error"),require("pith"),require("lodash.debounce"),require("lodash.isequal"),require("lodash.clonedeep"),require("qrcode"),require("unicode-default-word-boundary"),require("svg-path-bbox"),require("lodash.chunk")):typeof define=="function"&&define.amd?define(["exports","@apollo/client/core","@spiffcommerce/papyrus","@apollo/client/link/context","@apollo/client/link/error","pith","lodash.debounce","lodash.isequal","lodash.clonedeep","qrcode","unicode-default-word-boundary","svg-path-bbox","lodash.chunk"],M):(u=typeof globalThis<"u"?globalThis:u||self,M(u.Core={},u.core,u.papyrus,u.context,u.error,u.pith,u.debounce,u.isEqual,u.cloneDeep,u.qrcode,u.unicodeDefaultWordBoundary,u.svgPathBbox,u.chunk))})(this,function(u,M,l,lA,dA,At,nt,at,ae,it,Ye,Pe,ot){"use strict";class st extends Error{constructor(e){super(e),this.name=this.constructor.name}}class ie extends st{constructor(e){super(`ConfigurationError - ${e}`)}}class oe extends ie{constructor(e){super(`Option not Configured: ${e.stepTitle}`),this.optionId=(e==null?void 0:e.optionId)||"N/A"}}class J extends ie{constructor(e){super(`Panel not Found: ${e.panelId}`),this.panelId=(e==null?void 0:e.panelId)||"N/A"}}class V extends ie{constructor(e){super(`Asset not found for variant: ${e.name}`),this.variant=e}}class X extends ie{constructor(e){super(`Resource not found for asset: ${e.name}`),this.asset=e}}class se extends ie{constructor(e,t){super(`Workflow Misconfiguration: ${e.stepName} - ${t}`),this.step=e}}class ue extends st{constructor(e){super(`ImplementationError - ${e}`)}}class k extends ue{constructor(e){super(`Unhandled Behavior Encountered: ${e}`)}}class q extends ue{constructor(e){super(`Parsing Error: ${e}`)}}class G extends ue{constructor(e){super(`Client Error: ${e}`)}}class Qe extends ue{constructor(e){super(`Resource Generation Failed: ${e}`)}}class BA{get(e){return localStorage.getItem(e)||void 0}set(e,t){localStorage.setItem(e,t)}remove(e){localStorage.removeItem(e)}getMap(e){const t=this.get(e);if(t)return new Map(JSON.parse(t))}setMap(e,t){const A=JSON.stringify([...t.entries()]);this.set(e,A)}}class rt{constructor(){this.storage=new Map}get(e){return this.storage.get(e)||void 0}set(e,t){this.storage.set(e,t)}remove(e){this.storage.delete(e)}getMap(e){const t=this.get(e);if(t)return new Map(JSON.parse(t))}setMap(e,t){const A=JSON.stringify([...t.entries()]);this.set(e,A)}}const P=(()=>{try{return localStorage?new BA:new rt}catch{return console.warn("Local storage was unavilable due to browser security settings. Using in-memory storage instead."),new rt}})();class wA{constructor(){this.defaultServerUrl="https://api.spiff.com.au",this.defaultServicesApiUrl="https://services.spiff.com.au",this.defaultHubUrl="https://hub.spiff.com.au",this.serverUrl=this.defaultServerUrl,this.servicesApiUrl=this.defaultServicesApiUrl,this.hubUrl=this.defaultHubUrl,this.serverUrlCallbacks=[]}getServerUrl(){return this.serverUrl}getServicesApiUrl(){return this.servicesApiUrl}getHubUrl(){return this.hubUrl}setServerUrl(e){this.serverUrl=e,this.serverUrlCallbacks.forEach(t=>t())}setServicesApiUrl(e){this.servicesApiUrl=e}setHubUrl(e){this.hubUrl=e}addServerUrlCallback(e){this.serverUrlCallbacks.push(e)}}const W=new wA;let ct;const gt=c=>{ct=c};let xe;const hA=c=>{xe=c},EA=()=>xe,CA=()=>new Promise(c=>{const e=W.getHubUrl(),t=A=>{A.origin===e&&(window.removeEventListener("message",t),c(A.data))};window.parent!==window&&(window.addEventListener("message",t,!1),window.parent.postMessage("ready",e))}),uA=async()=>{const c={applicationKey:xe,customerToken:ct};return typeof window<"u"&&(window.location.href.includes("/workflows/product/")||window.location.href.includes("hub=true"))?{...await CA(),...c}:c};class QA{constructor(){this.shadowGraphqlClient=this.constructShadowGraphqlClient(),W.addServerUrlCallback(()=>{this.shadowGraphqlClient=this.constructShadowGraphqlClient()})}getShadowGraphqlClient(){return this.shadowGraphqlClient}constructShadowGraphqlClient(){const e=M.createHttpLink({uri:`${W.getServerUrl()}/graphql`,fetch:l.fetch}),t=lA.setContext(async(i,o)=>{const{headers:s}=o,r=s||{},g=await uA(),B=o.bearer??g.bearer,d=o.partnerId??g.partnerId,w=o.activeIntegration??g.activeIntegration,h=o.transactionOwnerId,C=o.customerToken??g.customerToken,E=o.applicationKey??g.applicationKey,m=o.bundleOwnerId;try{if(window&&window.__SENTRY__){const Q=window.__SENTRY__.hub;if(Q){const F=Q.traceHeaders();Object.entries(F).forEach(([I,f])=>{r[I]=f})}}}catch{}return B&&(r.Authorization=`Bearer ${B}`),d&&(r.partnerId=d),w&&(r.activeIntegration=w),h&&(r.transactionOwnerId=h),C&&(r.customerToken=C),E&&(r["X-Application-Key"]=E),m&&(r.bundleOwnerId=m),{headers:r}}),A=dA.onError(({operation:i,graphQLErrors:o,networkError:s})=>{const r=o||[];s&&console.log("GraphQL Network error"),r.forEach(()=>console.log("GraphQL Error: "+i.operationName))});function n(){return{read(i=null){return i},merge(i,o){return o||i||null}}}const a=new M.InMemoryCache({addTypename:!1,typePolicies:{Transaction:{fields:{transactionOwnerId:n(),customLogoLink:n(),workflowFooterLogoLink:n(),workflowState:n(),externalDesignProductId:n(),externalDesignProductVariantId:n(),externalCartProductId:n(),externalCartProductVariantId:n(),lastSyncedAt:n(),quantity:n(),lineItem:n()}},WorkflowProduct:{fields:{isPresent:n()}},Product:{fields:{imageUrl:n(),overlayImageUrl:n(),preloadImageUrl:n(),weight:n(),conversionConfiguration:n()}}}});return new M.ApolloClient({link:M.from([A,t,e]),cache:a,name:"Core"})}}const N=new QA,mA=M.gql`
|
|
2
2
|
fragment AssetMetadataFields on Asset {
|
|
3
3
|
metadata {
|
|
4
4
|
key
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
...AssetFields
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
`,lt=async c=>(await N.getShadowGraphqlClient().query({query:IA,errorPolicy:"all",fetchPolicy:"no-cache",variables:{keys:c}})).data.assets,FA=async c=>(await N.getShadowGraphqlClient().query({query:fA,errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:c}})).data.materials,MA=async(c,e,t,A,n)=>{var i;return(i=(await N.getShadowGraphqlClient().mutate({mutation:DA,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:c,type:e,mimeType:t,anonymous:A,temporary:n}})).data)==null?void 0:i.assetCreate};class SA{constructor(){this.cache=new Map,this.bgrmCache=new Map,this.materialCache=new Map,this.loadImageAsFileInfo=async e=>{const t=await e.arrayBuffer();return{name:e.name.substring(e.name.lastIndexOf("/")+1),blob:
|
|
105
|
+
`,lt=async c=>(await N.getShadowGraphqlClient().query({query:IA,errorPolicy:"all",fetchPolicy:"no-cache",variables:{keys:c}})).data.assets,FA=async c=>(await N.getShadowGraphqlClient().query({query:fA,errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:c}})).data.materials,MA=async(c,e,t,A,n)=>{var i;return(i=(await N.getShadowGraphqlClient().mutate({mutation:DA,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:c,type:e,mimeType:t,anonymous:A,temporary:n}})).data)==null?void 0:i.assetCreate};class SA{constructor(){this.cache=new Map,this.bgrmCache=new Map,this.materialCache=new Map,this.loadImageAsFileInfo=async e=>{const t=await e.arrayBuffer(),A=await l.getAttributesFromArrayBuffer(t),n=(a,i)=>{const o=atob(a.split(",")[1]),s=[];for(let r=0;r<o.length;r++)s.push(o.charCodeAt(r));return new Blob([new Uint8Array(s)],{type:i})};return{name:e.name.substring(e.name.lastIndexOf("/")+1),blob:n(A.dataUrl,e.type)}}}async getLocalOrFromServer(e){if(this.cache.has(e)){const n=this.cache.get(e);if(!n)throw new k("Failed to get asset from cache!");return n}const A=(async()=>(await lt([e]))[0])();return this.cache.set(e,A),A}cacheAsset(e){if(!e.key)throw new k("Asset has no key!");this.cache.has(e.key)||this.cache.set(e.key,Promise.resolve(e))}cacheMaterial(e){if(!e.id)throw new k("Material has no id!");this.materialCache.has(e.id)||this.materialCache.set(e.id,Promise.resolve(e))}async getMaterialLocalOrFromServer(e){if(this.materialCache.has(e))return this.materialCache.get(e);const A=(async()=>(await FA([e]))[0])();return this.materialCache.set(e,A),A}async uploadAssetWithProgress(e,t,A,n,a){const i=await this.dispatchCreateAssetRequest(e,t,n,a);if(!i)throw new Error("Failed to create asset.");return await new Promise((o,s)=>{const r=new XMLHttpRequest;r.open("PUT",i.assetResponse.uploadUrl,!0),r.setRequestHeader("Content-Type",i.mimeType),r.setRequestHeader("Cache-Control","public,max-age=31536000,immutable"),r.upload.onprogress=g=>{g.lengthComputable&&A(g.loaded*100/g.total)},r.onload=()=>{const g=i.assetResponse.asset;He.add(i.assetResponse.asset),o(g)},r.onerror=s,r.send(e.blob)}),this.cacheAsset(i.assetResponse.asset),i.assetResponse.asset}async uploadAsset(e,t,A,n){return this.uploadAssetWithProgress(e,t,()=>{},A,n)}async uploadFile(e,t){const A=!(e.type==="image/svg+xml"||e.type==="application/pdf"),n=A?l.AssetType.Image:l.AssetType.Illustration;if(A){const a=await this.loadImageAsFileInfo(e);return await this.uploadAssetWithProgress(a,n,t,!0)}else{const a={name:e.name,blob:new Blob([e],{type:e.type})};return await this.uploadAssetWithProgress(a,n,t,!0)}}async removeBackgroundFromAsset(e){if(this.bgrmCache.has(e.key))return this.bgrmCache.get(e.key);const A=(async()=>{var a,i;const n=await N.getShadowGraphqlClient().mutate({mutation:pA,fetchPolicy:"no-cache",errorPolicy:"all",variables:{key:e.key}});if(!((i=(a=n.data)==null?void 0:a.assetRemoveBackground)!=null&&i.key))throw new Error("Failed to remove background from image");return n.data.assetRemoveBackground})();return this.bgrmCache.set(e.key,A),A}removePersistedAsset(e){He.remove(e)}getPersistedAssets(){return He.list()}async dispatchCreateAssetRequest(e,t,A,n){const a=e.blob.type?e.blob.type:this.guessMIME(e.name),i=await MA(e.name,t,a,A,n);if(i)return{assetResponse:i,mimeType:a}}guessMIME(e){const t=e.split(".").pop();switch(t){case"glb":return"model/gltf-binary";case"ttf":return"font/ttf";case"mkv":return"video/x-matroska";default:throw new k("Unexpected mimetype: "+t)}}}const ce="persistentAssets";class He{static add(e){if(!e.fileLink){console.error("Failed to find cdn link on asset, cannot persist!");return}const t=new Map;t.set(e.key||"",e.fileLink);const A=P.getMap(ce);A&&A.forEach((n,a)=>{t.set(a,n)}),P.setMap(ce,t)}static remove(e){const t=P.getMap(ce);if(!t)return;const A=Array.from(t.entries()).find(n=>n[0]===e);A&&(t.delete(A[0]),P.setMap(ce,t))}static list(){const e=P.getMap(ce);return e?Array.from(e.entries()).map(t=>({assetKey:t[0],src:t[1]})):[]}}const v=new SA;class yA{constructor(){this.cache={},this.disabled=!1}get(e){if(this.disabled)return;const t=JSON.stringify(e);return this.cache[t]}set(e,t){if(this.disabled)return t;const A=JSON.stringify(e);return this.cache[A]=t,t}disable(e){this.disabled=e}}const Z=new yA,dt=M.gql`
|
|
106
106
|
fragment OptionFields on Option {
|
|
107
107
|
id
|
|
108
108
|
name
|
|
@@ -2002,7 +2002,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
2002
2002
|
}
|
|
2003
2003
|
}
|
|
2004
2004
|
}
|
|
2005
|
-
`;function je(c){const e=JSON.parse(atob(c.split(".")[1])).exp;return Math.floor(new Date().getTime()/1e3)>=e}const Qn=async c=>{var i,o;const t=((i=Object.entries(localStorage).find(([s,r])=>s.startsWith("CognitoIdentityServiceProvider")&&s.endsWith("idToken")))==null?void 0:i[0])||"",A=localStorage.getItem(t),n={};return A&&!je(A)&&(n.Authorization=`Bearer ${A}`),(o=(await N.getShadowGraphqlClient().mutate({mutation:Cn,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:c.name,layouts:c.layouts,workflowId:c.workflowId,transactionId:c.transactionId,previewImage:c.previewImage,useThreeDimPreview:c.useThreeDimPreview,metadata:c.metadata,selectedVariants:c.selectedVariants},context:{headers:n}})).data)==null?void 0:o.designCreate},mn=async c=>{var i,o;
|
|
2005
|
+
`;function je(c){const e=JSON.parse(atob(c.split(".")[1])).exp;return Math.floor(new Date().getTime()/1e3)>=e}const Qn=async c=>{var i,o;const t=((i=Object.entries(localStorage).find(([s,r])=>s.startsWith("CognitoIdentityServiceProvider")&&s.endsWith("idToken")))==null?void 0:i[0])||"",A=localStorage.getItem(t),n={};return A&&!je(A)&&(n.Authorization=`Bearer ${A}`),(o=(await N.getShadowGraphqlClient().mutate({mutation:Cn,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:c.name,layouts:c.layouts,workflowId:c.workflowId,transactionId:c.transactionId,previewImage:c.previewImage,useThreeDimPreview:c.useThreeDimPreview,metadata:c.metadata,selectedVariants:c.selectedVariants},context:{headers:n}})).data)==null?void 0:o.designCreate},mn=async c=>{var i,o;const t=((i=Object.entries(localStorage).find(([s,r])=>s.startsWith("CognitoIdentityServiceProvider")&&s.endsWith("idToken")))==null?void 0:i[0])||"",A=localStorage.getItem(t),n={};return A&&!je(A)&&(n.Authorization=`Bearer ${A}`),(o=(await N.getShadowGraphqlClient().mutate({mutation:un,errorPolicy:"all",fetchPolicy:"no-cache",variables:{inputs:c.map(s=>({name:s.name,layouts:s.layouts,workflowId:s.workflowId,transactionId:s.transactionId,previewImage:s.previewImage,useThreeDimPreview:s.useThreeDimPreview,metadata:s.metadata,selectedVariants:s.selectedVariants}))},context:{headers:n}})).data)==null?void 0:o.designCreateMany},Ke=(c,e,t)=>{const A=a=>{const i={};if(a.type==="Frame"){const o=c[a.stepName],s=a.data;if(!o||!o.image||s.hideImageInCart&&t)return i;i[`${a.stepTitle} image`]=o.image}if(a.type==="Illustration"){const o=c[a.stepName],s=a.data;if(!o||s.hideColorsInCart&&t||!o.colors)return i;if(o.colors.length>0){const r=o.colors.join(", ").toUpperCase();i[`${a.stepTitle} colors`]=r}}if(a.type==="Module"){const o=c[a.stepName],s=a.data;if(!o||o.text===void 0||o.text===null||s.hideTextInCart&&t)return i;i[`${a.stepTitle} text`]=o.text}if(a.type==="Text"){const o=c[a.stepName];if(!o)return i;const s=a.data;(!s.hideTextInCart||!t&&o.text!==void 0&&o.text!==null)&&(i[`${a.stepTitle} text`]=o.text),o.color&&(!s.hideColorInCart||!t)&&(i[`${a.stepTitle} color`]=o.color)}return i},n={};return e.steps.forEach(a=>{Object.assign(n,A(a))}),n},In=(c,e,t,A)=>{const n={};let a;if(t){a=Ke(t,e,!1);for(const i of Object.keys(a))n[i]={value:a[i],priceModifier:0}}else if(A){a=A;for(const i of Object.keys(a))n[i]={value:a[i],priceModifier:0}}for(const i of Object.keys(c)){const o=c[i],s=e.steps.find(r=>r.stepTitle===i);if(o.length===1)n[`${s==null?void 0:s.stepTitle} selection`]={value:o[0].name,priceModifier:o[0].priceModifier};else if(o.length>1)for(let r=0;r<o.length;r++)n[`${s==null?void 0:s.stepTitle} selection ${r+1}`]={value:o[r].name,priceModifier:o[r].priceModifier}}return n},jt=(c,e,t,A,n,a,i,o)=>{var h,C;const s=e.basePrice||0,r=c.priceModifierTotal||0,g=In(A,t,void 0,a),d=(P.getMap("transactionOwnerIds")||new Map).get(c.id),w={additionalExternalProductId:(h=c.integrationProduct)==null?void 0:h.additionalExternalProductId,additionalExternalVariantId:(C=c.integrationProduct)==null?void 0:C.additionalExternalVariantId,baseCost:s,designProductId:c.externalDesignProductId,designProductVariantId:c.externalDesignProductVariantId,event:"onComplete",exportedData:g,externalCartProductId:c.externalCartProductId,externalCartProductVariantId:c.externalCartProductVariantId,lineItemImageUrl:i||"",optionsCost:r,processExecutionId:o,quantity:c.quantity,transactionId:c.id,transactionOwnerId:d,weight:e.weight,workflowViewerLink:c.workflowViewerLink||"",workflowViewerReadOnlyLink:c.workflowViewerReadOnlyLink||""};return a&&(w.metadata=a),A&&(w.selectedVariants=A),n&&(w.sku=n),w},Kt=async(c,e,t,A,n,a,i,o,s,r)=>{var S;await(async()=>{var T;if(r!==void 0)return r;await c.outstandingRequestsPromise();const x=(P.getMap("transactionOwnerIds")||new Map).get(n.id),H=await N.getShadowGraphqlClient().query({query:ut,variables:{ids:[n.id]},fetchPolicy:"no-cache",errorPolicy:"all",context:{transactionOwnerId:x}}),R=(T=H.data)==null?void 0:T.transactions[0].workflowState;return H.errors?(H.errors.forEach(b=>{H.errors&&console.log("Server Error:",b.message)}),null):R??null})()||(console.warn("State mismatch detected. Uploading known state explicitly"),console.warn("State Object:",JSON.stringify(A())),await c.updateStateWithServerImmediate(A),console.log("Server state is undefined @ Workflow completion"));const d=c.getPreviewService(),w=(S=e==null?void 0:e.finalizeStepConfig)==null?void 0:S.lookAtAnimation,h=d&&e.showModelOnFinishStep&&!!w,C=s&&Ke(s,e,!0),E=s&&Ke(s,e,!1),m=async y=>{const x={};let Y=0;if(Object.keys(a).length>0)for(const H of Object.keys(a)){const R=a[H],T=e.steps.find(b=>b.stepName===H);for(let b=0;b<R.selections.length;++b){const z=R.selections[b];if(T&&(!y||T.option&&(T.option.variants||[]).length>1&&!T.data.hideSelectionInCart&&!T.data.hideSelectionsInCart)){const et=T.stepTitle;x[et]?x[et].push({id:z.id||"",name:z.name,priceModifier:z.priceModifier}):x[et]=[{id:z.id||"",name:z.name,priceModifier:z.priceModifier}]}Y+=z.priceModifier}}return[x,Y]},[Q]=await m(!0),F=Object.fromEntries(Object.keys(Q).map(y=>[y,Q[y].map(x=>x.id)])),[I]=await m(!1),f=Object.fromEntries(Object.keys(I).map(y=>[y,I[y].map(x=>x.id)])),D=await o(h,n.id);return{designDetails:(()=>{const y={name:i,layouts:t.map(x=>({index:x.index,panelId:x.panelId})),workflowId:e.id,transactionId:n.id,useThreeDimPreview:!!h,previewImage:D};if(E){const x=[];for(const[Y,H]of Object.entries(E))x.push({key:Y,value:H});y.metadata=x}if(F){const x=[];for(const[Y,H]of Object.entries(f))x.push({key:Y,ids:H});y.selectedVariants=x}return y})(),cartSelectionsWithPrices:Q,cartMetadata:C}},Vt=async(c,e,t,A,n,a,i,o,s,r,g)=>{var m,Q;s("workflow.steps.finish.finalize.buildingLayouts");const{designDetails:B,cartSelectionsWithPrices:d,cartMetadata:w}=await Kt(c,e,t,A,a,i,o,r,g);s("workflow.steps.finish.finalize.creatingDesign");const h=await Qn(B),C=(m=h==null?void 0:h.transaction)==null?void 0:m.previewImageLink;if(!(h!=null&&h.transaction))throw new Error("Failed to create design");s("workflow.steps.finish.finalize.updatingTransaction");const E=h.transaction;return jt(E,n,e,d,h==null?void 0:h.sku,w,C,(Q=h==null?void 0:h.processExecution)==null?void 0:Q.id)},fn=async(c,e,t)=>{e("workflow.steps.finish.finalize.buildingLayouts"),await Promise.all(c.map(async o=>{await o.workflowManager.outstandingRequestsPromise()}));const n=await(async()=>{var r;const s=await N.getShadowGraphqlClient().query({query:ut,variables:{ids:c.map(g=>g.transaction.id)},fetchPolicy:"no-cache",errorPolicy:"all"});return s.errors?(s.errors.forEach(g=>{s.errors&&console.log("Server Error:",g.message)}),null):(r=s.data)!=null&&r.transactions?s.data.transactions.map(g=>g.workflowState??null):null})(),a=await Promise.all(c.map(async(o,s)=>await Kt(o.workflowManager,o.workflow,o.layouts,o.getReducerState,o.transaction,o.workflowSelections,o.designName,t??(()=>Promise.resolve(void 0)),o.workflowMetadata,n?n[s]:void 0)));e("workflow.steps.finish.finalize.creatingDesign");const i=await mn(a.map(o=>o.designDetails));if(!i)throw new Error("Failed to create designs");return e("workflow.steps.finish.finalize.updatingTransaction"),i.map((o,s)=>{var d;const r=c[s],g=a[s],B=o.transaction;return jt(B,r.product,r.workflow,g.cartSelectionsWithPrices,o.sku,g.cartMetadata,void 0,(d=o.processExecution)==null?void 0:d.id)})};class Dn{constructor(){this.localPersistenceKey="designTransactions",this.storageMethod="Local",this.designSavedListeners=[]}attachSaveListener(e){this.designSavedListeners.push(e)}detachSaveListener(e){this.designSavedListeners=this.designSavedListeners.filter(t=>t!==e)}async getSavedDesigns(){if(this.storageMethod==="Local"){const e=P.get(this.localPersistenceKey);return e?JSON.parse(e):[]}throw new k("Unexpected storage method requested")}async getSavedDesignByTransaction(e){return(await this.getSavedDesigns()).find(A=>A.transactionId===e)}async addDesign(e){const A=(await this.getSavedDesigns()).filter(n=>n.transactionId!==e.transactionId);A.unshift(e),await this.setDesigns(A),this.designSavedListeners.forEach(n=>n(e))}async renameDesign(e,t){const A=await this.getSavedDesigns(),n=A.find(a=>a.transactionId===e);if(!n)throw new Error(`No saved design for transaction ${e}.`);n.title=t,await this.setDesigns(A)}async removeDesign(e){const t=await this.getSavedDesigns();await this.setDesigns(t.filter(A=>A.transactionId!==e))}async setDesigns(e){if(this.storageMethod==="Local"){P.set(this.localPersistenceKey,JSON.stringify(e));return}throw new k("Unexpected storage method requested")}}const Fe=new Dn,pn=M.gql`
|
|
2006
2006
|
mutation AddTransactionStakeholder($id: String!, $type: String!, $details: CustomerDetailsInput!) {
|
|
2007
2007
|
transactionAddStakeholder(id: $id, details: $details, type: $type) {
|
|
2008
2008
|
id
|