@spiffcommerce/core 17.5.0 → 17.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.d.ts CHANGED
@@ -2196,7 +2196,9 @@ declare class SpiffCommerceClient {
2196
2196
  * @param collectionId Optional: The id of the product collection that the bundle can use.
2197
2197
  * @returns A bundle to be used for grouping and operating on large amounts of workflow experiences.
2198
2198
  */
2199
- getNewBundle(collectionId?: string): Promise<Bundle>;
2199
+ getNewBundle(collectionId?: string, initialMetadata?: {
2200
+ [key: string]: string;
2201
+ }): Promise<Bundle>;
2200
2202
  /**
2201
2203
  * Retrieves an existing bundle from the API, by id.
2202
2204
  * @param bundleId The id of the bundle to retrieve.
package/dist/index.js CHANGED
@@ -7491,8 +7491,8 @@ const Ms = (c, A) => {
7491
7491
  }
7492
7492
  `, fn = y`
7493
7493
  ${nt}
7494
- mutation CreateBundle($collectionId: String) {
7495
- bundleCreate(collectionId: $collectionId) {
7494
+ mutation CreateBundle($collectionId: String, $initialMetadata: [MetadataInput!]) {
7495
+ bundleCreate(collectionId: $collectionId, metadata: $initialMetadata) {
7496
7496
  id
7497
7497
  bundleOwnerId
7498
7498
  metadata {
@@ -9711,21 +9711,22 @@ class Bs {
9711
9711
  * @param collectionId Optional: The id of the product collection that the bundle can use.
9712
9712
  * @returns A bundle to be used for grouping and operating on large amounts of workflow experiences.
9713
9713
  */
9714
- async getNewBundle(A) {
9715
- var s;
9716
- const t = (s = (await N.getShadowGraphqlClient().mutate({
9714
+ async getNewBundle(A, e) {
9715
+ var i;
9716
+ const a = (i = (await N.getShadowGraphqlClient().mutate({
9717
9717
  mutation: fn,
9718
9718
  variables: {
9719
- collectionId: A
9719
+ collectionId: A,
9720
+ initialMetadata: e ? Object.entries(e).map((o, r) => ({ key: o, value: r })) : void 0
9720
9721
  },
9721
9722
  fetchPolicy: "no-cache"
9722
- })).data) == null ? void 0 : s.bundleCreate;
9723
- if (!(t != null && t.id))
9723
+ })).data) == null ? void 0 : i.bundleCreate;
9724
+ if (!(a != null && a.id))
9724
9725
  throw new Error("Unable to create bundle");
9725
- const a = x.getMap("bundlePartnerIds") || /* @__PURE__ */ new Map();
9726
- a.set(t.id, t.partner.id), x.setMap("bundlePartnerIds", a);
9727
- const n = x.getMap("bundleOwnerIds") || /* @__PURE__ */ new Map();
9728
- return n.set(t.id, t.bundleOwnerId), x.setMap("bundleOwnerIds", n), new me(this, t, void 0, void 0, t.bundleOwnerId);
9726
+ const n = x.getMap("bundlePartnerIds") || /* @__PURE__ */ new Map();
9727
+ n.set(a.id, a.partner.id), x.setMap("bundlePartnerIds", n);
9728
+ const s = x.getMap("bundleOwnerIds") || /* @__PURE__ */ new Map();
9729
+ return s.set(a.id, a.bundleOwnerId), x.setMap("bundleOwnerIds", s), new me(this, a, void 0, void 0, a.bundleOwnerId);
9729
9730
  }
9730
9731
  /**
9731
9732
  * Retrieves an existing bundle from the API, by id.
@@ -2039,8 +2039,8 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
2039
2039
  }
2040
2040
  `,Yn=M.gql`
2041
2041
  ${JA}
2042
- mutation CreateBundle($collectionId: String) {
2043
- bundleCreate(collectionId: $collectionId) {
2042
+ mutation CreateBundle($collectionId: String, $initialMetadata: [MetadataInput!]) {
2043
+ bundleCreate(collectionId: $collectionId, metadata: $initialMetadata) {
2044
2044
  id
2045
2045
  bundleOwnerId
2046
2046
  metadata {
@@ -2821,4 +2821,4 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
2821
2821
  }
2822
2822
  }
2823
2823
  }
2824
- `,ee=async g=>{var e;for(const A in g.layouts){const t=g.layouts[A].elements.filter(a=>a.type===c.LayoutElementType.Illustration);for(let a=0;a<t.length;++a){const i=t[a];i.src&&i.svg&&(i.cachedObjectURL=await c.svgObjectURL(i.svg))}const n=g.layouts[A].elements.filter(a=>a.type===c.LayoutElementType.Textbox);for(let a=0;a<n.length;++a){const i=n[a];(e=i.fontData)!=null&&e.assetUrl&&await c.loadFont(i.fontData.assetUrl)}}},oa=async(g,e)=>{var n;const A=await H.getShadowGraphqlClient().query({query:$n(((n=e==null?void 0:e.assets)==null?void 0:n.metadata)||!1),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:g}}),t=A.data.workflows;if(t===void 0||t.length!==g.length)throw new Error(`Unable to read workflows: ${A.errors??"Length mismatch in response"}`);return t.forEach(a=>{a.steps.forEach(i=>{var o,s,r;delete i.data.__typename,(o=i.option)!=null&&o.id&&((s=i.option.defaultVariant)!=null&&s.asset&&b.cacheAsset(i.option.defaultVariant.asset),i.option.colorProfile&&b.cacheAsset(i.option.colorProfile),(r=i.option.variants)==null||r.forEach(l=>{l.asset&&b.cacheAsset(l.asset),l.displayImage&&b.cacheAsset(l.displayImage),l.thumbnail&&b.cacheAsset(l.thumbnail),l.material&&b.cacheMaterial(l.material)}),q.set({id:i.option.id},Promise.resolve(i.option)))})}),t},sa=async(g,e)=>{const t=(await e).find(n=>n.id===g);if(!t)throw new Error(`Workflow not found: ${g}`);return t},ze=async(g,e)=>{const A=g.map(o=>q.get({id:o,options:e})),t=g.filter((o,s)=>A[s]===void 0);if(t.length===0)return Promise.all(A);const n=oa(t,e),a=t.map(o=>q.set({id:o,options:e},sa(o,n))),i=A.filter(o=>o!==void 0);return await Promise.all(i.concat(a))},Be=async(g,e)=>(await ze([g],e))[0],ra=g=>g.sort((e,A)=>e.index-A.index).map(e=>({id:c.generate(),panelId:e.name,name:e.name,index:e.index,createdAt:new Date,updatedAt:new Date,transparentBackground:e.transparentBackground,height:e.height,width:e.width,previewRegion:e.previewRegion,useEditableArea:e.useEditableArea,editableArea:e.editableArea})),je=(g,e)=>{const A=g.workflowState,t=A?JSON.parse(A):void 0;return t?Object.values(t.layouts).map(n=>n.layout):ra(e.panels)};class qA{constructor(e){this.updateTransactionState=async A=>{try{return H.getShadowGraphqlClient().mutate({...A,mutation:ft})}catch(t){throw console.error(t),new R("Critical - Unable to synchronize workflow state with server.")}},this.initialized=!1,this.options=e,this.options.applicationKey&&nt(this.options.applicationKey)}getAssetManager(){return b}getCurrencyCode(){if(this.currencyCode===void 0)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!this.options.applicationKey)throw new Error("Application key required to use Flow Service.");return new VA}async authenticateBundleFromLocalStorage(e){var n,a;const A=P.getMap("bundleOwnerIds");if(A!=null&&A.has(e))return Promise.resolve({success:!0,stakeholderType:oe.Owner});const t=P.getMap("bundlePartnerIds")||new Map;if(t.has(e)){const i=t.get(e),s=(P.getMap("partnerCustomerIds")||new Map).get(i);if(s&&await this.authenticateCustomerId(s)){const l=(a=(n=this.customer)==null?void 0:n.bundleStakeholders)==null?void 0:a.find(d=>{var B;return((B=d.bundle)==null?void 0:B.id)===e});if(l)return Promise.resolve({success:!0,stakeholderType:l.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(e){var l,d,B,w,E,m;const A=H.getShadowGraphqlClient(),t=await A.query({query:_n,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:e}});if(!t.data.transactions||t.data.transactions.length===0)throw new Error(`Transaction not found: ${e}`);const n=t.data.transactions[0];if(!((d=(l=n.product)==null?void 0:l.partner)==null?void 0:d.id))throw new Error(`Unable to read transaction: ${e}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const i=P.getMap("transactionOwnerIds");if(i!=null&&i.has(e))return Promise.resolve({success:!0,stakeholderType:oe.Owner});const o=P.getMap("transactionCustomerIds");if(o!=null&&o.has(e)){const h=o.get(e);if(h&&await this.authenticateCustomerId(h)){const C=((w=(B=this.customer)==null?void 0:B.bundleStakeholders)==null?void 0:w.find(D=>{var I,F;return(F=(I=D.bundle)==null?void 0:I.transactions)==null?void 0:F.some(p=>p.id===e)}))||((m=(E=this.customer)==null?void 0:E.stakeholders)==null?void 0:m.find(D=>{var I;return((I=D.transaction)==null?void 0:I.id)===e}));if(C)return Promise.resolve({success:!0,stakeholderType:C.type})}}const r=(await A.query({query:ea,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!r)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:r.overrideTheme,customLogoLink:n.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(e){const A=P.getMap("transactionCustomerIds");A!=null&&A.has(e)&&(A.delete(e),P.setMap("transactionCustomerIds",A))}getStakeholderTypeForTransaction(e){var t,n;const A=(n=(t=this.customer)==null?void 0:t.stakeholders)==null?void 0:n.find(a=>{var i;return((i=a.transaction)==null?void 0:i.id)===e});if(A)return A.type}async getOrCreateCustomer(e){var i;this.customer=void 0;const A=H.getShadowGraphqlClient(),n=(await A.query({query:Aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e}})).data.customer;if(!n.id){const s=(i=(await A.mutate({mutation:ta,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:e}}})).data)==null?void 0:i.customerCreate;if(!s)throw new Error("Unable to create customer.");return this.storeCustomer(s),this.customer=s,{customer:s,isAuthenticated:!1}}this.storeCustomer(n);const a=await this.authenticateCustomerId(n.id);return{customer:this.customer||n,isAuthenticated:a}}async authenticateCustomerId(e){var o;const A=H.getShadowGraphqlClient(),t=P.getMap("customerTokens");if(!(t!=null&&t.has(e)))return!1;const n=t.get(e);if(!n)return!1;const i=(o=(await A.mutate({mutation:na,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data)==null?void 0:o.customerAuthenticate;return i?(this.storeCustomer(i),AA(n),this.customer=i,!0):!1}async generateVerificationCode(e){await H.getShadowGraphqlClient().mutate({mutation:aa,variables:{emailAddress:e}})}async verifyCode(e,A){var a,i;const n=(a=(await H.getShadowGraphqlClient().mutate({mutation:ia,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e,verificationCode:A}})).data)==null?void 0:a.customerVerifyCode;if(n!=null&&n.loginToken){if(!((i=n.partner)!=null&&i.id))throw new Error(`Unable to find customer: ${e}`);const o=P.getMap("customerTokens")||new Map;return o.set(n.id,n.loginToken),P.setMap("customerTokens",o),this.storeCustomer(n),AA(n.loginToken),this.customer={...n,loginToken:void 0},!0}return!1}async getNewBundle(e){var i;const t=(i=(await H.getShadowGraphqlClient().mutate({mutation:Yn,variables:{collectionId:e},fetchPolicy:"no-cache"})).data)==null?void 0:i.bundleCreate;if(!(t!=null&&t.id))throw new Error("Unable to create bundle");const n=P.getMap("bundlePartnerIds")||new Map;n.set(t.id,t.partner.id),P.setMap("bundlePartnerIds",n);const a=P.getMap("bundleOwnerIds")||new Map;return a.set(t.id,t.bundleOwnerId),P.setMap("bundleOwnerIds",a),new KA(this,t,void 0,void 0,t.bundleOwnerId)}async getExistingBundle(e,A,t){var l,d,B,w;const n=P.getMap("bundleOwnerIds"),a=n==null?void 0:n.get(e),i=await H.getShadowGraphqlClient().query({query:Fn,variables:{id:e},fetchPolicy:"no-cache",context:{bundleOwnerId:a}});if(!((l=i.data)!=null&&l.bundles)||((d=i.data)==null?void 0:d.bundles.length)===0||!((B=i.data)!=null&&B.bundles[0]))throw new Error(`Unable to find bundle: ${e}`);const o=(w=i.data)==null?void 0:w.bundles[0],s=P.getMap("bundlePartnerIds")||new Map;s.set(o.id,o.partner.id),P.setMap("bundlePartnerIds",s);const r=new KA(this,o,A,t,a);return await r.getInitializationPromise(),r}async getBundleStakeholders(){var a;if(!this.customer)throw new Error("Customer not authenticated.");const e=await H.getShadowGraphqlClient().query({query:Sn,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!((a=e.data)!=null&&a.customers)||e.data.customers.length===0)throw new Error("Unable to find customer.");const t=e.data.customers[0].bundleStakeholders||[],n=P.getMap("bundlePartnerIds")||new Map;return t.forEach(i=>{var o,s;(o=i.bundle)!=null&&o.id&&((s=i.bundle.partner)!=null&&s.id)&&n.set(i.bundle.id,i.bundle.partner.id)}),P.setMap("bundlePartnerIds",n),t}async getWorkflowExperience(e,A,t,n){var d,B,w,E,m;if(!n)return await this.getWorkflowExperienceDeprecated(e,A,t);const a=async()=>{var u,C;const h=H.getShadowGraphqlClient();if(n.type==="transaction"){const{transactionId:D,readOnly:I}=n,F=await h.query({query:Ce,variables:{ids:[D]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!((u=F.data)!=null&&u.transactions)||F.data.transactions.length===0)throw new R("Existing transaction not found.");const p=(C=F.data)==null?void 0:C.transactions[0];if(!p.workflowId)throw new R("Existing transaction has no workflow ID.");const f=await Be(p.workflowId);if(!p.product)throw new R("Failed to load transaction, product not available.");return{transaction:p,workflow:f,readOnly:I}}if(n.type==="integration"||n.type==="external"){const D=async()=>{const f=n.type==="integration"?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},S=await h.mutate({mutation:cA,variables:{...f,workflowId:n.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!S.data||!S.data.transactionCreate)throw new R("Failed to create transaction!");const y=S.data.transactionCreate;if(!y.product)throw new R("Failed to create transaction, product not available.");return y},I=Be(n.workflowId,n==null?void 0:n.graphql),[F,p]=await Promise.all([D(),I]);return{transaction:F,workflow:p}}throw new R("No workflow ID provided.")},{transaction:i,workflow:o,readOnly:s}=await a();this.currencyCode=(d=i.product.partner)==null?void 0:d.currencyCode;const r={product:i.product,transaction:i,layouts:[],singleVariantsRenderable:(B=n==null?void 0:n.workflowConfiguration)==null?void 0:B.singleVariantsRenderable,stateMutationFunc:s?async()=>{throw new U("State mutation is forbidden in read only mode!")}:async h=>{const C=(P.getMap("transactionOwnerIds")||new Map).get(i.id)||void 0;return this.updateTransactionState({...h,context:{transactionOwnerId:C}})},readOnly:s,workflow:o};if(n.type==="transaction"&&i.workflowState){const h=JSON.parse(i.workflowState);r.layouts=Object.values(h.layouts).map(u=>u.layout),await c.rehydrateSerializedLayout(h),await ee(h),r.reloadedState=h}else if(!s&&n.workflowState){const h=JSON.parse(n.workflowState);r.layouts=Object.values(h.layouts).map(u=>u.layout),await c.rehydrateSerializedLayout(h),await ee(h),r.reloadedState=h}else r.layouts=je(r.transaction,r.workflow);if(r.renderableContextService=new pe(r.layouts),n.previewService?(r.previewService=n.previewService,(w=r.product)!=null&&w.modelUrl&&(r.modelContainer=r.previewService.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))):(r.previewService=t&&t(o),(E=r.product)!=null&&E.modelUrl&&(r.modelContainer=(m=r.previewService)==null?void 0:m.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))),n.type!=="transaction"){const h=P.getMap("transactionOwnerIds")||new Map;h.set(i.id,i.transactionOwnerId),P.setMap("transactionOwnerIds",h)}else r.isReloadedTransaction=!0;this.initialized=!0,this.experienceOptions=r;const l=new ge(this,r);return await l.getWorkflowManager().getInitializationPromise(),n.type!=="transaction"&&this.customer&&await l.attachCustomerDetails({email:this.customer.emailAddress}),l}async getWorkflowExperiences(e,A){if(e.length===0)throw new R("No options provided!");const t=H.getShadowGraphqlClient(),n=e.map((C,D)=>({option:C,index:D})),a=n.filter(C=>C.option.type==="transaction"),i=n.filter(C=>C.option.type==="integration"||C.option.type==="external"),o=async()=>{var F,p;if(a.length===0)return[];const C=a.map(f=>f.option.transactionId),D=await t.query({query:Ce,variables:{ids:C},errorPolicy:"all",fetchPolicy:"no-cache"}),I=D.data.transactions;if(I.length!==a.length){const f=((p=(F=D.errors)==null?void 0:F[0])==null?void 0:p.message)||"Unknown error";throw new R(`Not all transactions were found: ${f}`)}return I.map((f,S)=>{var y;return{transaction:f,workflowId:f.workflowId,readOnly:((y=a.find(Y=>Y.option.transactionId===f.id))==null?void 0:y.option.readOnly)??!1,index:a[S].index}})},s=async()=>{var I,F,p;if(i.length===0)return[];const C=await t.mutate({mutation:ut,variables:{inputs:i.map(f=>({integrationProductId:f.option.type==="integration"?f.option.integrationProductId:void 0,externalIntegrationId:f.option.type==="external"?f.option.externalIntegrationId:void 0,externalProductId:f.option.type==="external"?f.option.externalProductId:void 0,workflowId:f.option.workflowId,claim:!0}))},errorPolicy:"all",fetchPolicy:"no-cache"}),D=(I=C.data)==null?void 0:I.transactionCreateMany;if(!D||D.length===0){const f=((p=(F=C.errors)==null?void 0:F[0])==null?void 0:p.message)||"Unknown error";throw new R(`Failed to create transactions: ${f}`)}return D.map((f,S)=>({transaction:f,workflowId:f.workflowId,readOnly:!1,index:i[S].index}))},r=(await Promise.all([o(),s()])).flat(),l=[...new Set(r.map(C=>C.workflowId))],d=await ze(l,A),B=new Map(d.map(C=>[C.id,C])),w=P.getMap("transactionOwnerIds")||new Map,E=r.map(async C=>{var G;const{transaction:D,workflowId:I,readOnly:F,index:p}=C,f=B.get(I),S=e[p];!w.get(D.id)&&D.transactionOwnerId&&w.set(D.id,D.transactionOwnerId);const y=w.get(D.id)||void 0,Y={product:D.product,transaction:D,layouts:[],singleVariantsRenderable:(G=S==null?void 0:S.workflowConfiguration)==null?void 0:G.singleVariantsRenderable,stateMutationFunc:F?async()=>{throw new U("State mutation is forbidden in read only mode!")}:async N=>this.updateTransactionState({...N,context:{transactionOwnerId:y}}),readOnly:F,workflow:f,isReloadedTransaction:S.type==="transaction"};if(S.type==="transaction"&&D.workflowState){const N=JSON.parse(D.workflowState);Y.layouts=Object.values(N.layouts).map(v=>v.layout),await c.rehydrateSerializedLayout(N),await ee(N),Y.reloadedState=N}else if(!F&&S.workflowState){const N=JSON.parse(S.workflowState);Y.layouts=Object.values(N.layouts).map(v=>v.layout),await c.rehydrateSerializedLayout(N),await ee(N),Y.reloadedState=N}else Y.layouts=je(Y.transaction,Y.workflow);return Y.renderableContextService=new pe(Y.layouts),this.initialized=!0,this.experienceOptions=Y,{experienceOptions:Y,index:p,options:S}});P.setMap("transactionOwnerIds",w);const u=(await Promise.all(E)).sort((C,D)=>C.index-D.index).map(async C=>{const{experienceOptions:D,options:I}=C,F=new ge(this,D);return await F.getWorkflowManager().getInitializationPromise(),I.type!=="transaction"&&this.customer&&await F.attachCustomerDetails({email:this.customer.emailAddress}),F});return await Promise.all(u)}async initFromIntegrationProduct(e){var i;if(e==="")throw new R("No integration product ID provided.");const t=await H.getShadowGraphqlClient().mutate({mutation:cA,variables:{integrationProductId:e,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!t.data||!t.data.transactionCreate)throw new R("Failed to create transaction!");const n=t.data.transactionCreate;if(!n.product)throw new R("Failed to create transaction, product not available.");this.currencyCode=(i=n.product.partner)==null?void 0:i.currencyCode;const a=P.getMap("transactionOwnerIds")||new Map;a.set(n.id,n.transactionOwnerId),P.setMap("transactionOwnerIds",a),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async o=>this.updateTransactionState({...o,context:{transactionOwnerId:n.transactionOwnerId}})},this.initialized=!0}async initFromTransaction(e,A=!1){var o,s,r,l;if(e==="")throw new R("No transaction ID provided.");const t=H.getShadowGraphqlClient(),n=async()=>{var w,E;const B=(w=(await t.query({query:Ce,variables:{ids:[e]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:w.transactions[0];if(!B)throw new R("Failed to read transaction.");if(!B.product)throw new R("Failed to load transaction, product not available.");this.currencyCode=(E=B.product.partner)==null?void 0:E.currencyCode,this.experienceOptions={product:B.product,transaction:B,layouts:[],stateMutationFunc:async()=>{throw new U("State mutation is forbidden in read only mode!")},readOnly:A},this.initialized=!0};if(A)return await n();const a=P.getMap("transactionOwnerIds")||new Map,i=a.get(e);if(i){const B=(o=(await t.query({query:Ce,variables:{ids:[e]},errorPolicy:"all"})).data)==null?void 0:o.transactions[0];if(!B)throw new R("Failed to read transaction.");if(!B.product)throw new R("Failed to load transaction, product not available.");this.currencyCode=(s=B.product.partner)==null?void 0:s.currencyCode,this.experienceOptions={product:B.product,transaction:B,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:i}}),readOnly:A},this.initialized=!0;return}try{const B=(r=(await t.mutate({mutation:It,variables:{id:e},errorPolicy:"all"})).data)==null?void 0:r.transactionClaim;if(!B)throw new R("Failed to read transaction.");if(!B.product)throw new R("Failed to load transaction, product not available.");this.currencyCode=(l=B.product.partner)==null?void 0:l.currencyCode,B.transactionOwnerId&&(a.set(B.id,B.transactionOwnerId),P.setMap("transactionOwnerIds",a)),this.experienceOptions={product:B.product,transaction:B,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:B.transactionOwnerId}}),readOnly:A},this.initialized=!0}catch{throw new R("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(e,A,t){var n,a,i,o;if(!this.initialized||!this.experienceOptions)throw new R("Cannot launch experience: Not initialized.");if(this.experienceOptions.transaction.workflowId){const s=await Be(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=s,this.experienceOptions.transaction.workflowState){const l=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(l.layouts).map(d=>d.layout),await c.rehydrateSerializedLayout(l),await ee(l),this.experienceOptions.reloadedState=l}this.experienceOptions.previewService=t&&t(s),this.experienceOptions.renderableContextService=new pe(this.experienceOptions.layouts),(n=this.experienceOptions.product)!=null&&n.modelUrl&&(this.experienceOptions.modelContainer=(a=this.experienceOptions.previewService)==null?void 0:a.loadModel({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}));const r=new ge(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}if(e){const r=(P.getMap("transactionOwnerIds")||new Map).get(this.experienceOptions.transaction.id),l=H.getShadowGraphqlClient().mutate({mutation:Dt,variables:{workflowId:e,id:this.experienceOptions.transaction.id},context:{transactionOwnerId:r}}),d=Be(e);if(await Promise.all([l,d]),this.experienceOptions.workflow=await d,A){const w=JSON.parse(A);this.experienceOptions.layouts=Object.values(w.layouts).map(E=>E.layout),await c.rehydrateSerializedLayout(w),await ee(w),this.experienceOptions.reloadedState=w}else this.experienceOptions.layouts=je(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=t&&t(await d),this.experienceOptions.renderableContextService=new pe(this.experienceOptions.layouts),(i=this.experienceOptions.product)!=null&&i.modelUrl&&(this.experienceOptions.modelContainer=(o=this.experienceOptions.previewService)==null?void 0:o.loadModel({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}));const B=new ge(this,this.experienceOptions);return await B.getWorkflowManager().getInitializationPromise(),B}throw new R("No workflow ID provided.")}getPreviewService(){var e;return(e=this.experienceOptions)==null?void 0:e.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new R("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new R("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}storeCustomer(e){const A=P.getMap("partnerCustomerIds")||new Map;A.set(e.partner.id,e.id),P.setMap("partnerCustomerIds",A)}}class ca{getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}async reset(){}updateStateWithServer(e){}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(e){}addPoller(e){}addConfirmCallback(e){}addEditedCallback(e){}addElementsCallback(e){}addInformationResultCallback(e){}addInitCallback(e){}addMakingAdjustmentsCallback(e){}addMandatoryCallback(e){}addMetadataCallback(e){}addSelectionCallback(e){}addStepSpecificStorageCallback(e,A){}addStorageCallback(e){}getCommandDispatcher(){return e=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(e){return[]}getSerializedStep(e,A){}getStepSpecificServices(e){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(e){}markUpdateCompleted(e){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}setCurrentAdjustingStepId(e){}setEditedStatus(e,A){}setInformationResults(e){}setMandatoryFulfilled(e,A){}async setSelectionsAndElements(e,A,t){}toggleDesignConfirmed(){}updateMetadata(e,A){}async updateStorage(e,A){}injectIntoPreviewService(e){return Promise.resolve()}ejectFromPreviewService(){}}var ZA=(g=>(g.SelectFrame="SelectFrame",g.SelectImage="SelectImage",g.Position="Position",g))(ZA||{});class $A extends O{constructor(e,A){var t;super(e,A),this.frameService=(t=this.manager.getStepSpecificServices(this.getId()))==null?void 0:t.frameService}selectVariant(e){const A=this.manager.getRegionElements(this.step.stepName);return me.selectVariant(this.step,e.getResource(),A,this.manager,t=>this.setUpdateState(t))}onFrameDataChanged(e){this.frameService&&this.frameService.onFrameDataChanged(A=>{A&&e(A)})}selectImage(e){return me.selectImage(this.step,e,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(e,A,t,n){return n&&n.length>1&&e===void 0?"SelectFrame":A||t||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}}Object.defineProperty(Q,"AssetType",{enumerable:!0,get:()=>c.AssetType}),Object.defineProperty(Q,"BringForwardCommand",{enumerable:!0,get:()=>c.BringForwardCommand}),Object.defineProperty(Q,"BringToBackCommand",{enumerable:!0,get:()=>c.BringToBackCommand}),Object.defineProperty(Q,"BringToFrontCommand",{enumerable:!0,get:()=>c.BringToFrontCommand}),Object.defineProperty(Q,"CanvasCommand",{enumerable:!0,get:()=>c.CanvasCommand}),Object.defineProperty(Q,"CommandContext",{enumerable:!0,get:()=>c.CommandContext}),Object.defineProperty(Q,"CreateElementCommand",{enumerable:!0,get:()=>c.CreateElementCommand}),Object.defineProperty(Q,"CreateLayoutCommand",{enumerable:!0,get:()=>c.CreateLayoutCommand}),Object.defineProperty(Q,"DeleteElementCommand",{enumerable:!0,get:()=>c.DeleteElementCommand}),Object.defineProperty(Q,"FontAlignmentCommand",{enumerable:!0,get:()=>c.FontAlignmentCommand}),Object.defineProperty(Q,"FontColorCommand",{enumerable:!0,get:()=>c.FontColorCommand}),Object.defineProperty(Q,"FontSizeCommand",{enumerable:!0,get:()=>c.FontSizeCommand}),Object.defineProperty(Q,"FontSourceCommand",{enumerable:!0,get:()=>c.FontSourceCommand}),Object.defineProperty(Q,"GroupCommand",{enumerable:!0,get:()=>c.GroupCommand}),Object.defineProperty(Q,"LayoutElementFactory",{enumerable:!0,get:()=>c.LayoutElementFactory}),Object.defineProperty(Q,"LayoutElementType",{enumerable:!0,get:()=>c.LayoutElementType}),Object.defineProperty(Q,"MoveCommand",{enumerable:!0,get:()=>c.MoveCommand}),Object.defineProperty(Q,"ResizeCommand",{enumerable:!0,get:()=>c.ResizeCommand}),Object.defineProperty(Q,"RotateCommand",{enumerable:!0,get:()=>c.RotateCommand}),Object.defineProperty(Q,"SendBackwardsCommand",{enumerable:!0,get:()=>c.SendBackwardsCommand}),Object.defineProperty(Q,"StepAspectType",{enumerable:!0,get:()=>c.StepAspectType}),Object.defineProperty(Q,"StepType",{enumerable:!0,get:()=>c.StepType}),Object.defineProperty(Q,"TextChangeCommand",{enumerable:!0,get:()=>c.TextChangeCommand}),Object.defineProperty(Q,"UnitOfMeasurement",{enumerable:!0,get:()=>c.UnitOfMeasurement}),Object.defineProperty(Q,"dataUrlFromExternalUrl",{enumerable:!0,get:()=>c.dataUrlFromExternalUrl}),Object.defineProperty(Q,"determineCorrectFontSizeAndLines",{enumerable:!0,get:()=>c.determineCorrectFontSizeAndLines}),Object.defineProperty(Q,"findElement",{enumerable:!0,get:()=>c.findElement}),Object.defineProperty(Q,"frameDataCache",{enumerable:!0,get:()=>c.frameDataCache}),Object.defineProperty(Q,"generate",{enumerable:!0,get:()=>c.generate}),Object.defineProperty(Q,"generateSVGWithUnknownColors",{enumerable:!0,get:()=>c.generateSVGWithUnknownColors}),Object.defineProperty(Q,"getAttributesFromArrayBuffer",{enumerable:!0,get:()=>c.getAttributesFromArrayBuffer}),Object.defineProperty(Q,"getAxisAlignedBoundingBox",{enumerable:!0,get:()=>c.getAxisAlignedBoundingBox}),Object.defineProperty(Q,"getFrameData",{enumerable:!0,get:()=>c.getFrameData}),Object.defineProperty(Q,"getSvgElement",{enumerable:!0,get:()=>c.getSvgElement}),Object.defineProperty(Q,"loadFont",{enumerable:!0,get:()=>c.loadFont}),Object.defineProperty(Q,"patternImageDataCache",{enumerable:!0,get:()=>c.patternImageDataCache}),Object.defineProperty(Q,"registerFetchImplementation",{enumerable:!0,get:()=>c.registerFetchImplementation}),Object.defineProperty(Q,"registerWindowImplementation",{enumerable:!0,get:()=>c.registerWindowImplementation}),Object.defineProperty(Q,"rehydrateSerializedLayout",{enumerable:!0,get:()=>c.rehydrateSerializedLayout}),Object.defineProperty(Q,"setCanvasModule",{enumerable:!0,get:()=>c.setCanvasModule}),Q.AssetNotFoundError=j,Q.CollectionProduct=OA,Q.ConversionDataType=rA,Q.ConversionLocation=sA,Q.FlowExecutionNodeResult=le,Q.FlowExecutionResult=WA,Q.FlowService=VA,Q.FrameService=BA,Q.FrameStep=ZA,Q.FrameStepHandle=$A,Q.GlobalPropertyHandle=Fe,Q.IllustrationStepHandle=SA,Q.InformationMessageType=ce,Q.InformationStepHandle=RA,Q.IntegrationType=iA,Q.LayoutNotFoundError=k,Q.MaterialStepHandle=YA,Q.MisconfigurationError=ne,Q.MockWorkflowManager=ca,Q.ModelStepHandle=yA,Q.ObjectInput=Oe,Q.ObjectInputType=XA,Q.OptionNotFoundError=te,Q.ParseError=X,Q.PictureStepHandle=PA,Q.ProductCameraRig=oA,Q.ProductCollection=LA,Q.ProductWorkflow=Le,Q.PromiseCache=q,Q.PromiseQueue=Ne,Q.QuestionStepHandle=NA,Q.QueueablePromise=Pe,Q.ResourceNotFoundError=W,Q.ShapeStepHandle=HA,Q.SpiffCommerceClient=qA,Q.StakeholderType=oe,Q.StepHandle=O,Q.TextStepHandle=xA,Q.Transform=jA,Q.TransformCollection=zA,Q.UnhandledBehaviorError=U,Q.Variant=z,Q.WorkflowExperienceImpl=ge,Q.assetService=b,Q.createDesign=kA,Q.designService=De,Q.digitalContentStepService=hA,Q.frameStepService=me,Q.generateCommands=bA,Q.generateStateFromDesignInputSteps=fn,Q.getBoundedOffsets=lA,Q.getWorkflow=Be,Q.getWorkflows=ze,Q.graphQlManager=H,Q.illustrationStepService=re,Q.materialStepService=He,Q.modelStepService=xe,Q.moduleStepService=CA,Q.optionService=J,Q.persistenceService=P,Q.pictureStepService=Re,Q.questionStepService=Ue,Q.shapeStepService=_,Q.shortenUrl=wA,Q.spiffCoreConfiguration=ae,Q.stepAspectValuesToDesignInputSteps=In,Q.textStepService=T,Q.toast=QA,Object.defineProperty(Q,Symbol.toStringTag,{value:"Module"})});
2824
+ `,ee=async g=>{var e;for(const A in g.layouts){const t=g.layouts[A].elements.filter(a=>a.type===c.LayoutElementType.Illustration);for(let a=0;a<t.length;++a){const i=t[a];i.src&&i.svg&&(i.cachedObjectURL=await c.svgObjectURL(i.svg))}const n=g.layouts[A].elements.filter(a=>a.type===c.LayoutElementType.Textbox);for(let a=0;a<n.length;++a){const i=n[a];(e=i.fontData)!=null&&e.assetUrl&&await c.loadFont(i.fontData.assetUrl)}}},oa=async(g,e)=>{var n;const A=await H.getShadowGraphqlClient().query({query:$n(((n=e==null?void 0:e.assets)==null?void 0:n.metadata)||!1),errorPolicy:"all",fetchPolicy:"no-cache",variables:{ids:g}}),t=A.data.workflows;if(t===void 0||t.length!==g.length)throw new Error(`Unable to read workflows: ${A.errors??"Length mismatch in response"}`);return t.forEach(a=>{a.steps.forEach(i=>{var o,s,r;delete i.data.__typename,(o=i.option)!=null&&o.id&&((s=i.option.defaultVariant)!=null&&s.asset&&b.cacheAsset(i.option.defaultVariant.asset),i.option.colorProfile&&b.cacheAsset(i.option.colorProfile),(r=i.option.variants)==null||r.forEach(l=>{l.asset&&b.cacheAsset(l.asset),l.displayImage&&b.cacheAsset(l.displayImage),l.thumbnail&&b.cacheAsset(l.thumbnail),l.material&&b.cacheMaterial(l.material)}),q.set({id:i.option.id},Promise.resolve(i.option)))})}),t},sa=async(g,e)=>{const t=(await e).find(n=>n.id===g);if(!t)throw new Error(`Workflow not found: ${g}`);return t},ze=async(g,e)=>{const A=g.map(o=>q.get({id:o,options:e})),t=g.filter((o,s)=>A[s]===void 0);if(t.length===0)return Promise.all(A);const n=oa(t,e),a=t.map(o=>q.set({id:o,options:e},sa(o,n))),i=A.filter(o=>o!==void 0);return await Promise.all(i.concat(a))},Be=async(g,e)=>(await ze([g],e))[0],ra=g=>g.sort((e,A)=>e.index-A.index).map(e=>({id:c.generate(),panelId:e.name,name:e.name,index:e.index,createdAt:new Date,updatedAt:new Date,transparentBackground:e.transparentBackground,height:e.height,width:e.width,previewRegion:e.previewRegion,useEditableArea:e.useEditableArea,editableArea:e.editableArea})),je=(g,e)=>{const A=g.workflowState,t=A?JSON.parse(A):void 0;return t?Object.values(t.layouts).map(n=>n.layout):ra(e.panels)};class qA{constructor(e){this.updateTransactionState=async A=>{try{return H.getShadowGraphqlClient().mutate({...A,mutation:ft})}catch(t){throw console.error(t),new R("Critical - Unable to synchronize workflow state with server.")}},this.initialized=!1,this.options=e,this.options.applicationKey&&nt(this.options.applicationKey)}getAssetManager(){return b}getCurrencyCode(){if(this.currencyCode===void 0)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!this.options.applicationKey)throw new Error("Application key required to use Flow Service.");return new VA}async authenticateBundleFromLocalStorage(e){var n,a;const A=P.getMap("bundleOwnerIds");if(A!=null&&A.has(e))return Promise.resolve({success:!0,stakeholderType:oe.Owner});const t=P.getMap("bundlePartnerIds")||new Map;if(t.has(e)){const i=t.get(e),s=(P.getMap("partnerCustomerIds")||new Map).get(i);if(s&&await this.authenticateCustomerId(s)){const l=(a=(n=this.customer)==null?void 0:n.bundleStakeholders)==null?void 0:a.find(d=>{var B;return((B=d.bundle)==null?void 0:B.id)===e});if(l)return Promise.resolve({success:!0,stakeholderType:l.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(e){var l,d,B,w,E,m;const A=H.getShadowGraphqlClient(),t=await A.query({query:_n,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:e}});if(!t.data.transactions||t.data.transactions.length===0)throw new Error(`Transaction not found: ${e}`);const n=t.data.transactions[0];if(!((d=(l=n.product)==null?void 0:l.partner)==null?void 0:d.id))throw new Error(`Unable to read transaction: ${e}`);if(n.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const i=P.getMap("transactionOwnerIds");if(i!=null&&i.has(e))return Promise.resolve({success:!0,stakeholderType:oe.Owner});const o=P.getMap("transactionCustomerIds");if(o!=null&&o.has(e)){const h=o.get(e);if(h&&await this.authenticateCustomerId(h)){const C=((w=(B=this.customer)==null?void 0:B.bundleStakeholders)==null?void 0:w.find(D=>{var I,F;return(F=(I=D.bundle)==null?void 0:I.transactions)==null?void 0:F.some(p=>p.id===e)}))||((m=(E=this.customer)==null?void 0:E.stakeholders)==null?void 0:m.find(D=>{var I;return((I=D.transaction)==null?void 0:I.id)===e}));if(C)return Promise.resolve({success:!0,stakeholderType:C.type})}}const r=(await A.query({query:ea,errorPolicy:"all",variables:{id:n.workflowId}})).data.workflow;if(!r)throw new Error(`Unable to read workflow: ${n.workflowId}`);return Promise.resolve({success:!1,theme:r.overrideTheme,customLogoLink:n.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(e){const A=P.getMap("transactionCustomerIds");A!=null&&A.has(e)&&(A.delete(e),P.setMap("transactionCustomerIds",A))}getStakeholderTypeForTransaction(e){var t,n;const A=(n=(t=this.customer)==null?void 0:t.stakeholders)==null?void 0:n.find(a=>{var i;return((i=a.transaction)==null?void 0:i.id)===e});if(A)return A.type}async getOrCreateCustomer(e){var i;this.customer=void 0;const A=H.getShadowGraphqlClient(),n=(await A.query({query:Aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e}})).data.customer;if(!n.id){const s=(i=(await A.mutate({mutation:ta,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:e}}})).data)==null?void 0:i.customerCreate;if(!s)throw new Error("Unable to create customer.");return this.storeCustomer(s),this.customer=s,{customer:s,isAuthenticated:!1}}this.storeCustomer(n);const a=await this.authenticateCustomerId(n.id);return{customer:this.customer||n,isAuthenticated:a}}async authenticateCustomerId(e){var o;const A=H.getShadowGraphqlClient(),t=P.getMap("customerTokens");if(!(t!=null&&t.has(e)))return!1;const n=t.get(e);if(!n)return!1;const i=(o=(await A.mutate({mutation:na,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:n}})).data)==null?void 0:o.customerAuthenticate;return i?(this.storeCustomer(i),AA(n),this.customer=i,!0):!1}async generateVerificationCode(e){await H.getShadowGraphqlClient().mutate({mutation:aa,variables:{emailAddress:e}})}async verifyCode(e,A){var a,i;const n=(a=(await H.getShadowGraphqlClient().mutate({mutation:ia,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:e,verificationCode:A}})).data)==null?void 0:a.customerVerifyCode;if(n!=null&&n.loginToken){if(!((i=n.partner)!=null&&i.id))throw new Error(`Unable to find customer: ${e}`);const o=P.getMap("customerTokens")||new Map;return o.set(n.id,n.loginToken),P.setMap("customerTokens",o),this.storeCustomer(n),AA(n.loginToken),this.customer={...n,loginToken:void 0},!0}return!1}async getNewBundle(e,A){var o;const n=(o=(await H.getShadowGraphqlClient().mutate({mutation:Yn,variables:{collectionId:e,initialMetadata:A?Object.entries(A).map((s,r)=>({key:s,value:r})):void 0},fetchPolicy:"no-cache"})).data)==null?void 0:o.bundleCreate;if(!(n!=null&&n.id))throw new Error("Unable to create bundle");const a=P.getMap("bundlePartnerIds")||new Map;a.set(n.id,n.partner.id),P.setMap("bundlePartnerIds",a);const i=P.getMap("bundleOwnerIds")||new Map;return i.set(n.id,n.bundleOwnerId),P.setMap("bundleOwnerIds",i),new KA(this,n,void 0,void 0,n.bundleOwnerId)}async getExistingBundle(e,A,t){var l,d,B,w;const n=P.getMap("bundleOwnerIds"),a=n==null?void 0:n.get(e),i=await H.getShadowGraphqlClient().query({query:Fn,variables:{id:e},fetchPolicy:"no-cache",context:{bundleOwnerId:a}});if(!((l=i.data)!=null&&l.bundles)||((d=i.data)==null?void 0:d.bundles.length)===0||!((B=i.data)!=null&&B.bundles[0]))throw new Error(`Unable to find bundle: ${e}`);const o=(w=i.data)==null?void 0:w.bundles[0],s=P.getMap("bundlePartnerIds")||new Map;s.set(o.id,o.partner.id),P.setMap("bundlePartnerIds",s);const r=new KA(this,o,A,t,a);return await r.getInitializationPromise(),r}async getBundleStakeholders(){var a;if(!this.customer)throw new Error("Customer not authenticated.");const e=await H.getShadowGraphqlClient().query({query:Sn,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!((a=e.data)!=null&&a.customers)||e.data.customers.length===0)throw new Error("Unable to find customer.");const t=e.data.customers[0].bundleStakeholders||[],n=P.getMap("bundlePartnerIds")||new Map;return t.forEach(i=>{var o,s;(o=i.bundle)!=null&&o.id&&((s=i.bundle.partner)!=null&&s.id)&&n.set(i.bundle.id,i.bundle.partner.id)}),P.setMap("bundlePartnerIds",n),t}async getWorkflowExperience(e,A,t,n){var d,B,w,E,m;if(!n)return await this.getWorkflowExperienceDeprecated(e,A,t);const a=async()=>{var u,C;const h=H.getShadowGraphqlClient();if(n.type==="transaction"){const{transactionId:D,readOnly:I}=n,F=await h.query({query:Ce,variables:{ids:[D]},errorPolicy:"all",fetchPolicy:"no-cache"});if(!((u=F.data)!=null&&u.transactions)||F.data.transactions.length===0)throw new R("Existing transaction not found.");const p=(C=F.data)==null?void 0:C.transactions[0];if(!p.workflowId)throw new R("Existing transaction has no workflow ID.");const f=await Be(p.workflowId);if(!p.product)throw new R("Failed to load transaction, product not available.");return{transaction:p,workflow:f,readOnly:I}}if(n.type==="integration"||n.type==="external"){const D=async()=>{const f=n.type==="integration"?{integrationProductId:n.integrationProductId}:{externalIntegrationId:n.externalIntegrationId,externalProductId:n.externalProductId},S=await h.mutate({mutation:cA,variables:{...f,workflowId:n.workflowId,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!S.data||!S.data.transactionCreate)throw new R("Failed to create transaction!");const y=S.data.transactionCreate;if(!y.product)throw new R("Failed to create transaction, product not available.");return y},I=Be(n.workflowId,n==null?void 0:n.graphql),[F,p]=await Promise.all([D(),I]);return{transaction:F,workflow:p}}throw new R("No workflow ID provided.")},{transaction:i,workflow:o,readOnly:s}=await a();this.currencyCode=(d=i.product.partner)==null?void 0:d.currencyCode;const r={product:i.product,transaction:i,layouts:[],singleVariantsRenderable:(B=n==null?void 0:n.workflowConfiguration)==null?void 0:B.singleVariantsRenderable,stateMutationFunc:s?async()=>{throw new U("State mutation is forbidden in read only mode!")}:async h=>{const C=(P.getMap("transactionOwnerIds")||new Map).get(i.id)||void 0;return this.updateTransactionState({...h,context:{transactionOwnerId:C}})},readOnly:s,workflow:o};if(n.type==="transaction"&&i.workflowState){const h=JSON.parse(i.workflowState);r.layouts=Object.values(h.layouts).map(u=>u.layout),await c.rehydrateSerializedLayout(h),await ee(h),r.reloadedState=h}else if(!s&&n.workflowState){const h=JSON.parse(n.workflowState);r.layouts=Object.values(h.layouts).map(u=>u.layout),await c.rehydrateSerializedLayout(h),await ee(h),r.reloadedState=h}else r.layouts=je(r.transaction,r.workflow);if(r.renderableContextService=new pe(r.layouts),n.previewService?(r.previewService=n.previewService,(w=r.product)!=null&&w.modelUrl&&(r.modelContainer=r.previewService.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))):(r.previewService=t&&t(o),(E=r.product)!=null&&E.modelUrl&&(r.modelContainer=(m=r.previewService)==null?void 0:m.loadModel({model:r.product.modelUrl,contextService:r.renderableContextService}))),n.type!=="transaction"){const h=P.getMap("transactionOwnerIds")||new Map;h.set(i.id,i.transactionOwnerId),P.setMap("transactionOwnerIds",h)}else r.isReloadedTransaction=!0;this.initialized=!0,this.experienceOptions=r;const l=new ge(this,r);return await l.getWorkflowManager().getInitializationPromise(),n.type!=="transaction"&&this.customer&&await l.attachCustomerDetails({email:this.customer.emailAddress}),l}async getWorkflowExperiences(e,A){if(e.length===0)throw new R("No options provided!");const t=H.getShadowGraphqlClient(),n=e.map((C,D)=>({option:C,index:D})),a=n.filter(C=>C.option.type==="transaction"),i=n.filter(C=>C.option.type==="integration"||C.option.type==="external"),o=async()=>{var F,p;if(a.length===0)return[];const C=a.map(f=>f.option.transactionId),D=await t.query({query:Ce,variables:{ids:C},errorPolicy:"all",fetchPolicy:"no-cache"}),I=D.data.transactions;if(I.length!==a.length){const f=((p=(F=D.errors)==null?void 0:F[0])==null?void 0:p.message)||"Unknown error";throw new R(`Not all transactions were found: ${f}`)}return I.map((f,S)=>{var y;return{transaction:f,workflowId:f.workflowId,readOnly:((y=a.find(Y=>Y.option.transactionId===f.id))==null?void 0:y.option.readOnly)??!1,index:a[S].index}})},s=async()=>{var I,F,p;if(i.length===0)return[];const C=await t.mutate({mutation:ut,variables:{inputs:i.map(f=>({integrationProductId:f.option.type==="integration"?f.option.integrationProductId:void 0,externalIntegrationId:f.option.type==="external"?f.option.externalIntegrationId:void 0,externalProductId:f.option.type==="external"?f.option.externalProductId:void 0,workflowId:f.option.workflowId,claim:!0}))},errorPolicy:"all",fetchPolicy:"no-cache"}),D=(I=C.data)==null?void 0:I.transactionCreateMany;if(!D||D.length===0){const f=((p=(F=C.errors)==null?void 0:F[0])==null?void 0:p.message)||"Unknown error";throw new R(`Failed to create transactions: ${f}`)}return D.map((f,S)=>({transaction:f,workflowId:f.workflowId,readOnly:!1,index:i[S].index}))},r=(await Promise.all([o(),s()])).flat(),l=[...new Set(r.map(C=>C.workflowId))],d=await ze(l,A),B=new Map(d.map(C=>[C.id,C])),w=P.getMap("transactionOwnerIds")||new Map,E=r.map(async C=>{var G;const{transaction:D,workflowId:I,readOnly:F,index:p}=C,f=B.get(I),S=e[p];!w.get(D.id)&&D.transactionOwnerId&&w.set(D.id,D.transactionOwnerId);const y=w.get(D.id)||void 0,Y={product:D.product,transaction:D,layouts:[],singleVariantsRenderable:(G=S==null?void 0:S.workflowConfiguration)==null?void 0:G.singleVariantsRenderable,stateMutationFunc:F?async()=>{throw new U("State mutation is forbidden in read only mode!")}:async N=>this.updateTransactionState({...N,context:{transactionOwnerId:y}}),readOnly:F,workflow:f,isReloadedTransaction:S.type==="transaction"};if(S.type==="transaction"&&D.workflowState){const N=JSON.parse(D.workflowState);Y.layouts=Object.values(N.layouts).map(v=>v.layout),await c.rehydrateSerializedLayout(N),await ee(N),Y.reloadedState=N}else if(!F&&S.workflowState){const N=JSON.parse(S.workflowState);Y.layouts=Object.values(N.layouts).map(v=>v.layout),await c.rehydrateSerializedLayout(N),await ee(N),Y.reloadedState=N}else Y.layouts=je(Y.transaction,Y.workflow);return Y.renderableContextService=new pe(Y.layouts),this.initialized=!0,this.experienceOptions=Y,{experienceOptions:Y,index:p,options:S}});P.setMap("transactionOwnerIds",w);const u=(await Promise.all(E)).sort((C,D)=>C.index-D.index).map(async C=>{const{experienceOptions:D,options:I}=C,F=new ge(this,D);return await F.getWorkflowManager().getInitializationPromise(),I.type!=="transaction"&&this.customer&&await F.attachCustomerDetails({email:this.customer.emailAddress}),F});return await Promise.all(u)}async initFromIntegrationProduct(e){var i;if(e==="")throw new R("No integration product ID provided.");const t=await H.getShadowGraphqlClient().mutate({mutation:cA,variables:{integrationProductId:e,claim:!0},errorPolicy:"all",fetchPolicy:"no-cache",context:this.options.applicationKey?{headers:{"X-Application-Key":this.options.applicationKey}}:void 0});if(!t.data||!t.data.transactionCreate)throw new R("Failed to create transaction!");const n=t.data.transactionCreate;if(!n.product)throw new R("Failed to create transaction, product not available.");this.currencyCode=(i=n.product.partner)==null?void 0:i.currencyCode;const a=P.getMap("transactionOwnerIds")||new Map;a.set(n.id,n.transactionOwnerId),P.setMap("transactionOwnerIds",a),this.experienceOptions={product:n.product,transaction:n,layouts:[],stateMutationFunc:async o=>this.updateTransactionState({...o,context:{transactionOwnerId:n.transactionOwnerId}})},this.initialized=!0}async initFromTransaction(e,A=!1){var o,s,r,l;if(e==="")throw new R("No transaction ID provided.");const t=H.getShadowGraphqlClient(),n=async()=>{var w,E;const B=(w=(await t.query({query:Ce,variables:{ids:[e]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:w.transactions[0];if(!B)throw new R("Failed to read transaction.");if(!B.product)throw new R("Failed to load transaction, product not available.");this.currencyCode=(E=B.product.partner)==null?void 0:E.currencyCode,this.experienceOptions={product:B.product,transaction:B,layouts:[],stateMutationFunc:async()=>{throw new U("State mutation is forbidden in read only mode!")},readOnly:A},this.initialized=!0};if(A)return await n();const a=P.getMap("transactionOwnerIds")||new Map,i=a.get(e);if(i){const B=(o=(await t.query({query:Ce,variables:{ids:[e]},errorPolicy:"all"})).data)==null?void 0:o.transactions[0];if(!B)throw new R("Failed to read transaction.");if(!B.product)throw new R("Failed to load transaction, product not available.");this.currencyCode=(s=B.product.partner)==null?void 0:s.currencyCode,this.experienceOptions={product:B.product,transaction:B,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:i}}),readOnly:A},this.initialized=!0;return}try{const B=(r=(await t.mutate({mutation:It,variables:{id:e},errorPolicy:"all"})).data)==null?void 0:r.transactionClaim;if(!B)throw new R("Failed to read transaction.");if(!B.product)throw new R("Failed to load transaction, product not available.");this.currencyCode=(l=B.product.partner)==null?void 0:l.currencyCode,B.transactionOwnerId&&(a.set(B.id,B.transactionOwnerId),P.setMap("transactionOwnerIds",a)),this.experienceOptions={product:B.product,transaction:B,layouts:[],stateMutationFunc:async w=>this.updateTransactionState({...w,context:{transactionOwnerId:B.transactionOwnerId}}),readOnly:A},this.initialized=!0}catch{throw new R("Attempted to access a transaction that isn't available.")}}async getWorkflowExperienceDeprecated(e,A,t){var n,a,i,o;if(!this.initialized||!this.experienceOptions)throw new R("Cannot launch experience: Not initialized.");if(this.experienceOptions.transaction.workflowId){const s=await Be(this.experienceOptions.transaction.workflowId);if(this.experienceOptions.workflow=s,this.experienceOptions.transaction.workflowState){const l=JSON.parse(this.experienceOptions.transaction.workflowState);this.experienceOptions.layouts=Object.values(l.layouts).map(d=>d.layout),await c.rehydrateSerializedLayout(l),await ee(l),this.experienceOptions.reloadedState=l}this.experienceOptions.previewService=t&&t(s),this.experienceOptions.renderableContextService=new pe(this.experienceOptions.layouts),(n=this.experienceOptions.product)!=null&&n.modelUrl&&(this.experienceOptions.modelContainer=(a=this.experienceOptions.previewService)==null?void 0:a.loadModel({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}));const r=new ge(this,this.experienceOptions);return await r.getWorkflowManager().getInitializationPromise(),r}if(e){const r=(P.getMap("transactionOwnerIds")||new Map).get(this.experienceOptions.transaction.id),l=H.getShadowGraphqlClient().mutate({mutation:Dt,variables:{workflowId:e,id:this.experienceOptions.transaction.id},context:{transactionOwnerId:r}}),d=Be(e);if(await Promise.all([l,d]),this.experienceOptions.workflow=await d,A){const w=JSON.parse(A);this.experienceOptions.layouts=Object.values(w.layouts).map(E=>E.layout),await c.rehydrateSerializedLayout(w),await ee(w),this.experienceOptions.reloadedState=w}else this.experienceOptions.layouts=je(this.experienceOptions.transaction,this.experienceOptions.workflow);this.experienceOptions.previewService=t&&t(await d),this.experienceOptions.renderableContextService=new pe(this.experienceOptions.layouts),(i=this.experienceOptions.product)!=null&&i.modelUrl&&(this.experienceOptions.modelContainer=(o=this.experienceOptions.previewService)==null?void 0:o.loadModel({model:this.experienceOptions.product.modelUrl,contextService:this.experienceOptions.renderableContextService}));const B=new ge(this,this.experienceOptions);return await B.getWorkflowManager().getInitializationPromise(),B}throw new R("No workflow ID provided.")}getPreviewService(){var e;return(e=this.experienceOptions)==null?void 0:e.previewService}getProduct(){if(!this.initialized||!this.experienceOptions)throw new R("Cannot get product: Not initialized.");return this.experienceOptions.product}getTransaction(){if(!this.initialized||!this.experienceOptions)throw new R("Cannot get transaction: Not initialized.");return this.experienceOptions.transaction}storeCustomer(e){const A=P.getMap("partnerCustomerIds")||new Map;A.set(e.partner.id,e.id),P.setMap("partnerCustomerIds",A)}}class ca{getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}async reset(){}updateStateWithServer(e){}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(e){}addPoller(e){}addConfirmCallback(e){}addEditedCallback(e){}addElementsCallback(e){}addInformationResultCallback(e){}addInitCallback(e){}addMakingAdjustmentsCallback(e){}addMandatoryCallback(e){}addMetadataCallback(e){}addSelectionCallback(e){}addStepSpecificStorageCallback(e,A){}addStorageCallback(e){}getCommandDispatcher(){return e=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(e){return[]}getSerializedStep(e,A){}getStepSpecificServices(e){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(e){}markUpdateCompleted(e){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}setCurrentAdjustingStepId(e){}setEditedStatus(e,A){}setInformationResults(e){}setMandatoryFulfilled(e,A){}async setSelectionsAndElements(e,A,t){}toggleDesignConfirmed(){}updateMetadata(e,A){}async updateStorage(e,A){}injectIntoPreviewService(e){return Promise.resolve()}ejectFromPreviewService(){}}var ZA=(g=>(g.SelectFrame="SelectFrame",g.SelectImage="SelectImage",g.Position="Position",g))(ZA||{});class $A extends O{constructor(e,A){var t;super(e,A),this.frameService=(t=this.manager.getStepSpecificServices(this.getId()))==null?void 0:t.frameService}selectVariant(e){const A=this.manager.getRegionElements(this.step.stepName);return me.selectVariant(this.step,e.getResource(),A,this.manager,t=>this.setUpdateState(t))}onFrameDataChanged(e){this.frameService&&this.frameService.onFrameDataChanged(A=>{A&&e(A)})}selectImage(e){return me.selectImage(this.step,e,this.manager)}getImageData(){if(this.frameService)return this.frameService.getImageData()}getCurrentFrameStep(e,A,t,n){return n&&n.length>1&&e===void 0?"SelectFrame":A||t||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}}Object.defineProperty(Q,"AssetType",{enumerable:!0,get:()=>c.AssetType}),Object.defineProperty(Q,"BringForwardCommand",{enumerable:!0,get:()=>c.BringForwardCommand}),Object.defineProperty(Q,"BringToBackCommand",{enumerable:!0,get:()=>c.BringToBackCommand}),Object.defineProperty(Q,"BringToFrontCommand",{enumerable:!0,get:()=>c.BringToFrontCommand}),Object.defineProperty(Q,"CanvasCommand",{enumerable:!0,get:()=>c.CanvasCommand}),Object.defineProperty(Q,"CommandContext",{enumerable:!0,get:()=>c.CommandContext}),Object.defineProperty(Q,"CreateElementCommand",{enumerable:!0,get:()=>c.CreateElementCommand}),Object.defineProperty(Q,"CreateLayoutCommand",{enumerable:!0,get:()=>c.CreateLayoutCommand}),Object.defineProperty(Q,"DeleteElementCommand",{enumerable:!0,get:()=>c.DeleteElementCommand}),Object.defineProperty(Q,"FontAlignmentCommand",{enumerable:!0,get:()=>c.FontAlignmentCommand}),Object.defineProperty(Q,"FontColorCommand",{enumerable:!0,get:()=>c.FontColorCommand}),Object.defineProperty(Q,"FontSizeCommand",{enumerable:!0,get:()=>c.FontSizeCommand}),Object.defineProperty(Q,"FontSourceCommand",{enumerable:!0,get:()=>c.FontSourceCommand}),Object.defineProperty(Q,"GroupCommand",{enumerable:!0,get:()=>c.GroupCommand}),Object.defineProperty(Q,"LayoutElementFactory",{enumerable:!0,get:()=>c.LayoutElementFactory}),Object.defineProperty(Q,"LayoutElementType",{enumerable:!0,get:()=>c.LayoutElementType}),Object.defineProperty(Q,"MoveCommand",{enumerable:!0,get:()=>c.MoveCommand}),Object.defineProperty(Q,"ResizeCommand",{enumerable:!0,get:()=>c.ResizeCommand}),Object.defineProperty(Q,"RotateCommand",{enumerable:!0,get:()=>c.RotateCommand}),Object.defineProperty(Q,"SendBackwardsCommand",{enumerable:!0,get:()=>c.SendBackwardsCommand}),Object.defineProperty(Q,"StepAspectType",{enumerable:!0,get:()=>c.StepAspectType}),Object.defineProperty(Q,"StepType",{enumerable:!0,get:()=>c.StepType}),Object.defineProperty(Q,"TextChangeCommand",{enumerable:!0,get:()=>c.TextChangeCommand}),Object.defineProperty(Q,"UnitOfMeasurement",{enumerable:!0,get:()=>c.UnitOfMeasurement}),Object.defineProperty(Q,"dataUrlFromExternalUrl",{enumerable:!0,get:()=>c.dataUrlFromExternalUrl}),Object.defineProperty(Q,"determineCorrectFontSizeAndLines",{enumerable:!0,get:()=>c.determineCorrectFontSizeAndLines}),Object.defineProperty(Q,"findElement",{enumerable:!0,get:()=>c.findElement}),Object.defineProperty(Q,"frameDataCache",{enumerable:!0,get:()=>c.frameDataCache}),Object.defineProperty(Q,"generate",{enumerable:!0,get:()=>c.generate}),Object.defineProperty(Q,"generateSVGWithUnknownColors",{enumerable:!0,get:()=>c.generateSVGWithUnknownColors}),Object.defineProperty(Q,"getAttributesFromArrayBuffer",{enumerable:!0,get:()=>c.getAttributesFromArrayBuffer}),Object.defineProperty(Q,"getAxisAlignedBoundingBox",{enumerable:!0,get:()=>c.getAxisAlignedBoundingBox}),Object.defineProperty(Q,"getFrameData",{enumerable:!0,get:()=>c.getFrameData}),Object.defineProperty(Q,"getSvgElement",{enumerable:!0,get:()=>c.getSvgElement}),Object.defineProperty(Q,"loadFont",{enumerable:!0,get:()=>c.loadFont}),Object.defineProperty(Q,"patternImageDataCache",{enumerable:!0,get:()=>c.patternImageDataCache}),Object.defineProperty(Q,"registerFetchImplementation",{enumerable:!0,get:()=>c.registerFetchImplementation}),Object.defineProperty(Q,"registerWindowImplementation",{enumerable:!0,get:()=>c.registerWindowImplementation}),Object.defineProperty(Q,"rehydrateSerializedLayout",{enumerable:!0,get:()=>c.rehydrateSerializedLayout}),Object.defineProperty(Q,"setCanvasModule",{enumerable:!0,get:()=>c.setCanvasModule}),Q.AssetNotFoundError=j,Q.CollectionProduct=OA,Q.ConversionDataType=rA,Q.ConversionLocation=sA,Q.FlowExecutionNodeResult=le,Q.FlowExecutionResult=WA,Q.FlowService=VA,Q.FrameService=BA,Q.FrameStep=ZA,Q.FrameStepHandle=$A,Q.GlobalPropertyHandle=Fe,Q.IllustrationStepHandle=SA,Q.InformationMessageType=ce,Q.InformationStepHandle=RA,Q.IntegrationType=iA,Q.LayoutNotFoundError=k,Q.MaterialStepHandle=YA,Q.MisconfigurationError=ne,Q.MockWorkflowManager=ca,Q.ModelStepHandle=yA,Q.ObjectInput=Oe,Q.ObjectInputType=XA,Q.OptionNotFoundError=te,Q.ParseError=X,Q.PictureStepHandle=PA,Q.ProductCameraRig=oA,Q.ProductCollection=LA,Q.ProductWorkflow=Le,Q.PromiseCache=q,Q.PromiseQueue=Ne,Q.QuestionStepHandle=NA,Q.QueueablePromise=Pe,Q.ResourceNotFoundError=W,Q.ShapeStepHandle=HA,Q.SpiffCommerceClient=qA,Q.StakeholderType=oe,Q.StepHandle=O,Q.TextStepHandle=xA,Q.Transform=jA,Q.TransformCollection=zA,Q.UnhandledBehaviorError=U,Q.Variant=z,Q.WorkflowExperienceImpl=ge,Q.assetService=b,Q.createDesign=kA,Q.designService=De,Q.digitalContentStepService=hA,Q.frameStepService=me,Q.generateCommands=bA,Q.generateStateFromDesignInputSteps=fn,Q.getBoundedOffsets=lA,Q.getWorkflow=Be,Q.getWorkflows=ze,Q.graphQlManager=H,Q.illustrationStepService=re,Q.materialStepService=He,Q.modelStepService=xe,Q.moduleStepService=CA,Q.optionService=J,Q.persistenceService=P,Q.pictureStepService=Re,Q.questionStepService=Ue,Q.shapeStepService=_,Q.shortenUrl=wA,Q.spiffCoreConfiguration=ae,Q.stepAspectValuesToDesignInputSteps=In,Q.textStepService=T,Q.toast=QA,Object.defineProperty(Q,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/core",
3
- "version": "17.5.0",
3
+ "version": "17.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.umd.cjs",