@spiffcommerce/core 21.16.0-alpha.0 → 21.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +17 -4
- package/dist/index.js +8 -5
- package/dist/index.umd.cjs +7 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -313,7 +313,6 @@ declare class LayoutPreviewBridge implements RenderableContext {
|
|
|
313
313
|
private staticCtxDirty;
|
|
314
314
|
private lastRequestedRenderArguments;
|
|
315
315
|
private lastCompletedStaticRender;
|
|
316
|
-
private lastModificationID;
|
|
317
316
|
private renderQueue;
|
|
318
317
|
constructor(id: string, name: string, service: LayoutPreviewService, panelSize: {
|
|
319
318
|
width: number;
|
|
@@ -340,7 +339,6 @@ declare class LayoutPreviewBridge implements RenderableContext {
|
|
|
340
339
|
* form of Date.now(). If this panel has never rendered undefined will be returned.
|
|
341
340
|
*/
|
|
342
341
|
getLastCompletedStaticRender(): number | undefined;
|
|
343
|
-
getLastModificationID(): string | undefined;
|
|
344
342
|
/**
|
|
345
343
|
* Actions to perform when a static render event is fired for this canvas.
|
|
346
344
|
*/
|
|
@@ -2119,6 +2117,7 @@ interface DesignCreationMessage {
|
|
|
2119
2117
|
additionalExternalProductId?: string;
|
|
2120
2118
|
additionalExternalVariantId?: string;
|
|
2121
2119
|
baseCost?: number;
|
|
2120
|
+
designExternalVariants?: DesignExternalVariant[];
|
|
2122
2121
|
designProductId?: string;
|
|
2123
2122
|
designProductVariantId?: string;
|
|
2124
2123
|
event: string;
|
|
@@ -2206,14 +2205,14 @@ interface Transaction {
|
|
|
2206
2205
|
* to this transaction, null unless the createDesignProduct flag was set
|
|
2207
2206
|
* and the design was finalized using createDesign operation.
|
|
2208
2207
|
*/
|
|
2209
|
-
/**@deprecated use externalCartProductVariantId instead of this moving forward */
|
|
2208
|
+
/**@deprecated use externalCartProductVariantId or designExternalVariants[x].externalProductVariantId instead of this moving forward */
|
|
2210
2209
|
externalDesignProductVariantId?: string;
|
|
2211
2210
|
/**
|
|
2212
2211
|
* The external product id representing the design product related
|
|
2213
2212
|
* to this transaction, null unless the createDesignProduct flag was set
|
|
2214
2213
|
* and the design was finalized using createDesign operation.
|
|
2215
2214
|
*/
|
|
2216
|
-
/**@deprecated use externalCartProductId instead of this moving forward. */
|
|
2215
|
+
/**@deprecated use externalCartProductId or designExternalVariants[x].externalProductId instead of this moving forward. */
|
|
2217
2216
|
externalDesignProductId?: string;
|
|
2218
2217
|
/**
|
|
2219
2218
|
* The external product id representing the product related to the transaction.
|
|
@@ -2251,6 +2250,20 @@ interface Transaction {
|
|
|
2251
2250
|
printFileName3?: string;
|
|
2252
2251
|
printFileName4?: string;
|
|
2253
2252
|
printFileName5?: string;
|
|
2253
|
+
/**
|
|
2254
|
+
* An array of objects containing information on additional products to add to the cart.
|
|
2255
|
+
* Typically only available when being passed to {@link DesignCreationMessage}
|
|
2256
|
+
*/
|
|
2257
|
+
designExternalVariants?: DesignExternalVariant[];
|
|
2258
|
+
}
|
|
2259
|
+
/**
|
|
2260
|
+
* An object containing ids for an external product/variant that should be added to the cart alongside the base product/variant.
|
|
2261
|
+
*/
|
|
2262
|
+
interface DesignExternalVariant {
|
|
2263
|
+
id?: string;
|
|
2264
|
+
externalProductId?: string;
|
|
2265
|
+
externalProductVariantId?: string;
|
|
2266
|
+
skuCode?: string;
|
|
2254
2267
|
}
|
|
2255
2268
|
/**
|
|
2256
2269
|
* An integration product represents the connection of a product in SpiffCommerce with
|
package/dist/index.js
CHANGED
|
@@ -6324,6 +6324,11 @@ const wA = D`
|
|
|
6324
6324
|
additionalExternalProductId
|
|
6325
6325
|
additionalExternalVariantId
|
|
6326
6326
|
}
|
|
6327
|
+
designExternalVariants {
|
|
6328
|
+
id
|
|
6329
|
+
externalProductId
|
|
6330
|
+
externalProductVariantId
|
|
6331
|
+
}
|
|
6327
6332
|
}
|
|
6328
6333
|
`, wn = D`
|
|
6329
6334
|
${wA}
|
|
@@ -6495,6 +6500,7 @@ const En = async (c) => {
|
|
|
6495
6500
|
additionalExternalProductId: (w = c.integrationProduct) == null ? void 0 : w.additionalExternalProductId,
|
|
6496
6501
|
additionalExternalVariantId: (E = c.integrationProduct) == null ? void 0 : E.additionalExternalVariantId,
|
|
6497
6502
|
baseCost: o,
|
|
6503
|
+
designExternalVariants: c.designExternalVariants,
|
|
6498
6504
|
designProductId: c.externalDesignProductId,
|
|
6499
6505
|
designProductVariantId: c.externalDesignProductVariantId,
|
|
6500
6506
|
event: "onComplete",
|
|
@@ -7687,7 +7693,7 @@ const Un = () => new Promise((c, e) => {
|
|
|
7687
7693
|
}), vn = Un();
|
|
7688
7694
|
class Gn {
|
|
7689
7695
|
constructor(e, t, A, a) {
|
|
7690
|
-
this.hasSetStaticContext = !1, this.interactiveDirty = !1, this.staticCtxDirty = !1, this.lastRequestedRenderArguments = void 0, this.lastCompletedStaticRender = void 0, this.
|
|
7696
|
+
this.hasSetStaticContext = !1, this.interactiveDirty = !1, this.staticCtxDirty = !1, this.lastRequestedRenderArguments = void 0, this.lastCompletedStaticRender = void 0, this.renderQueue = new AA(2), this.id = e, this.name = t, this.service = A, this.panelSize = a;
|
|
7691
7697
|
}
|
|
7692
7698
|
getID() {
|
|
7693
7699
|
return this.id;
|
|
@@ -7729,9 +7735,6 @@ class Gn {
|
|
|
7729
7735
|
getLastCompletedStaticRender() {
|
|
7730
7736
|
return this.lastCompletedStaticRender;
|
|
7731
7737
|
}
|
|
7732
|
-
getLastModificationID() {
|
|
7733
|
-
return this.lastModificationID;
|
|
7734
|
-
}
|
|
7735
7738
|
/**
|
|
7736
7739
|
* Actions to perform when a static render event is fired for this canvas.
|
|
7737
7740
|
*/
|
|
@@ -7740,7 +7743,7 @@ class Gn {
|
|
|
7740
7743
|
this.lastRequestedRenderArguments = t;
|
|
7741
7744
|
const A = this.getStaticContext();
|
|
7742
7745
|
if (!A) {
|
|
7743
|
-
this.markLastCompletedStaticRender(), this.setStaticContextDirty(!
|
|
7746
|
+
this.markLastCompletedStaticRender(), this.setStaticContextDirty(!1);
|
|
7744
7747
|
return;
|
|
7745
7748
|
}
|
|
7746
7749
|
this.renderQueue.enqueue(
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1960,6 +1960,11 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
1960
1960
|
additionalExternalProductId
|
|
1961
1961
|
additionalExternalVariantId
|
|
1962
1962
|
}
|
|
1963
|
+
designExternalVariants {
|
|
1964
|
+
id
|
|
1965
|
+
externalProductId
|
|
1966
|
+
externalProductVariantId
|
|
1967
|
+
}
|
|
1963
1968
|
}
|
|
1964
1969
|
`,In=M.gql`
|
|
1965
1970
|
${Xt}
|
|
@@ -2007,7 +2012,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
2007
2012
|
}
|
|
2008
2013
|
}
|
|
2009
2014
|
}
|
|
2010
|
-
`;function We(c){const e=JSON.parse(atob(c.split(".")[1])).exp;return Math.floor(new Date().getTime()/1e3)>=e}const Dn=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&&!We(A)&&(n.Authorization=`Bearer ${A}`),(o=(await N.getShadowGraphqlClient().mutate({mutation:In,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},Fn=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&&!We(A)&&(n.Authorization=`Bearer ${A}`),(o=(await N.getShadowGraphqlClient().mutate({mutation:pn,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},Xe=(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},Mn=(c,e,t,A)=>{const n={};let a;if(t){a=Xe(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},qt=(c,e,t,A,n,a,i,o)=>{var h,C;const s=e.basePrice||0,r=c.priceModifierTotal||0,g=Mn(A,t,void 0,a),d=(Y.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},Zt=async(c,e,t,A,n,a,i,o,s,r)=>{var y;await(async()=>{var T;if(r!==void 0)return r;await c.outstandingRequestsPromise();const x=(Y.getMap("transactionOwnerIds")||new Map).get(n.id),H=await N.getShadowGraphqlClient().query({query:pt,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=(y=e==null?void 0:e.finalizeStepConfig)==null?void 0:y.lookAtAnimation,h=d&&e.showModelOnFinishStep&&!!w,C=s&&Xe(s,e,!0),E=s&&Xe(s,e,!1),m=async S=>{const x={};let P=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 j=R.selections[b];if(T&&(!S||T.option&&(T.option.variants||[]).length>1&&!T.data.hideSelectionInCart&&!T.data.hideSelectionsInCart)){const nt=T.stepTitle;x[nt]?x[nt].push({id:j.id||"",name:j.name,priceModifier:j.priceModifier}):x[nt]=[{id:j.id||"",name:j.name,priceModifier:j.priceModifier}]}P+=j.priceModifier}}return[x,P]},[Q]=await m(!0),F=Object.fromEntries(Object.keys(Q).map(S=>[S,Q[S].map(x=>x.id)])),[f]=await m(!1),p=Object.fromEntries(Object.keys(f).map(S=>[S,f[S].map(x=>x.id)]));let I=await o(h,n.id);if(I){const S=await(await fetch(I)).blob();I=(await G.uploadAsset({name:`${n.id}-preview-image.png`,blob:S},l.AssetType.Image,!0,!1)).fileLink}return{designDetails:(()=>{const S={name:i,layouts:t.map(x=>({index:x.index,panelId:x.panelId})),workflowId:e.id,transactionId:n.id,useThreeDimPreview:!!h,previewImage:I};if(E){const x=[];for(const[P,H]of Object.entries(E))x.push({key:P,value:H});S.metadata=x}if(F){const x=[];for(const[P,H]of Object.entries(p))x.push({key:P,ids:H});S.selectedVariants=x}return S})(),cartSelectionsWithPrices:Q,cartMetadata:C}},$t=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 Zt(c,e,t,A,a,i,o,r,g);s("workflow.steps.finish.finalize.creatingDesign");const h=await Dn(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 qt(E,n,e,d,h==null?void 0:h.sku,w,C,(Q=h==null?void 0:h.processExecution)==null?void 0:Q.id)},yn=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:pt,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 Zt(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 Fn(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 qt(B,r.product,r.workflow,g.cartSelectionsWithPrices,o.sku,g.cartMetadata,void 0,(d=o.processExecution)==null?void 0:d.id)})};class Sn{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=Y.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"){Y.set(this.localPersistenceKey,JSON.stringify(e));return}throw new k("Unexpected storage method requested")}}const Ye=new Sn,Yn=M.gql`
|
|
2015
|
+
`;function We(c){const e=JSON.parse(atob(c.split(".")[1])).exp;return Math.floor(new Date().getTime()/1e3)>=e}const Dn=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&&!We(A)&&(n.Authorization=`Bearer ${A}`),(o=(await N.getShadowGraphqlClient().mutate({mutation:In,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},Fn=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&&!We(A)&&(n.Authorization=`Bearer ${A}`),(o=(await N.getShadowGraphqlClient().mutate({mutation:pn,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},Xe=(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},Mn=(c,e,t,A)=>{const n={};let a;if(t){a=Xe(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},qt=(c,e,t,A,n,a,i,o)=>{var h,C;const s=e.basePrice||0,r=c.priceModifierTotal||0,g=Mn(A,t,void 0,a),d=(Y.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,designExternalVariants:c.designExternalVariants,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},Zt=async(c,e,t,A,n,a,i,o,s,r)=>{var y;await(async()=>{var T;if(r!==void 0)return r;await c.outstandingRequestsPromise();const x=(Y.getMap("transactionOwnerIds")||new Map).get(n.id),H=await N.getShadowGraphqlClient().query({query:pt,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=(y=e==null?void 0:e.finalizeStepConfig)==null?void 0:y.lookAtAnimation,h=d&&e.showModelOnFinishStep&&!!w,C=s&&Xe(s,e,!0),E=s&&Xe(s,e,!1),m=async S=>{const x={};let P=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 j=R.selections[b];if(T&&(!S||T.option&&(T.option.variants||[]).length>1&&!T.data.hideSelectionInCart&&!T.data.hideSelectionsInCart)){const nt=T.stepTitle;x[nt]?x[nt].push({id:j.id||"",name:j.name,priceModifier:j.priceModifier}):x[nt]=[{id:j.id||"",name:j.name,priceModifier:j.priceModifier}]}P+=j.priceModifier}}return[x,P]},[Q]=await m(!0),F=Object.fromEntries(Object.keys(Q).map(S=>[S,Q[S].map(x=>x.id)])),[f]=await m(!1),p=Object.fromEntries(Object.keys(f).map(S=>[S,f[S].map(x=>x.id)]));let I=await o(h,n.id);if(I){const S=await(await fetch(I)).blob();I=(await G.uploadAsset({name:`${n.id}-preview-image.png`,blob:S},l.AssetType.Image,!0,!1)).fileLink}return{designDetails:(()=>{const S={name:i,layouts:t.map(x=>({index:x.index,panelId:x.panelId})),workflowId:e.id,transactionId:n.id,useThreeDimPreview:!!h,previewImage:I};if(E){const x=[];for(const[P,H]of Object.entries(E))x.push({key:P,value:H});S.metadata=x}if(F){const x=[];for(const[P,H]of Object.entries(p))x.push({key:P,ids:H});S.selectedVariants=x}return S})(),cartSelectionsWithPrices:Q,cartMetadata:C}},$t=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 Zt(c,e,t,A,a,i,o,r,g);s("workflow.steps.finish.finalize.creatingDesign");const h=await Dn(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 qt(E,n,e,d,h==null?void 0:h.sku,w,C,(Q=h==null?void 0:h.processExecution)==null?void 0:Q.id)},yn=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:pt,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 Zt(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 Fn(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 qt(B,r.product,r.workflow,g.cartSelectionsWithPrices,o.sku,g.cartMetadata,void 0,(d=o.processExecution)==null?void 0:d.id)})};class Sn{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=Y.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"){Y.set(this.localPersistenceKey,JSON.stringify(e));return}throw new k("Unexpected storage method requested")}}const Ye=new Sn,Yn=M.gql`
|
|
2011
2016
|
mutation AddTransactionStakeholder($id: String!, $type: String!, $details: CustomerDetailsInput!) {
|
|
2012
2017
|
transactionAddStakeholder(id: $id, details: $details, type: $type) {
|
|
2013
2018
|
id
|
|
@@ -2042,7 +2047,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
2042
2047
|
/>
|
|
2043
2048
|
</svg>
|
|
2044
2049
|
`,h={"spiff-fill-shape":{browserValue:i.color||"#000000"}},C=l.generate();return new l.CreateElementCommand({colors:h,id:C,svg:d,type:l.LayoutElementType.Illustration,y:g.top,x:g.left,rotation:g.rotation,width:g.width,height:g.height,layer:g.layer,layerIndex:g.layerIndex,immutable:g.immutable},B)},s=A.data.regions;try{return s.map(o)}catch(g){return console.error(g),[]}},Gn=async(c,e,t)=>{const A=[],a=(()=>{var r,g;return e.type===l.StepType.ProductOverlay?t||((r=e.data.asset)==null?void 0:r.fileLink)||"":((g=e.data.asset)==null?void 0:g.fileLink)||""})(),o=(()=>a.endsWith(".jpeg")||a.endsWith(".jpg")||a.endsWith(".png")?l.LayoutElementType.Image:(a.endsWith(".svg"),l.LayoutElementType.Illustration))(),s=e.data.regions;if(o==="image")try{s.forEach(r=>{const g=c.find(d=>d.panelId===r.panelId);if(!g)throw new J(r);const B={id:l.generate(),src:a,type:o,y:r.top,x:r.left,width:r.width,height:r.height,layer:r.layer,layerIndex:r.layerIndex,productOverlay:e.type===l.StepType.ProductOverlay?!0:void 0,scaleX:1,scaleY:1,rotation:r.rotation,excludeFromExport:e.data.excludeFromPrint,preserveAspectRatio:"none"};A.push(new l.CreateElementCommand(B,g))})}catch(r){console.error(r)}else{const r=await l.fetchAsString(a,!0),g=B=>{const d=/<svg.*?<\/svg>/s,w=B.match(d)||[],h=(w==null?void 0:w.length)>0?w[0]:"",m=l.domParser().parseFromString(h,"image/svg+xml").firstElementChild;if(!m)throw new $("Failed to read SVG.");return l.sanitizeSvgTree(m),l.xmlSerializer().serializeToString(m)};s.forEach(B=>{const d=c.find(h=>h.panelId===B.panelId);if(!d)throw new J(B);const w={id:l.generate(),src:a,asset_key:a,svg:g(r),colors:{},type:o,y:B.top,x:B.left,width:B.width,height:B.height,layer:B.layer,layerIndex:B.layerIndex,scaleX:1,scaleY:1,rotation:B.rotation,productOverlay:e.type===l.StepType.ProductOverlay?!0:void 0,excludeFromExport:e.data.excludeFromPrint};A.push(new l.CreateElementCommand(w,d))})}return A},kn=async(c,e,t,A)=>{const n=[],a=t.data,i=30,o=E=>E.vertical?"center":E.textAlign||"center",s=()=>{var F;const E=A.option;if(!E)return;const m=((F=E.variants)==null?void 0:F.find(f=>f.id===a.fontVariantId))||l.getDefaultVariant(E);if(!m||!m.asset)return;e[A.stepName]={selectedVariants:[m]};const Q=m.asset.fileLink;if(Q)return Q},g=await(async()=>{const E=s();if(!E)return;const m=await l.loadFont(E);return{assetUrl:E,name:m.names.fullName.en}})(),B=(A.data.replaceableText?A.data.replaceableText.replace("{{}}",a.text):a.text)||"",d=l.applyTextTransformations(B,{vertical:A.data.vertical,uppercase:A.data.uppercase}),w=async E=>{const m=E.colorOption;if(!m)return;const Q=L.getDefaultVariant(m);return Q==null?void 0:Q.color},h=a.color||await w(A.data),C=A.data.regions;for(const E of C){const m=c.find(F=>F.panelId===E.panelId);if(!m)continue;const Q={stepName:t.name,id:l.generate(),align:o(A.data),curved:A.data.curved,fill:a.color||h||"#000000",fontData:g,fontSize:A.data.size||i,height:E.height,layer:E.layer,layerIndex:E.layerIndex,paths:A.data.paths,rotation:E.rotation,text:d,type:l.LayoutElementType.Textbox,vertical:A.data.vertical,verticalAlign:A.data.verticalAlign||"middle",width:E.width,x:E.left,y:E.top};if(g){const[F,f]=l.determineCorrectFontSizeAndLines(A.data.size||i,g,E,[l.applyTextTransformations(d,{vertical:A.data.vertical,uppercase:A.data.uppercase})],{size:A.data.size,minSize:A.data.minSize,maxSize:A.data.maxSize});n.push(new l.CreateElementCommand({...Q,fontSize:F,text:Q.curved?Q.text:(f||[]).join(`
|
|
2045
|
-
`)},m))}else n.push(new l.CreateElementCommand(Q,m))}return n},bn=(c,e)=>c.conditions?c.conditions.every(t=>{const A=e[t.targetStepName];if(A&&A.selectedVariants){const n=A.selectedVariants;return t.requiredVariantSelections.some(a=>n.find(i=>i.id===a)!==void 0)}return!1}):!0,eA=async(c,e,t,A)=>{const n=[],a={};for(const i of c){const o=e.steps.find(s=>s.stepName===i.name);if(o)switch(o.type){case l.StepType.DigitalContent:n.push(...await xn(t,i,o));break;case l.StepType.Frame:case l.StepType.Photo:n.push(...await Nn(t,a,i,o));break;case l.StepType.Illustration:n.push(...await Hn(t,a,i,o));break;case l.StepType.Module:n.push(...await Rn(t,i,o));break;case l.StepType.Picture:n.push(...await Un(t,a,i,o));break;case l.StepType.Shape:n.push(...await vn(t,a,i,o));break;case l.StepType.Text:n.push(...await kn(t,a,i,o));break}}for(const i of e.steps)i.type!==l.StepType.SilentIllustration&&i.type!==l.StepType.ProductOverlay||bn(i,a)&&n.push(...await Gn(t,i,A));return n};class Pe{constructor(e){this.handleCompleteRender=null;const t=new Map;e.forEach(A=>t.set(A.id,new Tn(A.id,A.name,this,{width:A.width,height:A.height}))),this.layouts=t}setCompleteRenderCallback(e){this.handleCompleteRender=e,e(Array.from(this.layouts.values()))}onCompleteRender(){this.handleCompleteRender&&this.handleCompleteRender(Array.from(this.layouts.values()))}getAll(){return this.layouts}}const Jn=(()=>new Promise((c,e)=>{const A=l.createCanvas().getContext("webgl2");c(!!A)}))();class Tn{constructor(e,t,A,n){this.hasSetStaticContext=!1,this.interactiveDirty=!1,this.staticCtxDirty=!1,this.lastRequestedRenderArguments=void 0,this.lastCompletedStaticRender=void 0,this.
|
|
2050
|
+
`)},m))}else n.push(new l.CreateElementCommand(Q,m))}return n},bn=(c,e)=>c.conditions?c.conditions.every(t=>{const A=e[t.targetStepName];if(A&&A.selectedVariants){const n=A.selectedVariants;return t.requiredVariantSelections.some(a=>n.find(i=>i.id===a)!==void 0)}return!1}):!0,eA=async(c,e,t,A)=>{const n=[],a={};for(const i of c){const o=e.steps.find(s=>s.stepName===i.name);if(o)switch(o.type){case l.StepType.DigitalContent:n.push(...await xn(t,i,o));break;case l.StepType.Frame:case l.StepType.Photo:n.push(...await Nn(t,a,i,o));break;case l.StepType.Illustration:n.push(...await Hn(t,a,i,o));break;case l.StepType.Module:n.push(...await Rn(t,i,o));break;case l.StepType.Picture:n.push(...await Un(t,a,i,o));break;case l.StepType.Shape:n.push(...await vn(t,a,i,o));break;case l.StepType.Text:n.push(...await kn(t,a,i,o));break}}for(const i of e.steps)i.type!==l.StepType.SilentIllustration&&i.type!==l.StepType.ProductOverlay||bn(i,a)&&n.push(...await Gn(t,i,A));return n};class Pe{constructor(e){this.handleCompleteRender=null;const t=new Map;e.forEach(A=>t.set(A.id,new Tn(A.id,A.name,this,{width:A.width,height:A.height}))),this.layouts=t}setCompleteRenderCallback(e){this.handleCompleteRender=e,e(Array.from(this.layouts.values()))}onCompleteRender(){this.handleCompleteRender&&this.handleCompleteRender(Array.from(this.layouts.values()))}getAll(){return this.layouts}}const Jn=(()=>new Promise((c,e)=>{const A=l.createCanvas().getContext("webgl2");c(!!A)}))();class Tn{constructor(e,t,A,n){this.hasSetStaticContext=!1,this.interactiveDirty=!1,this.staticCtxDirty=!1,this.lastRequestedRenderArguments=void 0,this.lastCompletedStaticRender=void 0,this.renderQueue=new ke(2),this.id=e,this.name=t,this.service=A,this.panelSize=n}getID(){return this.id}getName(){return this.name}getPanelSize(){return this.panelSize}getStaticContext(){return this.textureCtx}setStaticContext(e){this.textureCtx=e,this.lastRequestedRenderArguments&&this.render(this.lastRequestedRenderArguments)}getStaticContextDirty(){return this.staticCtxDirty}setStaticContextDirty(e){this.staticCtxDirty=e}getInteractiveCanvasDirty(){return this.interactiveDirty}setInteractiveCanvasDirty(e){this.interactiveDirty=e}markLastCompletedStaticRender(){this.lastCompletedStaticRender=Date.now(),this.service.onCompleteRender()}getLastCompletedStaticRender(){return this.lastCompletedStaticRender}async render(e){const t=se(e);this.lastRequestedRenderArguments=t;const A=this.getStaticContext();if(!A){this.markLastCompletedStaticRender(),this.setStaticContextDirty(!1);return}this.renderQueue.enqueue(new On(this.getID(),A,await Jn,()=>{this.markLastCompletedStaticRender(),this.setStaticContextDirty(!0)},t))}}class On extends Ge{constructor(e,t,A,n,a){super(),this.layoutId=e,this.ctx=t,this.nonPOTSupport=A,this.onRender=n,this.layouts=a}getDynamicTextureResolution(){return this.getIsMobile()||!this.offscreenRenderingSupported()?{width:1024,height:1024}:{width:2048,height:2048}}getIsMobile(){return window.innerWidth<=480}offscreenRenderingSupported(){return navigator.userAgent.includes("SamsungBrowser")?!1:!!window.Worker&&!!window.OffscreenCanvas}resizeFit(e,t=4096){const A=t/e.width,n=t/e.height,a=Math.min(A,n);return a>1?e:{width:e.width*a,height:e.height*a}}async execute(){const e=this.layouts.find(w=>w.layoutState.layout.id===this.layoutId);if(!e)return;const t=e.layoutState.elements||[],A=e.layoutState.layout.width,n=e.layoutState.layout.height,a=A===1||n===1?{width:1,height:1}:this.getDynamicTextureResolution(),i=a.width,o=a.height;let s,r;if(this.nonPOTSupport){const w=i/o;A/n<w?(s=i,r=n*(i/A)):(s=A*(o/n),r=o);const C=this.resizeFit({width:s,height:r});s=C.width,r=C.height}else s=a.width,r=a.height;const g=l.getSvgElement(e.layoutState.layout,t,{renderingConfiguration:{purpose:l.LayoutRenderingPurpose.ThreeD}}),B=l.renderPapyrusComponentAsString(g),d=await it.Pith.from(this.ctx,B,{anonymousCrossOrigin:!0,ignoreDimensions:!this.nonPOTSupport,ignoreAnimation:!0,ignoreClear:!0,ignoreMouse:!0,enableRedraw:!1,createCanvas:l.createCanvas,createImage:l.loadImage,DOMParser:l.getDomParser(),fetch:l.fetch});d.resize(s,r),await d.render(),this.onRender()}}const Ln=(c,e)=>{const t=[];return c.forEach(A=>{const n=e.steps.find(a=>a.stepName===A.stepName);(n==null?void 0:n.type)===l.StepType.Text&&A.stepAspectType==="Text"&&t.push({name:n.stepName,data:{text:A.value}})}),t},zn=async(c,e,t,A)=>{let n={serializableWorkflow:{steps:[]},layouts:{}};n=new l.GroupCommand(t.map(s=>new l.CreateLayoutCommand(s))).apply(n);const i=await eA(c,e,t,A);return new l.GroupCommand(i).apply(n)},jn=M.gql`
|
|
2046
2051
|
${te}
|
|
2047
2052
|
fragment ProductFields on Product {
|
|
2048
2053
|
id
|