@useinsider/guido 3.30.0-beta.02005ef → 3.30.0-beta.0c48424

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.
@@ -1,8 +1,8 @@
1
1
  import { ToasterTypeOptions as l } from "../enums/toaster.js";
2
- import { ref as p } from "vue";
3
- import { useToaster as u } from "./useToaster.js";
2
+ import { ref as u } from "vue";
3
+ import { useToaster as p } from "./useToaster.js";
4
4
  import { useTranslations as f } from "./useTranslations.js";
5
- const d = ["accessExpired", "domainRestricted", "ipRestricted", "insiderAccessRestricted"], n = p(null), a = (e) => {
5
+ const d = ["accessExpired", "domainRestricted", "ipRestricted", "insiderAccessRestricted"], n = u(null), a = (e) => {
6
6
  try {
7
7
  return new URL(e, window.location.href).origin === window.location.origin;
8
8
  } catch {
@@ -22,31 +22,34 @@ const d = ["accessExpired", "domainRestricted", "ipRestricted", "insiderAccessRe
22
22
  } catch {
23
23
  return null;
24
24
  }
25
- }, y = (e) => typeof (e == null ? void 0 : e.message) == "string" ? e.message : "", s = (e) => y(e) || f()("user-management.collaborate-forbidden-action"), c = (e) => {
26
- u().showToaster({ type: l.Error, message: e });
25
+ }, y = (e) => typeof (e == null ? void 0 : e.message) == "string" ? e.message : "", i = (e) => y(e) || f()("user-management.collaborate-forbidden-action"), s = (e) => {
26
+ p().showToaster({ type: l.Error, message: e });
27
27
  }, R = (e, o, t) => {
28
28
  if (t && !a(t))
29
29
  return;
30
30
  const r = w(o);
31
31
  if (e === 403) {
32
- c(s(r));
32
+ s(i(r));
33
33
  return;
34
34
  }
35
35
  if (e === 401 && (r == null ? void 0 : r.type) === "groupLevelAccess") {
36
- c(s(r));
36
+ s(i(r));
37
37
  return;
38
38
  }
39
39
  if (e === 401 && typeof (r == null ? void 0 : r.type) == "string" && d.includes(r.type)) {
40
- const i = typeof r.redirect == "string" ? g(r.redirect) : "";
41
- if (i) {
42
- window.location.replace(i);
40
+ const c = typeof r.redirect == "string" ? g(r.redirect) : "";
41
+ if (c) {
42
+ window.location.replace(c);
43
43
  return;
44
44
  }
45
45
  }
46
46
  e !== 401 && e !== 419 || n.value || (window.isSessionExpired = !0, n.value = { status: e, data: r });
47
- }, T = () => ({ authError: n });
47
+ }, T = (e) => {
48
+ s(i(e));
49
+ }, O = () => ({ authError: n });
48
50
  export {
49
51
  a as isPanelOrigin,
50
52
  R as reportAuthError,
51
- T as useAuthError
53
+ T as reportProductRefusal,
54
+ O as useAuthError
52
55
  };
@@ -1,233 +1,241 @@
1
- import { useConfig as V } from "./useConfig.js";
2
- import { getIgnoredRecommendationBlockIds as M } from "../config/compiler/utils/recommendationIgnoreUtils.js";
3
- import { TemplateTypes as W } from "../enums/defaults.js";
4
- import { CONDITION_TAG_REGEX as G, DISPLAY_CONDITIONS_REGEX as H, DISPLAY_CONDITIONS_EXCEPTIONS_REGEX as K, CampaignCouldNotBeSavedKey as X, CanNotMakeAnyChangesForRunningKey as P, DATA_ATTRIBUTE_REGEX as Y, DYNAMIC_CONTENT_TAG_REGEX as $, ALLOWED_DYNAMIC_SYSTEM_TOKENS as U, VALID_DYNAMIC_VARIABLE_REGEX as j } from "../enums/html-validator.js";
5
- import { ToasterTypeOptions as c } from "../enums/toaster.js";
6
- import { BLOCK_ROOT_SELECTOR as q } from "../extensions/Blocks/Checkbox/constants/selectors.js";
7
- import { itemsBlockDynamicVariables as z } from "../extensions/Blocks/Items/enums/productEnums.js";
8
- import { BLOCK_ROOT_SELECTOR as Z } from "../extensions/Blocks/RadioButton/constants/selectors.js";
9
- import { RECOMMENDATION_VARIABLE_BUILTIN_ATTRIBUTES as J } from "../extensions/Blocks/Recommendation/constants/selectors.js";
10
- import { useRecommendationExtensionStore as Q } from "../extensions/Blocks/Recommendation/store/recommendation.js";
11
- import { filterToProductAttrValue as ee } from "../extensions/Blocks/Recommendation/utils/compositionKeys.js";
12
- import { STRATEGY_FIELD_KEY as te, RecommendationAssignStrategyKey as ne, RecommendationRequiredFieldsKey as se } from "../extensions/Blocks/Recommendation/validation/requiredFields.js";
13
- import { useRecommendationStore as re } from "../stores/recommendation.js";
14
- import { base64EncodeWithSpecialChars as oe } from "../utils/base64.js";
15
- import { computed as ie } from "vue";
16
- import { useHttp as ae } from "./useHttp.js";
17
- import { useToaster as ce } from "./useToaster.js";
18
- import { useTranslations as le } from "./useTranslations.js";
19
- const me = /recommendation-id="(\d+)"/g;
20
- function ue(s) {
21
- return [...s.matchAll(me)].map((m) => m[1]);
1
+ import { useConfig as W } from "./useConfig.js";
2
+ import { getIgnoredRecommendationBlockIds as G } from "../config/compiler/utils/recommendationIgnoreUtils.js";
3
+ import { TemplateTypes as H } from "../enums/defaults.js";
4
+ import { CONDITION_TAG_REGEX as K, DISPLAY_CONDITIONS_REGEX as P, DISPLAY_CONDITIONS_EXCEPTIONS_REGEX as X, CampaignCouldNotBeSavedKey as Y, CanNotMakeAnyChangesForRunningKey as $, DATA_ATTRIBUTE_REGEX as j, DYNAMIC_CONTENT_TAG_REGEX as U, ALLOWED_DYNAMIC_SYSTEM_TOKENS as q, VALID_DYNAMIC_VARIABLE_REGEX as z } from "../enums/html-validator.js";
5
+ import { ToasterTypeOptions as l } from "../enums/toaster.js";
6
+ import { BLOCK_ROOT_SELECTOR as Z } from "../extensions/Blocks/Checkbox/constants/selectors.js";
7
+ import { itemsBlockDynamicVariables as J } from "../extensions/Blocks/Items/enums/productEnums.js";
8
+ import { BLOCK_ROOT_SELECTOR as Q } from "../extensions/Blocks/RadioButton/constants/selectors.js";
9
+ import { RECOMMENDATION_VARIABLE_BUILTIN_ATTRIBUTES as ee } from "../extensions/Blocks/Recommendation/constants/selectors.js";
10
+ import { useRecommendationExtensionStore as te } from "../extensions/Blocks/Recommendation/store/recommendation.js";
11
+ import { filterToProductAttrValue as ne } from "../extensions/Blocks/Recommendation/utils/compositionKeys.js";
12
+ import { STRATEGY_FIELD_KEY as se, RecommendationAssignStrategyKey as re, RecommendationRequiredFieldsKey as oe } from "../extensions/Blocks/Recommendation/validation/requiredFields.js";
13
+ import { useRecommendationStore as ie } from "../stores/recommendation.js";
14
+ import { base64EncodeWithSpecialChars as ae } from "../utils/base64.js";
15
+ import { isPlainObject as S } from "../utils/genericUtil.js";
16
+ import { computed as ce } from "vue";
17
+ import { useHttp as le } from "./useHttp.js";
18
+ import { useToaster as me } from "./useToaster.js";
19
+ import { useTranslations as ue } from "./useTranslations.js";
20
+ const de = /recommendation-id="(\d+)"/g;
21
+ function fe(s) {
22
+ return [...s.matchAll(de)].map((m) => m[1]);
22
23
  }
23
- function de(s, m) {
24
- return m.some((f) => s.startsWith(`${f}_`));
24
+ function ge(s, m) {
25
+ return m.some((g) => s.startsWith(`${g}_`));
25
26
  }
26
- const fe = /^(\d+)_\d+_(.+)$/;
27
- function ge(s) {
28
- const m = s.match(fe);
27
+ const pe = /^(\d+)_\d+_(.+)$/;
28
+ function Ee(s) {
29
+ const m = s.match(pe);
29
30
  return m ? { recoId: m[1], attribute: m[2] } : null;
30
31
  }
31
- function pe(s) {
32
- const m = new Set(J);
33
- return Object.values(s).forEach((f) => {
34
- m.add(ee(f).toLowerCase());
32
+ function ye(s) {
33
+ const m = new Set(ee);
34
+ return Object.values(s).forEach((g) => {
35
+ m.add(ne(g).toLowerCase());
35
36
  }), m;
36
37
  }
37
- function Ee(s, m, f, o, d) {
38
+ function Ce(s, m, g, p, o) {
38
39
  const u = s.match(/{{([a-zA-Z0-9_.\s]*)}}/gm);
39
40
  if (!u)
40
41
  return [];
41
- const p = new Set(m.map((C) => C.toLowerCase())), E = [];
42
- return u.forEach((C) => {
43
- const g = C.slice(2, -2).trim().toLowerCase();
44
- if (g !== "" && p.has(g))
42
+ const d = new Set(m.map((y) => y.toLowerCase())), E = [];
43
+ return u.forEach((y) => {
44
+ const f = y.slice(2, -2).trim().toLowerCase();
45
+ if (f !== "" && d.has(f))
45
46
  return;
46
- const y = ge(g);
47
- if (y && o.has(y.recoId)) {
48
- if (!d || d.has(y.attribute))
47
+ const C = Ee(f);
48
+ if (C && p.has(C.recoId)) {
49
+ if (!o || o.has(C.attribute))
49
50
  return;
50
- E.push(g);
51
+ E.push(f);
51
52
  return;
52
53
  }
53
- de(g, f) || g.includes(".") || E.push(g);
54
+ ge(f, g) || f.includes(".") || E.push(f);
54
55
  }), E;
55
56
  }
56
- function Ce(s) {
57
- return (s.replace(Y, "$1").match($) ?? []).filter((o) => {
58
- const d = o.slice(2, -2), u = d.indexOf("|"), p = (u === -1 ? d : d.slice(0, u)).trim();
59
- return U.includes(p) ? !1 : j.test(p) ? u !== -1 && d.slice(u + 1).trim() === "" : !0;
57
+ function he(s) {
58
+ return (s.replace(j, "$1").match(U) ?? []).filter((p) => {
59
+ const o = p.slice(2, -2), u = o.indexOf("|"), d = (u === -1 ? o : o.slice(0, u)).trim();
60
+ return q.includes(d) ? !1 : z.test(d) ? u !== -1 && o.slice(u + 1).trim() === "" : !0;
60
61
  });
61
62
  }
62
- const Ve = () => {
63
- const { showToaster: s } = ce(), { post: m } = ae(), { config: f } = V(), o = le(), d = re(), u = Q(), p = ie(
63
+ const Ge = () => {
64
+ const { showToaster: s, handleError: m } = me(), { post: g } = le(), { config: p } = W(), o = ue(), u = ie(), d = te(), E = ce(
64
65
  () => {
65
66
  var e, t;
66
- return ((t = (e = f.value) == null ? void 0 : e.partner) == null ? void 0 : t.messageType) === W.transactional;
67
+ return ((t = (e = p.value) == null ? void 0 : e.partner) == null ? void 0 : t.messageType) === H.transactional;
67
68
  }
68
- ), E = async (e) => {
69
+ ), y = async (e) => {
69
70
  if (e.size === 0)
70
71
  return /* @__PURE__ */ new Set();
71
72
  try {
72
- await u.fetchRecommendationFilters();
73
+ await d.fetchRecommendationFilters();
73
74
  } catch {
74
75
  return null;
75
76
  }
76
- return pe(u.filterList);
77
- }, C = async (e) => {
78
- const n = await m(
79
- "/newsletter/template-library/check-template-html-body",
80
- { html: oe(e) }
81
- ), { status: r, message: a } = n.data;
82
- return r || s({
83
- type: c.Error,
84
- message: r === void 0 ? a : o("newsletter.invalid-url-link-for-toaster")
85
- }), o(X), a === o(P) && s({
86
- type: c.Error,
77
+ return ye(d.filterList);
78
+ }, f = async (e, t) => {
79
+ const n = "/newsletter/template-library/check-template-html-body";
80
+ let r;
81
+ try {
82
+ ({ data: r } = await g(
83
+ n,
84
+ { html: ae(e) }
85
+ ));
86
+ } catch (c) {
87
+ return t || m(c, "Failed to check links"), !1;
88
+ }
89
+ const a = S(r) ? r.status : void 0, i = S(r) && typeof r.message == "string" ? r.message : "";
90
+ return a || s({
91
+ type: l.Error,
92
+ message: a === void 0 && i ? i : o("newsletter.invalid-url-link-for-toaster")
93
+ }), o(Y), i === o($) && s({
94
+ type: l.Error,
87
95
  message: o("newsletter.already-in-progress")
88
- }), r;
89
- }, g = (e) => !["if", "endif", "else", "elif", "now"].includes(e.toLowerCase()), y = (e) => ["if", "endif"].includes(e.toLowerCase()), S = (e, t) => {
96
+ }), !!a;
97
+ }, C = (e) => !["if", "endif", "else", "elif", "now"].includes(e.toLowerCase()), R = (e) => ["if", "endif"].includes(e.toLowerCase()), _ = (e, t) => {
90
98
  const n = e.match(/({%(.*?)%})/g);
91
99
  let r = !0;
92
- return n !== null && !p.value && n.forEach((a) => {
100
+ return n !== null && !E.value && n.forEach((a) => {
93
101
  const i = a.slice(2, -2).trim().match(/(".*?"|[^"\s]+)(?=\s*|\s*$)/g);
94
102
  if (i && i.length > 0) {
95
- const [l] = i;
96
- g(l) && !t.includes(l) && (s({
97
- type: c.Warning,
103
+ const [c] = i;
104
+ C(c) && !t.includes(c) && (s({
105
+ type: l.Warning,
98
106
  message: o("custom-fields.invalid-custom-fields")
99
107
  }), r = !1);
100
108
  }
101
109
  }), r;
102
- }, R = async (e, t, n) => {
103
- const r = n ? await C(e) : !0;
104
- return S(e, t) && r;
105
- }, _ = (e) => e.length > 0 ? !0 : (s({
106
- type: c.Warning,
110
+ }, A = async (e, t, n, r) => {
111
+ const a = n ? await f(e, r) : !0;
112
+ return _(e, t) && a;
113
+ }, O = (e) => e.length > 0 ? !0 : (s({
114
+ type: l.Warning,
107
115
  message: o("newsletter.html-content-is-empty")
108
- }), !1), A = (e) => {
116
+ }), !1), b = (e) => {
109
117
  const t = (e.match(/{/gm) || []).length, n = (e.match(/}/gm) || []).length;
110
118
  return t > n && s({
111
- type: c.Warning,
119
+ type: l.Warning,
112
120
  message: o("custom-fields.missing-closing-braces")
113
121
  }), t < n && s({
114
- type: c.Warning,
122
+ type: l.Warning,
115
123
  message: o("custom-fields.missing-opening-braces")
116
124
  }), t === n;
117
- }, O = (e) => {
118
- const t = Ce(e).length === 0;
125
+ }, w = (e) => {
126
+ const t = he(e).length === 0;
119
127
  return t || s({
120
- type: c.Warning,
128
+ type: l.Warning,
121
129
  message: o("custom-fields.invalid-custom-fields")
122
130
  }), t;
123
- }, b = (e, t, n, r) => {
124
- if (p.value)
131
+ }, N = (e, t, n, r) => {
132
+ if (E.value)
125
133
  return !0;
126
- const a = Ee(
134
+ const a = Ce(
127
135
  e,
128
136
  t,
129
- ue(e),
137
+ fe(e),
130
138
  n,
131
139
  r
132
140
  );
133
141
  if (a.length > 0) {
134
142
  const i = `
135
143
  <ul>
136
- ${a.map((l) => `<li>${l}</li>`).join("")}
144
+ ${a.map((c) => `<li>${c}</li>`).join("")}
137
145
  </ul>
138
146
  `;
139
147
  return s({
140
- type: c.Error,
148
+ type: l.Error,
141
149
  message: o("custom-fields.invalid-custom-fields") + i
142
150
  }), !1;
143
151
  }
144
152
  return !0;
145
- }, w = (e) => {
146
- const t = e.match(G), n = [];
153
+ }, L = (e) => {
154
+ const t = e.match(K), n = [];
147
155
  let r = !0;
148
156
  if (t && t.forEach((a) => {
149
- const i = a.match(H), l = a.match(K), v = (i == null ? void 0 : i.join("")) || "";
150
- (!i || a !== v) && !l && (s({
151
- type: c.Error,
157
+ const i = a.match(P), c = a.match(X), I = (i == null ? void 0 : i.join("")) || "";
158
+ (!i || a !== I) && !c && (s({
159
+ type: l.Error,
152
160
  message: o("newsletter.display-conditions-invalid-syntax")
153
161
  }), r = !1), i && i.forEach((h) => {
154
162
  h.trim() === "=" && (s({
155
- type: c.Error,
163
+ type: l.Error,
156
164
  message: o("custom-conditions.wrong-equality-operators")
157
165
  }), r = !1);
158
- const T = h.match(/^[a-zA-Z]*$/g);
159
- T && T.forEach((I) => {
160
- y(I) && n.push(I);
166
+ const v = h.match(/^[a-zA-Z]*$/g);
167
+ v && v.forEach((T) => {
168
+ R(T) && n.push(T);
161
169
  });
162
170
  });
163
171
  }), n.length) {
164
- const a = n.filter((l) => l === "if"), i = n.filter((l) => l === "endif");
172
+ const a = n.filter((c) => c === "if"), i = n.filter((c) => c === "endif");
165
173
  a.length !== i.length && (s({
166
- type: c.Error,
174
+ type: l.Error,
167
175
  message: o("custom-conditions.missing-if-endif-tag")
168
176
  }), r = !1);
169
177
  }
170
178
  return r;
171
- }, N = (e) => {
179
+ }, B = (e) => {
172
180
  const t = (e.match(/{% /gm) || []).length, n = (e.match(/ %}/gm) || []).length, r = t === n;
173
181
  return r || s({
174
- type: c.Warning,
182
+ type: l.Warning,
175
183
  message: o("custom-conditions.no-space-after-braces")
176
184
  }), r;
177
- }, L = (e) => (e.match(/({%(.*?)%})/g) || []).filter((n) => n.includes("if")).map((n) => (n.match(/{{.*}}/gm) || []).length).reduce((n, r) => n + r, 0) > 0 ? (s({
178
- type: c.Warning,
185
+ }, F = (e) => (e.match(/({%(.*?)%})/g) || []).filter((n) => n.includes("if")).map((n) => (n.match(/{{.*}}/gm) || []).length).reduce((n, r) => n + r, 0) > 0 ? (s({
186
+ type: l.Warning,
179
187
  message: o("custom-conditions.no-braces-inside-if-tag")
180
- }), !1) : !0, B = () => {
181
- if (!u.hasInvalidBlock())
188
+ }), !1) : !0, k = () => {
189
+ if (!d.hasInvalidBlock())
182
190
  return !0;
183
- const e = u.invalidBlockFields(), t = e.length > 0 && e.every((n) => n === te);
191
+ const e = d.invalidBlockFields(), t = e.length > 0 && e.every((n) => n === se);
184
192
  return s({
185
- type: t ? c.Warning : c.Error,
186
- message: o(t ? ne : se)
193
+ type: t ? l.Warning : l.Error,
194
+ message: o(t ? re : oe)
187
195
  }), !1;
188
- }, F = () => d.recommendationConfigs && Object.values(d.recommendationConfigs).find((t) => t.filters.find((n) => n.value === "")) !== void 0 ? (s({
189
- type: c.Error,
196
+ }, x = () => u.recommendationConfigs && Object.values(u.recommendationConfigs).find((t) => t.filters.find((n) => n.value === "")) !== void 0 ? (s({
197
+ type: l.Error,
190
198
  message: o("newsletter.fill-all-necessary-fields")
191
- }), !1) : !0, x = (e) => {
199
+ }), !1) : !0, D = (e) => {
192
200
  const t = /src="[^"]*\.(svg|pst)"/gm;
193
201
  return e.match(t) === null ? !0 : (s({
194
- type: c.Error,
202
+ type: l.Error,
195
203
  message: o("newsletter.invalid-image-type")
196
204
  }), !1);
197
- }, D = (e) => {
198
- const r = new DOMParser().parseFromString(e, "text/html").querySelectorAll(q);
205
+ }, V = (e) => {
206
+ const r = new DOMParser().parseFromString(e, "text/html").querySelectorAll(Z);
199
207
  return Array.from(r).find((i) => {
200
- var l;
201
- return !((l = i.id) != null && l.trim());
208
+ var c;
209
+ return !((c = i.id) != null && c.trim());
202
210
  }) ? (s({
203
- type: c.Error,
211
+ type: l.Error,
204
212
  message: o("unsubscribe-templates.select-checkbox-groups")
205
213
  }), !1) : !0;
206
- }, k = (e) => {
207
- const r = new DOMParser().parseFromString(e, "text/html").querySelectorAll(Z);
214
+ }, M = (e) => {
215
+ const r = new DOMParser().parseFromString(e, "text/html").querySelectorAll(Q);
208
216
  return Array.from(r).find((i) => {
209
- var l;
210
- return !((l = i.id) != null && l.trim());
217
+ var c;
218
+ return !((c = i.id) != null && c.trim());
211
219
  }) ? (s({
212
- type: c.Error,
220
+ type: l.Error,
213
221
  message: o("unsubscribe-templates.select-radio-button-groups")
214
222
  }), !1) : !0;
215
223
  };
216
- return { validateHtml: async (e, t, n = !1) => {
217
- var v, h;
218
- const r = [
224
+ return { validateHtml: async (e, t, n = !1, r = !1) => {
225
+ var h, v;
226
+ const a = [
219
227
  ...t.map((T) => T.value),
220
- ...z,
221
- ...((h = (v = f.value) == null ? void 0 : v.template) == null ? void 0 : h.customFieldAttributes) ?? []
222
- ], a = M(e), i = await E(a);
223
- return await R(e, r, n) && _(e) && A(e) && O(e) && b(e, r, a, i) && w(e) && N(e) && L(e) && B() && F() && x(e) && D(e) && k(e);
228
+ ...J,
229
+ ...((v = (h = p.value) == null ? void 0 : h.template) == null ? void 0 : v.customFieldAttributes) ?? []
230
+ ], i = G(e), c = await y(i);
231
+ return await A(e, a, n, r) && O(e) && b(e) && w(e) && N(e, a, i, c) && L(e) && B(e) && F(e) && k() && x() && D(e) && V(e) && M(e);
224
232
  } };
225
233
  };
226
234
  export {
227
- pe as buildPartnerAttributeNameSet,
228
- Ee as findInvalidCustomFields,
229
- Ce as getInvalidDynamicContentTags,
230
- ue as getRecommendationBlockIds,
231
- ge as parseRecommendationVariable,
232
- Ve as useHtmlValidator
235
+ ye as buildPartnerAttributeNameSet,
236
+ Ce as findInvalidCustomFields,
237
+ he as getInvalidDynamicContentTags,
238
+ fe as getRecommendationBlockIds,
239
+ Ee as parseRecommendationVariable,
240
+ Ge as useHtmlValidator
233
241
  };
@@ -1,98 +1,107 @@
1
- import { getCsrfToken as D } from "../utils/genericUtil.js";
2
- import { ref as T, computed as w } from "vue";
3
- import { isPanelOrigin as j, reportAuthError as X } from "./useAuthError.js";
4
- const k = [401, 403, 419], _ = (g = {}) => {
5
- const f = T(!1), n = T(null), c = T(null), b = w(() => f.value), y = w(() => n.value !== null), E = {
1
+ import { getCsrfToken as X, isPlainObject as k } from "../utils/genericUtil.js";
2
+ import { ref as g, computed as T } from "vue";
3
+ import { isPanelOrigin as b, reportAuthError as F, reportProductRefusal as M } from "./useAuthError.js";
4
+ const N = [401, 403, 419], J = (y = {}) => {
5
+ const m = g(!1), a = g(null), f = g(null), P = T(() => m.value), x = T(() => a.value !== null), v = {
6
6
  baseURL: "",
7
7
  timeout: 1e4,
8
8
  retry: 0,
9
9
  retryDelay: 1e3,
10
10
  headers: {
11
11
  "Content-Type": "application/json",
12
- "X-CSRF-TOKEN": D(),
12
+ "X-CSRF-TOKEN": X(),
13
13
  Accept: "application/json",
14
14
  // Without this a guest fetch gets a 302 to the login page, never an auth status.
15
15
  "X-Requested-With": "XMLHttpRequest"
16
16
  },
17
- ...g
18
- }, x = (e, r) => {
17
+ ...y
18
+ }, A = (e, r) => {
19
19
  if (e.startsWith("http://") || e.startsWith("https://"))
20
20
  return e;
21
- const t = r || E.baseURL || "";
22
- return t.endsWith("/") && e.startsWith("/") ? `${t}${e.slice(1)}` : t.endsWith("/") || e.startsWith("/") ? `${t}${e}` : `${t}/${e}`;
23
- }, R = (e) => new Promise((r, t) => {
21
+ const s = r || v.baseURL || "";
22
+ return s.endsWith("/") && e.startsWith("/") ? `${s}${e.slice(1)}` : s.endsWith("/") || e.startsWith("/") ? `${s}${e}` : `${s}/${e}`;
23
+ }, S = (e) => new Promise((r, s) => {
24
24
  setTimeout(() => {
25
- t(new Error("Request timeout"));
25
+ s(new Error("Request timeout"));
26
26
  }, e);
27
- }), P = (e) => new Promise((r) => {
27
+ }), U = (e) => new Promise((r) => {
28
28
  setTimeout(r, e);
29
- }), i = async (e, r, t, W = {}) => {
30
- n.value = null, f.value = !0, c.value = new AbortController();
31
- const a = { ...E, ...W }, p = x(r, a.baseURL), d = {
29
+ }), u = async (e, r, s, j = {}) => {
30
+ a.value = null, m.value = !0, f.value = new AbortController();
31
+ const i = { ...v, ...j }, h = A(r, i.baseURL), p = {
32
32
  method: e,
33
- headers: { ...a.headers },
34
- signal: c.value.signal,
35
- ...a
33
+ headers: { ...i.headers },
34
+ signal: f.value.signal,
35
+ ...i
36
36
  };
37
- t && ["POST", "PUT", "PATCH"].includes(e) && (t instanceof FormData ? (delete d.headers["Content-Type"], d.body = t) : d.body = JSON.stringify(t));
38
- const v = async (m = 0) => {
37
+ s && ["POST", "PUT", "PATCH"].includes(e) && (s instanceof FormData ? (delete p.headers["Content-Type"], p.body = s) : p.body = JSON.stringify(s));
38
+ const E = async (w = 0) => {
39
+ var R;
39
40
  if (window.isSessionExpired) {
40
- n.value = { message: "Session expired", authReported: !0 };
41
+ a.value = { message: "Session expired", authReported: !0 };
41
42
  const o = new Error("Session expired");
42
43
  throw o.authReported = !0, o;
43
44
  }
44
45
  try {
45
- const o = [fetch(p, d)];
46
- a.timeout && o.push(R(a.timeout));
47
- const s = await Promise.race(o);
48
- if (!s.ok) {
49
- const H = `HTTP Error: ${s.status} ${s.statusText}`, l = new Error(H);
50
- throw l.status = s.status, l.statusText = s.statusText, l.response = s, l.authReported = k.includes(s.status) && j(p), l.authReported && Promise.resolve().then(() => s.clone().text().catch(() => "")).then((O) => X(
51
- s.status,
52
- O,
53
- new URL(p, window.location.href).href
46
+ const o = [fetch(h, p)];
47
+ i.timeout && o.push(S(i.timeout));
48
+ const t = await Promise.race(o);
49
+ if (!t.ok) {
50
+ const c = `HTTP Error: ${t.status} ${t.statusText}`, d = new Error(c);
51
+ throw d.status = t.status, d.statusText = t.statusText, d.response = t, d.authReported = N.includes(t.status) && b(h), d.authReported && Promise.resolve().then(() => t.clone().text().catch(() => "")).then((D) => F(
52
+ t.status,
53
+ D,
54
+ new URL(h, window.location.href).href
54
55
  )).catch(() => {
55
- }), l;
56
+ }), d;
56
57
  }
57
- let h;
58
- const u = s.headers.get("content-type");
59
- return u != null && u.includes("application/json") ? h = await s.json() : u != null && u.includes("text/") ? h = await s.text() : h = await s.blob(), {
60
- data: h,
61
- status: s.status,
62
- statusText: s.statusText,
63
- headers: s.headers
58
+ let n;
59
+ const l = t.headers.get("content-type");
60
+ if (l != null && l.includes("application/json") ? n = await t.json() : l != null && l.includes("text/") ? n = await t.text() : n = await t.blob(), b(h) && k(n) && n.unauthorized === !0 && n.success === !1) {
61
+ const c = new Error(
62
+ typeof n.message == "string" ? n.message : "Product access refused"
63
+ );
64
+ throw c.status = t.status, c.authReported = !0, M(n), a.value = { message: c.message, status: t.status, authReported: !0 }, c;
65
+ }
66
+ return {
67
+ data: n,
68
+ status: t.status,
69
+ statusText: t.statusText,
70
+ headers: t.headers
64
71
  };
65
72
  } catch (o) {
66
- const s = o instanceof Error && o.name === "AbortError";
67
- if (m < (a.retry || 0) && !s)
68
- return await P(a.retryDelay || 1e3), v(m + 1);
69
- throw o instanceof Error ? o.name === "AbortError" ? n.value = { message: "Request was cancelled" } : n.value = { message: o.message } : n.value = o, o;
73
+ if ((R = a.value) != null && R.authReported)
74
+ throw o;
75
+ const t = o instanceof Error && o.name === "AbortError";
76
+ if (w < (i.retry || 0) && !t)
77
+ return await U(i.retryDelay || 1e3), E(w + 1);
78
+ throw o instanceof Error ? o.name === "AbortError" ? a.value = { message: "Request was cancelled" } : a.value = { message: o.message } : a.value = o, o;
70
79
  }
71
80
  };
72
81
  try {
73
- return await v();
82
+ return await E();
74
83
  } finally {
75
- f.value = !1, c.value = null;
84
+ m.value = !1, f.value = null;
76
85
  }
77
- }, A = (e, r) => i("GET", e, void 0, r), S = (e, r, t) => i("POST", e, r, t), U = (e, r, t) => i("PUT", e, r, t), C = (e, r, t) => i("PATCH", e, r, t), $ = (e, r) => i("DELETE", e, void 0, r), q = (e) => {
78
- c.value && c.value.abort(e);
79
- }, L = () => {
80
- n.value = null;
86
+ }, C = (e, r) => u("GET", e, void 0, r), $ = (e, r, s) => u("POST", e, r, s), q = (e, r, s) => u("PUT", e, r, s), L = (e, r, s) => u("PATCH", e, r, s), O = (e, r) => u("DELETE", e, void 0, r), W = (e) => {
87
+ f.value && f.value.abort(e);
88
+ }, H = () => {
89
+ a.value = null;
81
90
  };
82
91
  return {
83
- loading: b,
84
- error: w(() => n.value),
85
- hasError: y,
86
- request: i,
87
- get: A,
88
- post: S,
89
- put: U,
90
- patch: C,
91
- delete: $,
92
- cancel: q,
93
- clearError: L
92
+ loading: P,
93
+ error: T(() => a.value),
94
+ hasError: x,
95
+ request: u,
96
+ get: C,
97
+ post: $,
98
+ put: q,
99
+ patch: L,
100
+ delete: O,
101
+ cancel: W,
102
+ clearError: H
94
103
  };
95
104
  };
96
105
  export {
97
- _ as useHttp
106
+ J as useHttp
98
107
  };
@@ -39,7 +39,7 @@ const Pt = () => {
39
39
  });
40
40
  }
41
41
  return !0;
42
- }, M = async (t, e) => !H(t.compiledHtml) || u("blockUnsubscribeLinks") && !V(t.rawHtml, e) || !E(t.compiledHtml) || !g(t.compiledHtml) ? !1 : u("liquidSyntax") ? b(t.compiledHtml) : y(t.compiledHtml, t.dynamicContentList, !0), v = async (t, e) => {
42
+ }, M = async (t, e) => !H(t.compiledHtml) || u("blockUnsubscribeLinks") && !V(t.rawHtml, e) || !E(t.compiledHtml) || !g(t.compiledHtml) ? !1 : u("liquidSyntax") ? b(t.compiledHtml) : y(t.compiledHtml, t.dynamicContentList, !0, e), v = async (t, e) => {
43
43
  if (!await C())
44
44
  return;
45
45
  const { unsubscribePayload: o, stripoModules: r } = x(t.rawHtml);