@spiffcommerce/core 16.10.2 → 16.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +86 -82
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -119,7 +119,7 @@ const Gt = () => {
|
|
|
119
119
|
} catch {
|
|
120
120
|
return console.warn("Local storage was unavilable due to browser security settings. Using in-memory storage instead."), new EA();
|
|
121
121
|
}
|
|
122
|
-
},
|
|
122
|
+
}, S = Gt();
|
|
123
123
|
class vt {
|
|
124
124
|
constructor() {
|
|
125
125
|
this.defaultServerUrl = "https://api.spiff.com.au", this.defaultServicesApiUrl = "https://services.spiff.com.au", this.defaultHubUrl = "https://hub.spiff.com.au", this.serverUrl = this.defaultServerUrl, this.servicesApiUrl = this.defaultServicesApiUrl, this.hubUrl = this.defaultHubUrl, this.serverUrlCallbacks = [];
|
|
@@ -510,27 +510,27 @@ class Je {
|
|
|
510
510
|
}
|
|
511
511
|
const A = /* @__PURE__ */ new Map();
|
|
512
512
|
A.set(e.key || "", e.fileLink);
|
|
513
|
-
const t =
|
|
513
|
+
const t = S.getMap(ne);
|
|
514
514
|
t && t.forEach((a, n) => {
|
|
515
515
|
A.set(n, a);
|
|
516
|
-
}),
|
|
516
|
+
}), S.setMap(ne, A);
|
|
517
517
|
}
|
|
518
518
|
/**
|
|
519
519
|
* Remove an existing asset from persistence. Noop if the asset doesn't exist.
|
|
520
520
|
* @param assetKey The key to remove.
|
|
521
521
|
*/
|
|
522
522
|
static remove(e) {
|
|
523
|
-
const A =
|
|
523
|
+
const A = S.getMap(ne);
|
|
524
524
|
if (!A)
|
|
525
525
|
return;
|
|
526
526
|
const t = Array.from(A.entries()).find((a) => a[0] === e);
|
|
527
|
-
t && (A.delete(t[0]),
|
|
527
|
+
t && (A.delete(t[0]), S.setMap(ne, A));
|
|
528
528
|
}
|
|
529
529
|
/**
|
|
530
530
|
* Get a list of all persisted assets.
|
|
531
531
|
*/
|
|
532
532
|
static list() {
|
|
533
|
-
const e =
|
|
533
|
+
const e = S.getMap(ne);
|
|
534
534
|
return e ? Array.from(e.entries()).map((A) => ({ assetKey: A[0], src: A[1] })) : [];
|
|
535
535
|
}
|
|
536
536
|
}
|
|
@@ -3343,10 +3343,10 @@ class Na {
|
|
|
3343
3343
|
D.push(
|
|
3344
3344
|
this.generateTextChangeCommandsForRegion(Y, t, p.id, U, i)
|
|
3345
3345
|
);
|
|
3346
|
-
const
|
|
3347
|
-
return
|
|
3346
|
+
const x = new J(p, E);
|
|
3347
|
+
return x.varying = i, {
|
|
3348
3348
|
regionElement: { id: C, region: l },
|
|
3349
|
-
commands: [
|
|
3349
|
+
commands: [x, ...D],
|
|
3350
3350
|
newElement: p,
|
|
3351
3351
|
fontData: a
|
|
3352
3352
|
};
|
|
@@ -4886,7 +4886,7 @@ class ka extends nA {
|
|
|
4886
4886
|
const Y = R("g");
|
|
4887
4887
|
p.appendChild(Y), Y.setAttribute("fill", "#9d2621"), Y.setAttribute("transform", "translate(1,1)"), Y.innerHTML = t;
|
|
4888
4888
|
const M = R("g");
|
|
4889
|
-
return p.appendChild(M), M.setAttribute("fill", "yellow"), M.innerHTML = t, new oA(p).transform(([
|
|
4889
|
+
return p.appendChild(M), M.setAttribute("fill", "yellow"), M.innerHTML = t, new oA(p).transform(([x, b]) => [x, b + (n / 2 - x) ** 2 / (n * 2.9)]), p;
|
|
4890
4890
|
}, [o, r, c] = $A(A);
|
|
4891
4891
|
if (!o)
|
|
4892
4892
|
return "";
|
|
@@ -4928,10 +4928,10 @@ class Ja extends nA {
|
|
|
4928
4928
|
const M = R("g");
|
|
4929
4929
|
m.appendChild(M), M.setAttribute("fill", "white"), M.innerHTML = a;
|
|
4930
4930
|
const U = new oA(m);
|
|
4931
|
-
return U.transform(([
|
|
4932
|
-
|
|
4933
|
-
b + (i / 3 -
|
|
4934
|
-
]), U.transform(([
|
|
4931
|
+
return U.transform(([x, b]) => [x, b + ((i - x) * b) ** 2 / (i * 5e4)]), U.transform(([x, b]) => [
|
|
4932
|
+
x,
|
|
4933
|
+
b + (i / 3 - x) ** 2 / i * this.indicator(x < i / 3)
|
|
4934
|
+
]), U.transform(([x, b]) => [x - (s - b) * (i - x) / 800, b]), m;
|
|
4935
4935
|
}, [c, B, l] = $A(A);
|
|
4936
4936
|
if (!c)
|
|
4937
4937
|
return "";
|
|
@@ -4978,7 +4978,7 @@ class La extends nA {
|
|
|
4978
4978
|
const F = R("g");
|
|
4979
4979
|
F.classList.add("module-layer2"), u.appendChild(F), F.setAttribute("fill", "rgb(255,209,0)"), F.setAttribute("transform", "translate(1,-0.1)"), F.innerHTML = i;
|
|
4980
4980
|
const Y = R("g");
|
|
4981
|
-
return Y.classList.add("module-layer3"), u.appendChild(Y), Y.setAttribute("fill", "white"), Y.innerHTML = i, new oA(u).transform(([U,
|
|
4981
|
+
return Y.classList.add("module-layer3"), u.appendChild(Y), Y.setAttribute("fill", "white"), Y.innerHTML = i, new oA(u).transform(([U, x]) => [U, x + (r / 2 - U) ** 2 / (r * 6)]), u;
|
|
4982
4982
|
}, l = R("g");
|
|
4983
4983
|
l.classList.add("module-root");
|
|
4984
4984
|
const d = R("defs");
|
|
@@ -5855,7 +5855,7 @@ class ja extends W {
|
|
|
5855
5855
|
throw new Error("Bulk step does not support variants.");
|
|
5856
5856
|
}
|
|
5857
5857
|
async setDesignName(e) {
|
|
5858
|
-
const t = (
|
|
5858
|
+
const t = (S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map()).get(this.manager.getTransaction().id);
|
|
5859
5859
|
await N.getShadowGraphqlClient().mutate({
|
|
5860
5860
|
mutation: Ka,
|
|
5861
5861
|
variables: {
|
|
@@ -5886,7 +5886,7 @@ class ja extends W {
|
|
|
5886
5886
|
window.open(this.transaction.bulkSourceUrl, "_blank");
|
|
5887
5887
|
}
|
|
5888
5888
|
async sendGoogleSheetLinkToEmail(e) {
|
|
5889
|
-
const t = (
|
|
5889
|
+
const t = (S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map()).get(this.manager.getTransaction().id);
|
|
5890
5890
|
await N.getShadowGraphqlClient().mutate({
|
|
5891
5891
|
mutation: nt,
|
|
5892
5892
|
variables: { id: this.transaction.id, details: { emailAddress: e }, type: "Owner" },
|
|
@@ -6476,7 +6476,7 @@ const st = y`
|
|
|
6476
6476
|
}
|
|
6477
6477
|
return a;
|
|
6478
6478
|
}, it = (g, e, A, t, a, n, s, i, o, r) => {
|
|
6479
|
-
const B = (
|
|
6479
|
+
const B = (S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map()).get(g.id), l = {
|
|
6480
6480
|
baseCost: A,
|
|
6481
6481
|
designProductId: g.externalDesignProductId,
|
|
6482
6482
|
designProductVariantId: g.externalDesignProductVariantId,
|
|
@@ -6534,7 +6534,7 @@ const st = y`
|
|
|
6534
6534
|
if (r !== void 0)
|
|
6535
6535
|
return r;
|
|
6536
6536
|
await g.outstandingRequestsPromise();
|
|
6537
|
-
const M = (
|
|
6537
|
+
const M = (S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map()).get(a.id), x = await N.getShadowGraphqlClient().query({
|
|
6538
6538
|
query: OA,
|
|
6539
6539
|
variables: { ids: [a.id] },
|
|
6540
6540
|
fetchPolicy: "no-cache",
|
|
@@ -6542,17 +6542,17 @@ const st = y`
|
|
|
6542
6542
|
context: {
|
|
6543
6543
|
transactionOwnerId: M
|
|
6544
6544
|
}
|
|
6545
|
-
}), b = (K =
|
|
6546
|
-
return
|
|
6547
|
-
|
|
6545
|
+
}), b = (K = x.data) == null ? void 0 : K.transactions[0].workflowState;
|
|
6546
|
+
return x.errors ? (x.errors.forEach((j) => {
|
|
6547
|
+
x.errors && console.log("Server Error:", j.message);
|
|
6548
6548
|
}), null) : b ?? null;
|
|
6549
6549
|
})() || (console.warn("State mismatch detected. Uploading known state explicitly"), console.warn("State Object:", JSON.stringify(t())), await g.updateStateWithServerImmediate(t), console.log("Server state is undefined @ Workflow completion"));
|
|
6550
6550
|
const l = g.getPreviewService(), d = (F = e == null ? void 0 : e.finalizeStepConfig) == null ? void 0 : F.lookAtAnimation, E = l && e.showModelOnFinishStep && !!d, C = o && qe(o, e, !0), w = o && qe(o, e, !1), Q = async (Y) => {
|
|
6551
6551
|
const M = {};
|
|
6552
6552
|
let U = 0;
|
|
6553
6553
|
if (Object.keys(n).length > 0)
|
|
6554
|
-
for (const
|
|
6555
|
-
const b = n[
|
|
6554
|
+
for (const x of Object.keys(n)) {
|
|
6555
|
+
const b = n[x], K = e.steps.find((j) => j.stepName === x);
|
|
6556
6556
|
for (let j = 0; j < b.selections.length; ++j) {
|
|
6557
6557
|
const q = b.selections[j];
|
|
6558
6558
|
if (K && (!Y || K.option && (K.option.variants || []).length > 1 && !K.data.hideSelectionInCart && !K.data.hideSelectionsInCart)) {
|
|
@@ -6596,14 +6596,14 @@ const st = y`
|
|
|
6596
6596
|
};
|
|
6597
6597
|
if (w) {
|
|
6598
6598
|
const M = [];
|
|
6599
|
-
for (const [U,
|
|
6600
|
-
M.push({ key: U, value:
|
|
6599
|
+
for (const [U, x] of Object.entries(w))
|
|
6600
|
+
M.push({ key: U, value: x });
|
|
6601
6601
|
Y.metadata = M;
|
|
6602
6602
|
}
|
|
6603
6603
|
if (u) {
|
|
6604
6604
|
const M = [];
|
|
6605
|
-
for (const [U,
|
|
6606
|
-
M.push({ key: U, ids:
|
|
6605
|
+
for (const [U, x] of Object.entries(p))
|
|
6606
|
+
M.push({ key: U, ids: x });
|
|
6607
6607
|
Y.selectedVariants = M;
|
|
6608
6608
|
}
|
|
6609
6609
|
return Y;
|
|
@@ -6721,7 +6721,7 @@ class gn {
|
|
|
6721
6721
|
*/
|
|
6722
6722
|
async getSavedDesigns() {
|
|
6723
6723
|
if (this.storageMethod === "Local") {
|
|
6724
|
-
const e =
|
|
6724
|
+
const e = S.get(this.localPersistenceKey);
|
|
6725
6725
|
return e ? JSON.parse(e) : [];
|
|
6726
6726
|
}
|
|
6727
6727
|
throw new v("Unexpected storage method requested");
|
|
@@ -6761,7 +6761,7 @@ class gn {
|
|
|
6761
6761
|
}
|
|
6762
6762
|
async setDesigns(e) {
|
|
6763
6763
|
if (this.storageMethod === "Local") {
|
|
6764
|
-
|
|
6764
|
+
S.set(this.localPersistenceKey, JSON.stringify(e));
|
|
6765
6765
|
return;
|
|
6766
6766
|
}
|
|
6767
6767
|
throw new v("Unexpected storage method requested");
|
|
@@ -6837,18 +6837,22 @@ class he {
|
|
|
6837
6837
|
return this.workflowManager;
|
|
6838
6838
|
}
|
|
6839
6839
|
async updateVariationRecords(e) {
|
|
6840
|
+
const t = (S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map()).get(this.workflowManager.getTransaction().id);
|
|
6840
6841
|
await N.getShadowGraphqlClient().mutate({
|
|
6841
6842
|
mutation: ca,
|
|
6842
6843
|
variables: {
|
|
6843
6844
|
transactionId: this.workflowManager.getTransaction().id,
|
|
6844
|
-
updates: e.map((
|
|
6845
|
-
recordNumber:
|
|
6846
|
-
values:
|
|
6847
|
-
aspect:
|
|
6848
|
-
stepName:
|
|
6849
|
-
value:
|
|
6845
|
+
updates: e.map((a) => ({
|
|
6846
|
+
recordNumber: a.recordNumber,
|
|
6847
|
+
values: a.values.map((n) => ({
|
|
6848
|
+
aspect: n.aspect,
|
|
6849
|
+
stepName: n.stepName,
|
|
6850
|
+
value: n.value
|
|
6850
6851
|
}))
|
|
6851
6852
|
}))
|
|
6853
|
+
},
|
|
6854
|
+
context: {
|
|
6855
|
+
transactionOwnerId: t
|
|
6852
6856
|
}
|
|
6853
6857
|
});
|
|
6854
6858
|
}
|
|
@@ -6960,7 +6964,7 @@ class he {
|
|
|
6960
6964
|
}
|
|
6961
6965
|
async assignCustomerDetails(e) {
|
|
6962
6966
|
var s, i, o;
|
|
6963
|
-
const t = (
|
|
6967
|
+
const t = (S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map()).get(this.getWorkflowManager().getTransaction().id), n = (o = (i = (s = (await N.getShadowGraphqlClient().mutate({
|
|
6964
6968
|
mutation: nt,
|
|
6965
6969
|
variables: {
|
|
6966
6970
|
id: this.getWorkflowManager().getTransaction().id,
|
|
@@ -6978,8 +6982,8 @@ class he {
|
|
|
6978
6982
|
);
|
|
6979
6983
|
if (n != null && n.customer) {
|
|
6980
6984
|
this.getWorkflowManager().setTransactionCustomer(n.customer);
|
|
6981
|
-
const r =
|
|
6982
|
-
r.set(this.getWorkflowManager().getTransaction().id, n.customer.id),
|
|
6985
|
+
const r = S.getMap("transactionCustomerIds") || /* @__PURE__ */ new Map();
|
|
6986
|
+
r.set(this.getWorkflowManager().getTransaction().id, n.customer.id), S.setMap("transactionCustomerIds", r);
|
|
6983
6987
|
}
|
|
6984
6988
|
}
|
|
6985
6989
|
attachRenderableSceneListener(e) {
|
|
@@ -7178,13 +7182,13 @@ const ln = [
|
|
|
7178
7182
|
ln.includes(m.tagName) && !m.attributes.getNamedItem("fill") && m.setAttribute("fill", "#000000");
|
|
7179
7183
|
const F = m.attributes.getNamedItem("fill");
|
|
7180
7184
|
if (F && F.value !== "none") {
|
|
7181
|
-
const M = F.value,
|
|
7182
|
-
m.classList.add(
|
|
7185
|
+
const M = F.value, x = `spiff-fill-${M.replace(/\W/g, "")}`;
|
|
7186
|
+
m.classList.add(x), C[x] = { browserValue: M };
|
|
7183
7187
|
}
|
|
7184
7188
|
const Y = m.attributes.getNamedItem("stroke");
|
|
7185
7189
|
if (Y && Y.value !== "none") {
|
|
7186
|
-
const M = Y.value,
|
|
7187
|
-
m.classList.add(
|
|
7190
|
+
const M = Y.value, x = `spiff-stroke-${M.replace(/\W/g, "")}`;
|
|
7191
|
+
m.classList.add(x), C[x] = { browserValue: M };
|
|
7188
7192
|
}
|
|
7189
7193
|
});
|
|
7190
7194
|
const Q = PA().serializeToString(E), h = a.colors;
|
|
@@ -8712,7 +8716,7 @@ class IA {
|
|
|
8712
8716
|
throw new Error(
|
|
8713
8717
|
"Unable to add transaction to bundle - Already Exists: " + t.filter((s) => !!s).map((s) => s == null ? void 0 : s.getWorkflowManager().getTransaction().id).join(", ")
|
|
8714
8718
|
);
|
|
8715
|
-
const a =
|
|
8719
|
+
const a = S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map(), n = A.map((s) => a.get(s));
|
|
8716
8720
|
await N.getShadowGraphqlClient().mutate({
|
|
8717
8721
|
mutation: Un,
|
|
8718
8722
|
variables: {
|
|
@@ -8741,7 +8745,7 @@ class IA {
|
|
|
8741
8745
|
(i) => i.getWorkflowManager().getTransaction().id === t
|
|
8742
8746
|
))
|
|
8743
8747
|
throw new Error("Unable to add transaction to bundle - Already Exists!");
|
|
8744
|
-
const s = (
|
|
8748
|
+
const s = (S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map()).get(t);
|
|
8745
8749
|
await N.getShadowGraphqlClient().mutate({
|
|
8746
8750
|
mutation: Hn,
|
|
8747
8751
|
variables: {
|
|
@@ -9950,12 +9954,12 @@ class ms {
|
|
|
9950
9954
|
*/
|
|
9951
9955
|
async authenticateBundleFromLocalStorage(e) {
|
|
9952
9956
|
var a, n;
|
|
9953
|
-
const A =
|
|
9957
|
+
const A = S.getMap("bundleOwnerIds");
|
|
9954
9958
|
if (A != null && A.has(e))
|
|
9955
9959
|
return Promise.resolve({ success: !0, stakeholderType: xe.Owner });
|
|
9956
|
-
const t =
|
|
9960
|
+
const t = S.getMap("bundlePartnerIds") || /* @__PURE__ */ new Map();
|
|
9957
9961
|
if (t.has(e)) {
|
|
9958
|
-
const s = t.get(e), o = (
|
|
9962
|
+
const s = t.get(e), o = (S.getMap("partnerCustomerIds") || /* @__PURE__ */ new Map()).get(s);
|
|
9959
9963
|
if (o && await this.authenticateCustomerId(o)) {
|
|
9960
9964
|
const c = (n = (a = this.customer) == null ? void 0 : a.bundleStakeholders) == null ? void 0 : n.find(
|
|
9961
9965
|
(B) => {
|
|
@@ -9999,10 +10003,10 @@ class ms {
|
|
|
9999
10003
|
throw new Error(`Unable to read transaction: ${e}`);
|
|
10000
10004
|
if (a.isOrdered)
|
|
10001
10005
|
return Promise.resolve({ success: !1, transactionReadOnly: !0 });
|
|
10002
|
-
const s =
|
|
10006
|
+
const s = S.getMap("transactionOwnerIds");
|
|
10003
10007
|
if (s != null && s.has(e))
|
|
10004
10008
|
return Promise.resolve({ success: !0, stakeholderType: xe.Owner });
|
|
10005
|
-
const i =
|
|
10009
|
+
const i = S.getMap("transactionCustomerIds");
|
|
10006
10010
|
if (i != null && i.has(e)) {
|
|
10007
10011
|
const w = i.get(e);
|
|
10008
10012
|
if (w && await this.authenticateCustomerId(w)) {
|
|
@@ -10043,8 +10047,8 @@ class ms {
|
|
|
10043
10047
|
this.customer = void 0;
|
|
10044
10048
|
}
|
|
10045
10049
|
clearCustomerForTransaction(e) {
|
|
10046
|
-
const A =
|
|
10047
|
-
A != null && A.has(e) && (A.delete(e),
|
|
10050
|
+
const A = S.getMap("transactionCustomerIds");
|
|
10051
|
+
A != null && A.has(e) && (A.delete(e), S.setMap("transactionCustomerIds", A));
|
|
10048
10052
|
}
|
|
10049
10053
|
getStakeholderTypeForTransaction(e) {
|
|
10050
10054
|
var t, a;
|
|
@@ -10095,7 +10099,7 @@ class ms {
|
|
|
10095
10099
|
}
|
|
10096
10100
|
async authenticateCustomerId(e) {
|
|
10097
10101
|
var i;
|
|
10098
|
-
const A = N.getShadowGraphqlClient(), t =
|
|
10102
|
+
const A = N.getShadowGraphqlClient(), t = S.getMap("customerTokens");
|
|
10099
10103
|
if (!(t != null && t.has(e)))
|
|
10100
10104
|
return !1;
|
|
10101
10105
|
const a = t.get(e);
|
|
@@ -10143,8 +10147,8 @@ class ms {
|
|
|
10143
10147
|
if (a != null && a.loginToken) {
|
|
10144
10148
|
if (!((s = a.partner) != null && s.id))
|
|
10145
10149
|
throw new Error(`Unable to find customer: ${e}`);
|
|
10146
|
-
const i =
|
|
10147
|
-
return i.set(a.id, a.loginToken),
|
|
10150
|
+
const i = S.getMap("customerTokens") || /* @__PURE__ */ new Map();
|
|
10151
|
+
return i.set(a.id, a.loginToken), S.setMap("customerTokens", i), this.storeCustomer(a), hA(a.loginToken), this.customer = {
|
|
10148
10152
|
...a,
|
|
10149
10153
|
loginToken: void 0
|
|
10150
10154
|
}, !0;
|
|
@@ -10166,10 +10170,10 @@ class ms {
|
|
|
10166
10170
|
})).data) == null ? void 0 : s.bundleCreate;
|
|
10167
10171
|
if (!(t != null && t.id))
|
|
10168
10172
|
throw new Error("Unable to create bundle");
|
|
10169
|
-
const a =
|
|
10170
|
-
a.set(t.id, t.partner.id),
|
|
10171
|
-
const n =
|
|
10172
|
-
return n.set(t.id, t.bundleOwnerId),
|
|
10173
|
+
const a = S.getMap("bundlePartnerIds") || /* @__PURE__ */ new Map();
|
|
10174
|
+
a.set(t.id, t.partner.id), S.setMap("bundlePartnerIds", a);
|
|
10175
|
+
const n = S.getMap("bundleOwnerIds") || /* @__PURE__ */ new Map();
|
|
10176
|
+
return n.set(t.id, t.bundleOwnerId), S.setMap("bundleOwnerIds", n), new IA(this, t, void 0, void 0, t.bundleOwnerId);
|
|
10173
10177
|
}
|
|
10174
10178
|
/**
|
|
10175
10179
|
* Retrieves an existing bundle from the API, by id.
|
|
@@ -10180,7 +10184,7 @@ class ms {
|
|
|
10180
10184
|
*/
|
|
10181
10185
|
async getExistingBundle(e, A, t) {
|
|
10182
10186
|
var c, B, l, d;
|
|
10183
|
-
const a =
|
|
10187
|
+
const a = S.getMap("bundleOwnerIds"), n = a == null ? void 0 : a.get(e), s = await N.getShadowGraphqlClient().query({
|
|
10184
10188
|
query: Sn,
|
|
10185
10189
|
variables: {
|
|
10186
10190
|
id: e
|
|
@@ -10192,8 +10196,8 @@ class ms {
|
|
|
10192
10196
|
});
|
|
10193
10197
|
if (!((c = s.data) != null && c.bundles) || ((B = s.data) == null ? void 0 : B.bundles.length) === 0 || !((l = s.data) != null && l.bundles[0]))
|
|
10194
10198
|
throw new Error(`Unable to find bundle: ${e}`);
|
|
10195
|
-
const i = (d = s.data) == null ? void 0 : d.bundles[0], o =
|
|
10196
|
-
o.set(i.id, i.partner.id),
|
|
10199
|
+
const i = (d = s.data) == null ? void 0 : d.bundles[0], o = S.getMap("bundlePartnerIds") || /* @__PURE__ */ new Map();
|
|
10200
|
+
o.set(i.id, i.partner.id), S.setMap("bundlePartnerIds", o);
|
|
10197
10201
|
const r = new IA(this, i, A, t, n);
|
|
10198
10202
|
return await r.getInitializationPromise(), r;
|
|
10199
10203
|
}
|
|
@@ -10214,11 +10218,11 @@ class ms {
|
|
|
10214
10218
|
});
|
|
10215
10219
|
if (!((n = e.data) != null && n.customers) || e.data.customers.length === 0)
|
|
10216
10220
|
throw new Error("Unable to find customer.");
|
|
10217
|
-
const t = e.data.customers[0].bundleStakeholders || [], a =
|
|
10221
|
+
const t = e.data.customers[0].bundleStakeholders || [], a = S.getMap("bundlePartnerIds") || /* @__PURE__ */ new Map();
|
|
10218
10222
|
return t.forEach((s) => {
|
|
10219
10223
|
var i, o;
|
|
10220
10224
|
(i = s.bundle) != null && i.id && ((o = s.bundle.partner) != null && o.id) && a.set(s.bundle.id, s.bundle.partner.id);
|
|
10221
|
-
}),
|
|
10225
|
+
}), S.setMap("bundlePartnerIds", a), t;
|
|
10222
10226
|
}
|
|
10223
10227
|
/**
|
|
10224
10228
|
* Creates a new instance of WorkflowExperience. A high level wrapper for workflows.
|
|
@@ -10292,7 +10296,7 @@ class ms {
|
|
|
10292
10296
|
stateMutationFunc: o ? async () => {
|
|
10293
10297
|
throw new v("State mutation is forbidden in read only mode!");
|
|
10294
10298
|
} : async (w) => {
|
|
10295
|
-
const h = (
|
|
10299
|
+
const h = (S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map()).get(s.id) || void 0;
|
|
10296
10300
|
return this.updateTransactionState({ ...w, context: { transactionOwnerId: h } });
|
|
10297
10301
|
},
|
|
10298
10302
|
readOnly: o,
|
|
@@ -10318,8 +10322,8 @@ class ms {
|
|
|
10318
10322
|
model: r.product.modelUrl,
|
|
10319
10323
|
contextService: r.renderableContextService
|
|
10320
10324
|
}))), a.type !== "transaction") {
|
|
10321
|
-
const w =
|
|
10322
|
-
w.set(s.id, s.transactionOwnerId),
|
|
10325
|
+
const w = S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map();
|
|
10326
|
+
w.set(s.id, s.transactionOwnerId), S.setMap("transactionOwnerIds", w);
|
|
10323
10327
|
} else
|
|
10324
10328
|
r.isReloadedTransaction = !0;
|
|
10325
10329
|
this.initialized = !0, this.experienceOptions = r;
|
|
@@ -10392,7 +10396,7 @@ class ms {
|
|
|
10392
10396
|
readOnly: !1,
|
|
10393
10397
|
index: s[F].index
|
|
10394
10398
|
}));
|
|
10395
|
-
}, r = (await Promise.all([i(), o()])).flat(), c = [...new Set(r.map((h) => h.workflowId))], B = await Bt(c, A), l = new Map(B.map((h) => [h.id, h])), d =
|
|
10399
|
+
}, r = (await Promise.all([i(), o()])).flat(), c = [...new Set(r.map((h) => h.workflowId))], B = await Bt(c, A), l = new Map(B.map((h) => [h.id, h])), d = S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map(), E = r.map(async (h) => {
|
|
10396
10400
|
var U;
|
|
10397
10401
|
const { transaction: u, workflowId: f, readOnly: p, index: D } = h, m = l.get(f), F = e[D];
|
|
10398
10402
|
!d.get(u.id) && u.transactionOwnerId && d.set(u.id, u.transactionOwnerId);
|
|
@@ -10403,17 +10407,17 @@ class ms {
|
|
|
10403
10407
|
singleVariantsRenderable: (U = F == null ? void 0 : F.workflowConfiguration) == null ? void 0 : U.singleVariantsRenderable,
|
|
10404
10408
|
stateMutationFunc: p ? async () => {
|
|
10405
10409
|
throw new v("State mutation is forbidden in read only mode!");
|
|
10406
|
-
} : async (
|
|
10410
|
+
} : async (x) => this.updateTransactionState({ ...x, context: { transactionOwnerId: Y } }),
|
|
10407
10411
|
readOnly: p,
|
|
10408
10412
|
workflow: m,
|
|
10409
10413
|
isReloadedTransaction: F.type === "transaction"
|
|
10410
10414
|
};
|
|
10411
10415
|
if (F.type === "transaction" && u.workflowState) {
|
|
10412
|
-
const
|
|
10413
|
-
M.layouts = Object.values(
|
|
10416
|
+
const x = JSON.parse(u.workflowState);
|
|
10417
|
+
M.layouts = Object.values(x.layouts).map((b) => b.layout), await ee(x), await Ae(x), M.reloadedState = x;
|
|
10414
10418
|
} else if (!p && F.workflowState) {
|
|
10415
|
-
const
|
|
10416
|
-
M.layouts = Object.values(
|
|
10419
|
+
const x = JSON.parse(F.workflowState);
|
|
10420
|
+
M.layouts = Object.values(x.layouts).map((b) => b.layout), await ee(x), await Ae(x), M.reloadedState = x;
|
|
10417
10421
|
} else
|
|
10418
10422
|
M.layouts = Oe(
|
|
10419
10423
|
M.transaction,
|
|
@@ -10423,7 +10427,7 @@ class ms {
|
|
|
10423
10427
|
M.layouts
|
|
10424
10428
|
), this.initialized = !0, this.experienceOptions = M, { experienceOptions: M, index: D, options: F };
|
|
10425
10429
|
});
|
|
10426
|
-
|
|
10430
|
+
S.setMap("transactionOwnerIds", d);
|
|
10427
10431
|
const Q = (await Promise.all(E)).sort((h, u) => h.index - u.index).map(async (h) => {
|
|
10428
10432
|
const { experienceOptions: u, options: f } = h, p = new he(this, u);
|
|
10429
10433
|
return await p.getWorkflowManager().getInitializationPromise(), f.type !== "transaction" && this.customer && await p.attachCustomerDetails({ email: this.customer.emailAddress }), p;
|
|
@@ -10457,8 +10461,8 @@ class ms {
|
|
|
10457
10461
|
if (!a.product)
|
|
10458
10462
|
throw new P("Failed to create transaction, product not available.");
|
|
10459
10463
|
this.currencyCode = (s = a.product.partner) == null ? void 0 : s.currencyCode;
|
|
10460
|
-
const n =
|
|
10461
|
-
n.set(a.id, a.transactionOwnerId),
|
|
10464
|
+
const n = S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map();
|
|
10465
|
+
n.set(a.id, a.transactionOwnerId), S.setMap("transactionOwnerIds", n), this.experienceOptions = {
|
|
10462
10466
|
product: a.product,
|
|
10463
10467
|
transaction: a,
|
|
10464
10468
|
layouts: [],
|
|
@@ -10499,7 +10503,7 @@ class ms {
|
|
|
10499
10503
|
};
|
|
10500
10504
|
if (A)
|
|
10501
10505
|
return await a();
|
|
10502
|
-
const n =
|
|
10506
|
+
const n = S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map(), s = n.get(e);
|
|
10503
10507
|
if (s) {
|
|
10504
10508
|
const l = (i = (await t.query({
|
|
10505
10509
|
query: we,
|
|
@@ -10531,7 +10535,7 @@ class ms {
|
|
|
10531
10535
|
throw new P("Failed to read transaction.");
|
|
10532
10536
|
if (!l.product)
|
|
10533
10537
|
throw new P("Failed to load transaction, product not available.");
|
|
10534
|
-
this.currencyCode = (c = l.product.partner) == null ? void 0 : c.currencyCode, l.transactionOwnerId && (n.set(l.id, l.transactionOwnerId),
|
|
10538
|
+
this.currencyCode = (c = l.product.partner) == null ? void 0 : c.currencyCode, l.transactionOwnerId && (n.set(l.id, l.transactionOwnerId), S.setMap("transactionOwnerIds", n)), this.experienceOptions = {
|
|
10535
10539
|
product: l.product,
|
|
10536
10540
|
transaction: l,
|
|
10537
10541
|
layouts: [],
|
|
@@ -10563,7 +10567,7 @@ class ms {
|
|
|
10563
10567
|
return await r.getWorkflowManager().getInitializationPromise(), r;
|
|
10564
10568
|
}
|
|
10565
10569
|
if (e) {
|
|
10566
|
-
const r = (
|
|
10570
|
+
const r = (S.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map()).get(this.experienceOptions.transaction.id), c = N.getShadowGraphqlClient().mutate({
|
|
10567
10571
|
mutation: ra,
|
|
10568
10572
|
variables: {
|
|
10569
10573
|
workflowId: e,
|
|
@@ -10617,8 +10621,8 @@ class ms {
|
|
|
10617
10621
|
return this.experienceOptions.transaction;
|
|
10618
10622
|
}
|
|
10619
10623
|
storeCustomer(e) {
|
|
10620
|
-
const A =
|
|
10621
|
-
A.set(e.partner.id, e.id),
|
|
10624
|
+
const A = S.getMap("partnerCustomerIds") || /* @__PURE__ */ new Map();
|
|
10625
|
+
A.set(e.partner.id, e.id), S.setMap("partnerCustomerIds", A);
|
|
10622
10626
|
}
|
|
10623
10627
|
}
|
|
10624
10628
|
class Hs {
|
|
@@ -10912,7 +10916,7 @@ export {
|
|
|
10912
10916
|
fa as moduleStepService,
|
|
10913
10917
|
z as optionService,
|
|
10914
10918
|
Qi as patternImageDataCache,
|
|
10915
|
-
|
|
10919
|
+
S as persistenceService,
|
|
10916
10920
|
qA as pictureStepService,
|
|
10917
10921
|
ZA as questionStepService,
|
|
10918
10922
|
ui as registerFetchImplementation,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1932,7 +1932,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
1932
1932
|
}
|
|
1933
1933
|
}
|
|
1934
1934
|
}
|
|
1935
|
-
`,ln=async l=>{var t;return(t=(await R.getShadowGraphqlClient().mutate({mutation:cn,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:l.name,layouts:l.layouts,workflowId:l.workflowId,transactionId:l.transactionId,previewImage:l.previewImage,useThreeDimPreview:l.useThreeDimPreview,metadata:l.metadata,selectedVariants:l.selectedVariants}})).data)==null?void 0:t.designCreate},Bn=async l=>{var t;return(t=(await R.getShadowGraphqlClient().mutate({mutation:gn,errorPolicy:"all",fetchPolicy:"no-cache",variables:{inputs:l.map(A=>({name:A.name,layouts:A.layouts,workflowId:A.workflowId,transactionId:A.transactionId,previewImage:A.previewImage,useThreeDimPreview:A.useThreeDimPreview,metadata:A.metadata,selectedVariants:A.selectedVariants}))}})).data)==null?void 0:t.designCreateMany},Oe=(l,e,t)=>{const A=a=>{const i={};if(a.type==="Frame"){const o=l[a.stepName],s=a.data;if(!o||!o.image||s.hideImageInCart&&t)return i;i[`${a.stepTitle} image`]=o.image}if(a.type==="Illustration"){const o=l[a.stepName],s=a.data;if(!o||s.hideColorsInCart&&t||!o.colors)return i;if(o.colors.length>0){const r=o.colors.join(", ").toUpperCase();i[`${a.stepTitle} colors`]=r}}if(a.type==="Module"){const o=l[a.stepName],s=a.data;if(!o||o.text===void 0||o.text===null||s.hideTextInCart&&t)return i;i[`${a.stepTitle} text`]=o.text}if(a.type==="Text"){const o=l[a.stepName];if(!o)return i;const s=a.data;(!s.hideTextInCart||!t&&o.text!==void 0&&o.text!==null)&&(i[`${a.stepTitle} text`]=o.text),o.color&&(!s.hideColorInCart||!t)&&(i[`${a.stepTitle} color`]=o.color)}return i},n={};return e.steps.forEach(a=>{Object.assign(n,A(a))}),n},dn=(l,e,t,A)=>{const n={};let a;if(t){a=Oe(t,e,!1);for(const i of Object.keys(a))n[i]={value:a[i],priceModifier:0}}else if(A){a=A;for(const i of Object.keys(a))n[i]={value:a[i],priceModifier:0}}for(const i of Object.keys(l)){const o=l[i],s=e.steps.find(r=>r.stepTitle===i);if(o.length===1)n[`${s==null?void 0:s.stepTitle} selection`]={value:o[0].name,priceModifier:o[0].priceModifier};else if(o.length>1)for(let r=0;r<o.length;r++)n[`${s==null?void 0:s.stepTitle} selection ${r+1}`]={value:o[r].name,priceModifier:o[r].priceModifier}}return n},Tt=(l,e,t,A,n,a,i,o,s,r)=>{const d=(N.getMap("transactionOwnerIds")||new Map).get(l.id),B={baseCost:t,designProductId:l.externalDesignProductId,designProductVariantId:l.externalDesignProductVariantId,event:"onComplete",exportedData:a,externalCartProductId:l.externalCartProductId,externalCartProductVariantId:l.externalCartProductVariantId,lineItemImageUrl:i||"",optionsCost:A,processExecutionId:r,transactionId:l.id,transactionOwnerId:d,weight:e.weight,workflowViewerLink:l.workflowViewerLink||"",workflowViewerReadOnlyLink:l.workflowViewerReadOnlyLink||""};return n&&(B.metadata=n),o&&(B.selectedVariants=o),s&&(B.sku=s),B},wn=(l,e,t,A)=>{const n=(e.basePrice||0)*(l.variationsCount||0),a=l.priceModifierTotal||0,i={items:{value:l.variationsCount?`${l.variationsCount}`:"0",priceModifier:0}};return Tt(l,e,n,a,void 0,i,t,void 0,void 0,A)},Jt=async(l,e,t,A,n,a,i,o)=>{const s=e.basePrice||0,r=l.priceModifierTotal||0,g=dn(A,t,void 0,a);return Tt(l,e,s,r,a,g,i,A,n,o)},Lt=async(l,e,t,A,n,a,i,o,s,r)=>{var S;await(async()=>{var O;if(r!==void 0)return r;await l.outstandingRequestsPromise();const y=(N.getMap("transactionOwnerIds")||new Map).get(n.id),P=await R.getShadowGraphqlClient().query({query:Bt,variables:{ids:[n.id]},fetchPolicy:"no-cache",errorPolicy:"all",context:{transactionOwnerId:y}}),v=(O=P.data)==null?void 0:O.transactions[0].workflowState;return P.errors?(P.errors.forEach(z=>{P.errors&&console.log("Server Error:",z.message)}),null):v??null})()||(console.warn("State mismatch detected. Uploading known state explicitly"),console.warn("State Object:",JSON.stringify(A())),await l.updateStateWithServerImmediate(A),console.log("Server state is undefined @ Workflow completion"));const B=l.getPreviewService(),w=(S=e==null?void 0:e.finalizeStepConfig)==null?void 0:S.lookAtAnimation,h=B&&e.showModelOnFinishStep&&!!w,Q=s&&Oe(s,e,!0),E=s&&Oe(s,e,!1),m=async Y=>{const y={};let G=0;if(Object.keys(a).length>0)for(const P of Object.keys(a)){const v=a[P],O=e.steps.find(z=>z.stepName===P);for(let z=0;z<v.selections.length;++z){const V=v.selections[z];if(O&&(!Y||O.option&&(O.option.variants||[]).length>1&&!O.data.hideSelectionInCart&&!O.data.hideSelectionsInCart)){const We=O.stepTitle;y[We]?y[We].push({id:V.id||"",name:V.name,priceModifier:V.priceModifier}):y[We]=[{id:V.id||"",name:V.name,priceModifier:V.priceModifier}]}G+=V.priceModifier}}return[y,G]},[C]=await m(!0),I=Object.fromEntries(Object.keys(C).map(Y=>[Y,C[Y].map(y=>y.id)])),[F]=await m(!1),D=Object.fromEntries(Object.keys(F).map(Y=>[Y,F[Y].map(y=>y.id)])),p=await o(h);return{designDetails:(()=>{const Y={name:i,layouts:t.map(y=>({index:y.index,panelId:y.panelId})),workflowId:e.id,transactionId:n.id,useThreeDimPreview:!!h,previewImage:p};if(E){const y=[];for(const[G,P]of Object.entries(E))y.push({key:G,value:P});Y.metadata=y}if(I){const y=[];for(const[G,P]of Object.entries(D))y.push({key:G,ids:P});Y.selectedVariants=y}return Y})(),cartSelectionsWithPrices:C,cartMetadata:Q}},Ot=async(l,e,t,A,n,a,i,o,s,r,g,d,B)=>{var I,F,D;s("workflow.steps.finish.finalize.buildingLayouts");const{designDetails:w,cartSelectionsWithPrices:h,cartMetadata:Q}=await Lt(l,e,t,A,a,i,o,d,B);s("workflow.steps.finish.finalize.creatingDesign"),a.bulk&&await r(g);const E=await ln(w),m=(I=E==null?void 0:E.transaction)==null?void 0:I.previewImageLink;if(!(E!=null&&E.transaction))throw new Error("Failed to create design");s("workflow.steps.finish.finalize.updatingTransaction");const C=E.transaction;return a.bulk?wn(C,n,m,(F=E==null?void 0:E.processExecution)==null?void 0:F.id):await Jt(C,n,e,h,E==null?void 0:E.sku,Q,m,(D=E==null?void 0:E.processExecution)==null?void 0:D.id)},En=async(l,e)=>{e("workflow.steps.finish.finalize.buildingLayouts"),await Promise.all(l.map(async i=>{await i.workflowManager.outstandingRequestsPromise()}));const A=await(async()=>{var s;const o=await R.getShadowGraphqlClient().query({query:Bt,variables:{ids:l.map(r=>r.transaction.id)},fetchPolicy:"no-cache",errorPolicy:"all"});return o.errors?(o.errors.forEach(r=>{o.errors&&console.log("Server Error:",r.message)}),null):(s=o.data)!=null&&s.transactions?o.data.transactions.map(r=>r.workflowState??null):null})(),n=await Promise.all(l.map(async(i,o)=>await Lt(i.workflowManager,i.workflow,i.layouts,i.getReducerState,i.transaction,i.workflowSelections,i.designName,()=>Promise.resolve(void 0),i.workflowMetadata,A?A[o]:void 0)));e("workflow.steps.finish.finalize.creatingDesign");const a=await Bn(n.map(i=>i.designDetails));if(!a)throw new Error("Failed to create designs");return e("workflow.steps.finish.finalize.updatingTransaction"),Promise.all(a.map(async(i,o)=>{var d;const s=l[o],r=n[o],g=i.transaction;return await Jt(g,s.product,s.workflow,r.cartSelectionsWithPrices,i.sku,r.cartMetadata,void 0,(d=i.processExecution)==null?void 0:d.id)}))};class hn{constructor(){this.localPersistenceKey="designTransactions",this.storageMethod="Local",this.designSavedListeners=[]}attachSaveListener(e){this.designSavedListeners.push(e)}detachSaveListener(e){this.designSavedListeners=this.designSavedListeners.filter(t=>t!==e)}async getSavedDesigns(){if(this.storageMethod==="Local"){const e=N.get(this.localPersistenceKey);return e?JSON.parse(e):[]}throw new U("Unexpected storage method requested")}async getSavedDesignByTransaction(e){return(await this.getSavedDesigns()).find(A=>A.transactionId===e)}async addDesign(e){const A=(await this.getSavedDesigns()).filter(n=>n.transactionId!==e.transactionId);A.unshift(e),await this.setDesigns(A),this.designSavedListeners.forEach(n=>n(e))}async renameDesign(e,t){const A=await this.getSavedDesigns(),n=A.find(a=>a.transactionId===e);if(!n)throw new Error(`No saved design for transaction ${e}.`);n.title=t,await this.setDesigns(A)}async removeDesign(e){const t=await this.getSavedDesigns();await this.setDesigns(t.filter(A=>A.transactionId!==e))}async setDesigns(e){if(this.storageMethod==="Local"){N.set(this.localPersistenceKey,JSON.stringify(e));return}throw new U("Unexpected storage method requested")}}const De=new hn;class Be{constructor(e,t){var n;if(this.renderableScenes=[],this.renderableSceneCallbacks=[],this.debouncedSavedDesignUpdate=Ze(async()=>{await De.getSavedDesignByTransaction(this.getWorkflowManager().getTransaction().id)&&this.save()},2500),this.getCanvasObjectURLAsync=async a=>new Promise((i,o)=>{try{a.toBlob(s=>{if(s){const r=URL.createObjectURL(s);i(r)}})}catch(s){o(s)}}),!t.workflow)throw new Error("No Workflow ID provided.");this.client=e;const A=t.layouts;this.commandContext=new c.CommandContext,this.commandContext.initialize(A,t.reloadedState),this.isReadOnly=t.transaction.isOrdered||!!t.readOnly,this.workflowManager=new sn(t.workflow,((n=t.product.profanities)==null?void 0:n.map(a=>a.word))||[],A,this.commandContext,a=>{try{this.debouncedSavedDesignUpdate()}catch{console.error("Failed to update saved design details.")}return t.stateMutationFunc(a)},t.transaction,t.product,t.previewService,t.renderableContextService,t.reloadedState,t.readOnly,t.modelContainer,t.isReloadedTransaction,t.singleVariantsRenderable),this.workflowManager.addSelectionCallback(a=>{const i=a.traversableScenes.map(o=>{const s=o.renderableSteps.map(r=>r.stepName);return{id:o.name,title:o.title,renderableSteps:s}});this.renderableScenes=i,this.renderableSceneCallbacks.forEach(o=>o(i))})}getClient(){return this.client}getIsReadOnly(){return this.isReadOnly}getCommandContext(){return this.commandContext}getWorkflowManager(){return this.workflowManager}async updateVariationRecords(e){await R.getShadowGraphqlClient().mutate({mutation:PA,variables:{transactionId:this.workflowManager.getTransaction().id,updates:e.map(t=>({recordNumber:t.recordNumber,values:t.values.map(A=>({aspect:A.aspect,stepName:A.stepName,value:A.value}))}))}})}async createPreviewImage(e,t){var C,I;const A=this.workflowManager.getWorkflow(),n=(C=A==null?void 0:A.finalizeStepConfig)==null?void 0:C.lookAtAnimation;if(e){if(!n)throw new Error("Failed to generate cart preview image!");return await((I=this.workflowManager.getPreviewService())==null?void 0:I.renderSceneScreenshot(t??512,n))||""}let a=2048;t&&t<=2048&&(a=t);const i=c.createCanvas(a,a),o=this.commandContext.getAllLayouts(),s=A.defaultPreviewPanelIndex||0,r=A.panels[s],g=o.find(F=>{var D;return((D=F.layoutState)==null?void 0:D.layout.panelId)===(r==null?void 0:r.name)})||o[0],d=g.layoutState.layout.previewRegion?{x:g.layoutState.layout.previewRegion.left,y:g.layoutState.layout.previewRegion.top,width:g.layoutState.layout.previewRegion.width,height:g.layoutState.layout.previewRegion.height}:{x:0,y:0,width:g.layoutState.layout.width,height:g.layoutState.layout.height},B=this.commandContext.getLayoutById(g.layoutState.layout.id),w=i.getContext("2d");if(!w)throw new he("Failed to obtain 2D context for preview image creation");const h=c.getSvgElement(B.layoutState.layout,B.layoutState.elements,{renderingConfiguration:{purpose:c.LayoutRenderingPurpose.Print,region:{left:d.x,top:d.y,width:d.width,height:d.height}}}),Q=c.renderPapyrusComponentAsString(h);await(await qe.Pith.from(w,Q,{anonymousCrossOrigin:!0,ignoreDimensions:!1,createCanvas:c.createCanvas,createImage:c.loadImage,DOMParser:c.getDomParser(),fetch:c.fetch})).render();const m=await this.getCanvasObjectURLAsync(i);return i.toDataURL(m)}getStepById(e){const t=this.getWorkflowManager().getWorkflow().steps.find(A=>A.stepName===e);if(!(!t||!this.stepHasHandle(t)))return le.get(this.getWorkflowManager(),t)}getSteps(){return this.getScenes().flatMap(e=>this.getStepsByScene(e))}getScenes(){return this.getWorkflowManager().getWorkflow().stepGroups.map(t=>({id:t.id,name:t.name,stepIds:t.stepNames}))}getSelectionPriceSubunits(){const e=this.getWorkflowManager().getWorkflowSelections();let t=0;return Object.values(e).forEach(A=>{t+=A.selections.map(n=>n.priceModifier).reduce((n,a)=>n+a)}),t}getBasePriceSubunits(){return this.getWorkflowManager().getProduct().basePrice||0}getTotalPriceSubunits(){return this.getBasePriceSubunits()+this.getSelectionPriceSubunits()}getBulkStep(){if(this.getWorkflowManager().getTransaction().bulk){const e=this.getWorkflowManager().getProduct().bulkConfiguration,t={type:c.StepType.Bulk,stepName:"Bulk",stepTitle:(e==null?void 0:e.stepTitle)??"workflow.steps.bulk.title",helpText:e==null?void 0:e.helpText,data:{aspects:Pe(this.getWorkflowManager().getWorkflow())},conditions:[]};return le.get(this.getWorkflowManager(),t)}}getStepByName(e){const t=this.getWorkflowManager().getWorkflow().steps.find(A=>A.stepTitle===e);if(!(!t||!this.stepHasHandle(t)))return le.get(this.getWorkflowManager(),t)}getStepsByType(e){return this.getWorkflowManager().getWorkflow().steps.filter(t=>t.type===e).map(t=>le.get(this.getWorkflowManager(),t))}getStepsByScene(e){if(!this.getWorkflowManager().getWorkflow().stepGroups.find(A=>A.name===e.name))throw new Error("Given scene is not present on workflow! Be careful when persisting scenes that you only use them with the relevant workflow.");return e.stepIds.map(A=>this.getWorkflowManager().getWorkflow().steps.find(n=>n.stepName===A)).filter(A=>this.stepHasHandle(A)).map(A=>le.get(this.getWorkflowManager(),A))}async attachCustomerDetails(e){return this.assignCustomerDetails({emailAddress:e.email})}async assignCustomerDetails(e){var i,o,s;const A=(N.getMap("transactionOwnerIds")||new Map).get(this.getWorkflowManager().getTransaction().id),a=(s=(o=(i=(await R.getShadowGraphqlClient().mutate({mutation:Yt,variables:{id:this.getWorkflowManager().getTransaction().id,details:e,type:"Owner"},context:{transactionOwnerId:A}})).data)==null?void 0:i.transactionAddStakeholder)==null?void 0:o.stakeholders)==null?void 0:s.find(r=>{var g;return((g=r.customer)==null?void 0:g.emailAddress)===e.emailAddress});if(a!=null&&a.customer){this.getWorkflowManager().setTransactionCustomer(a.customer);const r=N.getMap("transactionCustomerIds")||new Map;r.set(this.getWorkflowManager().getTransaction().id,a.customer.id),N.setMap("transactionCustomerIds",r)}}attachRenderableSceneListener(e){this.renderableSceneCallbacks.push(e),e(this.renderableScenes)}detachRenderableSceneListener(e){this.renderableSceneCallbacks=this.renderableSceneCallbacks.filter(t=>t!==e)}async save(e){if(!this.getCommandContext().getState())throw new U("State undefined!");const n={title:await(async()=>{var s;if(e)return e;const a=this.getWorkflowManager().getTransaction().id,o=(s=(await De.getSavedDesigns()).find(r=>r.transactionId===a))==null?void 0:s.title;return o||"My design"})(),thumbnail:await this.createPreviewImage(!1,256),transactionId:this.getWorkflowManager().getTransaction().id,productId:this.getWorkflowManager().getProduct().id,integrationProductId:this.getWorkflowManager().getTransaction().integrationProduct.id,workflowName:this.getWorkflowManager().getWorkflow().name,workflowId:this.getWorkflowManager().getWorkflow().id,lastEdited:new Date};return await De.addDesign(n),n}async copy(){var o;const e=te(this.getCommandContext().getState());if(!e)throw new U("Internal state is undefined! Cannot copy experience!");const t=JSON.stringify(e.transaction),A=this.getWorkflowManager().getWorkflow(),n=new nA({}),a=(o=this.getWorkflowManager().getTransaction().integrationProduct)==null?void 0:o.id;if(!a)throw new U("Integration product id is undefined!");return await n.initFromIntegrationProduct(a),await n.getWorkflowExperience(A.id,t,void 0)}async onDesignFinished(e,t=!0){return Ot(this.workflowManager,this.workflowManager.getWorkflow(),this.workflowManager.getLayouts(),()=>this.commandContext.getState(),this.workflowManager.getProduct(),this.workflowManager.getTransaction(),this.workflowManager.getWorkflowSelections(),this.workflowManager.getWorkflow().name,e||(()=>{}),A=>this.updateVariationRecords(A),this.workflowManager.getVariationRecords(),A=>t?this.createPreviewImage(A,1024):Promise.resolve(void 0),this.workflowManager.getWorkflowMetadata())}stepHasHandle(e){return e.type!==c.StepType.SilentIllustration&&e.type!==c.StepType.ProductOverlay}getExportedData(){var n;const e=new Map,t=this.getWorkflowManager().getWorkflowMetadata(),A=this.getWorkflowManager().getWorkflowSelections();return Object.keys(t).forEach(a=>{const i=this.workflowManager.getWorkflow().steps.find(s=>s.stepName===a);if(!i)return;e.has(i.stepTitle)||e.set(i.stepTitle,{});const o=t[a];Object.keys(o).forEach(s=>{e.get(i.stepTitle)[s]=o[s]})}),(n=Object.keys(A))==null||n.forEach(a=>{const i=this.workflowManager.getWorkflow().steps.find(o=>o.stepName===a);i&&(e.has(i.stepTitle)||e.set(i.stepTitle,{}),e.get(i.stepTitle).selection=A[a].selections[0].name)}),e}}const Cn=["altGlyph","circle","ellipse","path","polygon","polyline","rect","text","textPath","tref","tspan"],Qn=async(l,e,t)=>{const A=e.data,n=t.data.baseUrl,a=A.assetUrl.replace("localhost","localstack"),i=n.slice(0,4)==="http"?"":"https://",o=new URL(i+n);o.searchParams.append("video",c.toBase64(JSON.stringify([{href:a}]))),o.pathname=o.pathname+(o.pathname.slice(-1)==="/"?"":"/");const s=o.toString(),g=`data:image/svg+xml;base64,${c.toBase64(await _e.toString(s,{type:"svg"}))}`,d=w=>{const h=l.find(E=>E.panelId===w.panelId);if(!h)throw new k(w);const Q=c.generate();return new c.CreateElementCommand({id:Q,src:g,type:c.LayoutElementType.Image,y:w.top,x:w.left,width:w.width,height:w.height,rotation:0},h)},B=t.data.regions;try{return B.map(d)}catch(w){return console.error(w),[]}},un=async(l,e,t,A)=>{const n=t.data,a=n.assetUrl,i=await c.getPatternImageData(a);try{const o=c.getVariant(n,A.option);o&&(e[A.stepName]={selectedVariants:[o]});const s=async r=>{var Q;const g=await c.generateFrameSVG(r||{width:1,height:1},(Q=o==null?void 0:o.asset)==null?void 0:Q.fileLink),d=await c.getFrameData(g),B=c.generate(),w=l.find(E=>E.panelId===r.panelId);if(!w)throw new k(r);const h=c.calculateOffsets(i,d,{scale:n.scale,left:n.x,top:n.y});return[new c.CreateElementCommand({id:B,path:d.path,dataWidth:d.width,dataHeight:d.height,type:c.LayoutElementType.Frame,focalBlur:A.data.focalBlur,focalBlurStrength:A.data.focalBlurStrength,focalBlurRadius:A.data.focalBlurRadius,forceImageCover:A.data.forceImageCover,x:r.left,y:r.top,width:r.width,height:r.height,layer:r.layer,layerIndex:r.layerIndex,rotation:r.rotation,scaleX:r.width/d.width,scaleY:r.height/d.height,pattern:void 0},w),new c.UpdateFramePattern(B,i,h)]};return(await Promise.all(A.data.regions.map(r=>s(r)))).flat()}catch(o){return console.error(o),[]}},mn=async(l,e,t,A)=>{var D,p;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((D=a.variants)==null?void 0:D.find(f=>f.id===n.illustrationVariantId))||c.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.illustrationVariantId}`),[];if(!i.asset)return console.error(`No asset for variant with ID: ${n.illustrationVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=(p=i.asset)==null?void 0:p.fileLink;if(!o)return console.error(`No asset link for variant with ID: ${n.illustrationVariantId}`),[];const s=await c.fetchAsString(o,!0),r=/<svg.*?<\/svg>/s,g=s.match(r)||[],d=(g==null?void 0:g.length)>0?g[0]:"",h=c.domParser().parseFromString(d,"image/svg+xml").firstElementChild;if(!h)return console.error("Failed to read SVG."),[];c.sanitizeSvgTree(h);const Q={};c.traverse(h,f=>{Cn.includes(f.tagName)&&!f.attributes.getNamedItem("fill")&&f.setAttribute("fill","#000000");const S=f.attributes.getNamedItem("fill");if(S&&S.value!=="none"){const y=S.value,P=`spiff-fill-${y.replace(/\W/g,"")}`;f.classList.add(P),Q[P]={browserValue:y}}const Y=f.attributes.getNamedItem("stroke");if(Y&&Y.value!=="none"){const y=Y.value,P=`spiff-stroke-${y.replace(/\W/g,"")}`;f.classList.add(P),Q[P]={browserValue:y}}});const m=c.xmlSerializer().serializeToString(h),C=n.colors;if(C){for(const[f,S]of Object.entries(Q))for(const Y of Object.keys(C))if(S.browserValue===Y){Q[f]={browserValue:C[Y]};break}}const I=f=>{const S=l.find(y=>y.panelId===f.panelId);if(!S)throw new k(f);const Y=c.generate();return new c.CreateElementCommand({colors:Q,id:Y,svg:m,type:c.LayoutElementType.Illustration,y:f.top,x:f.left,rotation:f.rotation,width:f.width,height:f.height,layer:f.layer,layerIndex:f.layerIndex,immutable:f.immutable},S)},F=A.data.regions;try{return F.map(I)}catch(f){return console.error(f),[]}},In=async(l,e,t)=>{const A=await Mt(t.data.module),n=e.data,a=(o,s)=>{const r=l.find(d=>d.panelId===s.panelId);if(!r)throw new k(s);const g=c.generate();return new c.CreateElementCommand({colors:{},id:g,svg:o,type:c.LayoutElementType.Illustration,y:s.top,x:s.left,rotation:s.rotation,width:s.width,height:s.height,layer:s.layer,layerIndex:s.layerIndex},r)},i=t.data.regions;try{return i.map(o=>a(A.svgPrint(n.text,o),o))}catch(o){return console.error(o),[]}},fn=async(l,e,t,A)=>{var g,d;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((g=a.variants)==null?void 0:g.find(B=>B.id===n.pictureVariantId))||c.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.pictureVariantId}`),[];if(!i.asset)return console.error(`No asset for variant with ID: ${n.pictureVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=(d=i.asset)==null?void 0:d.fileLink;if(!o)return console.error(`No asset link for variant with ID: ${n.pictureVariantId}`),[];const s=B=>{const w=l.find(Q=>Q.panelId===B.panelId);if(!w)throw new k(B);const h=c.generate();return new c.CreateElementCommand({id:h,src:o,type:c.LayoutElementType.Image,y:B.top,x:B.left,rotation:B.rotation,width:B.width,height:B.height,layer:B.layer,layerIndex:B.layerIndex,immutable:B.immutable,preserveAspectRatio:"none"},w)},r=A.data.regions;try{return r.map(s)}catch(B){return console.error(B),[]}},Dn=async(l,e,t,A)=>{var r;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((r=a.variants)==null?void 0:r.find(g=>g.id===n.colorVariantId))||c.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.colorVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=g=>{const d=l.find(E=>E.panelId===g.panelId);if(!d)throw new k(g);const B=`
|
|
1935
|
+
`,ln=async l=>{var t;return(t=(await R.getShadowGraphqlClient().mutate({mutation:cn,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:l.name,layouts:l.layouts,workflowId:l.workflowId,transactionId:l.transactionId,previewImage:l.previewImage,useThreeDimPreview:l.useThreeDimPreview,metadata:l.metadata,selectedVariants:l.selectedVariants}})).data)==null?void 0:t.designCreate},Bn=async l=>{var t;return(t=(await R.getShadowGraphqlClient().mutate({mutation:gn,errorPolicy:"all",fetchPolicy:"no-cache",variables:{inputs:l.map(A=>({name:A.name,layouts:A.layouts,workflowId:A.workflowId,transactionId:A.transactionId,previewImage:A.previewImage,useThreeDimPreview:A.useThreeDimPreview,metadata:A.metadata,selectedVariants:A.selectedVariants}))}})).data)==null?void 0:t.designCreateMany},Oe=(l,e,t)=>{const A=a=>{const i={};if(a.type==="Frame"){const o=l[a.stepName],s=a.data;if(!o||!o.image||s.hideImageInCart&&t)return i;i[`${a.stepTitle} image`]=o.image}if(a.type==="Illustration"){const o=l[a.stepName],s=a.data;if(!o||s.hideColorsInCart&&t||!o.colors)return i;if(o.colors.length>0){const r=o.colors.join(", ").toUpperCase();i[`${a.stepTitle} colors`]=r}}if(a.type==="Module"){const o=l[a.stepName],s=a.data;if(!o||o.text===void 0||o.text===null||s.hideTextInCart&&t)return i;i[`${a.stepTitle} text`]=o.text}if(a.type==="Text"){const o=l[a.stepName];if(!o)return i;const s=a.data;(!s.hideTextInCart||!t&&o.text!==void 0&&o.text!==null)&&(i[`${a.stepTitle} text`]=o.text),o.color&&(!s.hideColorInCart||!t)&&(i[`${a.stepTitle} color`]=o.color)}return i},n={};return e.steps.forEach(a=>{Object.assign(n,A(a))}),n},dn=(l,e,t,A)=>{const n={};let a;if(t){a=Oe(t,e,!1);for(const i of Object.keys(a))n[i]={value:a[i],priceModifier:0}}else if(A){a=A;for(const i of Object.keys(a))n[i]={value:a[i],priceModifier:0}}for(const i of Object.keys(l)){const o=l[i],s=e.steps.find(r=>r.stepTitle===i);if(o.length===1)n[`${s==null?void 0:s.stepTitle} selection`]={value:o[0].name,priceModifier:o[0].priceModifier};else if(o.length>1)for(let r=0;r<o.length;r++)n[`${s==null?void 0:s.stepTitle} selection ${r+1}`]={value:o[r].name,priceModifier:o[r].priceModifier}}return n},Tt=(l,e,t,A,n,a,i,o,s,r)=>{const d=(N.getMap("transactionOwnerIds")||new Map).get(l.id),B={baseCost:t,designProductId:l.externalDesignProductId,designProductVariantId:l.externalDesignProductVariantId,event:"onComplete",exportedData:a,externalCartProductId:l.externalCartProductId,externalCartProductVariantId:l.externalCartProductVariantId,lineItemImageUrl:i||"",optionsCost:A,processExecutionId:r,transactionId:l.id,transactionOwnerId:d,weight:e.weight,workflowViewerLink:l.workflowViewerLink||"",workflowViewerReadOnlyLink:l.workflowViewerReadOnlyLink||""};return n&&(B.metadata=n),o&&(B.selectedVariants=o),s&&(B.sku=s),B},wn=(l,e,t,A)=>{const n=(e.basePrice||0)*(l.variationsCount||0),a=l.priceModifierTotal||0,i={items:{value:l.variationsCount?`${l.variationsCount}`:"0",priceModifier:0}};return Tt(l,e,n,a,void 0,i,t,void 0,void 0,A)},Jt=async(l,e,t,A,n,a,i,o)=>{const s=e.basePrice||0,r=l.priceModifierTotal||0,g=dn(A,t,void 0,a);return Tt(l,e,s,r,a,g,i,A,n,o)},Lt=async(l,e,t,A,n,a,i,o,s,r)=>{var S;await(async()=>{var O;if(r!==void 0)return r;await l.outstandingRequestsPromise();const y=(N.getMap("transactionOwnerIds")||new Map).get(n.id),P=await R.getShadowGraphqlClient().query({query:Bt,variables:{ids:[n.id]},fetchPolicy:"no-cache",errorPolicy:"all",context:{transactionOwnerId:y}}),v=(O=P.data)==null?void 0:O.transactions[0].workflowState;return P.errors?(P.errors.forEach(z=>{P.errors&&console.log("Server Error:",z.message)}),null):v??null})()||(console.warn("State mismatch detected. Uploading known state explicitly"),console.warn("State Object:",JSON.stringify(A())),await l.updateStateWithServerImmediate(A),console.log("Server state is undefined @ Workflow completion"));const B=l.getPreviewService(),w=(S=e==null?void 0:e.finalizeStepConfig)==null?void 0:S.lookAtAnimation,h=B&&e.showModelOnFinishStep&&!!w,Q=s&&Oe(s,e,!0),E=s&&Oe(s,e,!1),m=async Y=>{const y={};let G=0;if(Object.keys(a).length>0)for(const P of Object.keys(a)){const v=a[P],O=e.steps.find(z=>z.stepName===P);for(let z=0;z<v.selections.length;++z){const V=v.selections[z];if(O&&(!Y||O.option&&(O.option.variants||[]).length>1&&!O.data.hideSelectionInCart&&!O.data.hideSelectionsInCart)){const We=O.stepTitle;y[We]?y[We].push({id:V.id||"",name:V.name,priceModifier:V.priceModifier}):y[We]=[{id:V.id||"",name:V.name,priceModifier:V.priceModifier}]}G+=V.priceModifier}}return[y,G]},[C]=await m(!0),I=Object.fromEntries(Object.keys(C).map(Y=>[Y,C[Y].map(y=>y.id)])),[F]=await m(!1),D=Object.fromEntries(Object.keys(F).map(Y=>[Y,F[Y].map(y=>y.id)])),p=await o(h);return{designDetails:(()=>{const Y={name:i,layouts:t.map(y=>({index:y.index,panelId:y.panelId})),workflowId:e.id,transactionId:n.id,useThreeDimPreview:!!h,previewImage:p};if(E){const y=[];for(const[G,P]of Object.entries(E))y.push({key:G,value:P});Y.metadata=y}if(I){const y=[];for(const[G,P]of Object.entries(D))y.push({key:G,ids:P});Y.selectedVariants=y}return Y})(),cartSelectionsWithPrices:C,cartMetadata:Q}},Ot=async(l,e,t,A,n,a,i,o,s,r,g,d,B)=>{var I,F,D;s("workflow.steps.finish.finalize.buildingLayouts");const{designDetails:w,cartSelectionsWithPrices:h,cartMetadata:Q}=await Lt(l,e,t,A,a,i,o,d,B);s("workflow.steps.finish.finalize.creatingDesign"),a.bulk&&await r(g);const E=await ln(w),m=(I=E==null?void 0:E.transaction)==null?void 0:I.previewImageLink;if(!(E!=null&&E.transaction))throw new Error("Failed to create design");s("workflow.steps.finish.finalize.updatingTransaction");const C=E.transaction;return a.bulk?wn(C,n,m,(F=E==null?void 0:E.processExecution)==null?void 0:F.id):await Jt(C,n,e,h,E==null?void 0:E.sku,Q,m,(D=E==null?void 0:E.processExecution)==null?void 0:D.id)},En=async(l,e)=>{e("workflow.steps.finish.finalize.buildingLayouts"),await Promise.all(l.map(async i=>{await i.workflowManager.outstandingRequestsPromise()}));const A=await(async()=>{var s;const o=await R.getShadowGraphqlClient().query({query:Bt,variables:{ids:l.map(r=>r.transaction.id)},fetchPolicy:"no-cache",errorPolicy:"all"});return o.errors?(o.errors.forEach(r=>{o.errors&&console.log("Server Error:",r.message)}),null):(s=o.data)!=null&&s.transactions?o.data.transactions.map(r=>r.workflowState??null):null})(),n=await Promise.all(l.map(async(i,o)=>await Lt(i.workflowManager,i.workflow,i.layouts,i.getReducerState,i.transaction,i.workflowSelections,i.designName,()=>Promise.resolve(void 0),i.workflowMetadata,A?A[o]:void 0)));e("workflow.steps.finish.finalize.creatingDesign");const a=await Bn(n.map(i=>i.designDetails));if(!a)throw new Error("Failed to create designs");return e("workflow.steps.finish.finalize.updatingTransaction"),Promise.all(a.map(async(i,o)=>{var d;const s=l[o],r=n[o],g=i.transaction;return await Jt(g,s.product,s.workflow,r.cartSelectionsWithPrices,i.sku,r.cartMetadata,void 0,(d=i.processExecution)==null?void 0:d.id)}))};class hn{constructor(){this.localPersistenceKey="designTransactions",this.storageMethod="Local",this.designSavedListeners=[]}attachSaveListener(e){this.designSavedListeners.push(e)}detachSaveListener(e){this.designSavedListeners=this.designSavedListeners.filter(t=>t!==e)}async getSavedDesigns(){if(this.storageMethod==="Local"){const e=N.get(this.localPersistenceKey);return e?JSON.parse(e):[]}throw new U("Unexpected storage method requested")}async getSavedDesignByTransaction(e){return(await this.getSavedDesigns()).find(A=>A.transactionId===e)}async addDesign(e){const A=(await this.getSavedDesigns()).filter(n=>n.transactionId!==e.transactionId);A.unshift(e),await this.setDesigns(A),this.designSavedListeners.forEach(n=>n(e))}async renameDesign(e,t){const A=await this.getSavedDesigns(),n=A.find(a=>a.transactionId===e);if(!n)throw new Error(`No saved design for transaction ${e}.`);n.title=t,await this.setDesigns(A)}async removeDesign(e){const t=await this.getSavedDesigns();await this.setDesigns(t.filter(A=>A.transactionId!==e))}async setDesigns(e){if(this.storageMethod==="Local"){N.set(this.localPersistenceKey,JSON.stringify(e));return}throw new U("Unexpected storage method requested")}}const De=new hn;class Be{constructor(e,t){var n;if(this.renderableScenes=[],this.renderableSceneCallbacks=[],this.debouncedSavedDesignUpdate=Ze(async()=>{await De.getSavedDesignByTransaction(this.getWorkflowManager().getTransaction().id)&&this.save()},2500),this.getCanvasObjectURLAsync=async a=>new Promise((i,o)=>{try{a.toBlob(s=>{if(s){const r=URL.createObjectURL(s);i(r)}})}catch(s){o(s)}}),!t.workflow)throw new Error("No Workflow ID provided.");this.client=e;const A=t.layouts;this.commandContext=new c.CommandContext,this.commandContext.initialize(A,t.reloadedState),this.isReadOnly=t.transaction.isOrdered||!!t.readOnly,this.workflowManager=new sn(t.workflow,((n=t.product.profanities)==null?void 0:n.map(a=>a.word))||[],A,this.commandContext,a=>{try{this.debouncedSavedDesignUpdate()}catch{console.error("Failed to update saved design details.")}return t.stateMutationFunc(a)},t.transaction,t.product,t.previewService,t.renderableContextService,t.reloadedState,t.readOnly,t.modelContainer,t.isReloadedTransaction,t.singleVariantsRenderable),this.workflowManager.addSelectionCallback(a=>{const i=a.traversableScenes.map(o=>{const s=o.renderableSteps.map(r=>r.stepName);return{id:o.name,title:o.title,renderableSteps:s}});this.renderableScenes=i,this.renderableSceneCallbacks.forEach(o=>o(i))})}getClient(){return this.client}getIsReadOnly(){return this.isReadOnly}getCommandContext(){return this.commandContext}getWorkflowManager(){return this.workflowManager}async updateVariationRecords(e){const A=(N.getMap("transactionOwnerIds")||new Map).get(this.workflowManager.getTransaction().id);await R.getShadowGraphqlClient().mutate({mutation:PA,variables:{transactionId:this.workflowManager.getTransaction().id,updates:e.map(n=>({recordNumber:n.recordNumber,values:n.values.map(a=>({aspect:a.aspect,stepName:a.stepName,value:a.value}))}))},context:{transactionOwnerId:A}})}async createPreviewImage(e,t){var C,I;const A=this.workflowManager.getWorkflow(),n=(C=A==null?void 0:A.finalizeStepConfig)==null?void 0:C.lookAtAnimation;if(e){if(!n)throw new Error("Failed to generate cart preview image!");return await((I=this.workflowManager.getPreviewService())==null?void 0:I.renderSceneScreenshot(t??512,n))||""}let a=2048;t&&t<=2048&&(a=t);const i=c.createCanvas(a,a),o=this.commandContext.getAllLayouts(),s=A.defaultPreviewPanelIndex||0,r=A.panels[s],g=o.find(F=>{var D;return((D=F.layoutState)==null?void 0:D.layout.panelId)===(r==null?void 0:r.name)})||o[0],d=g.layoutState.layout.previewRegion?{x:g.layoutState.layout.previewRegion.left,y:g.layoutState.layout.previewRegion.top,width:g.layoutState.layout.previewRegion.width,height:g.layoutState.layout.previewRegion.height}:{x:0,y:0,width:g.layoutState.layout.width,height:g.layoutState.layout.height},B=this.commandContext.getLayoutById(g.layoutState.layout.id),w=i.getContext("2d");if(!w)throw new he("Failed to obtain 2D context for preview image creation");const h=c.getSvgElement(B.layoutState.layout,B.layoutState.elements,{renderingConfiguration:{purpose:c.LayoutRenderingPurpose.Print,region:{left:d.x,top:d.y,width:d.width,height:d.height}}}),Q=c.renderPapyrusComponentAsString(h);await(await qe.Pith.from(w,Q,{anonymousCrossOrigin:!0,ignoreDimensions:!1,createCanvas:c.createCanvas,createImage:c.loadImage,DOMParser:c.getDomParser(),fetch:c.fetch})).render();const m=await this.getCanvasObjectURLAsync(i);return i.toDataURL(m)}getStepById(e){const t=this.getWorkflowManager().getWorkflow().steps.find(A=>A.stepName===e);if(!(!t||!this.stepHasHandle(t)))return le.get(this.getWorkflowManager(),t)}getSteps(){return this.getScenes().flatMap(e=>this.getStepsByScene(e))}getScenes(){return this.getWorkflowManager().getWorkflow().stepGroups.map(t=>({id:t.id,name:t.name,stepIds:t.stepNames}))}getSelectionPriceSubunits(){const e=this.getWorkflowManager().getWorkflowSelections();let t=0;return Object.values(e).forEach(A=>{t+=A.selections.map(n=>n.priceModifier).reduce((n,a)=>n+a)}),t}getBasePriceSubunits(){return this.getWorkflowManager().getProduct().basePrice||0}getTotalPriceSubunits(){return this.getBasePriceSubunits()+this.getSelectionPriceSubunits()}getBulkStep(){if(this.getWorkflowManager().getTransaction().bulk){const e=this.getWorkflowManager().getProduct().bulkConfiguration,t={type:c.StepType.Bulk,stepName:"Bulk",stepTitle:(e==null?void 0:e.stepTitle)??"workflow.steps.bulk.title",helpText:e==null?void 0:e.helpText,data:{aspects:Pe(this.getWorkflowManager().getWorkflow())},conditions:[]};return le.get(this.getWorkflowManager(),t)}}getStepByName(e){const t=this.getWorkflowManager().getWorkflow().steps.find(A=>A.stepTitle===e);if(!(!t||!this.stepHasHandle(t)))return le.get(this.getWorkflowManager(),t)}getStepsByType(e){return this.getWorkflowManager().getWorkflow().steps.filter(t=>t.type===e).map(t=>le.get(this.getWorkflowManager(),t))}getStepsByScene(e){if(!this.getWorkflowManager().getWorkflow().stepGroups.find(A=>A.name===e.name))throw new Error("Given scene is not present on workflow! Be careful when persisting scenes that you only use them with the relevant workflow.");return e.stepIds.map(A=>this.getWorkflowManager().getWorkflow().steps.find(n=>n.stepName===A)).filter(A=>this.stepHasHandle(A)).map(A=>le.get(this.getWorkflowManager(),A))}async attachCustomerDetails(e){return this.assignCustomerDetails({emailAddress:e.email})}async assignCustomerDetails(e){var i,o,s;const A=(N.getMap("transactionOwnerIds")||new Map).get(this.getWorkflowManager().getTransaction().id),a=(s=(o=(i=(await R.getShadowGraphqlClient().mutate({mutation:Yt,variables:{id:this.getWorkflowManager().getTransaction().id,details:e,type:"Owner"},context:{transactionOwnerId:A}})).data)==null?void 0:i.transactionAddStakeholder)==null?void 0:o.stakeholders)==null?void 0:s.find(r=>{var g;return((g=r.customer)==null?void 0:g.emailAddress)===e.emailAddress});if(a!=null&&a.customer){this.getWorkflowManager().setTransactionCustomer(a.customer);const r=N.getMap("transactionCustomerIds")||new Map;r.set(this.getWorkflowManager().getTransaction().id,a.customer.id),N.setMap("transactionCustomerIds",r)}}attachRenderableSceneListener(e){this.renderableSceneCallbacks.push(e),e(this.renderableScenes)}detachRenderableSceneListener(e){this.renderableSceneCallbacks=this.renderableSceneCallbacks.filter(t=>t!==e)}async save(e){if(!this.getCommandContext().getState())throw new U("State undefined!");const n={title:await(async()=>{var s;if(e)return e;const a=this.getWorkflowManager().getTransaction().id,o=(s=(await De.getSavedDesigns()).find(r=>r.transactionId===a))==null?void 0:s.title;return o||"My design"})(),thumbnail:await this.createPreviewImage(!1,256),transactionId:this.getWorkflowManager().getTransaction().id,productId:this.getWorkflowManager().getProduct().id,integrationProductId:this.getWorkflowManager().getTransaction().integrationProduct.id,workflowName:this.getWorkflowManager().getWorkflow().name,workflowId:this.getWorkflowManager().getWorkflow().id,lastEdited:new Date};return await De.addDesign(n),n}async copy(){var o;const e=te(this.getCommandContext().getState());if(!e)throw new U("Internal state is undefined! Cannot copy experience!");const t=JSON.stringify(e.transaction),A=this.getWorkflowManager().getWorkflow(),n=new nA({}),a=(o=this.getWorkflowManager().getTransaction().integrationProduct)==null?void 0:o.id;if(!a)throw new U("Integration product id is undefined!");return await n.initFromIntegrationProduct(a),await n.getWorkflowExperience(A.id,t,void 0)}async onDesignFinished(e,t=!0){return Ot(this.workflowManager,this.workflowManager.getWorkflow(),this.workflowManager.getLayouts(),()=>this.commandContext.getState(),this.workflowManager.getProduct(),this.workflowManager.getTransaction(),this.workflowManager.getWorkflowSelections(),this.workflowManager.getWorkflow().name,e||(()=>{}),A=>this.updateVariationRecords(A),this.workflowManager.getVariationRecords(),A=>t?this.createPreviewImage(A,1024):Promise.resolve(void 0),this.workflowManager.getWorkflowMetadata())}stepHasHandle(e){return e.type!==c.StepType.SilentIllustration&&e.type!==c.StepType.ProductOverlay}getExportedData(){var n;const e=new Map,t=this.getWorkflowManager().getWorkflowMetadata(),A=this.getWorkflowManager().getWorkflowSelections();return Object.keys(t).forEach(a=>{const i=this.workflowManager.getWorkflow().steps.find(s=>s.stepName===a);if(!i)return;e.has(i.stepTitle)||e.set(i.stepTitle,{});const o=t[a];Object.keys(o).forEach(s=>{e.get(i.stepTitle)[s]=o[s]})}),(n=Object.keys(A))==null||n.forEach(a=>{const i=this.workflowManager.getWorkflow().steps.find(o=>o.stepName===a);i&&(e.has(i.stepTitle)||e.set(i.stepTitle,{}),e.get(i.stepTitle).selection=A[a].selections[0].name)}),e}}const Cn=["altGlyph","circle","ellipse","path","polygon","polyline","rect","text","textPath","tref","tspan"],Qn=async(l,e,t)=>{const A=e.data,n=t.data.baseUrl,a=A.assetUrl.replace("localhost","localstack"),i=n.slice(0,4)==="http"?"":"https://",o=new URL(i+n);o.searchParams.append("video",c.toBase64(JSON.stringify([{href:a}]))),o.pathname=o.pathname+(o.pathname.slice(-1)==="/"?"":"/");const s=o.toString(),g=`data:image/svg+xml;base64,${c.toBase64(await _e.toString(s,{type:"svg"}))}`,d=w=>{const h=l.find(E=>E.panelId===w.panelId);if(!h)throw new k(w);const Q=c.generate();return new c.CreateElementCommand({id:Q,src:g,type:c.LayoutElementType.Image,y:w.top,x:w.left,width:w.width,height:w.height,rotation:0},h)},B=t.data.regions;try{return B.map(d)}catch(w){return console.error(w),[]}},un=async(l,e,t,A)=>{const n=t.data,a=n.assetUrl,i=await c.getPatternImageData(a);try{const o=c.getVariant(n,A.option);o&&(e[A.stepName]={selectedVariants:[o]});const s=async r=>{var Q;const g=await c.generateFrameSVG(r||{width:1,height:1},(Q=o==null?void 0:o.asset)==null?void 0:Q.fileLink),d=await c.getFrameData(g),B=c.generate(),w=l.find(E=>E.panelId===r.panelId);if(!w)throw new k(r);const h=c.calculateOffsets(i,d,{scale:n.scale,left:n.x,top:n.y});return[new c.CreateElementCommand({id:B,path:d.path,dataWidth:d.width,dataHeight:d.height,type:c.LayoutElementType.Frame,focalBlur:A.data.focalBlur,focalBlurStrength:A.data.focalBlurStrength,focalBlurRadius:A.data.focalBlurRadius,forceImageCover:A.data.forceImageCover,x:r.left,y:r.top,width:r.width,height:r.height,layer:r.layer,layerIndex:r.layerIndex,rotation:r.rotation,scaleX:r.width/d.width,scaleY:r.height/d.height,pattern:void 0},w),new c.UpdateFramePattern(B,i,h)]};return(await Promise.all(A.data.regions.map(r=>s(r)))).flat()}catch(o){return console.error(o),[]}},mn=async(l,e,t,A)=>{var D,p;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((D=a.variants)==null?void 0:D.find(f=>f.id===n.illustrationVariantId))||c.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.illustrationVariantId}`),[];if(!i.asset)return console.error(`No asset for variant with ID: ${n.illustrationVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=(p=i.asset)==null?void 0:p.fileLink;if(!o)return console.error(`No asset link for variant with ID: ${n.illustrationVariantId}`),[];const s=await c.fetchAsString(o,!0),r=/<svg.*?<\/svg>/s,g=s.match(r)||[],d=(g==null?void 0:g.length)>0?g[0]:"",h=c.domParser().parseFromString(d,"image/svg+xml").firstElementChild;if(!h)return console.error("Failed to read SVG."),[];c.sanitizeSvgTree(h);const Q={};c.traverse(h,f=>{Cn.includes(f.tagName)&&!f.attributes.getNamedItem("fill")&&f.setAttribute("fill","#000000");const S=f.attributes.getNamedItem("fill");if(S&&S.value!=="none"){const y=S.value,P=`spiff-fill-${y.replace(/\W/g,"")}`;f.classList.add(P),Q[P]={browserValue:y}}const Y=f.attributes.getNamedItem("stroke");if(Y&&Y.value!=="none"){const y=Y.value,P=`spiff-stroke-${y.replace(/\W/g,"")}`;f.classList.add(P),Q[P]={browserValue:y}}});const m=c.xmlSerializer().serializeToString(h),C=n.colors;if(C){for(const[f,S]of Object.entries(Q))for(const Y of Object.keys(C))if(S.browserValue===Y){Q[f]={browserValue:C[Y]};break}}const I=f=>{const S=l.find(y=>y.panelId===f.panelId);if(!S)throw new k(f);const Y=c.generate();return new c.CreateElementCommand({colors:Q,id:Y,svg:m,type:c.LayoutElementType.Illustration,y:f.top,x:f.left,rotation:f.rotation,width:f.width,height:f.height,layer:f.layer,layerIndex:f.layerIndex,immutable:f.immutable},S)},F=A.data.regions;try{return F.map(I)}catch(f){return console.error(f),[]}},In=async(l,e,t)=>{const A=await Mt(t.data.module),n=e.data,a=(o,s)=>{const r=l.find(d=>d.panelId===s.panelId);if(!r)throw new k(s);const g=c.generate();return new c.CreateElementCommand({colors:{},id:g,svg:o,type:c.LayoutElementType.Illustration,y:s.top,x:s.left,rotation:s.rotation,width:s.width,height:s.height,layer:s.layer,layerIndex:s.layerIndex},r)},i=t.data.regions;try{return i.map(o=>a(A.svgPrint(n.text,o),o))}catch(o){return console.error(o),[]}},fn=async(l,e,t,A)=>{var g,d;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((g=a.variants)==null?void 0:g.find(B=>B.id===n.pictureVariantId))||c.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.pictureVariantId}`),[];if(!i.asset)return console.error(`No asset for variant with ID: ${n.pictureVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=(d=i.asset)==null?void 0:d.fileLink;if(!o)return console.error(`No asset link for variant with ID: ${n.pictureVariantId}`),[];const s=B=>{const w=l.find(Q=>Q.panelId===B.panelId);if(!w)throw new k(B);const h=c.generate();return new c.CreateElementCommand({id:h,src:o,type:c.LayoutElementType.Image,y:B.top,x:B.left,rotation:B.rotation,width:B.width,height:B.height,layer:B.layer,layerIndex:B.layerIndex,immutable:B.immutable,preserveAspectRatio:"none"},w)},r=A.data.regions;try{return r.map(s)}catch(B){return console.error(B),[]}},Dn=async(l,e,t,A)=>{var r;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((r=a.variants)==null?void 0:r.find(g=>g.id===n.colorVariantId))||c.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.colorVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=g=>{const d=l.find(E=>E.panelId===g.panelId);if(!d)throw new k(g);const B=`
|
|
1936
1936
|
<svg
|
|
1937
1937
|
xmlns="http://www.w3.org/2000/svg"
|
|
1938
1938
|
xmlnsXlink="http://www.w3.org/1999/xlink"
|