@spiffcommerce/core 26.4.2 → 26.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1302,7 +1302,7 @@
|
|
|
1302
1302
|
matrix(${o}, ${-c}, ${c}, ${o}, 0, 0)
|
|
1303
1303
|
matrix(1, 0, 0, 1, ${-n.width/2}, ${-n.height/2})
|
|
1304
1304
|
matrix(${n.scaleX}, 0, 0, ${n.scaleY}, 0, 0)
|
|
1305
|
-
`,children:S.jsx(Ga,{id:t,x:0,y:0,rotation:0,width:n.width,height:n.height,clipPath:n.path,children:l()})})})]})},Ta=new Map;class Ds{constructor(t){this.font=t,this.glyphsFromText=new Map,this.kerningValues=new Map,this.height=this.calculateApproximateHeight()}getFont(){return this.font}getGlyphs(t){const e=this.glyphsFromText.get(t);if(e)return e;const A=this.font.stringToGlyphs(t);return this.glyphsFromText.set(t,A),A}getApproximateHeight(){return this.height}getExactHeight(t){const e=this.font.stringToGlyphs(t);let A=0,a=0;return e.forEach(i=>{const s=i.getMetrics();A=Math.max(A,s.yMax),a=Math.min(a,s.yMin)}),A-a}getKerningValue(t,e){if(!t.name||!e.name)return;let A=this.kerningValues.get(t.name);A||(A=new Map,this.kerningValues.set(t.name,A));let a=A.get(e.name);return a||(a=this.font.getKerningValue(t,e),A.set(e.name,a)),a}calculateApproximateHeight(){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e=this.font.stringToGlyphs(t);let A=0,a=0;return e.forEach(i=>{const s=i.getMetrics();A=Math.max(A,s.yMax),a=Math.min(a,s.yMin)}),A-a}}const Is=n=>n.substring(0,5).toLowerCase().trim()==="data:",be=new Map,pt=async n=>{if(be.has(n))return be.get(n);const e=(async()=>{try{return mt(n).getFont()}catch{if(Is(n)){const A=ua(n),a=ze.parse(A);return tA(n,a),a}else{const A=await Ie(n,!0),a=ze.parse(A);return tA(n,a),await $n(a,n),a}}})();return be.set(n,e),e},fA=n=>{const t=ua(n),e=ze.parse(t);return tA(n,e),e},mt=n=>{const t=Ta.get(n);if(t)return t;throw new Error("Font metrics unavailable for font")},tA=(n,t)=>{const e=new Ds(t);return Ta.set(n,e),e},Fs=async n=>{const t=it(),e=t.parseFromString(n,"image/svg+xml"),A=e.firstElementChild,a=new Map;A.querySelectorAll("style").forEach(l=>{var d;(d=aa.parse(l.innerHTML).stylesheet)==null||d.rules.forEach(B=>{var h,C,w;if(B.type==="font-face"&&B.declarations){const u=(h=B.declarations.find(f=>f.property==="font-family"))==null?void 0:h.value,E=(C=B.declarations.find(f=>f.property==="src"))==null?void 0:C.value,m=(w=E==null?void 0:E.match(/'(https.*?)'/))==null?void 0:w[1];u&&m&&a.set(u,m)}})});const s=e.querySelectorAll("tspan");for(let l=0;l<s.length;l++){const g=s.item(l),d=g.closest("text"),B=g.closest("g"),h=d.getAttribute("font-family"),C=await pt(a.get(h)),w=d.getAttribute("fill"),u=C.getPath(g.innerHTML,0,0,parseInt(d.getAttribute("font-size")??"72")),E=u.getBoundingBox().x2-u.getBoundingBox().x1;let m=0;const f=g.getAttribute("text-anchor");f==="middle"?m=E/2:f==="end"&&(m=E);const D=C.getPath(g.innerHTML,parseFloat(g.getAttribute("x")??"0")-m,parseFloat(g.getAttribute("y")??"0"),parseInt(d.getAttribute("font-size")??"72"),{fill:w}).toSVG(2),F=t.parseFromString(D,"image/svg+xml").firstElementChild;F.setAttribute("xmlns","http://www.w3.org/2000/svg")
|
|
1305
|
+
`,children:S.jsx(Ga,{id:t,x:0,y:0,rotation:0,width:n.width,height:n.height,clipPath:n.path,children:l()})})})]})},Ta=new Map;class Ds{constructor(t){this.font=t,this.glyphsFromText=new Map,this.kerningValues=new Map,this.height=this.calculateApproximateHeight()}getFont(){return this.font}getGlyphs(t){const e=this.glyphsFromText.get(t);if(e)return e;const A=this.font.stringToGlyphs(t);return this.glyphsFromText.set(t,A),A}getApproximateHeight(){return this.height}getExactHeight(t){const e=this.font.stringToGlyphs(t);let A=0,a=0;return e.forEach(i=>{const s=i.getMetrics();A=Math.max(A,s.yMax),a=Math.min(a,s.yMin)}),A-a}getKerningValue(t,e){if(!t.name||!e.name)return;let A=this.kerningValues.get(t.name);A||(A=new Map,this.kerningValues.set(t.name,A));let a=A.get(e.name);return a||(a=this.font.getKerningValue(t,e),A.set(e.name,a)),a}calculateApproximateHeight(){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e=this.font.stringToGlyphs(t);let A=0,a=0;return e.forEach(i=>{const s=i.getMetrics();A=Math.max(A,s.yMax),a=Math.min(a,s.yMin)}),A-a}}const Is=n=>n.substring(0,5).toLowerCase().trim()==="data:",be=new Map,pt=async n=>{if(be.has(n))return be.get(n);const e=(async()=>{try{return mt(n).getFont()}catch{if(Is(n)){const A=ua(n),a=ze.parse(A);return tA(n,a),a}else{const A=await Ie(n,!0),a=ze.parse(A);return tA(n,a),await $n(a,n),a}}})();return be.set(n,e),e},fA=n=>{const t=ua(n),e=ze.parse(t);return tA(n,e),e},mt=n=>{const t=Ta.get(n);if(t)return t;throw new Error("Font metrics unavailable for font")},tA=(n,t)=>{const e=new Ds(t);return Ta.set(n,e),e},Fs=async n=>{const t=it(),e=t.parseFromString(n,"image/svg+xml"),A=e.firstElementChild,a=new Map;A.querySelectorAll("style").forEach(l=>{var d;(d=aa.parse(l.innerHTML).stylesheet)==null||d.rules.forEach(B=>{var h,C,w;if(B.type==="font-face"&&B.declarations){const u=(h=B.declarations.find(f=>f.property==="font-family"))==null?void 0:h.value,E=(C=B.declarations.find(f=>f.property==="src"))==null?void 0:C.value,m=(w=E==null?void 0:E.match(/'(https.*?)'/))==null?void 0:w[1];u&&m&&a.set(u,m)}})});const s=e.querySelectorAll("tspan");for(let l=0;l<s.length;l++){const g=s.item(l),d=g.closest("text"),B=g.closest("g"),h=d.getAttribute("font-family"),C=await pt(a.get(h)),w=d.getAttribute("fill"),u=C.getPath(g.innerHTML,0,0,parseInt(d.getAttribute("font-size")??"72")),E=u.getBoundingBox().x2-u.getBoundingBox().x1;let m=0;const f=g.getAttribute("text-anchor");f==="middle"?m=E/2:f==="end"&&(m=E);const D=C.getPath(g.innerHTML,parseFloat(g.getAttribute("x")??"0")-m,parseFloat(g.getAttribute("y")??"0"),parseInt(d.getAttribute("font-size")??"72"),{fill:w}).toSVG(2),F=t.parseFromString(D,"image/svg+xml").firstElementChild;B.appendChild(F),F.setAttribute("xmlns","http://www.w3.org/2000/svg")}return e.querySelectorAll("text").forEach(l=>l.remove()),Qt().serializeToString(A)},we=(n,t,e,A)=>Math.max(xs(n.join(`
|
|
1306
1306
|
`),e,A),t),WA=(n,t,e,A,a,i)=>{const s=(i||QA)*a.getApproximateHeight(),r=t.split(`
|
|
1307
1307
|
`);try{const o=r.flatMap(l=>Be(l,n.width,A,a)),c=o.flatMap(l=>l.lines);return{lines:c,requiredHeight:o.flatMap(l=>l.lines).length*(A*s),fontSize:e,requiredWidth:we(c,n.width,A,a)}}catch{const c=t.split("");return{lines:c,requiredHeight:c.length*(A*s),fontSize:e,requiredWidth:we(c,n.width,A,a)}}},Be=(n,t,e,A)=>{const a=gt(n,e,A);if(a<=t)return{lines:[n],width:a};if(!(n.indexOf(" ")>-1)){if(n.length<=1)throw new Error(`Character ${n} is wider than region`);const l=Math.floor(n.length/2),g=Be(n.slice(0,l),t,e,A),d=Be(n.slice(l),t,e,A);return{lines:[...g.lines,...d.lines],width:Math.max(g.width,d.width)}}const s=n.split(" "),r=[];let o=-1/0,c=0;for(;c<s.length;){const l=s[c];if(gt(l,e,A)>t){const g=Be(l,t,e,A);r.push(...g.lines),o=Math.max(o,g.width),c++}else{const g=[l];o=Math.max(o,gt(l,e,A));let d=c+1,B=!0;for(;d<s.length&&B;){const h=s[d],C=gt(`${g.join(" ")} ${h}`,e,A);C<=t?(g.push(h),o=Math.max(o,C),d++):B=!1}r.push(g.join(" ")),c=d}}if(o<0)throw new Error(`No max width calculated for text: ${r}.`);return{lines:r,width:o}},ys=(n,t,e,A,a,i)=>{const s=(i??QA)*t.getApproximateHeight(),r=1/e.unitsPerEm,o=Ja(n,r,t),c=n.length*s*r,l=A/o,g=a/c;return Math.min(g,l)},Ms=(n,t,e,A)=>{var c;const a=mt(t.fontData.assetUrl),i=a.getFont(),s=t.fontSize/i.unitsPerEm;if(!e)return WA(t,n,t.fontSize,s,a,A);let r;if(t.text?r=t.text.split(`
|
|
1308
1308
|
`):r=((c=t.input)==null?void 0:c.split(`
|
|
@@ -3353,7 +3353,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
3353
3353
|
}
|
|
3354
3354
|
}
|
|
3355
3355
|
}
|
|
3356
|
-
`,Mo=async(n,t)=>{var a;const e=await y.getShadowGraphqlClient().query({query:Ti(((a=t==null?void 0:t.assets)==null?void 0:a.metadata)||!1),errorPolicy:"all",variables:{ids:n}});if(e.error)throw e.error;if(e.errors)throw e.errors.forEach(i=>console.error(i)),new Error("Unable to read workflows. Consult GraphQL errors.");const A=e.data.workflows;if(A===void 0||A.length!==n.length)throw new Error(`Unable to read workflows: ${e.errors??"Length mismatch in response"}`);return A.forEach(i=>{i.steps.forEach(s=>{var r,o,c;delete s.data.__typename,(r=s.option)!=null&&r.id&&((o=s.option.defaultVariant)!=null&&o.asset&&G.cacheAsset(s.option.defaultVariant.asset),s.option.colorProfile&&G.cacheAsset(s.option.colorProfile),(c=s.option.variants)==null||c.forEach(l=>{l.asset&&G.cacheAsset(l.asset),l.thumbnail&&G.cacheAsset(l.thumbnail),l.material&&G.cacheMaterial(l.material)}),Nt.set({id:s.option.id},Promise.resolve(s.option)))}),i.finalizeStepConfig||(i.finalizeStepConfig={}),i.finalizeStepConfig.termsMarkdown=i.partner.termsMarkdown}),A},So=async(n,t)=>{const A=(await t).find(a=>a.id===n);if(!A)throw new Error(`Workflow not found: ${n}`);return A},bA=async(n,t)=>{const e=n.map(r=>Nt.get({id:r,options:t})),A=n.filter((r,o)=>e[o]===void 0);if(A.length===0)return Promise.all(e);const a=Mo(A,t),i=A.map(r=>Nt.set({id:r,options:t},So(r,a))),s=e.filter(r=>r!==void 0);return await Promise.all(s.concat(i))},xo=async(n,t)=>(await bA([n],t))[0],Yo=n=>n.sort((t,e)=>t.index-e.index).map(t=>({id:H(),panelId:t.name,name:t.name,index:t.index,createdAt:new Date,updatedAt:new Date,transparentBackground:t.transparentBackground,height:t.height,width:t.width,previewRegion:t.previewRegion,useEditableArea:t.useEditableArea,editableArea:t.editableArea})),Po=(n,t)=>{const e=n.workflowState,A=e?JSON.parse(e):void 0;return A?Object.values(A.layouts).map(a=>a.layout):Yo(t.panels)};class vo{constructor(t){this.activeIntegration=void 0,this.updateTransactionState=async e=>{try{return y.getShadowGraphqlClient().mutate({...e,mutation:Si})}catch(A){throw console.error(A),new lt("Critical - Unable to synchronize workflow state with server.")}},this.options=t,this.options.applicationKey&&ai(this.options.applicationKey),console.debug("------------------------"),console.debug("Spiff Commerce Core SDK"),console.debug("Version: 26.4.2"),console.debug(`Application Key Provided: ${!!this.options.applicationKey}`),console.debug("------------------------")}configure(t){dt.setHubUrl(t.hubUrl),dt.setServerUrl(t.serverUrl),dt.setServicesApiUrl(t.servicesApiUrl),this.marketplaceThemeInstallId=t.marketplaceThemeInstallId,this.marketplaceThemeInstallConfigurationId=t.marketplaceThemeInstallConfigurationId,t.bearerAuthenticationToken&&fa(t.bearerAuthenticationToken),this.options.applicationKey&&this.getIntegration()}getAssetManager(){return G}getCurrencyCode(){if(this.currencyCode===void 0)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!ni())throw new Error("Application key required to use Flow Service.");return new Pn}async getIntegration(){if(this.activeIntegration)return this.activeIntegration;if(!this.options.applicationKey)throw new Error("Cannot get current Integration without specifying an Application Key.");return this.activeIntegration=kn(this.options.applicationKey),this.activeIntegration}async canUseAddon(t){var e;try{return((e=(await this.getIntegration()).partner.activeAddons)==null?void 0:e.includes(t))??!1}catch(A){return console.error(A),!1}}async authenticateBundleFromLocalStorage(t){var a,i;const e=N.getMap("bundleOwnerIds");if(e!=null&&e.has(t))return Promise.resolve({success:!0,stakeholderType:Vt.Owner});const A=N.getMap("bundlePartnerIds")||new Map;if(A.has(t)){const s=A.get(t),o=(N.getMap("partnerCustomerIds")||new Map).get(s);if(o&&await this.authenticateCustomerId(o)){const l=(i=(a=this.customer)==null?void 0:a.bundleStakeholders)==null?void 0:i.find(g=>{var d;return((d=g.bundle)==null?void 0:d.id)===t});if(l)return Promise.resolve({success:!0,stakeholderType:l.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){var l,g,d,B,h,C;const e=y.getShadowGraphqlClient(),A=await e.query({query:Ji,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!A.data.transactions||A.data.transactions.length===0)throw new Error(`Transaction not found: ${t}`);const a=A.data.transactions[0];if(!((g=(l=a.product)==null?void 0:l.partner)==null?void 0:g.id))throw new Error(`Unable to read transaction: ${t}`);if(a.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const s=N.getMap("transactionOwnerIds");if(s!=null&&s.has(t))return Promise.resolve({success:!0,stakeholderType:Vt.Owner});const r=N.getMap("transactionCustomerIds");if(r!=null&&r.has(t)){const w=r.get(t);if(w&&await this.authenticateCustomerId(w)){const E=((B=(d=this.customer)==null?void 0:d.bundleStakeholders)==null?void 0:B.find(m=>{var f,Q;return(Q=(f=m.bundle)==null?void 0:f.transactions)==null?void 0:Q.some(D=>D.id===t)}))||((C=(h=this.customer)==null?void 0:h.stakeholders)==null?void 0:C.find(m=>{var f;return((f=m.transaction)==null?void 0:f.id)===t}));if(E)return Promise.resolve({success:!0,stakeholderType:E.type})}}const c=(await e.query({query:Li,errorPolicy:"all",variables:{id:a.workflowId}})).data.workflow;if(!c)throw new Error(`Unable to read workflow: ${a.workflowId}`);return Promise.resolve({success:!1,theme:c.overrideTheme,customLogoLink:a.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=N.getMap("transactionCustomerIds");e!=null&&e.has(t)&&(e.delete(t),N.setMap("transactionCustomerIds",e))}async customerHasBundleTemplates(t){const a=(await y.getShadowGraphqlClient().query({query:ea,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;return a.id?a.hasBundleTemplates??!1:!1}getStakeholderTypeForTransaction(t){var A,a;const e=(a=(A=this.customer)==null?void 0:A.stakeholders)==null?void 0:a.find(i=>{var s;return((s=i.transaction)==null?void 0:s.id)===t});if(e)return e.type}async getOrCreateCustomer(t){var s;this.customer=void 0;const e=y.getShadowGraphqlClient(),a=(await e.query({query:ea,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!a.id){const o=(s=(await e.mutate({mutation:po,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data)==null?void 0:s.customerCreate;if(!o)throw new Error("Unable to create customer.");return this.storeCustomer(o),this.customer=o,{customer:o,isAuthenticated:!1}}this.storeCustomer(a);const i=await this.authenticateCustomerId(a.id);return{customer:this.customer||a,isAuthenticated:i}}getCustomer(){return this.customer}async authenticateCustomerId(t){var r;const e=y.getShadowGraphqlClient(),A=N.getMap("customerTokens");if(!(A!=null&&A.has(t)))return!1;const a=A.get(t);if(!a)return!1;const s=(r=(await e.mutate({mutation:Do,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:a}})).data)==null?void 0:r.customerAuthenticate;return s?(this.storeCustomer(s),zA(a),this.customer=s,!0):!1}async generateVerificationCode(t){await y.getShadowGraphqlClient().mutate({mutation:Io,variables:{emailAddress:t}})}async verifyCode(t,e){var i,s;const a=(i=(await y.getShadowGraphqlClient().mutate({mutation:Fo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data)==null?void 0:i.customerVerifyCode;if(a!=null&&a.loginToken){if(!((s=a.partner)!=null&&s.id))throw new Error(`Unable to find customer: ${t}`);const r=N.getMap("customerTokens")||new Map;return r.set(a.id,a.loginToken),N.setMap("customerTokens",r),this.storeCustomer(a),zA(a.loginToken),this.customer={...a,loginToken:void 0},!0}return!1}async getCustomerMetafields(){var e;if(!((e=this.customer)!=null&&e.id))throw new Error("Customer must be logged in before calling this function.");return(await y.getShadowGraphqlClient().query({query:yo,variables:{id:this.customer.id}})).data.metafields}async getNewBundle(t,e,A){var c,l,g,d,B;const i=(g=(await y.getShadowGraphqlClient().mutate({mutation:Ir(((l=(c=A==null?void 0:A.graphql)==null?void 0:c.productCollection)==null?void 0:l.eagerFetchProducts)||!1),variables:{collectionId:t,initialMetadata:e?Object.entries(e).map((h,C)=>({key:h[0],value:h[1]})):void 0,marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId},fetchPolicy:"no-cache"})).data)==null?void 0:g.bundleCreate;if(!(i!=null&&i.id))throw new Error("Unable to create bundle");const s=N.getMap("bundlePartnerIds")||new Map;s.set(i.id,i.partner.id),N.setMap("bundlePartnerIds",s);const r=N.getMap("bundleOwnerIds")||new Map;r.set(i.id,i.bundleOwnerId),N.setMap("bundleOwnerIds",r);const o=new Oe(this,i,void 0,void 0,i.bundleOwnerId,{eagerFetchProducts:(B=(d=A==null?void 0:A.graphql)==null?void 0:d.productCollection)==null?void 0:B.eagerFetchProducts});return await o.getInitializationPromise(),o}async getExistingBundle(t,e,A,a){var w,u,E,m,f,Q,D,I,F,x,Y;const i=N.getMap("bundleOwnerIds"),s=i==null?void 0:i.get(t),o=((w=Object.entries(localStorage).find(([P,v])=>P.startsWith("CognitoIdentityServiceProvider")&&P.endsWith("idToken")))==null?void 0:w[0])||"",c=localStorage.getItem(o),l={};c&&!fe(c)&&(l.Authorization=`Bearer ${c}`);const g={bundleOwnerId:s,...l,...(u=a==null?void 0:a.graphql)==null?void 0:u.additionalHeaders},d=await y.getShadowGraphqlClient().query({query:fr(((m=(E=a==null?void 0:a.graphql)==null?void 0:E.productCollection)==null?void 0:m.eagerFetchProducts)||!1),variables:{id:t},fetchPolicy:"no-cache",context:{headers:g}});if(!((f=d.data)!=null&&f.bundles)||((Q=d.data)==null?void 0:Q.bundles.length)===0||!((D=d.data)!=null&&D.bundles[0]))throw new Error(`Unable to find bundle: ${t}`);const B=(I=d.data)==null?void 0:I.bundles[0],h=N.getMap("bundlePartnerIds")||new Map;h.set(B.id,B.partner.id),N.setMap("bundlePartnerIds",h);const C=new Oe(this,B,e,A,s,{additionalHeaders:(F=a==null?void 0:a.graphql)==null?void 0:F.additionalHeaders,eagerFetchProducts:(Y=(x=a==null?void 0:a.graphql)==null?void 0:x.productCollection)==null?void 0:Y.eagerFetchProducts,existingGlobalPropertyState:d.data.globalPropertyState});return await C.getInitializationPromise(),C}async duplicateBundle(t,e,A,a){var w,u,E,m,f,Q,D,I;const i=(w=N.getMap("bundleOwnerIds"))==null?void 0:w.get(t),r=((u=Object.entries(localStorage).find(([F,x])=>F.startsWith("CognitoIdentityServiceProvider")&&F.endsWith("idToken")))==null?void 0:u[0])||"",o=localStorage.getItem(r),c={};o&&!fe(o)&&(c.Authorization=`Bearer ${o}`);const l={bundleOwnerId:i,...c,...(E=a==null?void 0:a.graphql)==null?void 0:E.additionalHeaders},d=(Q=(await y.getShadowGraphqlClient().mutate({mutation:Fr(((f=(m=a==null?void 0:a.graphql)==null?void 0:m.productCollection)==null?void 0:f.eagerFetchProducts)||!1),variables:{id:t,template:e,marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId,duplicateTransactions:A},context:{headers:l},fetchPolicy:"no-cache"})).data)==null?void 0:Q.bundleDuplicate;if(!(d!=null&&d.id))throw new Error("Unable to duplicate bundle");const B=N.getMap("bundlePartnerIds")||new Map;B.set(d.id,d.partner.id),N.setMap("bundlePartnerIds",B);const h=N.getMap("bundleOwnerIds")||new Map;h.set(d.id,d.bundleOwnerId),N.setMap("bundleOwnerIds",h);const C=new Oe(this,d,void 0,void 0,d.bundleOwnerId,{eagerFetchProducts:(I=(D=a==null?void 0:a.graphql)==null?void 0:D.productCollection)==null?void 0:I.eagerFetchProducts});return await C.getInitializationPromise(),C}async getBundlesForCustomer(t){var i;if(!((i=this.customer)!=null&&i.id))throw new Error("Customer not authenticated.");const{includeMetadata:e,...A}=t;return(await y.getShadowGraphqlClient().query({query:Rr(e??!1),variables:{...A,id:this.customer.id},fetchPolicy:"no-cache"})).data.customerBundlesFeed}async getBundleStakeholders(){var i;if(!this.customer)throw new Error("Customer not authenticated.");const t=await y.getShadowGraphqlClient().query({query:Qr,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!((i=t.data)!=null&&i.customers)||t.data.customers.length===0)throw new Error("Unable to find customer.");const A=t.data.customers[0].bundleStakeholders||[],a=N.getMap("bundlePartnerIds")||new Map;return A.forEach(s=>{var r,o;(r=s.bundle)!=null&&r.id&&((o=s.bundle.partner)!=null&&o.id)&&a.set(s.bundle.id,s.bundle.partner.id)}),N.setMap("bundlePartnerIds",a),A}async getWorkflowExperience(t,e){if(!t)throw new Error("getWorkflowExperience has been called without an options object! This is not supported.");const A=await this.getWorkflowExperiences([t],t.graphql),a=A[0];return e&&await a.getWorkflowManager().injectIntoPreviewService(e(a.getWorkflowManager().getWorkflow())),A[0]}async getWorkflowExperiences(t,e){if(t.length===0)throw new lt("No options provided!");const A=y.getShadowGraphqlClient(),a=async Q=>{var x,Y,P;if(Q.length===0)return[];const D=Q.map(v=>v.option.transactionId),I=await A.query({query:Mi,variables:{ids:D},errorPolicy:"all",fetchPolicy:"no-cache"}),F=I.data.transactions;if(F.length!==Q.length){const v=((Y=(x=I.errors)==null?void 0:x[0])==null?void 0:Y.message)||"Unknown error";throw new lt(`Not all transactions were found: ${v}`)}return!this.activeIntegration&&((P=F[0].integrationProduct)!=null&&P.integration)&&(this.activeIntegration=Promise.resolve(F[0].integrationProduct.integration)),F.map((v,b)=>{var K;return{transaction:v,workflowId:v.workflowId,readOnly:((K=Q.find(j=>j.option.transactionId===v.id))==null?void 0:K.option.readOnly)??!1,index:Q[b].index}})},i=async Q=>{var F,x,Y;if(Q.length===0)return[];const D=await A.mutate({mutation:yi,variables:{inputs:Q.map(P=>({integrationProductId:P.option.type==="integration"?P.option.integrationProductId:void 0,externalIntegrationId:P.option.type==="external"?P.option.externalIntegrationId:void 0,externalProductId:P.option.type==="external"?P.option.externalProductId:void 0,workflowId:P.option.workflowId,designName:P.option.designName,claim:!0})),marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId},errorPolicy:"all",fetchPolicy:"no-cache"}),I=(F=D.data)==null?void 0:F.transactionCreateMany;if(!I||I.length===0){const P=((Y=(x=D.errors)==null?void 0:x[0])==null?void 0:Y.message)||"Unknown error";throw new lt(`Failed to create transactions: ${P}`)}return I.map((P,v)=>({transaction:P,workflowId:P.workflowId,readOnly:!1,index:Q[v].index}))},s=t.map((Q,D)=>({option:Q,index:D})),r=s.filter(Q=>Q.option.type==="transaction"),o=s.filter(Q=>Q.option.type==="integration"||Q.option.type==="external"),c=GA(r,10),l=GA(o,10),g=(await Promise.all([...c.map(a),...l.map(i)])).flat(),d=[...new Set(g.map(Q=>Q.workflowId))],B=await bA(d,e),h=new Map(B.map(Q=>[Q.id,Q])),C=N.getMap("transactionOwnerIds")||new Map,w=g.map(async Q=>{var K;const{transaction:D,workflowId:I,readOnly:F,index:x}=Q,Y=h.get(I),P=t[x];!C.get(D.id)&&D.transactionOwnerId&&C.set(D.id,D.transactionOwnerId);const v=C.get(D.id)||void 0,b={product:D.product,transaction:D,layouts:[],singleVariantsRenderable:(K=P==null?void 0:P.workflowConfiguration)==null?void 0:K.singleVariantsRenderable,stateMutationFunc:F?async()=>{throw new L("State mutation is forbidden in read only mode!")}:async j=>this.updateTransactionState({...j,context:{transactionOwnerId:v,bundleOwnerId:e==null?void 0:e.bundleOwnerId}}),readOnly:F,workflow:Y,isReloadedTransaction:P.type==="transaction"};if(P.type==="transaction"&&D.workflowState){const j=JSON.parse(D.workflowState);b.layouts=Object.values(j.layouts||{}).map(At=>At.layout),await eA(j),b.reloadedState=j}else if(!F&&P.workflowState){const j=JSON.parse(P.workflowState);b.layouts=Object.values(j.layouts||{}).map(At=>At.layout),await eA(j),b.reloadedState=j}else b.layouts=Po(b.transaction,b.workflow);return b.renderableContextService=new oo(b.layouts),b.delayWorkflowStateSync=!0,{experienceOptions:b,index:x,options:P}}),u=await Promise.all(w);N.setMap("transactionOwnerIds",C);const m=u.sort((Q,D)=>Q.index-D.index).map(async Q=>{const{experienceOptions:D,options:I}=Q,F=new In(this,D);return await F.getWorkflowManager().getInitializationPromise(),I.type!=="transaction"&&this.customer&&await F.attachCustomerDetails({email:this.customer.emailAddress}),F}),f=await Promise.all(m);return f.forEach(Q=>Q.getWorkflowManager().setWorkflowStateSyncEnabled(!0)),f}storeCustomer(t){const e=N.getMap("partnerCustomerIds")||new Map;e.set(t.partner.id,t.id),N.setMap("partnerCustomerIds",e)}async getIntegrationProductById(t){var i,s;const a=(i=(await y.getShadowGraphqlClient().query({query:vi,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:i.integrationProducts;if(!a||a.length===0||!((s=a[0])!=null&&s.id))throw new Error("Integration product not found.");return new rA(a[0])}async getIntegrationProductFromExternalIds(t,e){var s;const i=(s=(await y.getShadowGraphqlClient().query({query:Ni,variables:{externalProductId:e,externalIntegrationId:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:s.integrationProductFromExternalIds;if(!(i!=null&&i.id))throw new Error("Integration product not found.");return new rA(i)}async getIntegrationProduct(t){return t.type==="integration"?this.getIntegrationProductById(t.integrationProductId):this.getIntegrationProductFromExternalIds(t.externalIntegrationId,t.externalProductId)}async getShareActionsForTransaction(t){const A=(N.getMap("transactionOwnerIds")||new Map).get(t)||void 0,a=await y.getShadowGraphqlClient().query({query:Pi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t},context:{transactionOwnerId:A}});if(!a.data.transactions||a.data.transactions.length!==1)throw new Error(`Failed to fetch share actions for transaction: ${t}`);return a.data.transactions[0].transactionShareActions}async placeOrder(t){const e=await y.getShadowGraphqlClient().mutate({mutation:Vi,variables:{orderItems:t}});if(e.errors)throw new Error(e.errors[0].message);if(!e.data)throw new Error("Failed to create order: No order data in response.");return{id:e.data.orderCreate.id,internalId:e.data.orderCreate.internalId}}}const kn=async n=>(await y.getShadowGraphqlClient().query({query:zi,errorPolicy:"all",fetchPolicy:"no-cache",context:{headers:{"x-application-key":n}}})).data.currentIntegration,No=async n=>{const e=await y.getShadowGraphqlClient().query({query:Yi,errorPolicy:"all",fetchPolicy:"network-only",variables:{id:n}});if(e.data.transactions.length!==0)return e.data.transactions[0]},ko=async(n,t)=>{var A;return(A=(await y.getShadowGraphqlClient().query({query:Oi,errorPolicy:"all",variables:{themeConfigurationId:n,themeInstallId:t}})).data)==null?void 0:A.marketplaceThemeInstallConfiguration},Ho=async n=>{var e,A,a;return(a=(A=(e=(await y.getShadowGraphqlClient().query({query:Ki,errorPolicy:"all",variables:{id:n}})).data)==null?void 0:e.bundles)==null?void 0:A[0])==null?void 0:a.marketplaceThemeInstallConfiguration},Ro=async n=>{var e,A,a;return(a=(A=(e=(await y.getShadowGraphqlClient().query({query:ji,errorPolicy:"all",variables:{id:n}})).data)==null?void 0:e.transactions)==null?void 0:A[0])==null?void 0:a.marketplaceThemeInstallConfiguration};class bo{approveTransaction(t){throw new Error("Method not implemented.")}rejectTransaction(t){throw new Error("Method not implemented.")}getClient(){return this.client??{}}getWorkflowExperience(){return{}}setClient(t){this.client=t}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}async reset(){}updateStateWithServer(t){}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,e){}addStorageCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,e){}getStepSpecificServices(t){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(t){}markUpdateCompleted(t){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}getStepSelections(){return{}}setCurrentAdjustingStepId(t){}setEditedStatus(t,e){}setInformationResults(t){}setMandatoryFulfilled(t,e){}async setSelectionsAndElements(t,e,A){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}setWorkflowStateSyncEnabled(t){}async updateTransactionShareActions(){}addValidationCallback(t){}setStepError(t,e,A){}getStepErrors(t){}getValidationErrors(){return{steps:new Map}}async updateTransactionStakeholders(){}getStepTags(t){return[]}}var Hn=(n=>(n.SelectFrame="SelectFrame",n.SelectImage="SelectImage",n.Position="Position",n))(Hn||{});class Rn extends et{constructor(t,e,A){var a;super(t,e,A),this.frameService=(a=this.manager.getStepSpecificServices(this.getId()))==null?void 0:a.frameService}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return ot.selectVariant(this.step,t.getResource(),e,this.manager,A=>this.setUpdateState(A))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged(e=>{e&&t(e)})}async selectImage(t,e=!0,A=!0){var a;if(await ot.selectImage(this.step,t,this.manager,A),e){const i=((a=this.manager.getStepStorage(this.step.stepName))==null?void 0:a.framePatternData)||{};this.manager.updateStorage(this.step.stepName,{framePatternData:{...i,originalAssetKey:t.key,backgroundRemovedAssetKey:void 0,useOriginalAsset:void 0}})}}async canUseBackgroundRemover(){return this.manager.getClient().canUseAddon(Qe.BackgroundRemover)}async canRemoveBackground(){var t,e,A,a;return await this.canUseBackgroundRemover()&&this.hasOriginalImageSelection()&&!!((e=(t=this.frameService)==null?void 0:t.getImageData())!=null&&e.src)&&!((a=(A=this.frameService)==null?void 0:A.getImageData())!=null&&a.svg)}async removeBackgroundFromImageSelection(t=!0){var i;if(!await this.canUseBackgroundRemover())throw new Error("The current Integration does not have access to the Background Remover. Please call canUseBackgroundRemover to ensure you disable this feature when appropriate.");const e=await this.getOriginalImageSelection();if(!e)throw new Error("You must supply an image selection before attempting to remove the background.");const A=await G.removeBackgroundFromAsset(e);t&&await ot.selectImage(this.step,A,this.manager,!1);const a=((i=this.manager.getStepStorage(this.step.stepName))==null?void 0:i.framePatternData)||{};return this.manager.updateStorage(this.step.stepName,{framePatternData:{...a,backgroundRemovedAssetKey:A.key,useOriginalAsset:!t}}),A}changeColors(t){ot.changeColors(this.step,this.manager,t)}getImageData(){if(this.frameService)return this.frameService.getImageData()}async getColorOption(){return this.step.data.colorOption}getAvailableColors(){return this.step.data.colorPickerEnabled?ot.availableColors(this.step,this.manager):Promise.resolve([])}isColorPickerEnabled(){return this.step.data.colorPickerEnabled??!1}async getOriginalImageColors(){const t=this.getImageData();return t!=null&&t.svg?(await st(t.svg)).colors:void 0}getMaxAllowedColors(){return this.step.data.maxColors}getUniqueColorCount(){return ot.getUniqueColorCount(this.step,this.manager)}getCurrentFrameStep(t,e,A,a){return a&&a.length>1&&t===void 0?"SelectFrame":e||A||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}getWhitelistedExtensions(){return[...this.step.data.whitelistedExtensions,...this.step.data.whitelistedExtensions.includes(".jpg")?[".jpeg"]:[]]}async getOriginalImageSelection(){var e,A;const t=(A=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:A.originalAssetKey;if(t)return G.getLocalOrFromServer(t)}async getBackgroundRemovedImageSelection(){var e,A;const t=(A=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:A.backgroundRemovedAssetKey;if(t)return G.getLocalOrFromServer(t)}hasOriginalImageSelection(){var t,e;return!!((e=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)!=null&&e.originalAssetKey)}hasBackgroundRemovedImageSelection(){var t,e;return!!((e=(t=this.getFrameStepStorage())==null?void 0:t.framePatternData)!=null&&e.backgroundRemovedAssetKey)}getUseOriginalImageSelection(){var t,e;return((e=(t=this.getFrameStepStorage())==null?void 0:t.framePatternData)==null?void 0:e.useOriginalAsset)??!1}async setUseOriginalImageSelection(t){var a;const e=((a=this.getFrameStepStorage())==null?void 0:a.framePatternData)||{};if(e.useOriginalAsset===t)return;const A=await this.getOriginalImageSelection();if(!A)throw new Error("You must provide an image selection before calling setUseOriginalImageSelection");if(t)await this.selectImage(A,!1,!1);else{const i=await this.getBackgroundRemovedImageSelection();if(!i)throw new Error("You must call removeBackgroundFromImageSelection before attempting to apply the image.");await this.selectImage(i,!1,!1)}this.manager.updateStorage(this.step.stepName,{framePatternData:{...e,useOriginalAsset:t}})}getFrameStepStorage(){return this.manager.getStepStorage(this.step.stepName)}}const Uo=p.gql`
|
|
3356
|
+
`,Mo=async(n,t)=>{var a;const e=await y.getShadowGraphqlClient().query({query:Ti(((a=t==null?void 0:t.assets)==null?void 0:a.metadata)||!1),errorPolicy:"all",variables:{ids:n}});if(e.error)throw e.error;if(e.errors)throw e.errors.forEach(i=>console.error(i)),new Error("Unable to read workflows. Consult GraphQL errors.");const A=e.data.workflows;if(A===void 0||A.length!==n.length)throw new Error(`Unable to read workflows: ${e.errors??"Length mismatch in response"}`);return A.forEach(i=>{i.steps.forEach(s=>{var r,o,c;delete s.data.__typename,(r=s.option)!=null&&r.id&&((o=s.option.defaultVariant)!=null&&o.asset&&G.cacheAsset(s.option.defaultVariant.asset),s.option.colorProfile&&G.cacheAsset(s.option.colorProfile),(c=s.option.variants)==null||c.forEach(l=>{l.asset&&G.cacheAsset(l.asset),l.thumbnail&&G.cacheAsset(l.thumbnail),l.material&&G.cacheMaterial(l.material)}),Nt.set({id:s.option.id},Promise.resolve(s.option)))}),i.finalizeStepConfig||(i.finalizeStepConfig={}),i.finalizeStepConfig.termsMarkdown=i.partner.termsMarkdown}),A},So=async(n,t)=>{const A=(await t).find(a=>a.id===n);if(!A)throw new Error(`Workflow not found: ${n}`);return A},bA=async(n,t)=>{const e=n.map(r=>Nt.get({id:r,options:t})),A=n.filter((r,o)=>e[o]===void 0);if(A.length===0)return Promise.all(e);const a=Mo(A,t),i=A.map(r=>Nt.set({id:r,options:t},So(r,a))),s=e.filter(r=>r!==void 0);return await Promise.all(s.concat(i))},xo=async(n,t)=>(await bA([n],t))[0],Yo=n=>n.sort((t,e)=>t.index-e.index).map(t=>({id:H(),panelId:t.name,name:t.name,index:t.index,createdAt:new Date,updatedAt:new Date,transparentBackground:t.transparentBackground,height:t.height,width:t.width,previewRegion:t.previewRegion,useEditableArea:t.useEditableArea,editableArea:t.editableArea})),Po=(n,t)=>{const e=n.workflowState,A=e?JSON.parse(e):void 0;return A?Object.values(A.layouts).map(a=>a.layout):Yo(t.panels)};class vo{constructor(t){this.activeIntegration=void 0,this.updateTransactionState=async e=>{try{return y.getShadowGraphqlClient().mutate({...e,mutation:Si})}catch(A){throw console.error(A),new lt("Critical - Unable to synchronize workflow state with server.")}},this.options=t,this.options.applicationKey&&ai(this.options.applicationKey),console.debug("------------------------"),console.debug("Spiff Commerce Core SDK"),console.debug("Version: 26.4.3"),console.debug(`Application Key Provided: ${!!this.options.applicationKey}`),console.debug("------------------------")}configure(t){dt.setHubUrl(t.hubUrl),dt.setServerUrl(t.serverUrl),dt.setServicesApiUrl(t.servicesApiUrl),this.marketplaceThemeInstallId=t.marketplaceThemeInstallId,this.marketplaceThemeInstallConfigurationId=t.marketplaceThemeInstallConfigurationId,t.bearerAuthenticationToken&&fa(t.bearerAuthenticationToken),this.options.applicationKey&&this.getIntegration()}getAssetManager(){return G}getCurrencyCode(){if(this.currencyCode===void 0)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!ni())throw new Error("Application key required to use Flow Service.");return new Pn}async getIntegration(){if(this.activeIntegration)return this.activeIntegration;if(!this.options.applicationKey)throw new Error("Cannot get current Integration without specifying an Application Key.");return this.activeIntegration=kn(this.options.applicationKey),this.activeIntegration}async canUseAddon(t){var e;try{return((e=(await this.getIntegration()).partner.activeAddons)==null?void 0:e.includes(t))??!1}catch(A){return console.error(A),!1}}async authenticateBundleFromLocalStorage(t){var a,i;const e=N.getMap("bundleOwnerIds");if(e!=null&&e.has(t))return Promise.resolve({success:!0,stakeholderType:Vt.Owner});const A=N.getMap("bundlePartnerIds")||new Map;if(A.has(t)){const s=A.get(t),o=(N.getMap("partnerCustomerIds")||new Map).get(s);if(o&&await this.authenticateCustomerId(o)){const l=(i=(a=this.customer)==null?void 0:a.bundleStakeholders)==null?void 0:i.find(g=>{var d;return((d=g.bundle)==null?void 0:d.id)===t});if(l)return Promise.resolve({success:!0,stakeholderType:l.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){var l,g,d,B,h,C;const e=y.getShadowGraphqlClient(),A=await e.query({query:Ji,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!A.data.transactions||A.data.transactions.length===0)throw new Error(`Transaction not found: ${t}`);const a=A.data.transactions[0];if(!((g=(l=a.product)==null?void 0:l.partner)==null?void 0:g.id))throw new Error(`Unable to read transaction: ${t}`);if(a.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const s=N.getMap("transactionOwnerIds");if(s!=null&&s.has(t))return Promise.resolve({success:!0,stakeholderType:Vt.Owner});const r=N.getMap("transactionCustomerIds");if(r!=null&&r.has(t)){const w=r.get(t);if(w&&await this.authenticateCustomerId(w)){const E=((B=(d=this.customer)==null?void 0:d.bundleStakeholders)==null?void 0:B.find(m=>{var f,Q;return(Q=(f=m.bundle)==null?void 0:f.transactions)==null?void 0:Q.some(D=>D.id===t)}))||((C=(h=this.customer)==null?void 0:h.stakeholders)==null?void 0:C.find(m=>{var f;return((f=m.transaction)==null?void 0:f.id)===t}));if(E)return Promise.resolve({success:!0,stakeholderType:E.type})}}const c=(await e.query({query:Li,errorPolicy:"all",variables:{id:a.workflowId}})).data.workflow;if(!c)throw new Error(`Unable to read workflow: ${a.workflowId}`);return Promise.resolve({success:!1,theme:c.overrideTheme,customLogoLink:a.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=N.getMap("transactionCustomerIds");e!=null&&e.has(t)&&(e.delete(t),N.setMap("transactionCustomerIds",e))}async customerHasBundleTemplates(t){const a=(await y.getShadowGraphqlClient().query({query:ea,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;return a.id?a.hasBundleTemplates??!1:!1}getStakeholderTypeForTransaction(t){var A,a;const e=(a=(A=this.customer)==null?void 0:A.stakeholders)==null?void 0:a.find(i=>{var s;return((s=i.transaction)==null?void 0:s.id)===t});if(e)return e.type}async getOrCreateCustomer(t){var s;this.customer=void 0;const e=y.getShadowGraphqlClient(),a=(await e.query({query:ea,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!a.id){const o=(s=(await e.mutate({mutation:po,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data)==null?void 0:s.customerCreate;if(!o)throw new Error("Unable to create customer.");return this.storeCustomer(o),this.customer=o,{customer:o,isAuthenticated:!1}}this.storeCustomer(a);const i=await this.authenticateCustomerId(a.id);return{customer:this.customer||a,isAuthenticated:i}}getCustomer(){return this.customer}async authenticateCustomerId(t){var r;const e=y.getShadowGraphqlClient(),A=N.getMap("customerTokens");if(!(A!=null&&A.has(t)))return!1;const a=A.get(t);if(!a)return!1;const s=(r=(await e.mutate({mutation:Do,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:a}})).data)==null?void 0:r.customerAuthenticate;return s?(this.storeCustomer(s),zA(a),this.customer=s,!0):!1}async generateVerificationCode(t){await y.getShadowGraphqlClient().mutate({mutation:Io,variables:{emailAddress:t}})}async verifyCode(t,e){var i,s;const a=(i=(await y.getShadowGraphqlClient().mutate({mutation:Fo,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data)==null?void 0:i.customerVerifyCode;if(a!=null&&a.loginToken){if(!((s=a.partner)!=null&&s.id))throw new Error(`Unable to find customer: ${t}`);const r=N.getMap("customerTokens")||new Map;return r.set(a.id,a.loginToken),N.setMap("customerTokens",r),this.storeCustomer(a),zA(a.loginToken),this.customer={...a,loginToken:void 0},!0}return!1}async getCustomerMetafields(){var e;if(!((e=this.customer)!=null&&e.id))throw new Error("Customer must be logged in before calling this function.");return(await y.getShadowGraphqlClient().query({query:yo,variables:{id:this.customer.id}})).data.metafields}async getNewBundle(t,e,A){var c,l,g,d,B;const i=(g=(await y.getShadowGraphqlClient().mutate({mutation:Ir(((l=(c=A==null?void 0:A.graphql)==null?void 0:c.productCollection)==null?void 0:l.eagerFetchProducts)||!1),variables:{collectionId:t,initialMetadata:e?Object.entries(e).map((h,C)=>({key:h[0],value:h[1]})):void 0,marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId},fetchPolicy:"no-cache"})).data)==null?void 0:g.bundleCreate;if(!(i!=null&&i.id))throw new Error("Unable to create bundle");const s=N.getMap("bundlePartnerIds")||new Map;s.set(i.id,i.partner.id),N.setMap("bundlePartnerIds",s);const r=N.getMap("bundleOwnerIds")||new Map;r.set(i.id,i.bundleOwnerId),N.setMap("bundleOwnerIds",r);const o=new Oe(this,i,void 0,void 0,i.bundleOwnerId,{eagerFetchProducts:(B=(d=A==null?void 0:A.graphql)==null?void 0:d.productCollection)==null?void 0:B.eagerFetchProducts});return await o.getInitializationPromise(),o}async getExistingBundle(t,e,A,a){var w,u,E,m,f,Q,D,I,F,x,Y;const i=N.getMap("bundleOwnerIds"),s=i==null?void 0:i.get(t),o=((w=Object.entries(localStorage).find(([P,v])=>P.startsWith("CognitoIdentityServiceProvider")&&P.endsWith("idToken")))==null?void 0:w[0])||"",c=localStorage.getItem(o),l={};c&&!fe(c)&&(l.Authorization=`Bearer ${c}`);const g={bundleOwnerId:s,...l,...(u=a==null?void 0:a.graphql)==null?void 0:u.additionalHeaders},d=await y.getShadowGraphqlClient().query({query:fr(((m=(E=a==null?void 0:a.graphql)==null?void 0:E.productCollection)==null?void 0:m.eagerFetchProducts)||!1),variables:{id:t},fetchPolicy:"no-cache",context:{headers:g}});if(!((f=d.data)!=null&&f.bundles)||((Q=d.data)==null?void 0:Q.bundles.length)===0||!((D=d.data)!=null&&D.bundles[0]))throw new Error(`Unable to find bundle: ${t}`);const B=(I=d.data)==null?void 0:I.bundles[0],h=N.getMap("bundlePartnerIds")||new Map;h.set(B.id,B.partner.id),N.setMap("bundlePartnerIds",h);const C=new Oe(this,B,e,A,s,{additionalHeaders:(F=a==null?void 0:a.graphql)==null?void 0:F.additionalHeaders,eagerFetchProducts:(Y=(x=a==null?void 0:a.graphql)==null?void 0:x.productCollection)==null?void 0:Y.eagerFetchProducts,existingGlobalPropertyState:d.data.globalPropertyState});return await C.getInitializationPromise(),C}async duplicateBundle(t,e,A,a){var w,u,E,m,f,Q,D,I;const i=(w=N.getMap("bundleOwnerIds"))==null?void 0:w.get(t),r=((u=Object.entries(localStorage).find(([F,x])=>F.startsWith("CognitoIdentityServiceProvider")&&F.endsWith("idToken")))==null?void 0:u[0])||"",o=localStorage.getItem(r),c={};o&&!fe(o)&&(c.Authorization=`Bearer ${o}`);const l={bundleOwnerId:i,...c,...(E=a==null?void 0:a.graphql)==null?void 0:E.additionalHeaders},d=(Q=(await y.getShadowGraphqlClient().mutate({mutation:Fr(((f=(m=a==null?void 0:a.graphql)==null?void 0:m.productCollection)==null?void 0:f.eagerFetchProducts)||!1),variables:{id:t,template:e,marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId,duplicateTransactions:A},context:{headers:l},fetchPolicy:"no-cache"})).data)==null?void 0:Q.bundleDuplicate;if(!(d!=null&&d.id))throw new Error("Unable to duplicate bundle");const B=N.getMap("bundlePartnerIds")||new Map;B.set(d.id,d.partner.id),N.setMap("bundlePartnerIds",B);const h=N.getMap("bundleOwnerIds")||new Map;h.set(d.id,d.bundleOwnerId),N.setMap("bundleOwnerIds",h);const C=new Oe(this,d,void 0,void 0,d.bundleOwnerId,{eagerFetchProducts:(I=(D=a==null?void 0:a.graphql)==null?void 0:D.productCollection)==null?void 0:I.eagerFetchProducts});return await C.getInitializationPromise(),C}async getBundlesForCustomer(t){var i;if(!((i=this.customer)!=null&&i.id))throw new Error("Customer not authenticated.");const{includeMetadata:e,...A}=t;return(await y.getShadowGraphqlClient().query({query:Rr(e??!1),variables:{...A,id:this.customer.id},fetchPolicy:"no-cache"})).data.customerBundlesFeed}async getBundleStakeholders(){var i;if(!this.customer)throw new Error("Customer not authenticated.");const t=await y.getShadowGraphqlClient().query({query:Qr,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!((i=t.data)!=null&&i.customers)||t.data.customers.length===0)throw new Error("Unable to find customer.");const A=t.data.customers[0].bundleStakeholders||[],a=N.getMap("bundlePartnerIds")||new Map;return A.forEach(s=>{var r,o;(r=s.bundle)!=null&&r.id&&((o=s.bundle.partner)!=null&&o.id)&&a.set(s.bundle.id,s.bundle.partner.id)}),N.setMap("bundlePartnerIds",a),A}async getWorkflowExperience(t,e){if(!t)throw new Error("getWorkflowExperience has been called without an options object! This is not supported.");const A=await this.getWorkflowExperiences([t],t.graphql),a=A[0];return e&&await a.getWorkflowManager().injectIntoPreviewService(e(a.getWorkflowManager().getWorkflow())),A[0]}async getWorkflowExperiences(t,e){if(t.length===0)throw new lt("No options provided!");const A=y.getShadowGraphqlClient(),a=async Q=>{var x,Y,P;if(Q.length===0)return[];const D=Q.map(v=>v.option.transactionId),I=await A.query({query:Mi,variables:{ids:D},errorPolicy:"all",fetchPolicy:"no-cache"}),F=I.data.transactions;if(F.length!==Q.length){const v=((Y=(x=I.errors)==null?void 0:x[0])==null?void 0:Y.message)||"Unknown error";throw new lt(`Not all transactions were found: ${v}`)}return!this.activeIntegration&&((P=F[0].integrationProduct)!=null&&P.integration)&&(this.activeIntegration=Promise.resolve(F[0].integrationProduct.integration)),F.map((v,b)=>{var K;return{transaction:v,workflowId:v.workflowId,readOnly:((K=Q.find(j=>j.option.transactionId===v.id))==null?void 0:K.option.readOnly)??!1,index:Q[b].index}})},i=async Q=>{var F,x,Y;if(Q.length===0)return[];const D=await A.mutate({mutation:yi,variables:{inputs:Q.map(P=>({integrationProductId:P.option.type==="integration"?P.option.integrationProductId:void 0,externalIntegrationId:P.option.type==="external"?P.option.externalIntegrationId:void 0,externalProductId:P.option.type==="external"?P.option.externalProductId:void 0,workflowId:P.option.workflowId,designName:P.option.designName,claim:!0})),marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId},errorPolicy:"all",fetchPolicy:"no-cache"}),I=(F=D.data)==null?void 0:F.transactionCreateMany;if(!I||I.length===0){const P=((Y=(x=D.errors)==null?void 0:x[0])==null?void 0:Y.message)||"Unknown error";throw new lt(`Failed to create transactions: ${P}`)}return I.map((P,v)=>({transaction:P,workflowId:P.workflowId,readOnly:!1,index:Q[v].index}))},s=t.map((Q,D)=>({option:Q,index:D})),r=s.filter(Q=>Q.option.type==="transaction"),o=s.filter(Q=>Q.option.type==="integration"||Q.option.type==="external"),c=GA(r,10),l=GA(o,10),g=(await Promise.all([...c.map(a),...l.map(i)])).flat(),d=[...new Set(g.map(Q=>Q.workflowId))],B=await bA(d,e),h=new Map(B.map(Q=>[Q.id,Q])),C=N.getMap("transactionOwnerIds")||new Map,w=g.map(async Q=>{var K;const{transaction:D,workflowId:I,readOnly:F,index:x}=Q,Y=h.get(I),P=t[x];!C.get(D.id)&&D.transactionOwnerId&&C.set(D.id,D.transactionOwnerId);const v=C.get(D.id)||void 0,b={product:D.product,transaction:D,layouts:[],singleVariantsRenderable:(K=P==null?void 0:P.workflowConfiguration)==null?void 0:K.singleVariantsRenderable,stateMutationFunc:F?async()=>{throw new L("State mutation is forbidden in read only mode!")}:async j=>this.updateTransactionState({...j,context:{transactionOwnerId:v,bundleOwnerId:e==null?void 0:e.bundleOwnerId}}),readOnly:F,workflow:Y,isReloadedTransaction:P.type==="transaction"};if(P.type==="transaction"&&D.workflowState){const j=JSON.parse(D.workflowState);b.layouts=Object.values(j.layouts||{}).map(At=>At.layout),await eA(j),b.reloadedState=j}else if(!F&&P.workflowState){const j=JSON.parse(P.workflowState);b.layouts=Object.values(j.layouts||{}).map(At=>At.layout),await eA(j),b.reloadedState=j}else b.layouts=Po(b.transaction,b.workflow);return b.renderableContextService=new oo(b.layouts),b.delayWorkflowStateSync=!0,{experienceOptions:b,index:x,options:P}}),u=await Promise.all(w);N.setMap("transactionOwnerIds",C);const m=u.sort((Q,D)=>Q.index-D.index).map(async Q=>{const{experienceOptions:D,options:I}=Q,F=new In(this,D);return await F.getWorkflowManager().getInitializationPromise(),I.type!=="transaction"&&this.customer&&await F.attachCustomerDetails({email:this.customer.emailAddress}),F}),f=await Promise.all(m);return f.forEach(Q=>Q.getWorkflowManager().setWorkflowStateSyncEnabled(!0)),f}storeCustomer(t){const e=N.getMap("partnerCustomerIds")||new Map;e.set(t.partner.id,t.id),N.setMap("partnerCustomerIds",e)}async getIntegrationProductById(t){var i,s;const a=(i=(await y.getShadowGraphqlClient().query({query:vi,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:i.integrationProducts;if(!a||a.length===0||!((s=a[0])!=null&&s.id))throw new Error("Integration product not found.");return new rA(a[0])}async getIntegrationProductFromExternalIds(t,e){var s;const i=(s=(await y.getShadowGraphqlClient().query({query:Ni,variables:{externalProductId:e,externalIntegrationId:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:s.integrationProductFromExternalIds;if(!(i!=null&&i.id))throw new Error("Integration product not found.");return new rA(i)}async getIntegrationProduct(t){return t.type==="integration"?this.getIntegrationProductById(t.integrationProductId):this.getIntegrationProductFromExternalIds(t.externalIntegrationId,t.externalProductId)}async getShareActionsForTransaction(t){const A=(N.getMap("transactionOwnerIds")||new Map).get(t)||void 0,a=await y.getShadowGraphqlClient().query({query:Pi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t},context:{transactionOwnerId:A}});if(!a.data.transactions||a.data.transactions.length!==1)throw new Error(`Failed to fetch share actions for transaction: ${t}`);return a.data.transactions[0].transactionShareActions}async placeOrder(t){const e=await y.getShadowGraphqlClient().mutate({mutation:Vi,variables:{orderItems:t}});if(e.errors)throw new Error(e.errors[0].message);if(!e.data)throw new Error("Failed to create order: No order data in response.");return{id:e.data.orderCreate.id,internalId:e.data.orderCreate.internalId}}}const kn=async n=>(await y.getShadowGraphqlClient().query({query:zi,errorPolicy:"all",fetchPolicy:"no-cache",context:{headers:{"x-application-key":n}}})).data.currentIntegration,No=async n=>{const e=await y.getShadowGraphqlClient().query({query:Yi,errorPolicy:"all",fetchPolicy:"network-only",variables:{id:n}});if(e.data.transactions.length!==0)return e.data.transactions[0]},ko=async(n,t)=>{var A;return(A=(await y.getShadowGraphqlClient().query({query:Oi,errorPolicy:"all",variables:{themeConfigurationId:n,themeInstallId:t}})).data)==null?void 0:A.marketplaceThemeInstallConfiguration},Ho=async n=>{var e,A,a;return(a=(A=(e=(await y.getShadowGraphqlClient().query({query:Ki,errorPolicy:"all",variables:{id:n}})).data)==null?void 0:e.bundles)==null?void 0:A[0])==null?void 0:a.marketplaceThemeInstallConfiguration},Ro=async n=>{var e,A,a;return(a=(A=(e=(await y.getShadowGraphqlClient().query({query:ji,errorPolicy:"all",variables:{id:n}})).data)==null?void 0:e.transactions)==null?void 0:A[0])==null?void 0:a.marketplaceThemeInstallConfiguration};class bo{approveTransaction(t){throw new Error("Method not implemented.")}rejectTransaction(t){throw new Error("Method not implemented.")}getClient(){return this.client??{}}getWorkflowExperience(){return{}}setClient(t){this.client=t}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}async reset(){}updateStateWithServer(t){}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,e){}addStorageCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,e){}getStepSpecificServices(t){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(t){}markUpdateCompleted(t){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}getStepSelections(){return{}}setCurrentAdjustingStepId(t){}setEditedStatus(t,e){}setInformationResults(t){}setMandatoryFulfilled(t,e){}async setSelectionsAndElements(t,e,A){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}setWorkflowStateSyncEnabled(t){}async updateTransactionShareActions(){}addValidationCallback(t){}setStepError(t,e,A){}getStepErrors(t){}getValidationErrors(){return{steps:new Map}}async updateTransactionStakeholders(){}getStepTags(t){return[]}}var Hn=(n=>(n.SelectFrame="SelectFrame",n.SelectImage="SelectImage",n.Position="Position",n))(Hn||{});class Rn extends et{constructor(t,e,A){var a;super(t,e,A),this.frameService=(a=this.manager.getStepSpecificServices(this.getId()))==null?void 0:a.frameService}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return ot.selectVariant(this.step,t.getResource(),e,this.manager,A=>this.setUpdateState(A))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged(e=>{e&&t(e)})}async selectImage(t,e=!0,A=!0){var a;if(await ot.selectImage(this.step,t,this.manager,A),e){const i=((a=this.manager.getStepStorage(this.step.stepName))==null?void 0:a.framePatternData)||{};this.manager.updateStorage(this.step.stepName,{framePatternData:{...i,originalAssetKey:t.key,backgroundRemovedAssetKey:void 0,useOriginalAsset:void 0}})}}async canUseBackgroundRemover(){return this.manager.getClient().canUseAddon(Qe.BackgroundRemover)}async canRemoveBackground(){var t,e,A,a;return await this.canUseBackgroundRemover()&&this.hasOriginalImageSelection()&&!!((e=(t=this.frameService)==null?void 0:t.getImageData())!=null&&e.src)&&!((a=(A=this.frameService)==null?void 0:A.getImageData())!=null&&a.svg)}async removeBackgroundFromImageSelection(t=!0){var i;if(!await this.canUseBackgroundRemover())throw new Error("The current Integration does not have access to the Background Remover. Please call canUseBackgroundRemover to ensure you disable this feature when appropriate.");const e=await this.getOriginalImageSelection();if(!e)throw new Error("You must supply an image selection before attempting to remove the background.");const A=await G.removeBackgroundFromAsset(e);t&&await ot.selectImage(this.step,A,this.manager,!1);const a=((i=this.manager.getStepStorage(this.step.stepName))==null?void 0:i.framePatternData)||{};return this.manager.updateStorage(this.step.stepName,{framePatternData:{...a,backgroundRemovedAssetKey:A.key,useOriginalAsset:!t}}),A}changeColors(t){ot.changeColors(this.step,this.manager,t)}getImageData(){if(this.frameService)return this.frameService.getImageData()}async getColorOption(){return this.step.data.colorOption}getAvailableColors(){return this.step.data.colorPickerEnabled?ot.availableColors(this.step,this.manager):Promise.resolve([])}isColorPickerEnabled(){return this.step.data.colorPickerEnabled??!1}async getOriginalImageColors(){const t=this.getImageData();return t!=null&&t.svg?(await st(t.svg)).colors:void 0}getMaxAllowedColors(){return this.step.data.maxColors}getUniqueColorCount(){return ot.getUniqueColorCount(this.step,this.manager)}getCurrentFrameStep(t,e,A,a){return a&&a.length>1&&t===void 0?"SelectFrame":e||A||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}getWhitelistedExtensions(){return[...this.step.data.whitelistedExtensions,...this.step.data.whitelistedExtensions.includes(".jpg")?[".jpeg"]:[]]}async getOriginalImageSelection(){var e,A;const t=(A=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:A.originalAssetKey;if(t)return G.getLocalOrFromServer(t)}async getBackgroundRemovedImageSelection(){var e,A;const t=(A=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:A.backgroundRemovedAssetKey;if(t)return G.getLocalOrFromServer(t)}hasOriginalImageSelection(){var t,e;return!!((e=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)!=null&&e.originalAssetKey)}hasBackgroundRemovedImageSelection(){var t,e;return!!((e=(t=this.getFrameStepStorage())==null?void 0:t.framePatternData)!=null&&e.backgroundRemovedAssetKey)}getUseOriginalImageSelection(){var t,e;return((e=(t=this.getFrameStepStorage())==null?void 0:t.framePatternData)==null?void 0:e.useOriginalAsset)??!1}async setUseOriginalImageSelection(t){var a;const e=((a=this.getFrameStepStorage())==null?void 0:a.framePatternData)||{};if(e.useOriginalAsset===t)return;const A=await this.getOriginalImageSelection();if(!A)throw new Error("You must provide an image selection before calling setUseOriginalImageSelection");if(t)await this.selectImage(A,!1,!1);else{const i=await this.getBackgroundRemovedImageSelection();if(!i)throw new Error("You must call removeBackgroundFromImageSelection before attempting to apply the image.");await this.selectImage(i,!1,!1)}this.manager.updateStorage(this.step.stepName,{framePatternData:{...e,useOriginalAsset:t}})}getFrameStepStorage(){return this.manager.getStepStorage(this.step.stepName)}}const Uo=p.gql`
|
|
3357
3357
|
query GetLoggedInCustomer($email: String!) {
|
|
3358
3358
|
customer(emailAddress: $email) {
|
|
3359
3359
|
id
|