@useinsider/guido 3.30.0-beta.0c48424 → 3.30.0-beta.0f74543

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 u } from "vue";
3
- import { useToaster as p } from "./useToaster.js";
2
+ import { ref as p } from "vue";
3
+ import { useToaster as u } from "./useToaster.js";
4
4
  import { useTranslations as f } from "./useTranslations.js";
5
- const d = ["accessExpired", "domainRestricted", "ipRestricted", "insiderAccessRestricted"], n = u(null), a = (e) => {
5
+ const d = ["accessExpired", "domainRestricted", "ipRestricted", "insiderAccessRestricted"], n = p(null), a = (e) => {
6
6
  try {
7
7
  return new URL(e, window.location.href).origin === window.location.origin;
8
8
  } catch {
@@ -22,34 +22,31 @@ 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 : "", i = (e) => y(e) || f()("user-management.collaborate-forbidden-action"), s = (e) => {
26
- p().showToaster({ type: l.Error, message: e });
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 });
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
- s(i(r));
32
+ c(s(r));
33
33
  return;
34
34
  }
35
35
  if (e === 401 && (r == null ? void 0 : r.type) === "groupLevelAccess") {
36
- s(i(r));
36
+ c(s(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 c = typeof r.redirect == "string" ? g(r.redirect) : "";
41
- if (c) {
42
- window.location.replace(c);
40
+ const i = typeof r.redirect == "string" ? g(r.redirect) : "";
41
+ if (i) {
42
+ window.location.replace(i);
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 = (e) => {
48
- s(i(e));
49
- }, O = () => ({ authError: n });
47
+ }, T = () => ({ authError: n });
50
48
  export {
51
49
  a as isPanelOrigin,
52
50
  R as reportAuthError,
53
- T as reportProductRefusal,
54
- O as useAuthError
51
+ T as useAuthError
55
52
  };
@@ -1,241 +1,233 @@
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]);
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]);
23
22
  }
24
- function ge(s, m) {
25
- return m.some((g) => s.startsWith(`${g}_`));
23
+ function de(s, m) {
24
+ return m.some((f) => s.startsWith(`${f}_`));
26
25
  }
27
- const pe = /^(\d+)_\d+_(.+)$/;
28
- function Ee(s) {
29
- const m = s.match(pe);
26
+ const fe = /^(\d+)_\d+_(.+)$/;
27
+ function ge(s) {
28
+ const m = s.match(fe);
30
29
  return m ? { recoId: m[1], attribute: m[2] } : null;
31
30
  }
32
- function ye(s) {
33
- const m = new Set(ee);
34
- return Object.values(s).forEach((g) => {
35
- m.add(ne(g).toLowerCase());
31
+ function pe(s) {
32
+ const m = new Set(J);
33
+ return Object.values(s).forEach((f) => {
34
+ m.add(ee(f).toLowerCase());
36
35
  }), m;
37
36
  }
38
- function Ce(s, m, g, p, o) {
37
+ function Ee(s, m, f, o, d) {
39
38
  const u = s.match(/{{([a-zA-Z0-9_.\s]*)}}/gm);
40
39
  if (!u)
41
40
  return [];
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))
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))
46
45
  return;
47
- const C = Ee(f);
48
- if (C && p.has(C.recoId)) {
49
- if (!o || o.has(C.attribute))
46
+ const y = ge(g);
47
+ if (y && o.has(y.recoId)) {
48
+ if (!d || d.has(y.attribute))
50
49
  return;
51
- E.push(f);
50
+ E.push(g);
52
51
  return;
53
52
  }
54
- ge(f, g) || f.includes(".") || E.push(f);
53
+ de(g, f) || g.includes(".") || E.push(g);
55
54
  }), E;
56
55
  }
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;
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;
61
60
  });
62
61
  }
63
- const Ge = () => {
64
- const { showToaster: s, handleError: m } = me(), { post: g } = le(), { config: p } = W(), o = ue(), u = ie(), d = te(), E = ce(
62
+ const Ve = () => {
63
+ const { showToaster: s } = ce(), { post: m } = ae(), { config: f } = V(), o = le(), d = re(), u = Q(), p = ie(
65
64
  () => {
66
65
  var e, t;
67
- return ((t = (e = p.value) == null ? void 0 : e.partner) == null ? void 0 : t.messageType) === H.transactional;
66
+ return ((t = (e = f.value) == null ? void 0 : e.partner) == null ? void 0 : t.messageType) === W.transactional;
68
67
  }
69
- ), y = async (e) => {
68
+ ), E = async (e) => {
70
69
  if (e.size === 0)
71
70
  return /* @__PURE__ */ new Set();
72
71
  try {
73
- await d.fetchRecommendationFilters();
72
+ await u.fetchRecommendationFilters();
74
73
  } catch {
75
74
  return null;
76
75
  }
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,
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,
95
87
  message: o("newsletter.already-in-progress")
96
- }), !!a;
97
- }, C = (e) => !["if", "endif", "else", "elif", "now"].includes(e.toLowerCase()), R = (e) => ["if", "endif"].includes(e.toLowerCase()), _ = (e, t) => {
88
+ }), r;
89
+ }, g = (e) => !["if", "endif", "else", "elif", "now"].includes(e.toLowerCase()), y = (e) => ["if", "endif"].includes(e.toLowerCase()), S = (e, t) => {
98
90
  const n = e.match(/({%(.*?)%})/g);
99
91
  let r = !0;
100
- return n !== null && !E.value && n.forEach((a) => {
92
+ return n !== null && !p.value && n.forEach((a) => {
101
93
  const i = a.slice(2, -2).trim().match(/(".*?"|[^"\s]+)(?=\s*|\s*$)/g);
102
94
  if (i && i.length > 0) {
103
- const [c] = i;
104
- C(c) && !t.includes(c) && (s({
105
- type: l.Warning,
95
+ const [l] = i;
96
+ g(l) && !t.includes(l) && (s({
97
+ type: c.Warning,
106
98
  message: o("custom-fields.invalid-custom-fields")
107
99
  }), r = !1);
108
100
  }
109
101
  }), r;
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,
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,
115
107
  message: o("newsletter.html-content-is-empty")
116
- }), !1), b = (e) => {
108
+ }), !1), A = (e) => {
117
109
  const t = (e.match(/{/gm) || []).length, n = (e.match(/}/gm) || []).length;
118
110
  return t > n && s({
119
- type: l.Warning,
111
+ type: c.Warning,
120
112
  message: o("custom-fields.missing-closing-braces")
121
113
  }), t < n && s({
122
- type: l.Warning,
114
+ type: c.Warning,
123
115
  message: o("custom-fields.missing-opening-braces")
124
116
  }), t === n;
125
- }, w = (e) => {
126
- const t = he(e).length === 0;
117
+ }, O = (e) => {
118
+ const t = Ce(e).length === 0;
127
119
  return t || s({
128
- type: l.Warning,
120
+ type: c.Warning,
129
121
  message: o("custom-fields.invalid-custom-fields")
130
122
  }), t;
131
- }, N = (e, t, n, r) => {
132
- if (E.value)
123
+ }, b = (e, t, n, r) => {
124
+ if (p.value)
133
125
  return !0;
134
- const a = Ce(
126
+ const a = Ee(
135
127
  e,
136
128
  t,
137
- fe(e),
129
+ ue(e),
138
130
  n,
139
131
  r
140
132
  );
141
133
  if (a.length > 0) {
142
134
  const i = `
143
135
  <ul>
144
- ${a.map((c) => `<li>${c}</li>`).join("")}
136
+ ${a.map((l) => `<li>${l}</li>`).join("")}
145
137
  </ul>
146
138
  `;
147
139
  return s({
148
- type: l.Error,
140
+ type: c.Error,
149
141
  message: o("custom-fields.invalid-custom-fields") + i
150
142
  }), !1;
151
143
  }
152
144
  return !0;
153
- }, L = (e) => {
154
- const t = e.match(K), n = [];
145
+ }, w = (e) => {
146
+ const t = e.match(G), n = [];
155
147
  let r = !0;
156
148
  if (t && t.forEach((a) => {
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,
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,
160
152
  message: o("newsletter.display-conditions-invalid-syntax")
161
153
  }), r = !1), i && i.forEach((h) => {
162
154
  h.trim() === "=" && (s({
163
- type: l.Error,
155
+ type: c.Error,
164
156
  message: o("custom-conditions.wrong-equality-operators")
165
157
  }), r = !1);
166
- const v = h.match(/^[a-zA-Z]*$/g);
167
- v && v.forEach((T) => {
168
- R(T) && n.push(T);
158
+ const T = h.match(/^[a-zA-Z]*$/g);
159
+ T && T.forEach((I) => {
160
+ y(I) && n.push(I);
169
161
  });
170
162
  });
171
163
  }), n.length) {
172
- const a = n.filter((c) => c === "if"), i = n.filter((c) => c === "endif");
164
+ const a = n.filter((l) => l === "if"), i = n.filter((l) => l === "endif");
173
165
  a.length !== i.length && (s({
174
- type: l.Error,
166
+ type: c.Error,
175
167
  message: o("custom-conditions.missing-if-endif-tag")
176
168
  }), r = !1);
177
169
  }
178
170
  return r;
179
- }, B = (e) => {
171
+ }, N = (e) => {
180
172
  const t = (e.match(/{% /gm) || []).length, n = (e.match(/ %}/gm) || []).length, r = t === n;
181
173
  return r || s({
182
- type: l.Warning,
174
+ type: c.Warning,
183
175
  message: o("custom-conditions.no-space-after-braces")
184
176
  }), r;
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,
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,
187
179
  message: o("custom-conditions.no-braces-inside-if-tag")
188
- }), !1) : !0, k = () => {
189
- if (!d.hasInvalidBlock())
180
+ }), !1) : !0, B = () => {
181
+ if (!u.hasInvalidBlock())
190
182
  return !0;
191
- const e = d.invalidBlockFields(), t = e.length > 0 && e.every((n) => n === se);
183
+ const e = u.invalidBlockFields(), t = e.length > 0 && e.every((n) => n === te);
192
184
  return s({
193
- type: t ? l.Warning : l.Error,
194
- message: o(t ? re : oe)
185
+ type: t ? c.Warning : c.Error,
186
+ message: o(t ? ne : se)
195
187
  }), !1;
196
- }, x = () => u.recommendationConfigs && Object.values(u.recommendationConfigs).find((t) => t.filters.find((n) => n.value === "")) !== void 0 ? (s({
197
- type: l.Error,
188
+ }, F = () => d.recommendationConfigs && Object.values(d.recommendationConfigs).find((t) => t.filters.find((n) => n.value === "")) !== void 0 ? (s({
189
+ type: c.Error,
198
190
  message: o("newsletter.fill-all-necessary-fields")
199
- }), !1) : !0, D = (e) => {
191
+ }), !1) : !0, x = (e) => {
200
192
  const t = /src="[^"]*\.(svg|pst)"/gm;
201
193
  return e.match(t) === null ? !0 : (s({
202
- type: l.Error,
194
+ type: c.Error,
203
195
  message: o("newsletter.invalid-image-type")
204
196
  }), !1);
205
- }, V = (e) => {
206
- const r = new DOMParser().parseFromString(e, "text/html").querySelectorAll(Z);
197
+ }, D = (e) => {
198
+ const r = new DOMParser().parseFromString(e, "text/html").querySelectorAll(q);
207
199
  return Array.from(r).find((i) => {
208
- var c;
209
- return !((c = i.id) != null && c.trim());
200
+ var l;
201
+ return !((l = i.id) != null && l.trim());
210
202
  }) ? (s({
211
- type: l.Error,
203
+ type: c.Error,
212
204
  message: o("unsubscribe-templates.select-checkbox-groups")
213
205
  }), !1) : !0;
214
- }, M = (e) => {
215
- const r = new DOMParser().parseFromString(e, "text/html").querySelectorAll(Q);
206
+ }, k = (e) => {
207
+ const r = new DOMParser().parseFromString(e, "text/html").querySelectorAll(Z);
216
208
  return Array.from(r).find((i) => {
217
- var c;
218
- return !((c = i.id) != null && c.trim());
209
+ var l;
210
+ return !((l = i.id) != null && l.trim());
219
211
  }) ? (s({
220
- type: l.Error,
212
+ type: c.Error,
221
213
  message: o("unsubscribe-templates.select-radio-button-groups")
222
214
  }), !1) : !0;
223
215
  };
224
- return { validateHtml: async (e, t, n = !1, r = !1) => {
225
- var h, v;
226
- const a = [
216
+ return { validateHtml: async (e, t, n = !1) => {
217
+ var v, h;
218
+ const r = [
227
219
  ...t.map((T) => T.value),
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);
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);
232
224
  } };
233
225
  };
234
226
  export {
235
- ye as buildPartnerAttributeNameSet,
236
- Ce as findInvalidCustomFields,
237
- he as getInvalidDynamicContentTags,
238
- fe as getRecommendationBlockIds,
239
- Ee as parseRecommendationVariable,
240
- Ge as useHtmlValidator
227
+ pe as buildPartnerAttributeNameSet,
228
+ Ee as findInvalidCustomFields,
229
+ Ce as getInvalidDynamicContentTags,
230
+ ue as getRecommendationBlockIds,
231
+ ge as parseRecommendationVariable,
232
+ Ve as useHtmlValidator
241
233
  };
@@ -1,107 +1,98 @@
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 = {
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 = {
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": X(),
12
+ "X-CSRF-TOKEN": D(),
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
- ...y
18
- }, A = (e, r) => {
17
+ ...g
18
+ }, x = (e, r) => {
19
19
  if (e.startsWith("http://") || e.startsWith("https://"))
20
20
  return e;
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) => {
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) => {
24
24
  setTimeout(() => {
25
- s(new Error("Request timeout"));
25
+ t(new Error("Request timeout"));
26
26
  }, e);
27
- }), U = (e) => new Promise((r) => {
27
+ }), P = (e) => new Promise((r) => {
28
28
  setTimeout(r, e);
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 = {
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 = {
32
32
  method: e,
33
- headers: { ...i.headers },
34
- signal: f.value.signal,
35
- ...i
33
+ headers: { ...a.headers },
34
+ signal: c.value.signal,
35
+ ...a
36
36
  };
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;
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) => {
40
39
  if (window.isSessionExpired) {
41
- a.value = { message: "Session expired", authReported: !0 };
40
+ n.value = { message: "Session expired", authReported: !0 };
42
41
  const o = new Error("Session expired");
43
42
  throw o.authReported = !0, o;
44
43
  }
45
44
  try {
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
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
55
54
  )).catch(() => {
56
- }), d;
55
+ }), l;
57
56
  }
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
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
71
64
  };
72
65
  } catch (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;
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;
79
70
  }
80
71
  };
81
72
  try {
82
- return await E();
73
+ return await v();
83
74
  } finally {
84
- m.value = !1, f.value = null;
75
+ f.value = !1, c.value = null;
85
76
  }
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;
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;
90
81
  };
91
82
  return {
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
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
103
94
  };
104
95
  };
105
96
  export {
106
- J as useHttp
97
+ _ as useHttp
107
98
  };
@@ -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, e), 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), v = async (t, e) => {
43
43
  if (!await C())
44
44
  return;
45
45
  const { unsubscribePayload: o, stripoModules: r } = x(t.rawHtml);