@spiffcommerce/core 26.5.0 → 26.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3371,7 +3371,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
3371
3371
  }
3372
3372
  }
3373
3373
  }
3374
- `,Mr=async(n,t)=>{var a;const e=await F.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 o,r,c;delete s.data.__typename,(o=s.option)!=null&&o.id&&((r=s.option.defaultVariant)!=null&&r.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},xr=async(n,t)=>{const A=(await t).find(a=>a.id===n);if(!A)throw new Error(`Workflow not found: ${n}`);return A},UA=async(n,t)=>{const e=n.map(o=>Nt.get({id:o,options:t})),A=n.filter((o,r)=>e[r]===void 0);if(A.length===0)return Promise.all(e);const a=Mr(A,t),i=A.map(o=>Nt.set({id:o,options:t},xr(o,a))),s=e.filter(o=>o!==void 0);return await Promise.all(s.concat(i))},Yr=async(n,t)=>(await UA([n],t))[0],Pr=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})),vr=(n,t)=>{const e=n.workflowState,A=e?JSON.parse(e):void 0;return A?Object.values(A.layouts).map(a=>a.layout):Pr(t.panels)};class Nr{constructor(t){this.activeIntegration=void 0,this.updateTransactionState=async e=>{try{return F.getShadowGraphqlClient().mutate({...e,mutation:Mi})}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.5.0"),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&&Qa(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:Wt.Owner});const A=N.getMap("bundlePartnerIds")||new Map;if(A.has(t)){const s=A.get(t),r=(N.getMap("partnerCustomerIds")||new Map).get(s);if(r&&await this.authenticateCustomerId(r)){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=F.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:Wt.Owner});const o=N.getMap("transactionCustomerIds");if(o!=null&&o.has(t)){const w=o.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 F.getShadowGraphqlClient().query({query:Aa,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=F.getShadowGraphqlClient(),a=(await e.query({query:Aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!a.id){const r=(s=(await e.mutate({mutation:Dr,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data)==null?void 0:s.customerCreate;if(!r)throw new Error("Unable to create customer.");return this.storeCustomer(r),this.customer=r,{customer:r,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 o;const e=F.getShadowGraphqlClient(),A=N.getMap("customerTokens");if(!(A!=null&&A.has(t)))return!1;const a=A.get(t);if(!a)return!1;const s=(o=(await e.mutate({mutation:Ir,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:a}})).data)==null?void 0:o.customerAuthenticate;return s?(this.storeCustomer(s),jA(a),this.customer=s,!0):!1}async generateVerificationCode(t){await F.getShadowGraphqlClient().mutate({mutation:Fr,variables:{emailAddress:t}})}async verifyCode(t,e){var i,s;const a=(i=(await F.getShadowGraphqlClient().mutate({mutation:yr,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 o=N.getMap("customerTokens")||new Map;return o.set(a.id,a.loginToken),N.setMap("customerTokens",o),this.storeCustomer(a),jA(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 F.getShadowGraphqlClient().query({query:Sr,variables:{id:this.customer.id}})).data.metafields}async getNewBundle(t,e,A){var c,l,g,d,B;const i=(g=(await F.getShadowGraphqlClient().mutate({mutation:yo(((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 o=N.getMap("bundleOwnerIds")||new Map;o.set(i.id,i.bundleOwnerId),N.setMap("bundleOwnerIds",o);const r=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 r.getInitializationPromise(),r}async getExistingBundle(t,e,A,a){var w,u,E,m,f,Q,D,I,y,x,Y;const i=N.getMap("bundleOwnerIds"),s=i==null?void 0:i.get(t),r=((w=Object.entries(localStorage).find(([P,v])=>P.startsWith("CognitoIdentityServiceProvider")&&P.endsWith("idToken")))==null?void 0:w[0])||"",c=localStorage.getItem(r),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 F.getShadowGraphqlClient().query({query:Qo(((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:(y=a==null?void 0:a.graphql)==null?void 0:y.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),o=((u=Object.entries(localStorage).find(([y,x])=>y.startsWith("CognitoIdentityServiceProvider")&&y.endsWith("idToken")))==null?void 0:u[0])||"",r=localStorage.getItem(o),c={};r&&!fe(r)&&(c.Authorization=`Bearer ${r}`);const l={bundleOwnerId:i,...c,...(E=a==null?void 0:a.graphql)==null?void 0:E.additionalHeaders},d=(Q=(await F.getShadowGraphqlClient().mutate({mutation:So(((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 F.getShadowGraphqlClient().query({query:Uo(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 F.getShadowGraphqlClient().query({query:po,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 o,r;(o=s.bundle)!=null&&o.id&&((r=s.bundle.partner)!=null&&r.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=F.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:Si,variables:{ids:D},errorPolicy:"all",fetchPolicy:"no-cache"}),y=I.data.transactions;if(y.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=y[0].integrationProduct)!=null&&P.integration)&&(this.activeIntegration=Promise.resolve(y[0].integrationProduct.integration)),y.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 y,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=(y=D.data)==null?void 0:y.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})),o=s.filter(Q=>Q.option.type==="transaction"),r=s.filter(Q=>Q.option.type==="integration"||Q.option.type==="external"),c=TA(o,10),l=TA(r,10),g=(await Promise.all([...c.map(a),...l.map(i)])).flat(),d=[...new Set(g.map(Q=>Q.workflowId))],B=await UA(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:y,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:y?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:y,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(!y&&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=vr(b.transaction,b.workflow);return b.renderableContextService=new lr(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,y=new In(this,D);return await y.getWorkflowManager().getInitializationPromise(),I.type!=="transaction"&&this.customer&&await y.attachCustomerDetails({email:this.customer.emailAddress}),y}),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 F.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 oA(a[0])}async getIntegrationProductFromExternalIds(t,e){var s;const i=(s=(await F.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 oA(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 F.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 F.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 F.getShadowGraphqlClient().query({query:zi,errorPolicy:"all",fetchPolicy:"no-cache",context:{headers:{"x-application-key":n}}})).data.currentIntegration,kr=async n=>{const e=await F.getShadowGraphqlClient().query({query:Yi,errorPolicy:"all",fetchPolicy:"network-only",variables:{id:n}});if(e.data.transactions.length!==0)return e.data.transactions[0]},Hr=async(n,t)=>{var A;return(A=(await F.getShadowGraphqlClient().query({query:Oi,errorPolicy:"all",variables:{themeConfigurationId:n,themeInstallId:t}})).data)==null?void 0:A.marketplaceThemeInstallConfiguration},Rr=async n=>{var e,A,a;return(a=(A=(e=(await F.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},br=async n=>{var e,A,a;return(a=(A=(e=(await F.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 Ur{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 rt.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 rt.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 rt.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){rt.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?rt.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 rt.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 Gr=p.gql`
3374
+ `,Mr=async(n,t)=>{var a;const e=await F.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 o,r,c;delete s.data.__typename,(o=s.option)!=null&&o.id&&((r=s.option.defaultVariant)!=null&&r.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},xr=async(n,t)=>{const A=(await t).find(a=>a.id===n);if(!A)throw new Error(`Workflow not found: ${n}`);return A},UA=async(n,t)=>{const e=n.map(o=>Nt.get({id:o,options:t})),A=n.filter((o,r)=>e[r]===void 0);if(A.length===0)return Promise.all(e);const a=Mr(A,t),i=A.map(o=>Nt.set({id:o,options:t},xr(o,a))),s=e.filter(o=>o!==void 0);return await Promise.all(s.concat(i))},Yr=async(n,t)=>(await UA([n],t))[0],Pr=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})),vr=(n,t)=>{const e=n.workflowState,A=e?JSON.parse(e):void 0;return A?Object.values(A.layouts).map(a=>a.layout):Pr(t.panels)};class Nr{constructor(t){this.activeIntegration=void 0,this.updateTransactionState=async e=>{try{return F.getShadowGraphqlClient().mutate({...e,mutation:Mi})}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.5.1"),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&&Qa(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:Wt.Owner});const A=N.getMap("bundlePartnerIds")||new Map;if(A.has(t)){const s=A.get(t),r=(N.getMap("partnerCustomerIds")||new Map).get(s);if(r&&await this.authenticateCustomerId(r)){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=F.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:Wt.Owner});const o=N.getMap("transactionCustomerIds");if(o!=null&&o.has(t)){const w=o.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 F.getShadowGraphqlClient().query({query:Aa,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=F.getShadowGraphqlClient(),a=(await e.query({query:Aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!a.id){const r=(s=(await e.mutate({mutation:Dr,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data)==null?void 0:s.customerCreate;if(!r)throw new Error("Unable to create customer.");return this.storeCustomer(r),this.customer=r,{customer:r,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 o;const e=F.getShadowGraphqlClient(),A=N.getMap("customerTokens");if(!(A!=null&&A.has(t)))return!1;const a=A.get(t);if(!a)return!1;const s=(o=(await e.mutate({mutation:Ir,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:a}})).data)==null?void 0:o.customerAuthenticate;return s?(this.storeCustomer(s),jA(a),this.customer=s,!0):!1}async generateVerificationCode(t){await F.getShadowGraphqlClient().mutate({mutation:Fr,variables:{emailAddress:t}})}async verifyCode(t,e){var i,s;const a=(i=(await F.getShadowGraphqlClient().mutate({mutation:yr,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 o=N.getMap("customerTokens")||new Map;return o.set(a.id,a.loginToken),N.setMap("customerTokens",o),this.storeCustomer(a),jA(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 F.getShadowGraphqlClient().query({query:Sr,variables:{id:this.customer.id}})).data.metafields}async getNewBundle(t,e,A){var c,l,g,d,B;const i=(g=(await F.getShadowGraphqlClient().mutate({mutation:yo(((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 o=N.getMap("bundleOwnerIds")||new Map;o.set(i.id,i.bundleOwnerId),N.setMap("bundleOwnerIds",o);const r=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 r.getInitializationPromise(),r}async getExistingBundle(t,e,A,a){var w,u,E,m,f,Q,D,I,y,x,Y;const i=N.getMap("bundleOwnerIds"),s=i==null?void 0:i.get(t),r=((w=Object.entries(localStorage).find(([P,v])=>P.startsWith("CognitoIdentityServiceProvider")&&P.endsWith("idToken")))==null?void 0:w[0])||"",c=localStorage.getItem(r),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 F.getShadowGraphqlClient().query({query:Qo(((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:(y=a==null?void 0:a.graphql)==null?void 0:y.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),o=((u=Object.entries(localStorage).find(([y,x])=>y.startsWith("CognitoIdentityServiceProvider")&&y.endsWith("idToken")))==null?void 0:u[0])||"",r=localStorage.getItem(o),c={};r&&!fe(r)&&(c.Authorization=`Bearer ${r}`);const l={bundleOwnerId:i,...c,...(E=a==null?void 0:a.graphql)==null?void 0:E.additionalHeaders},d=(Q=(await F.getShadowGraphqlClient().mutate({mutation:So(((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 F.getShadowGraphqlClient().query({query:Uo(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 F.getShadowGraphqlClient().query({query:po,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 o,r;(o=s.bundle)!=null&&o.id&&((r=s.bundle.partner)!=null&&r.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=F.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:Si,variables:{ids:D},errorPolicy:"all",fetchPolicy:"no-cache"}),y=I.data.transactions;if(y.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=y[0].integrationProduct)!=null&&P.integration)&&(this.activeIntegration=Promise.resolve(y[0].integrationProduct.integration)),y.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 y,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=(y=D.data)==null?void 0:y.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})),o=s.filter(Q=>Q.option.type==="transaction"),r=s.filter(Q=>Q.option.type==="integration"||Q.option.type==="external"),c=TA(o,10),l=TA(r,10),g=(await Promise.all([...c.map(a),...l.map(i)])).flat(),d=[...new Set(g.map(Q=>Q.workflowId))],B=await UA(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:y,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:y?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:y,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(!y&&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=vr(b.transaction,b.workflow);return b.renderableContextService=new lr(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,y=new In(this,D);return await y.getWorkflowManager().getInitializationPromise(),I.type!=="transaction"&&this.customer&&await y.attachCustomerDetails({email:this.customer.emailAddress}),y}),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 F.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 oA(a[0])}async getIntegrationProductFromExternalIds(t,e){var s;const i=(s=(await F.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 oA(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 F.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 F.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 F.getShadowGraphqlClient().query({query:zi,errorPolicy:"all",fetchPolicy:"no-cache",context:{headers:{"x-application-key":n}}})).data.currentIntegration,kr=async n=>{const e=await F.getShadowGraphqlClient().query({query:Yi,errorPolicy:"all",fetchPolicy:"network-only",variables:{id:n}});if(e.data.transactions.length!==0)return e.data.transactions[0]},Hr=async(n,t)=>{var A;return(A=(await F.getShadowGraphqlClient().query({query:Oi,errorPolicy:"all",variables:{themeConfigurationId:n,themeInstallId:t}})).data)==null?void 0:A.marketplaceThemeInstallConfiguration},Rr=async n=>{var e,A,a;return(a=(A=(e=(await F.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},br=async n=>{var e,A,a;return(a=(A=(e=(await F.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 Ur{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 rt.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 rt.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 rt.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){rt.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?rt.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 rt.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 Gr=p.gql`
3375
3375
  query GetLoggedInCustomer($email: String!) {
3376
3376
  customer(emailAddress: $email) {
3377
3377
  id
package/dist/index.mjs CHANGED
@@ -16206,7 +16206,7 @@ class dc {
16206
16206
  } catch (A) {
16207
16207
  throw console.error(A), new rt("Critical - Unable to synchronize workflow state with server.");
16208
16208
  }
16209
- }, this.options = t, this.options.applicationKey && pi(this.options.applicationKey), console.debug("------------------------"), console.debug("Spiff Commerce Core SDK"), console.debug("Version: 26.5.0"), console.debug(`Application Key Provided: ${!!this.options.applicationKey}`), console.debug("------------------------");
16209
+ }, this.options = t, this.options.applicationKey && pi(this.options.applicationKey), console.debug("------------------------"), console.debug("Spiff Commerce Core SDK"), console.debug("Version: 26.5.1"), console.debug(`Application Key Provided: ${!!this.options.applicationKey}`), console.debug("------------------------");
16210
16210
  }
16211
16211
  configure(t) {
16212
16212
  ut.setHubUrl(t.hubUrl), ut.setServerUrl(t.serverUrl), ut.setServicesApiUrl(t.servicesApiUrl), this.marketplaceThemeInstallId = t.marketplaceThemeInstallId, this.marketplaceThemeInstallConfigurationId = t.marketplaceThemeInstallConfigurationId, t.bearerAuthenticationToken && Ii(t.bearerAuthenticationToken), this.options.applicationKey && this.getIntegration();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/core",
3
- "version": "26.5.0",
3
+ "version": "26.5.1",
4
4
  "description": "Core client API for interacting with the Spiff Commerce backend.",
5
5
  "source": "src/index.ts",
6
6
  "main": "./dist/index.js",