@spiffcommerce/core 21.9.0-alpha.6 → 21.9.0-alpha.8
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 +1 -0
- package/dist/index.js +38 -18
- package/dist/index.umd.cjs +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3199,6 +3199,7 @@ declare class FrameStepHandle extends StepHandle<FrameStepData> {
|
|
|
3199
3199
|
hasOverlayImageUrl(): any;
|
|
3200
3200
|
getOriginalImageSelection(): Promise<Asset | undefined>;
|
|
3201
3201
|
getBackgroundRemovedImageSelection(): Promise<Asset | undefined>;
|
|
3202
|
+
hasBackgroundRemovedImageSelection(): boolean;
|
|
3202
3203
|
getUseOriginalImageSelection(): boolean;
|
|
3203
3204
|
setUseOriginalImageSelection(value: boolean): Promise<void>;
|
|
3204
3205
|
}
|
package/dist/index.js
CHANGED
|
@@ -8136,14 +8136,7 @@ class Xn extends gt {
|
|
|
8136
8136
|
backgroundRemovedAssetKey: a.key,
|
|
8137
8137
|
useOriginalAsset: !e
|
|
8138
8138
|
}, o = [e ? A.setAspect(this.property.name, a.key, i) : A.setAspectStorage(this.property.name, i)];
|
|
8139
|
-
|
|
8140
|
-
const r = async () => {
|
|
8141
|
-
const B = this.getSharedSteps().map((l) => l.selectImage(a, !1));
|
|
8142
|
-
await Promise.all(B);
|
|
8143
|
-
};
|
|
8144
|
-
o.push(r());
|
|
8145
|
-
}
|
|
8146
|
-
return await Promise.all(o), this.updateSharedStepStorage(i), a;
|
|
8139
|
+
return e && o.push(this.applyImageSelection(a, void 0, !1)), await Promise.all(o), this.updateSharedStepStorage(i), a;
|
|
8147
8140
|
}
|
|
8148
8141
|
/**
|
|
8149
8142
|
* Returns `true` if the state has an image assigned, otherwise `false`.
|
|
@@ -8183,22 +8176,45 @@ class Xn extends gt {
|
|
|
8183
8176
|
return ((e = this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name)) == null ? void 0 : e.useOriginalAsset) ?? !1;
|
|
8184
8177
|
}
|
|
8185
8178
|
async setUseOriginalImage(e) {
|
|
8186
|
-
const t = this.
|
|
8187
|
-
|
|
8179
|
+
const t = await this.getOriginalImage();
|
|
8180
|
+
if (!t)
|
|
8181
|
+
throw new Error("You must select an image before calling setUseOriginalImage");
|
|
8182
|
+
const A = this.bundle.getGlobalPropertyStateManager(), a = A.getAspectStorage(this.property.name);
|
|
8183
|
+
if ((a == null ? void 0 : a.useOriginalAsset) === e)
|
|
8184
|
+
return;
|
|
8185
|
+
const n = {
|
|
8186
|
+
...a,
|
|
8188
8187
|
useOriginalAsset: e
|
|
8189
|
-
};
|
|
8190
|
-
|
|
8188
|
+
}, i = [A.setAspectStorage(this.property.name, n)];
|
|
8189
|
+
if (e)
|
|
8190
|
+
i.push(this.applyImageSelection(t, void 0, !1));
|
|
8191
|
+
else {
|
|
8192
|
+
const s = async () => {
|
|
8193
|
+
const o = await this.getBackgroundRemovedImage();
|
|
8194
|
+
if (!o)
|
|
8195
|
+
throw new Error(
|
|
8196
|
+
"You must call removeBackgroundFromImage before attempting to use that version of the image."
|
|
8197
|
+
);
|
|
8198
|
+
this.applyImageSelection(o, void 0, !1);
|
|
8199
|
+
};
|
|
8200
|
+
i.push(s());
|
|
8201
|
+
}
|
|
8202
|
+
this.updateSharedStepStorage(n);
|
|
8191
8203
|
}
|
|
8192
8204
|
async applyGlobalState(e) {
|
|
8193
8205
|
const t = this.getStateValue();
|
|
8194
8206
|
if (!t)
|
|
8195
8207
|
return Promise.resolve();
|
|
8196
8208
|
const A = await v.getLocalOrFromServer(t);
|
|
8197
|
-
|
|
8209
|
+
if (!A)
|
|
8210
|
+
return Promise.resolve();
|
|
8211
|
+
await this.applyImageSelection(A, e);
|
|
8212
|
+
const a = this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name);
|
|
8213
|
+
a && this.updateSharedStepStorage(a);
|
|
8198
8214
|
}
|
|
8199
|
-
async applyImageSelection(e, t) {
|
|
8200
|
-
const
|
|
8201
|
-
await Promise.all(
|
|
8215
|
+
async applyImageSelection(e, t, A = !0) {
|
|
8216
|
+
const n = this.getSharedSteps(t).map((i) => i.selectImage(e, A));
|
|
8217
|
+
await Promise.all(n);
|
|
8202
8218
|
}
|
|
8203
8219
|
updateSharedStepStorage(e) {
|
|
8204
8220
|
this.bundle.getWorkflowExperiences().forEach(
|
|
@@ -11184,6 +11200,10 @@ class Si extends W {
|
|
|
11184
11200
|
if (e)
|
|
11185
11201
|
return v.getLocalOrFromServer(e);
|
|
11186
11202
|
}
|
|
11203
|
+
hasBackgroundRemovedImageSelection() {
|
|
11204
|
+
var e, t;
|
|
11205
|
+
return !!((t = (e = this.manager.getStepStorage(this.step.stepName)) == null ? void 0 : e.framePatternData) != null && t.backgroundRemovedAssetKey);
|
|
11206
|
+
}
|
|
11187
11207
|
getUseOriginalImageSelection() {
|
|
11188
11208
|
var e, t;
|
|
11189
11209
|
return ((t = (e = this.manager.getStepStorage(this.step.stepName)) == null ? void 0 : e.framePatternData) == null ? void 0 : t.useOriginalAsset) ?? !1;
|
|
@@ -11197,14 +11217,14 @@ class Si extends W {
|
|
|
11197
11217
|
if (!A)
|
|
11198
11218
|
throw new Error("You must provide an image selection before calling setUseOriginalImageSelection");
|
|
11199
11219
|
if (e)
|
|
11200
|
-
this.selectImage(A, !1);
|
|
11220
|
+
await this.selectImage(A, !1);
|
|
11201
11221
|
else {
|
|
11202
11222
|
const n = await this.getBackgroundRemovedImageSelection();
|
|
11203
11223
|
if (!n)
|
|
11204
11224
|
throw new Error(
|
|
11205
11225
|
"You must call removeBackgroundFromImageSelection before attempting to apply the image."
|
|
11206
11226
|
);
|
|
11207
|
-
this.selectImage(n, !1);
|
|
11227
|
+
await this.selectImage(n, !1);
|
|
11208
11228
|
}
|
|
11209
11229
|
this.manager.updateStorage(this.step.stepName, {
|
|
11210
11230
|
framePatternData: { ...t, useOriginalAsset: e }
|
package/dist/index.umd.cjs
CHANGED
|
@@ -2320,7 +2320,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
2320
2320
|
id
|
|
2321
2321
|
}
|
|
2322
2322
|
}
|
|
2323
|
-
`;class ea{constructor(e){this.handleCache={},this.bundle=e}async getHandle(e){if(this.handleCache[e.name])return this.handleCache[e.name];const t=await this.createHandle(e);return this.handleCache[e.name]=t,t}async getHandles(){var t;if(!((t=this.bundle.getProductCollection())!=null&&t.getResource().globalPropertyConfiguration))return[];const e=this.bundle.getProductCollection().getResource().globalPropertyConfiguration;return Promise.all(e.aspects.map(A=>this.getHandle(A)))}applyConditionsFromState(e,t){return t?e.filter(A=>this.aspectConditionsSatisfied(A.getRawProperty(),t)):e}aspectConditionsSatisfied(e,t){return!e.conditions||e.conditions.length===0?!0:e.conditions.some(A=>{const n=t.aspects.find(a=>a.name===A.targetAspectName);return n?A.requiredVariantSelections.some(a=>a===n.value):!1})}async createHandle(e){switch(e.type){case l.AspectType.FileUpload:return new Zt(this.bundle,e);case l.AspectType.Option:{const t=e.entityId?await O.getOption(e.entityId):void 0;return(t==null?void 0:t.type)==="Color"?new _t(this.bundle,e,t):new Ke(this.bundle,e,t)}case l.AspectType.Text:return new $t(this.bundle,e)}}}class Se{constructor(e,t){this.bundle=e,this.property=t}getName(){return this.property.name}getTitle(){return this.property.title}getDescription(){return this.property.description}getType(){return this.property.type}getRawProperty(){return this.property}getSharedSteps(e){return(e??this.bundle.getWorkflowExperiences()).flatMap(n=>n.getSteps().filter(a=>{var i;return a.getOverrideGlobalPropertyConfiguration(this.property.type)?!1:(i=a.getRaw().globalPropertyAspectConfigurations)==null?void 0:i.some(o=>{var s,r;return o.globalPropertyConfigurationId===((r=(s=this.bundle.getProductCollection())==null?void 0:s.getResource().globalPropertyConfiguration)==null?void 0:r.id)&&o.aspectName===this.property.name})}))}getStateValue(){return this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name)}}class Zt extends Se{constructor(e,t){super(e,t)}async selectImage(e){const t=this.bundle.getGlobalPropertyStateManager();await Promise.all([t.setAspect(this.property.name,e.key,{...t.getAspectStorage(this.property.name)||{},originalAssetKey:e.key,backgroundRemovedAssetKey:void 0,useOriginalAsset:void 0}),this.applyImageSelection(e)])}async removeBackgroundFromImage(e=!0){const t=await this.getOriginalImage();if(!t)throw new Error("You must supply an image selection before attempting to remove the background.");const A=this.bundle.getGlobalPropertyStateManager(),n=await v.removeBackgroundFromAsset(t),i={...A.getAspectStorage(this.property.name),backgroundRemovedAssetKey:n.key,useOriginalAsset:!e},s=[e?A.setAspect(this.property.name,n.key,i):A.setAspectStorage(this.property.name,i)];
|
|
2323
|
+
`;class ea{constructor(e){this.handleCache={},this.bundle=e}async getHandle(e){if(this.handleCache[e.name])return this.handleCache[e.name];const t=await this.createHandle(e);return this.handleCache[e.name]=t,t}async getHandles(){var t;if(!((t=this.bundle.getProductCollection())!=null&&t.getResource().globalPropertyConfiguration))return[];const e=this.bundle.getProductCollection().getResource().globalPropertyConfiguration;return Promise.all(e.aspects.map(A=>this.getHandle(A)))}applyConditionsFromState(e,t){return t?e.filter(A=>this.aspectConditionsSatisfied(A.getRawProperty(),t)):e}aspectConditionsSatisfied(e,t){return!e.conditions||e.conditions.length===0?!0:e.conditions.some(A=>{const n=t.aspects.find(a=>a.name===A.targetAspectName);return n?A.requiredVariantSelections.some(a=>a===n.value):!1})}async createHandle(e){switch(e.type){case l.AspectType.FileUpload:return new Zt(this.bundle,e);case l.AspectType.Option:{const t=e.entityId?await O.getOption(e.entityId):void 0;return(t==null?void 0:t.type)==="Color"?new _t(this.bundle,e,t):new Ke(this.bundle,e,t)}case l.AspectType.Text:return new $t(this.bundle,e)}}}class Se{constructor(e,t){this.bundle=e,this.property=t}getName(){return this.property.name}getTitle(){return this.property.title}getDescription(){return this.property.description}getType(){return this.property.type}getRawProperty(){return this.property}getSharedSteps(e){return(e??this.bundle.getWorkflowExperiences()).flatMap(n=>n.getSteps().filter(a=>{var i;return a.getOverrideGlobalPropertyConfiguration(this.property.type)?!1:(i=a.getRaw().globalPropertyAspectConfigurations)==null?void 0:i.some(o=>{var s,r;return o.globalPropertyConfigurationId===((r=(s=this.bundle.getProductCollection())==null?void 0:s.getResource().globalPropertyConfiguration)==null?void 0:r.id)&&o.aspectName===this.property.name})}))}getStateValue(){return this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name)}}class Zt extends Se{constructor(e,t){super(e,t)}async selectImage(e){const t=this.bundle.getGlobalPropertyStateManager();await Promise.all([t.setAspect(this.property.name,e.key,{...t.getAspectStorage(this.property.name)||{},originalAssetKey:e.key,backgroundRemovedAssetKey:void 0,useOriginalAsset:void 0}),this.applyImageSelection(e)])}async removeBackgroundFromImage(e=!0){const t=await this.getOriginalImage();if(!t)throw new Error("You must supply an image selection before attempting to remove the background.");const A=this.bundle.getGlobalPropertyStateManager(),n=await v.removeBackgroundFromAsset(t),i={...A.getAspectStorage(this.property.name),backgroundRemovedAssetKey:n.key,useOriginalAsset:!e},s=[e?A.setAspect(this.property.name,n.key,i):A.setAspectStorage(this.property.name,i)];return e&&s.push(this.applyImageSelection(n,void 0,!1)),await Promise.all(s),this.updateSharedStepStorage(i),n}hasImage(){return!!this.getStateValue()}async getImage(){const e=this.getStateValue();if(e)return v.getLocalOrFromServer(e)}async getOriginalImage(){const e=this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name);if(e!=null&&e.originalAssetKey)return v.getLocalOrFromServer(e.originalAssetKey)}async getBackgroundRemovedImage(){const e=this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name);if(e!=null&&e.backgroundRemovedAssetKey)return v.getLocalOrFromServer(e.backgroundRemovedAssetKey)}getUseOriginalImage(){var e;return((e=this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name))==null?void 0:e.useOriginalAsset)??!1}async setUseOriginalImage(e){const t=await this.getOriginalImage();if(!t)throw new Error("You must select an image before calling setUseOriginalImage");const A=this.bundle.getGlobalPropertyStateManager(),n=A.getAspectStorage(this.property.name);if((n==null?void 0:n.useOriginalAsset)===e)return;const a={...n,useOriginalAsset:e},i=[A.setAspectStorage(this.property.name,a)];if(e)i.push(this.applyImageSelection(t,void 0,!1));else{const o=async()=>{const s=await this.getBackgroundRemovedImage();if(!s)throw new Error("You must call removeBackgroundFromImage before attempting to use that version of the image.");this.applyImageSelection(s,void 0,!1)};i.push(o())}this.updateSharedStepStorage(a)}async applyGlobalState(e){const t=this.getStateValue();if(!t)return Promise.resolve();const A=await v.getLocalOrFromServer(t);if(!A)return Promise.resolve();await this.applyImageSelection(A,e);const n=this.bundle.getGlobalPropertyStateManager().getAspectStorage(this.property.name);n&&this.updateSharedStepStorage(n)}async applyImageSelection(e,t,A=!0){const a=this.getSharedSteps(t).map(i=>i.selectImage(e,A));await Promise.all(a)}updateSharedStepStorage(e){this.bundle.getWorkflowExperiences().forEach(A=>A.getSteps().forEach(n=>{var i;if(n.getOverrideGlobalPropertyConfiguration(this.property.type))return;((i=n.getRaw().globalPropertyAspectConfigurations)==null?void 0:i.some(o=>{var s,r;return o.globalPropertyConfigurationId===((r=(s=this.bundle.getProductCollection())==null?void 0:s.getResource().globalPropertyConfiguration)==null?void 0:r.id)&&o.aspectName===this.property.name}))&&A.getWorkflowManager().updateStorage(n.getId(),{framePatternData:e})}))}}class $t extends Se{constructor(e,t){super(e,t)}getText(){const e=this.getStateValue();return e||""}async setText(e){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,e),this.applyTextSelection(e)])}async applyGlobalState(e){const t=this.getStateValue();if(!t)return Promise.resolve();await this.applyTextSelection(t,e)}async applyTextSelection(e,t){const n=this.getSharedSteps(t).map(a=>{a.setText(e)});await Promise.all(n)}}class Ke extends Se{constructor(e,t,A){super(e,t),this.optionResource=A}getCurrentVariant(){var t,A;if(!this.optionResource)return;const e=this.getStateValue();if(e){const n=(A=this.optionResource.variants)==null?void 0:A.find(a=>a.id===e);return n?new K(n):void 0}else{const n=(t=this.optionResource.variants)==null?void 0:t.find(a=>{var i,o;return a.id===((o=(i=this.optionResource)==null?void 0:i.defaultVariant)==null?void 0:o.id)});return n?new K(n):void 0}}getAvailableVariants(){var t,A;return(((A=(t=this.optionResource)==null?void 0:t.variants)==null?void 0:A.filter(n=>n.enabled))||[]).map(n=>new K(n))}getAllVariants(){var t;return(((t=this.optionResource)==null?void 0:t.variants)||[]).map(A=>new K(A))}async selectVariant(e){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,e.getId()),this.applyVariantSelection(e)])}async applyGlobalState(e){var n,a;const t=this.getStateValue();if(!t)return Promise.resolve();const A=(a=(n=this.optionResource)==null?void 0:n.variants)==null?void 0:a.find(i=>i.id===t);return A?this.applyVariantSelection(new K(A),e):Promise.resolve()}async applyVariantSelection(e,t){const n=this.getSharedSteps(t).map(a=>a.selectVariant(e));await Promise.all(n)}}class _t extends Ke{constructor(e,t,A){super(e,t,A)}setCustomColor(e){this.getSharedSteps().forEach(A=>A.setCustomColor(e))}getCustomColor(){return this.getSharedSteps()[0].getCustomColor()}}const Ve=M.gql`
|
|
2324
2324
|
fragment GlobalPropertyStateAspectFields on GlobalPropertyStateAspect {
|
|
2325
2325
|
name
|
|
2326
2326
|
value
|
|
@@ -3023,4 +3023,4 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
3023
3023
|
}
|
|
3024
3024
|
}
|
|
3025
3025
|
}
|
|
3026
|
-
`,ne=async c=>{var e;for(const t in c.layouts){const A=c.layouts[t].elements.filter(a=>a.type===l.LayoutElementType.Illustration);for(let a=0;a<A.length;++a){const i=A[a];i.src&&i.svg&&(i.cachedObjectURL=await l.svgObjectURL(i.svg))}const n=c.layouts[t].elements.filter(a=>a.type===l.LayoutElementType.Textbox);for(let a=0;a<n.length;++a){const i=n[a];(e=i.fontData)!=null&&e.assetUrl&&await l.loadFont(i.fontData.assetUrl)}}},fa=async(c,e)=>{var n;const t=await N.getShadowGraphqlClient().query({query:Ba(((n=e==null?void 0:e.assets)==null?void 0:n.metadata)||!1),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:c}}),A=t.data.workflows;if(A===void 0||A.length!==c.length)throw new Error(`Unable to read workflows: ${t.errors??"Length mismatch in response"}`);return A.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&&v.cacheAsset(i.option.defaultVariant.asset),i.option.colorProfile&&v.cacheAsset(i.option.colorProfile),(r=i.option.variants)==null||r.forEach(g=>{g.asset&&v.cacheAsset(g.asset),g.displayImage&&v.cacheAsset(g.displayImage),g.thumbnail&&v.cacheAsset(g.thumbnail),g.material&&v.cacheMaterial(g.material)}),Z.set({id:i.option.id},Promise.resolve(i.option)))})}),A},Da=async(c,e)=>{const A=(await e).find(n=>n.id===c);if(!A)throw new Error(`Workflow not found: ${c}`);return A},Ze=async(c,e)=>{const t=c.map(o=>Z.get({id:o,options:e})),A=c.filter((o,s)=>t[s]===void 0);if(A.length===0)return Promise.all(t);const n=fa(A,e),a=A.map(o=>Z.set({id:o,options:e},Da(o,n))),i=t.filter(o=>o!==void 0);return await Promise.all(i.concat(a))},Ee=async(c,e)=>(await Ze([c],e))[0],pa=c=>c.sort((e,t)=>e.index-t.index).map(e=>({id:l.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})),$e=(c,e)=>{const t=c.workflowState,A=t?JSON.parse(t):void 0;return A?Object.values(A.layouts).map(n=>n.layout):pa(e.panels)};class sA{constructor(e){this.updateTransactionState=async t=>{try{return N.getShadowGraphqlClient().mutate({...t,mutation:UA})}catch(A){throw console.error(A),new G("Critical - Unable to synchronize workflow state with server.")}},this.initialized=!1,this.options=e,this.options.applicationKey&&wA(this.options.applicationKey)}getAssetManager(){return v}getCurrencyCode(){if(this.currencyCode===void 0)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!hA())throw new Error("Application key required to use Flow Service.");return new aA}async getIntegration(){return(await N.getShadowGraphqlClient().query({query:ha,errorPolicy:"all"})).data.currentIntegration}async authenticateBundleFromLocalStorage(e){var n,a;const t=P.getMap("bundleOwnerIds");if(t!=null&&t.has(e))return Promise.resolve({success:!0,stakeholderType:ce.Owner});const A=P.getMap("bundlePartnerIds")||new Map;if(A.has(e)){const i=A.get(e),s=(P.getMap("partnerCustomerIds")||new Map).get(i);if(s&&await this.authenticateCustomerId(s)){const g=(a=(n=this.customer)==null?void 0:n.bundleStakeholders)==null?void 0:a.find(B=>{var d;return((d=B.bundle)==null?void 0:d.id)===e});if(g)return Promise.resolve({success:!0,stakeholderType:g.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(e){var g,B,d,w,h,C;const t=N.getShadowGraphqlClient(),A=await t.query({query:wa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:e}});if(!A.data.transactions||A.data.transactions.length===0)throw new Error(`Transaction not found: ${e}`);const n=A.data.transactions[0];if(!((B=(g=n.product)==null?void 0:g.partner)==null?void 0:B.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:ce.Owner});const o=P.getMap("transactionCustomerIds");if(o!=null&&o.has(e)){const E=o.get(e);if(E&&await this.authenticateCustomerId(E)){const Q=((w=(d=this.customer)==null?void 0:d.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=(h=this.customer)==null?void 0:h.stakeholders)==null?void 0:C.find(F=>{var I;return((I=F.transaction)==null?void 0:I.id)===e}));if(Q)return Promise.resolve({success:!0,stakeholderType:Q.type})}}const r=(await t.query({query:Ea,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 t=P.getMap("transactionCustomerIds");t!=null&&t.has(e)&&(t.delete(e),P.setMap("transactionCustomerIds",t))}getStakeholderTypeForTransaction(e){var A,n;const t=(n=(A=this.customer)==null?void 0:A.stakeholders)==null?void 0:n.find(a=>{var i;return((i=a.transaction)==null?void 0:i.id)===e});if(t)return t.type}async getOrCreateCustomer(e){var i;this.customer=void 0;const t=N.getShadowGraphqlClient(),n=(await t.query({query:Ca,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e}})).data.customer;if(!n.id){const s=(i=(await t.mutate({mutation:ua,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 t=N.getShadowGraphqlClient(),A=P.getMap("customerTokens");if(!(A!=null&&A.has(e)))return!1;const n=A.get(e);if(!n)return!1;const i=(o=(await t.mutate({mutation:Qa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data)==null?void 0:o.customerAuthenticate;return i?(this.storeCustomer(i),ct(n),this.customer=i,!0):!1}async generateVerificationCode(e){await N.getShadowGraphqlClient().mutate({mutation:ma,variables:{emailAddress:e}})}async verifyCode(e,t){var a,i;const n=(a=(await N.getShadowGraphqlClient().mutate({mutation:Ia,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e,verificationCode:t}})).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),ct(n.loginToken),this.customer={...n,loginToken:void 0},!0}return!1}async getNewBundle(e,t,A){var s,r,g;const a=(g=(await N.getShadowGraphqlClient().mutate({mutation:zn(((r=(s=A==null?void 0:A.graphql)==null?void 0:s.productCollection)==null?void 0:r.eagerFetchProducts)||!1),variables:{collectionId:e,initialMetadata:t?Object.entries(t).map((B,d)=>({key:B[0],value:B[1]})):void 0},fetchPolicy:"no-cache"})).data)==null?void 0:g.bundleCreate;if(!(a!=null&&a.id))throw new Error("Unable to create bundle");const i=P.getMap("bundlePartnerIds")||new Map;i.set(a.id,a.partner.id),P.setMap("bundlePartnerIds",i);const o=P.getMap("bundleOwnerIds")||new Map;return o.set(a.id,a.bundleOwnerId),P.setMap("bundleOwnerIds",o),new nA(this,a,void 0,void 0,a.bundleOwnerId)}async getExistingBundle(e,t,A,n){var E,m,Q,F,I,f,D,p,S;const a=P.getMap("bundleOwnerIds"),i=a==null?void 0:a.get(e),s=((E=Object.entries(localStorage).find(([y,x])=>y.startsWith("CognitoIdentityServiceProvider")&&y.endsWith("idToken")))==null?void 0:E[0])||"",r=localStorage.getItem(s),g={};r&&(g.Authorization=`Bearer ${r}`);const B={bundleOwnerId:i,...g,...(m=n==null?void 0:n.graphql)==null?void 0:m.additionalHeaders},d=await N.getShadowGraphqlClient().query({query:Jn(((F=(Q=n==null?void 0:n.graphql)==null?void 0:Q.productCollection)==null?void 0:F.eagerFetchProducts)||!1),variables:{id:e},fetchPolicy:"no-cache",context:{headers:B}});if(!((I=d.data)!=null&&I.bundles)||((f=d.data)==null?void 0:f.bundles.length)===0||!((D=d.data)!=null&&D.bundles[0]))throw new Error(`Unable to find bundle: ${e}`);const w=(p=d.data)==null?void 0:p.bundles[0],h=P.getMap("bundlePartnerIds")||new Map;h.set(w.id,w.partner.id),P.setMap("bundlePartnerIds",h);const C=new nA(this,w,t,A,i,{additionalHeaders:(S=n==null?void 0:n.graphql)==null?void 0:S.additionalHeaders});return await C.getInitializationPromise(),C}async getBundleStakeholders(){var a;if(!this.customer)throw new Error("Customer not authenticated.");const e=await N.getShadowGraphqlClient().query({query:On,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 A=e.data.customers[0].bundleStakeholders||[],n=P.getMap("bundlePartnerIds")||new Map;return A.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),A}async getWorkflowExperience(e,t,A,n){var B,d,w,h,C;if(!n)return await this.getWorkflowExperienceDeprecated(e,t,A);const a=async()=>{var m,Q;const E=N.getShadowGraphqlClient();if(n.type==="transaction"){const{transactionId:F,readOnly:I}=n,f=await E.query({query:me,variables:{ids:[F]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!((m=f.data)!=null&&m.transactions)||f.data.transactions.length===0)throw new G("Existing transaction not found.");const D=(Q=f.data)==null?void 0:Q.transactions[0];if(!D.workflowId)throw new G("Existing transaction has no workflow ID.");const p=await Ee(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 E.mutate({mutation:Et,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=Ee(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=(B=i.product.partner)==null?void 0:B.currencyCode;const r={product:i.product,transaction:i,layouts:[],singleVariantsRenderable:(d=n==null?void 0:n.workflowConfiguration)==null?void 0:d.singleVariantsRenderable,stateMutationFunc:s?async()=>{throw new k("State mutation is forbidden in read only mode!")}:async E=>{const Q=(P.getMap("transactionOwnerIds")||new Map).get(i.id)||void 0;return this.updateTransactionState({...E,context:{transactionOwnerId:Q}})},readOnly:s,workflow:o};if(n.type==="transaction"&&i.workflowState){const E=JSON.parse(i.workflowState);r.layouts=Object.values(E.layouts).map(m=>m.layout),await l.rehydrateSerializedLayout(E),await ne(E),r.reloadedState=E}else if(!s&&n.workflowState){const E=JSON.parse(n.workflowState);r.layouts=Object.values(E.layouts).map(m=>m.layout),await l.rehydrateSerializedLayout(E),await ne(E),r.reloadedState=E}else r.layouts=$e(r.transaction,r.workflow);if(r.renderableContextService=new Me(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=A&&A(o),(h=r.product)!=null&&h.modelUrl&&(r.modelContainer=(C=r.previewService)==null?void 0:C.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))),n.type!=="transaction"){const E=P.getMap("transactionOwnerIds")||new Map;E.set(i.id,i.transactionOwnerId),P.setMap("transactionOwnerIds",E)}else r.isReloadedTransaction=!0;this.initialized=!0,this.experienceOptions=r;const g=new we(this,r);return await g.getWorkflowManager().getInitializationPromise(),n.type!=="transaction"&&this.customer&&await g.attachCustomerDetails({email:this.customer.emailAddress}),g}async getWorkflowExperiences(e,t){if(e.length===0)throw new G("No options provided!");const A=N.getShadowGraphqlClient(),n=async f=>{var y,x;if(f.length===0)return[];const D=f.map(Y=>Y.option.transactionId),p=await A.query({query:me,variables:{ids:D},errorPolicy:"all",fetchPolicy:"no-cache"}),S=p.data.transactions;if(S.length!==f.length){const Y=((x=(y=p.errors)==null?void 0:y[0])==null?void 0:x.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,x;if(f.length===0)return[];const D=await A.mutate({mutation:HA,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=((x=(y=D.errors)==null?void 0:y[0])==null?void 0:x.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=it(o,10),g=it(s,10),B=(await Promise.all([...r.map(n),...g.map(a)])).flat(),d=[...new Set(B.map(f=>f.workflowId))],w=await Ze(d,t),h=new Map(w.map(f=>[f.id,f])),C=P.getMap("transactionOwnerIds")||new Map,E=B.map(async f=>{var T;const{transaction:D,workflowId:p,readOnly:S,index:y}=f,x=h.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 k("State mutation is forbidden in read only mode!")}:async b=>this.updateTransactionState({...b,context:{transactionOwnerId:H}}),readOnly:S,workflow:x,isReloadedTransaction:Y.type==="transaction"};if(Y.type==="transaction"&&D.workflowState){const b=JSON.parse(D.workflowState);R.layouts=Object.values(b.layouts||{}).map(z=>z.layout),await l.rehydrateSerializedLayout(b),await ne(b),R.reloadedState=b}else if(!S&&Y.workflowState){const b=JSON.parse(Y.workflowState);R.layouts=Object.values(b.layouts||{}).map(z=>z.layout),await l.rehydrateSerializedLayout(b),await ne(b),R.reloadedState=b}else R.layouts=$e(R.transaction,R.workflow);return R.renderableContextService=new Me(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(E)).sort((f,D)=>f.index-D.index).map(async f=>{const{experienceOptions:D,options:p}=f,S=new we(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 A=await N.getShadowGraphqlClient().mutate({mutation:Et,variables:{integrationProductId:e,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!A.data||!A.data.transactionCreate)throw new G("Failed to create transaction!");const n=A.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,t=!1){var o,s,r,g;if(e==="")throw new G("No transaction ID provided.");const A=N.getShadowGraphqlClient(),n=async()=>{var w,h;const d=(w=(await A.query({query:me,variables:{ids:[e]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:w.transactions[0];if(!d)throw new G("Failed to read transaction.");if(!d.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(h=d.product.partner)==null?void 0:h.currencyCode,this.experienceOptions={product:d.product,transaction:d,layouts:[],stateMutationFunc:async()=>{throw new k("State mutation is forbidden in read only mode!")},readOnly:t},this.initialized=!0};if(t)return await n();const a=P.getMap("transactionOwnerIds")||new Map,i=a.get(e);if(i){const d=(o=(await A.query({query:me,variables:{ids:[e]},errorPolicy:"all"})).data)==null?void 0:o.transactions[0];if(!d)throw new G("Failed to read transaction.");if(!d.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(s=d.product.partner)==null?void 0:s.currencyCode,this.experienceOptions={product:d.product,transaction:d,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:i}}),readOnly:t},this.initialized=!0;return}try{const d=(r=(await A.mutate({mutation:RA,variables:{id:e},errorPolicy:"all"})).data)==null?void 0:r.transactionClaim;if(!d)throw new G("Failed to read transaction.");if(!d.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(g=d.product.partner)==null?void 0:g.currencyCode,d.transactionOwnerId&&(a.set(d.id,d.transactionOwnerId),P.setMap("transactionOwnerIds",a)),this.experienceOptions={product:d.product,transaction:d,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:d.transactionOwnerId}}),readOnly:t},this.initialized=!0}catch{throw new G("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(e,t,A){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 Ee(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=s,this.experienceOptions.transaction.workflowState){const g=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(g.layouts).map(B=>B.layout),await l.rehydrateSerializedLayout(g),await ne(g),this.experienceOptions.reloadedState=g}this.experienceOptions.previewService=A&&A(s),this.experienceOptions.renderableContextService=new Me(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 we(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}if(e){const r=(P.getMap("transactionOwnerIds")||new Map).get(this.experienceOptions.transaction.id),g=N.getShadowGraphqlClient().mutate({mutation:GA,variables:{workflowId:e,id:this.experienceOptions.transaction.id},context:{transactionOwnerId:r}}),B=Ee(e);if(await Promise.all([g,B]),this.experienceOptions.workflow=await B,t){const w=JSON.parse(t);this.experienceOptions.layouts=Object.values(w.layouts).map(h=>h.layout),await l.rehydrateSerializedLayout(w),await ne(w),this.experienceOptions.reloadedState=w}else this.experienceOptions.layouts=$e(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await B),this.experienceOptions.renderableContextService=new Me(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 d=new we(this,this.experienceOptions);return await d.getWorkflowManager().getInitializationPromise(),d}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}configureUrls(e,t,A){W.setHubUrl(e),W.setServerUrl(t),W.setServicesApiUrl(A)}storeCustomer(e){const t=P.getMap("partnerCustomerIds")||new Map;t.set(e.partner.id,e.id),P.setMap("partnerCustomerIds",t)}async getIntegrationProductById(e){var a,i;const n=(a=(await N.getShadowGraphqlClient().query({query:kA,variables:{ids:[e]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:a.integrationProducts;if(!n||n.length===0||!((i=n[0])!=null&&i.id))throw new Error("Integration product not found.");return new qe(n[0])}async getIntegrationProductFromExternalIds(e,t){var i;const a=(i=(await N.getShadowGraphqlClient().query({query:bA,variables:{externalProductId:t,externalIntegrationId:e},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:i.integrationProductFromExternalIds;if(!(a!=null&&a.id))throw new Error("Integration product not found.");return new qe(a)}async getIntegrationProduct(e){return e.type==="integration"?this.getIntegrationProductById(e.integrationProductId):this.getIntegrationProductFromExternalIds(e.externalIntegrationId,e.externalProductId)}}class Fa{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,t){}addStorageCallback(e){}getCommandDispatcher(){return e=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(e){return[]}getSerializedStep(e,t){}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,t){}setInformationResults(e){}setMandatoryFulfilled(e,t){}async setSelectionsAndElements(e,t,A){}toggleDesignConfirmed(){}updateMetadata(e,t){}async updateStorage(e,t){}injectIntoPreviewService(e){return Promise.resolve()}ejectFromPreviewService(){}setWorkflowStateSyncEnabled(e){}}var rA=(c=>(c.SelectFrame="SelectFrame",c.SelectImage="SelectImage",c.Position="Position",c))(rA||{});class cA extends j{constructor(e,t){var A;super(e,t),this.frameService=(A=this.manager.getStepSpecificServices(this.getId()))==null?void 0:A.frameService}selectVariant(e){const t=this.manager.getRegionElements(this.step.stepName);return le.selectVariant(this.step,e.getResource(),t,this.manager,A=>this.setUpdateState(A))}onFrameDataChanged(e){this.frameService&&this.frameService.onFrameDataChanged(t=>{t&&e(t)})}async selectImage(e,t=!0){var A;if(await le.selectImage(this.step,e,this.manager),t){const n=((A=this.manager.getStepStorage(this.step.stepName))==null?void 0:A.framePatternData)||{};this.manager.updateStorage(this.step.stepName,{framePatternData:{...n,originalAssetKey:e.key,backgroundRemovedAssetKey:void 0,useOriginalAsset:void 0}})}}async removeBackgroundFromImageSelection(e=!0){var a;const t=await this.getOriginalImageSelection();if(!t)throw new Error("You must supply an image selection before attempting to remove the background.");const A=await v.removeBackgroundFromAsset(t);e&&await le.selectImage(this.step,A,this.manager);const n=((a=this.manager.getStepStorage(this.step.stepName))==null?void 0:a.framePatternData)||{};return this.manager.updateStorage(this.step.stepName,{framePatternData:{...n,backgroundRemovedAssetKey:A.key,useOriginalAsset:!e}}),A}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(e,t,A,n){return n&&n.length>1&&e===void 0?"SelectFrame":t||A||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}async getOriginalImageSelection(){var t,A;const e=(A=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)==null?void 0:A.originalAssetKey;if(e)return v.getLocalOrFromServer(e)}async getBackgroundRemovedImageSelection(){var t,A;const e=(A=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)==null?void 0:A.backgroundRemovedAssetKey;if(e)return v.getLocalOrFromServer(e)}getUseOriginalImageSelection(){var e,t;return((t=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:t.useOriginalAsset)??!1}async setUseOriginalImageSelection(e){var n;const t=((n=this.manager.getStepStorage(this.step.stepName))==null?void 0:n.framePatternData)||{};if(t.useOriginalAsset===e)return;const A=await this.getOriginalImageSelection();if(!A)throw new Error("You must provide an image selection before calling setUseOriginalImageSelection");if(e)this.selectImage(A,!1);else{const a=await this.getBackgroundRemovedImageSelection();if(!a)throw new Error("You must call removeBackgroundFromImageSelection before attempting to apply the image.");this.selectImage(a,!1)}this.manager.updateStorage(this.step.stepName,{framePatternData:{...t,useOriginalAsset:e}})}}Object.defineProperty(u,"AspectType",{enumerable:!0,get:()=>l.AspectType}),Object.defineProperty(u,"AssetType",{enumerable:!0,get:()=>l.AssetType}),Object.defineProperty(u,"BringForwardCommand",{enumerable:!0,get:()=>l.BringForwardCommand}),Object.defineProperty(u,"BringToBackCommand",{enumerable:!0,get:()=>l.BringToBackCommand}),Object.defineProperty(u,"BringToFrontCommand",{enumerable:!0,get:()=>l.BringToFrontCommand}),Object.defineProperty(u,"CanvasCommand",{enumerable:!0,get:()=>l.CanvasCommand}),Object.defineProperty(u,"CommandContext",{enumerable:!0,get:()=>l.CommandContext}),Object.defineProperty(u,"CreateElementCommand",{enumerable:!0,get:()=>l.CreateElementCommand}),Object.defineProperty(u,"CreateLayoutCommand",{enumerable:!0,get:()=>l.CreateLayoutCommand}),Object.defineProperty(u,"DeleteElementCommand",{enumerable:!0,get:()=>l.DeleteElementCommand}),Object.defineProperty(u,"FontAlignmentCommand",{enumerable:!0,get:()=>l.FontAlignmentCommand}),Object.defineProperty(u,"FontColorCommand",{enumerable:!0,get:()=>l.FontColorCommand}),Object.defineProperty(u,"FontSizeCommand",{enumerable:!0,get:()=>l.FontSizeCommand}),Object.defineProperty(u,"FontSourceCommand",{enumerable:!0,get:()=>l.FontSourceCommand}),Object.defineProperty(u,"GroupCommand",{enumerable:!0,get:()=>l.GroupCommand}),Object.defineProperty(u,"LayoutElementFactory",{enumerable:!0,get:()=>l.LayoutElementFactory}),Object.defineProperty(u,"LayoutElementType",{enumerable:!0,get:()=>l.LayoutElementType}),Object.defineProperty(u,"MoveCommand",{enumerable:!0,get:()=>l.MoveCommand}),Object.defineProperty(u,"ResizeCommand",{enumerable:!0,get:()=>l.ResizeCommand}),Object.defineProperty(u,"RotateCommand",{enumerable:!0,get:()=>l.RotateCommand}),Object.defineProperty(u,"SendBackwardsCommand",{enumerable:!0,get:()=>l.SendBackwardsCommand}),Object.defineProperty(u,"StepAspectType",{enumerable:!0,get:()=>l.StepAspectType}),Object.defineProperty(u,"StepType",{enumerable:!0,get:()=>l.StepType}),Object.defineProperty(u,"TextChangeCommand",{enumerable:!0,get:()=>l.TextChangeCommand}),Object.defineProperty(u,"UnitOfMeasurement",{enumerable:!0,get:()=>l.UnitOfMeasurement}),Object.defineProperty(u,"dataUrlFromExternalUrl",{enumerable:!0,get:()=>l.dataUrlFromExternalUrl}),Object.defineProperty(u,"determineCorrectFontSizeAndLines",{enumerable:!0,get:()=>l.determineCorrectFontSizeAndLines}),Object.defineProperty(u,"findElement",{enumerable:!0,get:()=>l.findElement}),Object.defineProperty(u,"frameDataCache",{enumerable:!0,get:()=>l.frameDataCache}),Object.defineProperty(u,"generate",{enumerable:!0,get:()=>l.generate}),Object.defineProperty(u,"generateSVGWithUnknownColors",{enumerable:!0,get:()=>l.generateSVGWithUnknownColors}),Object.defineProperty(u,"getAttributesFromArrayBuffer",{enumerable:!0,get:()=>l.getAttributesFromArrayBuffer}),Object.defineProperty(u,"getAxisAlignedBoundingBox",{enumerable:!0,get:()=>l.getAxisAlignedBoundingBox}),Object.defineProperty(u,"getFrameData",{enumerable:!0,get:()=>l.getFrameData}),Object.defineProperty(u,"getSvgElement",{enumerable:!0,get:()=>l.getSvgElement}),Object.defineProperty(u,"loadFont",{enumerable:!0,get:()=>l.loadFont}),Object.defineProperty(u,"patternImageDataCache",{enumerable:!0,get:()=>l.patternImageDataCache}),Object.defineProperty(u,"registerFetchImplementation",{enumerable:!0,get:()=>l.registerFetchImplementation}),Object.defineProperty(u,"registerWindowImplementation",{enumerable:!0,get:()=>l.registerWindowImplementation}),Object.defineProperty(u,"rehydrateSerializedLayout",{enumerable:!0,get:()=>l.rehydrateSerializedLayout}),Object.defineProperty(u,"setCanvasModule",{enumerable:!0,get:()=>l.setCanvasModule}),u.ArrayInput=ra,u.AssetNotFoundError=V,u.CollectionProduct=ye,u.ColorOptionGlobalPropertyHandle=_t,u.ConversionDataType=ht,u.ConversionLocation=wt,u.FileUploadGlobalPropertyHandle=Zt,u.FlowExecutionNodeResult=he,u.FlowExecutionResult=iA,u.FlowService=aA,u.FrameService=mt,u.FrameStep=rA,u.FrameStepHandle=cA,u.GlobalPropertyHandle=Se,u.IllustrationStepHandle=Ut,u.InformationMessageType=Be,u.InformationStepHandle=Ot,u.IntegrationProduct=qe,u.IntegrationType=dt,u.LayoutNotFoundError=J,u.MaterialStepHandle=Gt,u.MisconfigurationError=se,u.MockWorkflowManager=Fa,u.ModelStepHandle=vt,u.ObjectInput=Xe,u.ObjectInputType=oA,u.OptionGlobalPropertyHandle=Ke,u.OptionNotFoundError=oe,u.ParseError=q,u.PictureStepHandle=kt,u.ProductCameraRig=Bt,u.ProductCollection=eA,u.ProductWorkflow=Ae,u.PromiseCache=Z,u.PromiseQueue=Ue,u.QuestionStepHandle=bt,u.QueueablePromise=Re,u.ResourceNotFoundError=X,u.ShapeStepHandle=Jt,u.SpiffCommerceClient=sA,u.StakeholderType=ce,u.StepHandle=j,u.TextGlobalPropertyHandle=$t,u.TextInput=sa,u.TextStepHandle=Tt,u.Transform=AA,u.TransformCollection=tA,u.UnhandledBehaviorError=k,u.Variant=K,u.WorkflowExperienceEventType=Vt,u.WorkflowExperienceImpl=we,u.assetService=v,u.createDesign=Kt,u.designService=Fe,u.digitalContentStepService=pt,u.frameStepService=le,u.generateCommands=Wt,u.generateStateFromDesignInputSteps=kn,u.getBoundedOffsets=Qt,u.getWorkflow=Ee,u.getWorkflows=Ze,u.graphQlManager=N,u.illustrationStepService=de,u.materialStepService=Ge,u.modelStepService=ve,u.moduleStepService=Ft,u.optionService=O,u.persistenceService=P,u.pictureStepService=ke,u.questionStepService=be,u.shapeStepService=te,u.shortenUrl=ft,u.spiffCoreConfiguration=W,u.stepAspectValuesToDesignInputSteps=vn,u.textStepService=L,u.toast=Mt,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
3026
|
+
`,ne=async c=>{var e;for(const t in c.layouts){const A=c.layouts[t].elements.filter(a=>a.type===l.LayoutElementType.Illustration);for(let a=0;a<A.length;++a){const i=A[a];i.src&&i.svg&&(i.cachedObjectURL=await l.svgObjectURL(i.svg))}const n=c.layouts[t].elements.filter(a=>a.type===l.LayoutElementType.Textbox);for(let a=0;a<n.length;++a){const i=n[a];(e=i.fontData)!=null&&e.assetUrl&&await l.loadFont(i.fontData.assetUrl)}}},fa=async(c,e)=>{var n;const t=await N.getShadowGraphqlClient().query({query:Ba(((n=e==null?void 0:e.assets)==null?void 0:n.metadata)||!1),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:c}}),A=t.data.workflows;if(A===void 0||A.length!==c.length)throw new Error(`Unable to read workflows: ${t.errors??"Length mismatch in response"}`);return A.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&&v.cacheAsset(i.option.defaultVariant.asset),i.option.colorProfile&&v.cacheAsset(i.option.colorProfile),(r=i.option.variants)==null||r.forEach(g=>{g.asset&&v.cacheAsset(g.asset),g.displayImage&&v.cacheAsset(g.displayImage),g.thumbnail&&v.cacheAsset(g.thumbnail),g.material&&v.cacheMaterial(g.material)}),Z.set({id:i.option.id},Promise.resolve(i.option)))})}),A},Da=async(c,e)=>{const A=(await e).find(n=>n.id===c);if(!A)throw new Error(`Workflow not found: ${c}`);return A},Ze=async(c,e)=>{const t=c.map(o=>Z.get({id:o,options:e})),A=c.filter((o,s)=>t[s]===void 0);if(A.length===0)return Promise.all(t);const n=fa(A,e),a=A.map(o=>Z.set({id:o,options:e},Da(o,n))),i=t.filter(o=>o!==void 0);return await Promise.all(i.concat(a))},Ee=async(c,e)=>(await Ze([c],e))[0],pa=c=>c.sort((e,t)=>e.index-t.index).map(e=>({id:l.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})),$e=(c,e)=>{const t=c.workflowState,A=t?JSON.parse(t):void 0;return A?Object.values(A.layouts).map(n=>n.layout):pa(e.panels)};class sA{constructor(e){this.updateTransactionState=async t=>{try{return N.getShadowGraphqlClient().mutate({...t,mutation:UA})}catch(A){throw console.error(A),new G("Critical - Unable to synchronize workflow state with server.")}},this.initialized=!1,this.options=e,this.options.applicationKey&&wA(this.options.applicationKey)}getAssetManager(){return v}getCurrencyCode(){if(this.currencyCode===void 0)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!hA())throw new Error("Application key required to use Flow Service.");return new aA}async getIntegration(){return(await N.getShadowGraphqlClient().query({query:ha,errorPolicy:"all"})).data.currentIntegration}async authenticateBundleFromLocalStorage(e){var n,a;const t=P.getMap("bundleOwnerIds");if(t!=null&&t.has(e))return Promise.resolve({success:!0,stakeholderType:ce.Owner});const A=P.getMap("bundlePartnerIds")||new Map;if(A.has(e)){const i=A.get(e),s=(P.getMap("partnerCustomerIds")||new Map).get(i);if(s&&await this.authenticateCustomerId(s)){const g=(a=(n=this.customer)==null?void 0:n.bundleStakeholders)==null?void 0:a.find(B=>{var d;return((d=B.bundle)==null?void 0:d.id)===e});if(g)return Promise.resolve({success:!0,stakeholderType:g.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(e){var g,B,d,w,h,C;const t=N.getShadowGraphqlClient(),A=await t.query({query:wa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:e}});if(!A.data.transactions||A.data.transactions.length===0)throw new Error(`Transaction not found: ${e}`);const n=A.data.transactions[0];if(!((B=(g=n.product)==null?void 0:g.partner)==null?void 0:B.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:ce.Owner});const o=P.getMap("transactionCustomerIds");if(o!=null&&o.has(e)){const E=o.get(e);if(E&&await this.authenticateCustomerId(E)){const Q=((w=(d=this.customer)==null?void 0:d.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=(h=this.customer)==null?void 0:h.stakeholders)==null?void 0:C.find(F=>{var I;return((I=F.transaction)==null?void 0:I.id)===e}));if(Q)return Promise.resolve({success:!0,stakeholderType:Q.type})}}const r=(await t.query({query:Ea,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 t=P.getMap("transactionCustomerIds");t!=null&&t.has(e)&&(t.delete(e),P.setMap("transactionCustomerIds",t))}getStakeholderTypeForTransaction(e){var A,n;const t=(n=(A=this.customer)==null?void 0:A.stakeholders)==null?void 0:n.find(a=>{var i;return((i=a.transaction)==null?void 0:i.id)===e});if(t)return t.type}async getOrCreateCustomer(e){var i;this.customer=void 0;const t=N.getShadowGraphqlClient(),n=(await t.query({query:Ca,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e}})).data.customer;if(!n.id){const s=(i=(await t.mutate({mutation:ua,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 t=N.getShadowGraphqlClient(),A=P.getMap("customerTokens");if(!(A!=null&&A.has(e)))return!1;const n=A.get(e);if(!n)return!1;const i=(o=(await t.mutate({mutation:Qa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data)==null?void 0:o.customerAuthenticate;return i?(this.storeCustomer(i),ct(n),this.customer=i,!0):!1}async generateVerificationCode(e){await N.getShadowGraphqlClient().mutate({mutation:ma,variables:{emailAddress:e}})}async verifyCode(e,t){var a,i;const n=(a=(await N.getShadowGraphqlClient().mutate({mutation:Ia,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e,verificationCode:t}})).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),ct(n.loginToken),this.customer={...n,loginToken:void 0},!0}return!1}async getNewBundle(e,t,A){var s,r,g;const a=(g=(await N.getShadowGraphqlClient().mutate({mutation:zn(((r=(s=A==null?void 0:A.graphql)==null?void 0:s.productCollection)==null?void 0:r.eagerFetchProducts)||!1),variables:{collectionId:e,initialMetadata:t?Object.entries(t).map((B,d)=>({key:B[0],value:B[1]})):void 0},fetchPolicy:"no-cache"})).data)==null?void 0:g.bundleCreate;if(!(a!=null&&a.id))throw new Error("Unable to create bundle");const i=P.getMap("bundlePartnerIds")||new Map;i.set(a.id,a.partner.id),P.setMap("bundlePartnerIds",i);const o=P.getMap("bundleOwnerIds")||new Map;return o.set(a.id,a.bundleOwnerId),P.setMap("bundleOwnerIds",o),new nA(this,a,void 0,void 0,a.bundleOwnerId)}async getExistingBundle(e,t,A,n){var E,m,Q,F,I,f,D,p,S;const a=P.getMap("bundleOwnerIds"),i=a==null?void 0:a.get(e),s=((E=Object.entries(localStorage).find(([y,x])=>y.startsWith("CognitoIdentityServiceProvider")&&y.endsWith("idToken")))==null?void 0:E[0])||"",r=localStorage.getItem(s),g={};r&&(g.Authorization=`Bearer ${r}`);const B={bundleOwnerId:i,...g,...(m=n==null?void 0:n.graphql)==null?void 0:m.additionalHeaders},d=await N.getShadowGraphqlClient().query({query:Jn(((F=(Q=n==null?void 0:n.graphql)==null?void 0:Q.productCollection)==null?void 0:F.eagerFetchProducts)||!1),variables:{id:e},fetchPolicy:"no-cache",context:{headers:B}});if(!((I=d.data)!=null&&I.bundles)||((f=d.data)==null?void 0:f.bundles.length)===0||!((D=d.data)!=null&&D.bundles[0]))throw new Error(`Unable to find bundle: ${e}`);const w=(p=d.data)==null?void 0:p.bundles[0],h=P.getMap("bundlePartnerIds")||new Map;h.set(w.id,w.partner.id),P.setMap("bundlePartnerIds",h);const C=new nA(this,w,t,A,i,{additionalHeaders:(S=n==null?void 0:n.graphql)==null?void 0:S.additionalHeaders});return await C.getInitializationPromise(),C}async getBundleStakeholders(){var a;if(!this.customer)throw new Error("Customer not authenticated.");const e=await N.getShadowGraphqlClient().query({query:On,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 A=e.data.customers[0].bundleStakeholders||[],n=P.getMap("bundlePartnerIds")||new Map;return A.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),A}async getWorkflowExperience(e,t,A,n){var B,d,w,h,C;if(!n)return await this.getWorkflowExperienceDeprecated(e,t,A);const a=async()=>{var m,Q;const E=N.getShadowGraphqlClient();if(n.type==="transaction"){const{transactionId:F,readOnly:I}=n,f=await E.query({query:me,variables:{ids:[F]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!((m=f.data)!=null&&m.transactions)||f.data.transactions.length===0)throw new G("Existing transaction not found.");const D=(Q=f.data)==null?void 0:Q.transactions[0];if(!D.workflowId)throw new G("Existing transaction has no workflow ID.");const p=await Ee(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 E.mutate({mutation:Et,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=Ee(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=(B=i.product.partner)==null?void 0:B.currencyCode;const r={product:i.product,transaction:i,layouts:[],singleVariantsRenderable:(d=n==null?void 0:n.workflowConfiguration)==null?void 0:d.singleVariantsRenderable,stateMutationFunc:s?async()=>{throw new k("State mutation is forbidden in read only mode!")}:async E=>{const Q=(P.getMap("transactionOwnerIds")||new Map).get(i.id)||void 0;return this.updateTransactionState({...E,context:{transactionOwnerId:Q}})},readOnly:s,workflow:o};if(n.type==="transaction"&&i.workflowState){const E=JSON.parse(i.workflowState);r.layouts=Object.values(E.layouts).map(m=>m.layout),await l.rehydrateSerializedLayout(E),await ne(E),r.reloadedState=E}else if(!s&&n.workflowState){const E=JSON.parse(n.workflowState);r.layouts=Object.values(E.layouts).map(m=>m.layout),await l.rehydrateSerializedLayout(E),await ne(E),r.reloadedState=E}else r.layouts=$e(r.transaction,r.workflow);if(r.renderableContextService=new Me(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=A&&A(o),(h=r.product)!=null&&h.modelUrl&&(r.modelContainer=(C=r.previewService)==null?void 0:C.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))),n.type!=="transaction"){const E=P.getMap("transactionOwnerIds")||new Map;E.set(i.id,i.transactionOwnerId),P.setMap("transactionOwnerIds",E)}else r.isReloadedTransaction=!0;this.initialized=!0,this.experienceOptions=r;const g=new we(this,r);return await g.getWorkflowManager().getInitializationPromise(),n.type!=="transaction"&&this.customer&&await g.attachCustomerDetails({email:this.customer.emailAddress}),g}async getWorkflowExperiences(e,t){if(e.length===0)throw new G("No options provided!");const A=N.getShadowGraphqlClient(),n=async f=>{var y,x;if(f.length===0)return[];const D=f.map(Y=>Y.option.transactionId),p=await A.query({query:me,variables:{ids:D},errorPolicy:"all",fetchPolicy:"no-cache"}),S=p.data.transactions;if(S.length!==f.length){const Y=((x=(y=p.errors)==null?void 0:y[0])==null?void 0:x.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,x;if(f.length===0)return[];const D=await A.mutate({mutation:HA,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=((x=(y=D.errors)==null?void 0:y[0])==null?void 0:x.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=it(o,10),g=it(s,10),B=(await Promise.all([...r.map(n),...g.map(a)])).flat(),d=[...new Set(B.map(f=>f.workflowId))],w=await Ze(d,t),h=new Map(w.map(f=>[f.id,f])),C=P.getMap("transactionOwnerIds")||new Map,E=B.map(async f=>{var T;const{transaction:D,workflowId:p,readOnly:S,index:y}=f,x=h.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 k("State mutation is forbidden in read only mode!")}:async b=>this.updateTransactionState({...b,context:{transactionOwnerId:H}}),readOnly:S,workflow:x,isReloadedTransaction:Y.type==="transaction"};if(Y.type==="transaction"&&D.workflowState){const b=JSON.parse(D.workflowState);R.layouts=Object.values(b.layouts||{}).map(z=>z.layout),await l.rehydrateSerializedLayout(b),await ne(b),R.reloadedState=b}else if(!S&&Y.workflowState){const b=JSON.parse(Y.workflowState);R.layouts=Object.values(b.layouts||{}).map(z=>z.layout),await l.rehydrateSerializedLayout(b),await ne(b),R.reloadedState=b}else R.layouts=$e(R.transaction,R.workflow);return R.renderableContextService=new Me(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(E)).sort((f,D)=>f.index-D.index).map(async f=>{const{experienceOptions:D,options:p}=f,S=new we(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 A=await N.getShadowGraphqlClient().mutate({mutation:Et,variables:{integrationProductId:e,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!A.data||!A.data.transactionCreate)throw new G("Failed to create transaction!");const n=A.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,t=!1){var o,s,r,g;if(e==="")throw new G("No transaction ID provided.");const A=N.getShadowGraphqlClient(),n=async()=>{var w,h;const d=(w=(await A.query({query:me,variables:{ids:[e]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:w.transactions[0];if(!d)throw new G("Failed to read transaction.");if(!d.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(h=d.product.partner)==null?void 0:h.currencyCode,this.experienceOptions={product:d.product,transaction:d,layouts:[],stateMutationFunc:async()=>{throw new k("State mutation is forbidden in read only mode!")},readOnly:t},this.initialized=!0};if(t)return await n();const a=P.getMap("transactionOwnerIds")||new Map,i=a.get(e);if(i){const d=(o=(await A.query({query:me,variables:{ids:[e]},errorPolicy:"all"})).data)==null?void 0:o.transactions[0];if(!d)throw new G("Failed to read transaction.");if(!d.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(s=d.product.partner)==null?void 0:s.currencyCode,this.experienceOptions={product:d.product,transaction:d,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:i}}),readOnly:t},this.initialized=!0;return}try{const d=(r=(await A.mutate({mutation:RA,variables:{id:e},errorPolicy:"all"})).data)==null?void 0:r.transactionClaim;if(!d)throw new G("Failed to read transaction.");if(!d.product)throw new G("Failed to load transaction, product not available.");this.currencyCode=(g=d.product.partner)==null?void 0:g.currencyCode,d.transactionOwnerId&&(a.set(d.id,d.transactionOwnerId),P.setMap("transactionOwnerIds",a)),this.experienceOptions={product:d.product,transaction:d,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:d.transactionOwnerId}}),readOnly:t},this.initialized=!0}catch{throw new G("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(e,t,A){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 Ee(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=s,this.experienceOptions.transaction.workflowState){const g=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(g.layouts).map(B=>B.layout),await l.rehydrateSerializedLayout(g),await ne(g),this.experienceOptions.reloadedState=g}this.experienceOptions.previewService=A&&A(s),this.experienceOptions.renderableContextService=new Me(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 we(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}if(e){const r=(P.getMap("transactionOwnerIds")||new Map).get(this.experienceOptions.transaction.id),g=N.getShadowGraphqlClient().mutate({mutation:GA,variables:{workflowId:e,id:this.experienceOptions.transaction.id},context:{transactionOwnerId:r}}),B=Ee(e);if(await Promise.all([g,B]),this.experienceOptions.workflow=await B,t){const w=JSON.parse(t);this.experienceOptions.layouts=Object.values(w.layouts).map(h=>h.layout),await l.rehydrateSerializedLayout(w),await ne(w),this.experienceOptions.reloadedState=w}else this.experienceOptions.layouts=$e(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=A&&A(await B),this.experienceOptions.renderableContextService=new Me(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 d=new we(this,this.experienceOptions);return await d.getWorkflowManager().getInitializationPromise(),d}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}configureUrls(e,t,A){W.setHubUrl(e),W.setServerUrl(t),W.setServicesApiUrl(A)}storeCustomer(e){const t=P.getMap("partnerCustomerIds")||new Map;t.set(e.partner.id,e.id),P.setMap("partnerCustomerIds",t)}async getIntegrationProductById(e){var a,i;const n=(a=(await N.getShadowGraphqlClient().query({query:kA,variables:{ids:[e]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:a.integrationProducts;if(!n||n.length===0||!((i=n[0])!=null&&i.id))throw new Error("Integration product not found.");return new qe(n[0])}async getIntegrationProductFromExternalIds(e,t){var i;const a=(i=(await N.getShadowGraphqlClient().query({query:bA,variables:{externalProductId:t,externalIntegrationId:e},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:i.integrationProductFromExternalIds;if(!(a!=null&&a.id))throw new Error("Integration product not found.");return new qe(a)}async getIntegrationProduct(e){return e.type==="integration"?this.getIntegrationProductById(e.integrationProductId):this.getIntegrationProductFromExternalIds(e.externalIntegrationId,e.externalProductId)}}class Fa{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,t){}addStorageCallback(e){}getCommandDispatcher(){return e=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(e){return[]}getSerializedStep(e,t){}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,t){}setInformationResults(e){}setMandatoryFulfilled(e,t){}async setSelectionsAndElements(e,t,A){}toggleDesignConfirmed(){}updateMetadata(e,t){}async updateStorage(e,t){}injectIntoPreviewService(e){return Promise.resolve()}ejectFromPreviewService(){}setWorkflowStateSyncEnabled(e){}}var rA=(c=>(c.SelectFrame="SelectFrame",c.SelectImage="SelectImage",c.Position="Position",c))(rA||{});class cA extends j{constructor(e,t){var A;super(e,t),this.frameService=(A=this.manager.getStepSpecificServices(this.getId()))==null?void 0:A.frameService}selectVariant(e){const t=this.manager.getRegionElements(this.step.stepName);return le.selectVariant(this.step,e.getResource(),t,this.manager,A=>this.setUpdateState(A))}onFrameDataChanged(e){this.frameService&&this.frameService.onFrameDataChanged(t=>{t&&e(t)})}async selectImage(e,t=!0){var A;if(await le.selectImage(this.step,e,this.manager),t){const n=((A=this.manager.getStepStorage(this.step.stepName))==null?void 0:A.framePatternData)||{};this.manager.updateStorage(this.step.stepName,{framePatternData:{...n,originalAssetKey:e.key,backgroundRemovedAssetKey:void 0,useOriginalAsset:void 0}})}}async removeBackgroundFromImageSelection(e=!0){var a;const t=await this.getOriginalImageSelection();if(!t)throw new Error("You must supply an image selection before attempting to remove the background.");const A=await v.removeBackgroundFromAsset(t);e&&await le.selectImage(this.step,A,this.manager);const n=((a=this.manager.getStepStorage(this.step.stepName))==null?void 0:a.framePatternData)||{};return this.manager.updateStorage(this.step.stepName,{framePatternData:{...n,backgroundRemovedAssetKey:A.key,useOriginalAsset:!e}}),A}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(e,t,A,n){return n&&n.length>1&&e===void 0?"SelectFrame":t||A||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}async getOriginalImageSelection(){var t,A;const e=(A=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)==null?void 0:A.originalAssetKey;if(e)return v.getLocalOrFromServer(e)}async getBackgroundRemovedImageSelection(){var t,A;const e=(A=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)==null?void 0:A.backgroundRemovedAssetKey;if(e)return v.getLocalOrFromServer(e)}hasBackgroundRemovedImageSelection(){var e,t;return!!((t=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)!=null&&t.backgroundRemovedAssetKey)}getUseOriginalImageSelection(){var e,t;return((t=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:t.useOriginalAsset)??!1}async setUseOriginalImageSelection(e){var n;const t=((n=this.manager.getStepStorage(this.step.stepName))==null?void 0:n.framePatternData)||{};if(t.useOriginalAsset===e)return;const A=await this.getOriginalImageSelection();if(!A)throw new Error("You must provide an image selection before calling setUseOriginalImageSelection");if(e)await this.selectImage(A,!1);else{const a=await this.getBackgroundRemovedImageSelection();if(!a)throw new Error("You must call removeBackgroundFromImageSelection before attempting to apply the image.");await this.selectImage(a,!1)}this.manager.updateStorage(this.step.stepName,{framePatternData:{...t,useOriginalAsset:e}})}}Object.defineProperty(u,"AspectType",{enumerable:!0,get:()=>l.AspectType}),Object.defineProperty(u,"AssetType",{enumerable:!0,get:()=>l.AssetType}),Object.defineProperty(u,"BringForwardCommand",{enumerable:!0,get:()=>l.BringForwardCommand}),Object.defineProperty(u,"BringToBackCommand",{enumerable:!0,get:()=>l.BringToBackCommand}),Object.defineProperty(u,"BringToFrontCommand",{enumerable:!0,get:()=>l.BringToFrontCommand}),Object.defineProperty(u,"CanvasCommand",{enumerable:!0,get:()=>l.CanvasCommand}),Object.defineProperty(u,"CommandContext",{enumerable:!0,get:()=>l.CommandContext}),Object.defineProperty(u,"CreateElementCommand",{enumerable:!0,get:()=>l.CreateElementCommand}),Object.defineProperty(u,"CreateLayoutCommand",{enumerable:!0,get:()=>l.CreateLayoutCommand}),Object.defineProperty(u,"DeleteElementCommand",{enumerable:!0,get:()=>l.DeleteElementCommand}),Object.defineProperty(u,"FontAlignmentCommand",{enumerable:!0,get:()=>l.FontAlignmentCommand}),Object.defineProperty(u,"FontColorCommand",{enumerable:!0,get:()=>l.FontColorCommand}),Object.defineProperty(u,"FontSizeCommand",{enumerable:!0,get:()=>l.FontSizeCommand}),Object.defineProperty(u,"FontSourceCommand",{enumerable:!0,get:()=>l.FontSourceCommand}),Object.defineProperty(u,"GroupCommand",{enumerable:!0,get:()=>l.GroupCommand}),Object.defineProperty(u,"LayoutElementFactory",{enumerable:!0,get:()=>l.LayoutElementFactory}),Object.defineProperty(u,"LayoutElementType",{enumerable:!0,get:()=>l.LayoutElementType}),Object.defineProperty(u,"MoveCommand",{enumerable:!0,get:()=>l.MoveCommand}),Object.defineProperty(u,"ResizeCommand",{enumerable:!0,get:()=>l.ResizeCommand}),Object.defineProperty(u,"RotateCommand",{enumerable:!0,get:()=>l.RotateCommand}),Object.defineProperty(u,"SendBackwardsCommand",{enumerable:!0,get:()=>l.SendBackwardsCommand}),Object.defineProperty(u,"StepAspectType",{enumerable:!0,get:()=>l.StepAspectType}),Object.defineProperty(u,"StepType",{enumerable:!0,get:()=>l.StepType}),Object.defineProperty(u,"TextChangeCommand",{enumerable:!0,get:()=>l.TextChangeCommand}),Object.defineProperty(u,"UnitOfMeasurement",{enumerable:!0,get:()=>l.UnitOfMeasurement}),Object.defineProperty(u,"dataUrlFromExternalUrl",{enumerable:!0,get:()=>l.dataUrlFromExternalUrl}),Object.defineProperty(u,"determineCorrectFontSizeAndLines",{enumerable:!0,get:()=>l.determineCorrectFontSizeAndLines}),Object.defineProperty(u,"findElement",{enumerable:!0,get:()=>l.findElement}),Object.defineProperty(u,"frameDataCache",{enumerable:!0,get:()=>l.frameDataCache}),Object.defineProperty(u,"generate",{enumerable:!0,get:()=>l.generate}),Object.defineProperty(u,"generateSVGWithUnknownColors",{enumerable:!0,get:()=>l.generateSVGWithUnknownColors}),Object.defineProperty(u,"getAttributesFromArrayBuffer",{enumerable:!0,get:()=>l.getAttributesFromArrayBuffer}),Object.defineProperty(u,"getAxisAlignedBoundingBox",{enumerable:!0,get:()=>l.getAxisAlignedBoundingBox}),Object.defineProperty(u,"getFrameData",{enumerable:!0,get:()=>l.getFrameData}),Object.defineProperty(u,"getSvgElement",{enumerable:!0,get:()=>l.getSvgElement}),Object.defineProperty(u,"loadFont",{enumerable:!0,get:()=>l.loadFont}),Object.defineProperty(u,"patternImageDataCache",{enumerable:!0,get:()=>l.patternImageDataCache}),Object.defineProperty(u,"registerFetchImplementation",{enumerable:!0,get:()=>l.registerFetchImplementation}),Object.defineProperty(u,"registerWindowImplementation",{enumerable:!0,get:()=>l.registerWindowImplementation}),Object.defineProperty(u,"rehydrateSerializedLayout",{enumerable:!0,get:()=>l.rehydrateSerializedLayout}),Object.defineProperty(u,"setCanvasModule",{enumerable:!0,get:()=>l.setCanvasModule}),u.ArrayInput=ra,u.AssetNotFoundError=V,u.CollectionProduct=ye,u.ColorOptionGlobalPropertyHandle=_t,u.ConversionDataType=ht,u.ConversionLocation=wt,u.FileUploadGlobalPropertyHandle=Zt,u.FlowExecutionNodeResult=he,u.FlowExecutionResult=iA,u.FlowService=aA,u.FrameService=mt,u.FrameStep=rA,u.FrameStepHandle=cA,u.GlobalPropertyHandle=Se,u.IllustrationStepHandle=Ut,u.InformationMessageType=Be,u.InformationStepHandle=Ot,u.IntegrationProduct=qe,u.IntegrationType=dt,u.LayoutNotFoundError=J,u.MaterialStepHandle=Gt,u.MisconfigurationError=se,u.MockWorkflowManager=Fa,u.ModelStepHandle=vt,u.ObjectInput=Xe,u.ObjectInputType=oA,u.OptionGlobalPropertyHandle=Ke,u.OptionNotFoundError=oe,u.ParseError=q,u.PictureStepHandle=kt,u.ProductCameraRig=Bt,u.ProductCollection=eA,u.ProductWorkflow=Ae,u.PromiseCache=Z,u.PromiseQueue=Ue,u.QuestionStepHandle=bt,u.QueueablePromise=Re,u.ResourceNotFoundError=X,u.ShapeStepHandle=Jt,u.SpiffCommerceClient=sA,u.StakeholderType=ce,u.StepHandle=j,u.TextGlobalPropertyHandle=$t,u.TextInput=sa,u.TextStepHandle=Tt,u.Transform=AA,u.TransformCollection=tA,u.UnhandledBehaviorError=k,u.Variant=K,u.WorkflowExperienceEventType=Vt,u.WorkflowExperienceImpl=we,u.assetService=v,u.createDesign=Kt,u.designService=Fe,u.digitalContentStepService=pt,u.frameStepService=le,u.generateCommands=Wt,u.generateStateFromDesignInputSteps=kn,u.getBoundedOffsets=Qt,u.getWorkflow=Ee,u.getWorkflows=Ze,u.graphQlManager=N,u.illustrationStepService=de,u.materialStepService=Ge,u.modelStepService=ve,u.moduleStepService=Ft,u.optionService=O,u.persistenceService=P,u.pictureStepService=ke,u.questionStepService=be,u.shapeStepService=te,u.shortenUrl=ft,u.spiffCoreConfiguration=W,u.stepAspectValuesToDesignInputSteps=vn,u.textStepService=L,u.toast=Mt,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED