@useinsider/guido 3.29.0 → 3.30.0-beta.232ea3c
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/@types/config/schemas.js +3 -3
- package/dist/@types/email-be/html-validation.js +28 -0
- package/dist/composables/useSave.js +19 -17
- package/dist/composables/useSaveValidation.js +134 -252
- package/dist/composables/useTranslations.js +14 -9
- package/dist/enums/email-be.js +27 -0
- package/dist/enums/save-validation.js +2 -2
- package/dist/node_modules/valibot/dist/index.js +232 -154
- package/dist/package.json.js +2 -2
- package/dist/services/emailBe/errors/ApiError.js +50 -0
- package/dist/services/emailBe/errors/handleApiError.js +31 -0
- package/dist/services/emailBe/errors/toApiError.js +71 -0
- package/dist/services/emailBe/html/HtmlValidationService.js +35 -0
- package/dist/services/emailBe/html/index.js +6 -0
- package/dist/services/emailBe/http/HttpManager.js +68 -0
- package/dist/services/emailBe/http/RetryStack.js +24 -0
- package/dist/services/emailBe/http/client.js +61 -0
- package/dist/services/emailBe/http/index.js +10 -0
- package/dist/services/emailBe/http/transportErrors.js +20 -0
- package/dist/src/@types/email-be/html-validation.d.ts +51 -0
- package/dist/src/composables/useSaveValidation.d.ts +2 -2
- package/dist/src/enums/email-be.d.ts +26 -0
- package/dist/src/enums/save-validation.d.ts +3 -15
- package/dist/src/services/emailBe/errors/ApiError.d.ts +40 -0
- package/dist/src/services/emailBe/errors/handleApiError.d.ts +11 -0
- package/dist/src/services/emailBe/errors/toApiError.d.ts +2 -0
- package/dist/src/services/emailBe/html/HtmlValidationService.d.ts +8 -0
- package/dist/src/services/emailBe/html/index.d.ts +2 -0
- package/dist/src/services/emailBe/http/HttpManager.d.ts +13 -0
- package/dist/src/services/emailBe/http/RetryStack.d.ts +6 -0
- package/dist/src/services/emailBe/http/client.d.ts +3 -0
- package/dist/src/services/emailBe/http/index.d.ts +2 -0
- package/dist/src/services/emailBe/http/transportErrors.d.ts +15 -0
- package/dist/src/services/emailBe/http/types.d.ts +46 -0
- package/dist/static/stripo-runtime-manifest.json.js +1 -1
- package/package.json +2 -2
package/dist/package.json.js
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var o = Object.defineProperty;
|
|
2
|
+
var d = (e, r, s) => r in e ? o(e, r, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[r] = s;
|
|
3
|
+
var t = (e, r, s) => d(e, typeof r != "symbol" ? r + "" : r, s);
|
|
4
|
+
class a extends Error {
|
|
5
|
+
constructor(s) {
|
|
6
|
+
super(s.message);
|
|
7
|
+
t(this, "status");
|
|
8
|
+
t(this, "code");
|
|
9
|
+
t(this, "meta");
|
|
10
|
+
t(this, "errors");
|
|
11
|
+
t(this, "requestId");
|
|
12
|
+
// Guido already showed the auth modal/toast for this failure, so callers must not toast again.
|
|
13
|
+
t(this, "authReported");
|
|
14
|
+
t(this, "cause");
|
|
15
|
+
this.name = new.target.name, this.status = s.status, this.code = s.code, this.meta = s.meta ?? {}, this.errors = s.errors ?? {}, this.requestId = s.requestId ?? "", this.authReported = s.authReported ?? !1, this.cause = s.cause;
|
|
16
|
+
}
|
|
17
|
+
is(s) {
|
|
18
|
+
return this.code === s;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class u extends a {
|
|
22
|
+
firstMessage() {
|
|
23
|
+
const [r] = Object.values(this.errors);
|
|
24
|
+
return (r == null ? void 0 : r[0]) ?? this.message;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
class h extends a {
|
|
28
|
+
}
|
|
29
|
+
class n extends a {
|
|
30
|
+
}
|
|
31
|
+
class l extends a {
|
|
32
|
+
}
|
|
33
|
+
class E extends a {
|
|
34
|
+
}
|
|
35
|
+
class x extends a {
|
|
36
|
+
}
|
|
37
|
+
class i extends a {
|
|
38
|
+
}
|
|
39
|
+
const m = (e) => e instanceof a;
|
|
40
|
+
export {
|
|
41
|
+
a as ApiError,
|
|
42
|
+
n as ForbiddenError,
|
|
43
|
+
i as NetworkError,
|
|
44
|
+
h as NotFoundError,
|
|
45
|
+
E as RateLimitError,
|
|
46
|
+
x as ServerError,
|
|
47
|
+
l as UnauthorizedError,
|
|
48
|
+
u as ValidationError,
|
|
49
|
+
m as isApiError
|
|
50
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useToaster as a } from "../../../composables/useToaster.js";
|
|
2
|
+
import { useTranslations as f } from "../../../composables/useTranslations.js";
|
|
3
|
+
import { ToasterTypeOptions as i } from "../../../enums/toaster.js";
|
|
4
|
+
import { UnauthorizedError as u, ValidationError as c } from "./ApiError.js";
|
|
5
|
+
import { toApiError as m } from "./toApiError.js";
|
|
6
|
+
const p = "products.something-went-wrong";
|
|
7
|
+
function l(o) {
|
|
8
|
+
return o instanceof c ? o.firstMessage() : f()(p);
|
|
9
|
+
}
|
|
10
|
+
function E(o, t) {
|
|
11
|
+
return (t == null ? void 0 : t[o.code]) ?? (t == null ? void 0 : t[o.status]);
|
|
12
|
+
}
|
|
13
|
+
function A(o, t) {
|
|
14
|
+
const r = m(o);
|
|
15
|
+
if (r.authReported || r instanceof u)
|
|
16
|
+
return r;
|
|
17
|
+
const s = E(r, t.overrides);
|
|
18
|
+
let n = "";
|
|
19
|
+
if (s) {
|
|
20
|
+
const e = s(r);
|
|
21
|
+
if (e === !1)
|
|
22
|
+
return r;
|
|
23
|
+
n = typeof e == "string" ? e : "";
|
|
24
|
+
} else
|
|
25
|
+
n = l(r);
|
|
26
|
+
return console.error(`${t.context} failed`, r), n && !t.silent && a().showToaster({ type: i.Error, message: n }), r;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
p as GENERIC_MESSAGE_KEY,
|
|
30
|
+
A as handleApiError
|
|
31
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { EmailBeErrorCodes as t } from "../../../enums/email-be.js";
|
|
2
|
+
import { HttpStatusError as u, TransportNetworkError as i, SessionExpiredError as c } from "../http/transportErrors.js";
|
|
3
|
+
import { isApiError as d, NetworkError as m, UnauthorizedError as a, ServerError as E, ApiError as N, RateLimitError as A, ValidationError as T, NotFoundError as f, ForbiddenError as I } from "./ApiError.js";
|
|
4
|
+
const p = {
|
|
5
|
+
400: t.BAD_REQUEST,
|
|
6
|
+
401: t.UNAUTHENTICATED,
|
|
7
|
+
403: t.FORBIDDEN,
|
|
8
|
+
404: t.NOT_FOUND,
|
|
9
|
+
409: t.CONFLICT,
|
|
10
|
+
419: t.SESSION_EXPIRED,
|
|
11
|
+
422: t.VALIDATION_FAILED,
|
|
12
|
+
429: t.RATE_LIMITED,
|
|
13
|
+
500: t.INTERNAL_ERROR,
|
|
14
|
+
502: t.BAD_GATEWAY
|
|
15
|
+
};
|
|
16
|
+
function R(e) {
|
|
17
|
+
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
18
|
+
}
|
|
19
|
+
function S(e) {
|
|
20
|
+
const { status: n } = e, o = R(e.body) ? e.body : {}, r = o.error ?? {}, s = {
|
|
21
|
+
status: n,
|
|
22
|
+
code: r.code ?? p[n] ?? t.UNKNOWN,
|
|
23
|
+
message: r.message ?? e.message,
|
|
24
|
+
meta: r.meta ?? {},
|
|
25
|
+
errors: r.errors ?? {},
|
|
26
|
+
requestId: o.requestId ?? e.requestId,
|
|
27
|
+
authReported: e.authReported,
|
|
28
|
+
cause: e
|
|
29
|
+
};
|
|
30
|
+
switch (n) {
|
|
31
|
+
case 401:
|
|
32
|
+
case 419:
|
|
33
|
+
return new a(s);
|
|
34
|
+
case 403:
|
|
35
|
+
return new I(s);
|
|
36
|
+
case 404:
|
|
37
|
+
return new f(s);
|
|
38
|
+
case 422:
|
|
39
|
+
return new T(s);
|
|
40
|
+
case 429:
|
|
41
|
+
return new A(s);
|
|
42
|
+
default:
|
|
43
|
+
return n >= 500 ? new E(s) : new N(s);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function g(e) {
|
|
47
|
+
if (d(e))
|
|
48
|
+
return e;
|
|
49
|
+
if (e instanceof u)
|
|
50
|
+
return S(e);
|
|
51
|
+
if (e instanceof i)
|
|
52
|
+
return new m({
|
|
53
|
+
status: 0,
|
|
54
|
+
code: e.isTimeout ? t.TIMEOUT : t.NETWORK,
|
|
55
|
+
message: e.message,
|
|
56
|
+
cause: e.cause
|
|
57
|
+
});
|
|
58
|
+
if (e instanceof c)
|
|
59
|
+
return new a({
|
|
60
|
+
status: 0,
|
|
61
|
+
code: t.SESSION_EXPIRED,
|
|
62
|
+
message: e.message,
|
|
63
|
+
authReported: !0,
|
|
64
|
+
cause: e
|
|
65
|
+
});
|
|
66
|
+
const n = e instanceof Error ? e.message : String(e);
|
|
67
|
+
return new E({ status: 0, code: t.UNKNOWN, message: n, cause: e });
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
g as toApiError
|
|
71
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { EmailBeEndPoints as a, EmailBeErrorCodes as s } from "../../../enums/email-be.js";
|
|
2
|
+
import { ApiError as i } from "../errors/ApiError.js";
|
|
3
|
+
import { handleApiError as c } from "../errors/handleApiError.js";
|
|
4
|
+
import { HtmlValidationResultSchema as m } from "../../../@types/email-be/html-validation.js";
|
|
5
|
+
import { base64EncodeWithSpecialChars as n } from "../../../utils/base64.js";
|
|
6
|
+
import { safeParse as d } from "../../../node_modules/valibot/dist/index.js";
|
|
7
|
+
const l = "[HTML_VALIDATION_SERVICE]", p = { maxRetries: 1, backoffMs: [500] };
|
|
8
|
+
class I {
|
|
9
|
+
constructor(t) {
|
|
10
|
+
this.http = t;
|
|
11
|
+
}
|
|
12
|
+
async validate({ html: t, syntax: o }) {
|
|
13
|
+
try {
|
|
14
|
+
const r = await this.http.request({
|
|
15
|
+
method: "POST",
|
|
16
|
+
url: a.HTML_VALIDATE,
|
|
17
|
+
body: { html: n(t), syntax: o },
|
|
18
|
+
retry: p
|
|
19
|
+
}), e = d(m, r);
|
|
20
|
+
if (!e.success)
|
|
21
|
+
throw new i({
|
|
22
|
+
status: 200,
|
|
23
|
+
code: s.INVALID_RESPONSE,
|
|
24
|
+
message: "Validate answered with an unexpected body",
|
|
25
|
+
cause: e.issues
|
|
26
|
+
});
|
|
27
|
+
return { ok: !0, data: e.output };
|
|
28
|
+
} catch (r) {
|
|
29
|
+
return { ok: !1, error: c(r, { context: `${l} validate` }) };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
I as HtmlValidationService
|
|
35
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var l = (r, t, e) => t in r ? u(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var o = (r, t, e) => l(r, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { toApiError as y } from "../errors/toApiError.js";
|
|
5
|
+
import { defaultRetryFor as d, shouldRetry as h, delay as p, backoffDelay as c } from "./RetryStack.js";
|
|
6
|
+
const f = 204, m = (r, t) => {
|
|
7
|
+
if (t === null || typeof t != "object" || Array.isArray(t))
|
|
8
|
+
return t;
|
|
9
|
+
const e = t;
|
|
10
|
+
return Object.fromEntries(Object.keys(e).sort().map((s) => [s, e[s]]));
|
|
11
|
+
};
|
|
12
|
+
function a(r) {
|
|
13
|
+
return r == null ? "" : typeof r == "string" ? r : JSON.stringify(r, m);
|
|
14
|
+
}
|
|
15
|
+
class w {
|
|
16
|
+
constructor(t, e) {
|
|
17
|
+
o(this, "inFlight", /* @__PURE__ */ new Map());
|
|
18
|
+
this.transport = t, this.defaults = e;
|
|
19
|
+
}
|
|
20
|
+
async request(t) {
|
|
21
|
+
return (await this.requestEnvelope(t)).data;
|
|
22
|
+
}
|
|
23
|
+
async requestEnvelope(t) {
|
|
24
|
+
if (!this.shouldDedup(t))
|
|
25
|
+
return this.executeWithRetry(t);
|
|
26
|
+
const e = this.buildKey(t), s = this.inFlight.get(e);
|
|
27
|
+
if (s)
|
|
28
|
+
return s;
|
|
29
|
+
const i = this.executeWithRetry(t);
|
|
30
|
+
this.inFlight.set(e, i);
|
|
31
|
+
try {
|
|
32
|
+
return await i;
|
|
33
|
+
} finally {
|
|
34
|
+
this.inFlight.delete(e);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
buildKey(t) {
|
|
38
|
+
return [
|
|
39
|
+
t.method,
|
|
40
|
+
t.url,
|
|
41
|
+
a(t.params),
|
|
42
|
+
a(t.body)
|
|
43
|
+
].join("|");
|
|
44
|
+
}
|
|
45
|
+
shouldDedup(t) {
|
|
46
|
+
return t.body instanceof FormData || t.dedup === !1 ? !1 : t.dedup === !0 || this.defaults.dedup && t.method === "GET";
|
|
47
|
+
}
|
|
48
|
+
resolveRetry(t) {
|
|
49
|
+
return t.retry === null ? null : t.retry ?? d(t.method, this.defaults.retry);
|
|
50
|
+
}
|
|
51
|
+
async executeWithRetry(t) {
|
|
52
|
+
const e = this.resolveRetry(t);
|
|
53
|
+
let s = 0;
|
|
54
|
+
for (; ; )
|
|
55
|
+
try {
|
|
56
|
+
const { status: i, data: n } = await this.transport.request(t);
|
|
57
|
+
return i === f || n === "" || n == null ? { data: void 0, meta: [] } : n;
|
|
58
|
+
} catch (i) {
|
|
59
|
+
const n = y(i);
|
|
60
|
+
if (!h(n, e, s))
|
|
61
|
+
throw n;
|
|
62
|
+
await p(c(e, s)), s += 1;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
w as HttpManager
|
|
68
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EmailBeErrorCodes as f } from "../../../enums/email-be.js";
|
|
2
|
+
import { NetworkError as o } from "../errors/ApiError.js";
|
|
3
|
+
const r = /* @__PURE__ */ new Set(["GET", "PUT", "DELETE"]);
|
|
4
|
+
function a(t, e) {
|
|
5
|
+
return r.has(t) ? e : null;
|
|
6
|
+
}
|
|
7
|
+
function E(t, e, n) {
|
|
8
|
+
return !e || n >= e.maxRetries || t.authReported ? !1 : t instanceof o ? t.code !== f.TIMEOUT : t.status === 429 || t.status >= 500;
|
|
9
|
+
}
|
|
10
|
+
function i(t, e) {
|
|
11
|
+
const n = t.backoffMs[t.backoffMs.length - 1] ?? 0;
|
|
12
|
+
return t.backoffMs[e] ?? n;
|
|
13
|
+
}
|
|
14
|
+
function c(t) {
|
|
15
|
+
return new Promise((e) => {
|
|
16
|
+
setTimeout(e, t);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
i as backoffDelay,
|
|
21
|
+
a as defaultRetryFor,
|
|
22
|
+
c as delay,
|
|
23
|
+
E as shouldRetry
|
|
24
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isPanelOrigin as u, reportAuthError as l } from "../../../composables/useAuthError.js";
|
|
2
|
+
import { getCsrfToken as p } from "../../../utils/genericUtil.js";
|
|
3
|
+
import { SessionExpiredError as h, TransportNetworkError as m, HttpStatusError as T } from "./transportErrors.js";
|
|
4
|
+
const w = 3e4, y = [401, 403, 419], S = ["POST", "PUT", "PATCH"], E = (t, s, e) => {
|
|
5
|
+
const o = new URLSearchParams();
|
|
6
|
+
Object.entries(e ?? {}).forEach(([i, r]) => {
|
|
7
|
+
r != null && o.append(i, String(r));
|
|
8
|
+
});
|
|
9
|
+
const n = o.toString();
|
|
10
|
+
return `${t}${s}${n ? `?${n}` : ""}`;
|
|
11
|
+
}, b = (t, s) => {
|
|
12
|
+
const e = {
|
|
13
|
+
Accept: "application/json",
|
|
14
|
+
"X-CSRF-TOKEN": p(),
|
|
15
|
+
// Without this a guest fetch gets a 302 to the login page, never an auth status.
|
|
16
|
+
"X-Requested-With": "XMLHttpRequest"
|
|
17
|
+
}, o = { method: t.method, headers: e, signal: s, credentials: "same-origin" };
|
|
18
|
+
return t.body !== void 0 && S.includes(t.method) && (t.body instanceof FormData ? o.body = t.body : (e["Content-Type"] = "application/json", o.body = JSON.stringify(t.body))), o;
|
|
19
|
+
}, f = (t) => {
|
|
20
|
+
if (t === "")
|
|
21
|
+
return null;
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(t);
|
|
24
|
+
} catch {
|
|
25
|
+
return t;
|
|
26
|
+
}
|
|
27
|
+
}, O = (t, s, e) => {
|
|
28
|
+
try {
|
|
29
|
+
l(t, s, new URL(e, window.location.href).href);
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
}, q = (t, s = w) => ({
|
|
33
|
+
async request(e) {
|
|
34
|
+
if (window.isSessionExpired)
|
|
35
|
+
throw new h();
|
|
36
|
+
const o = E(t, e.url, e.params), n = new AbortController(), i = setTimeout(() => n.abort(), e.timeoutMs ?? s);
|
|
37
|
+
let r, c;
|
|
38
|
+
try {
|
|
39
|
+
r = await fetch(o, b(e, n.signal)), c = await r.text();
|
|
40
|
+
} catch (a) {
|
|
41
|
+
throw new m(n.signal.aborted, a);
|
|
42
|
+
} finally {
|
|
43
|
+
clearTimeout(i);
|
|
44
|
+
}
|
|
45
|
+
const d = f(c);
|
|
46
|
+
if (!r.ok) {
|
|
47
|
+
const a = y.includes(r.status) && u(o);
|
|
48
|
+
throw a && O(r.status, c, o), new T(
|
|
49
|
+
r.status,
|
|
50
|
+
d,
|
|
51
|
+
r.headers.get("x-request-id") ?? "",
|
|
52
|
+
a
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return { status: r.status, data: d };
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
export {
|
|
59
|
+
w as REQUEST_TIMEOUT_MS,
|
|
60
|
+
q as createFetchTransport
|
|
61
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EMAIL_BE_BASE_URL as r } from "../../../enums/email-be.js";
|
|
2
|
+
import { createFetchTransport as t } from "./client.js";
|
|
3
|
+
import { HttpManager as e } from "./HttpManager.js";
|
|
4
|
+
const a = new e(t(r), {
|
|
5
|
+
retry: { maxRetries: 2, backoffMs: [250, 1e3] },
|
|
6
|
+
dedup: !0
|
|
7
|
+
});
|
|
8
|
+
export {
|
|
9
|
+
a as emailBeHttp
|
|
10
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class i extends Error {
|
|
2
|
+
constructor(r, t, e, o) {
|
|
3
|
+
super(`HTTP Error: ${r}`), this.status = r, this.body = t, this.requestId = e, this.authReported = o, this.name = "HttpStatusError";
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
class n extends Error {
|
|
7
|
+
constructor(r, t) {
|
|
8
|
+
super(r ? "Request timeout" : "Network error"), this.isTimeout = r, this.cause = t, this.name = "TransportNetworkError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class u extends Error {
|
|
12
|
+
constructor() {
|
|
13
|
+
super("Session expired"), this.name = "SessionExpiredError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
i as HttpStatusError,
|
|
18
|
+
u as SessionExpiredError,
|
|
19
|
+
n as TransportNetworkError
|
|
20
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { HtmlSyntaxValue } from '@@/Enums/email-be';
|
|
2
|
+
import * as v from 'valibot';
|
|
3
|
+
export declare const HtmlValidationErrorSchema: v.ObjectSchema<{
|
|
4
|
+
readonly code: v.StringSchema<undefined>;
|
|
5
|
+
readonly trans: v.ObjectSchema<{
|
|
6
|
+
readonly key: v.StringSchema<undefined>;
|
|
7
|
+
readonly replace: v.UnionSchema<[v.RecordSchema<v.StringSchema<undefined>, v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>, v.SchemaWithPipe<readonly [v.TupleSchema<[], undefined>, v.TransformAction<[], {}>]>], undefined>;
|
|
8
|
+
}, undefined>;
|
|
9
|
+
readonly anchor: v.SchemaWithFallback<v.NullableSchema<v.ObjectSchema<{
|
|
10
|
+
readonly selector: v.StringSchema<undefined>;
|
|
11
|
+
readonly indexes: v.ArraySchema<v.NumberSchema<undefined>, undefined>;
|
|
12
|
+
}, undefined>, undefined>, null>;
|
|
13
|
+
readonly details: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
14
|
+
}, undefined>;
|
|
15
|
+
export declare const HtmlValidationResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
16
|
+
readonly valid: v.BooleanSchema<undefined>;
|
|
17
|
+
readonly errors: v.ArraySchema<v.ObjectSchema<{
|
|
18
|
+
readonly code: v.StringSchema<undefined>;
|
|
19
|
+
readonly trans: v.ObjectSchema<{
|
|
20
|
+
readonly key: v.StringSchema<undefined>;
|
|
21
|
+
readonly replace: v.UnionSchema<[v.RecordSchema<v.StringSchema<undefined>, v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>, v.SchemaWithPipe<readonly [v.TupleSchema<[], undefined>, v.TransformAction<[], {}>]>], undefined>;
|
|
22
|
+
}, undefined>;
|
|
23
|
+
readonly anchor: v.SchemaWithFallback<v.NullableSchema<v.ObjectSchema<{
|
|
24
|
+
readonly selector: v.StringSchema<undefined>;
|
|
25
|
+
readonly indexes: v.ArraySchema<v.NumberSchema<undefined>, undefined>;
|
|
26
|
+
}, undefined>, undefined>, null>;
|
|
27
|
+
readonly details: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
28
|
+
}, undefined>, undefined>;
|
|
29
|
+
}, undefined>, v.CheckAction<{
|
|
30
|
+
valid: boolean;
|
|
31
|
+
errors: {
|
|
32
|
+
code: string;
|
|
33
|
+
trans: {
|
|
34
|
+
key: string;
|
|
35
|
+
replace: {
|
|
36
|
+
[x: string]: string | number;
|
|
37
|
+
} | {};
|
|
38
|
+
};
|
|
39
|
+
anchor: {
|
|
40
|
+
selector: string;
|
|
41
|
+
indexes: number[];
|
|
42
|
+
} | null;
|
|
43
|
+
details: string[];
|
|
44
|
+
}[];
|
|
45
|
+
}, "valid must match the error list">]>;
|
|
46
|
+
export type HtmlValidationError = v.InferOutput<typeof HtmlValidationErrorSchema>;
|
|
47
|
+
export type HtmlValidationResult = v.InferOutput<typeof HtmlValidationResultSchema>;
|
|
48
|
+
export type ValidateHtmlParams = {
|
|
49
|
+
html: string;
|
|
50
|
+
syntax: HtmlSyntaxValue;
|
|
51
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DynamicContent } from '@@/Types/generic';
|
|
2
2
|
import type { SaveValidationError } from '@@/Types/save-validation';
|
|
3
3
|
export declare const useSaveValidation: () => {
|
|
4
|
-
collectSaveValidationErrors: (compiledHtml: string, dynamicContentList: DynamicContent[], rawHtml: string) => Promise<SaveValidationError[]>;
|
|
5
|
-
validateCurrentTemplate: () => Promise<SaveValidationError[]>;
|
|
4
|
+
collectSaveValidationErrors: (compiledHtml: string, dynamicContentList: DynamicContent[], rawHtml: string) => Promise<SaveValidationError[] | null>;
|
|
5
|
+
validateCurrentTemplate: () => Promise<SaveValidationError[] | null>;
|
|
6
6
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const EMAIL_BE_BASE_URL = "/email-proxy";
|
|
2
|
+
export declare const EmailBeEndPoints: {
|
|
3
|
+
readonly HTML_VALIDATE: "/v1/html/validate";
|
|
4
|
+
};
|
|
5
|
+
export declare const EmailBeErrorCodes: {
|
|
6
|
+
readonly BAD_GATEWAY: "bad_gateway";
|
|
7
|
+
readonly BAD_REQUEST: "bad_request";
|
|
8
|
+
readonly CONFLICT: "conflict";
|
|
9
|
+
readonly FORBIDDEN: "forbidden";
|
|
10
|
+
readonly INTERNAL_ERROR: "internal_error";
|
|
11
|
+
readonly NOT_FOUND: "not_found";
|
|
12
|
+
readonly RATE_LIMITED: "rate_limited";
|
|
13
|
+
readonly UNAUTHENTICATED: "unauthenticated";
|
|
14
|
+
readonly VALIDATION_FAILED: "validation_failed";
|
|
15
|
+
readonly SESSION_EXPIRED: "session_expired";
|
|
16
|
+
readonly INVALID_RESPONSE: "invalid_response";
|
|
17
|
+
readonly NETWORK: "network_error";
|
|
18
|
+
readonly TIMEOUT: "timeout";
|
|
19
|
+
readonly UNKNOWN: "unknown";
|
|
20
|
+
};
|
|
21
|
+
export type ApiErrorCode = typeof EmailBeErrorCodes[keyof typeof EmailBeErrorCodes];
|
|
22
|
+
export declare const HtmlSyntax: {
|
|
23
|
+
readonly PONGO: "pongo";
|
|
24
|
+
readonly LIQUID: "liquid";
|
|
25
|
+
};
|
|
26
|
+
export type HtmlSyntaxValue = typeof HtmlSyntax[keyof typeof HtmlSyntax];
|
|
@@ -1,28 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stable discriminators for each save-validation rule site — one per rule that
|
|
3
|
-
* can produce a drawer row, kept in sync with the collector
|
|
3
|
+
* can produce a drawer row, kept in sync with the collector; email-be rows share EmailBeHtml.
|
|
4
4
|
*/
|
|
5
5
|
export declare enum SaveValidationRule {
|
|
6
|
-
CouponTagModified = "coupon-tag-modified",
|
|
7
|
-
DuplicateUnsubBlock = "duplicate-unsub-block",
|
|
8
|
-
UnsubBlockMissingTemplate = "unsub-block-missing-template",
|
|
9
|
-
LiquidSyntax = "liquid-syntax",
|
|
10
|
-
InvalidLinks = "invalid-links",
|
|
11
|
-
LinkCheckInProgress = "link-check-in-progress",
|
|
12
6
|
CustomFieldScript = "custom-field-script",
|
|
13
|
-
EmptyHtml = "empty-html",
|
|
14
|
-
MismatchedBraces = "mismatched-braces",
|
|
15
7
|
InvalidDynamicTag = "invalid-dynamic-tag",
|
|
16
8
|
InvalidCustomField = "invalid-custom-field",
|
|
17
|
-
ConditionsSyntax = "conditions-syntax",
|
|
18
|
-
WrongEqualityOperator = "wrong-equality-operator",
|
|
19
9
|
MissingIfEndif = "missing-if-endif",
|
|
20
|
-
ConditionTagSpacing = "condition-tag-spacing",
|
|
21
|
-
BracesInsideIfTag = "braces-inside-if-tag",
|
|
22
10
|
RecommendationRequiredFields = "recommendation-required-fields",
|
|
23
11
|
RecommendationFilters = "recommendation-filters",
|
|
24
|
-
InvalidImageType = "invalid-image-type",
|
|
25
12
|
CheckboxUnsubGroup = "checkbox-unsub-group",
|
|
26
13
|
RadioButtonUnsubGroup = "radio-button-unsub-group",
|
|
27
|
-
ExternallyManagedUnsubscribe = "externally-managed-unsubscribe"
|
|
14
|
+
ExternallyManagedUnsubscribe = "externally-managed-unsubscribe",
|
|
15
|
+
EmailBeHtml = "email-be-html"
|
|
28
16
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ApiErrorCode } from '@@/Enums/email-be';
|
|
2
|
+
export type ValidationErrors = Record<string, string[]>;
|
|
3
|
+
export interface ApiErrorInit {
|
|
4
|
+
status: number;
|
|
5
|
+
code: string;
|
|
6
|
+
message: string;
|
|
7
|
+
meta?: Record<string, unknown>;
|
|
8
|
+
errors?: ValidationErrors;
|
|
9
|
+
requestId?: string;
|
|
10
|
+
authReported?: boolean;
|
|
11
|
+
cause?: unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare class ApiError extends Error {
|
|
14
|
+
readonly status: number;
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly meta: Record<string, unknown>;
|
|
17
|
+
readonly errors: ValidationErrors;
|
|
18
|
+
readonly requestId: string;
|
|
19
|
+
readonly authReported: boolean;
|
|
20
|
+
readonly cause: unknown;
|
|
21
|
+
constructor(init: ApiErrorInit);
|
|
22
|
+
is(code: ApiErrorCode): boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare class ValidationError extends ApiError {
|
|
25
|
+
firstMessage(): string;
|
|
26
|
+
}
|
|
27
|
+
export declare class NotFoundError extends ApiError {
|
|
28
|
+
}
|
|
29
|
+
export declare class ForbiddenError extends ApiError {
|
|
30
|
+
}
|
|
31
|
+
export declare class UnauthorizedError extends ApiError {
|
|
32
|
+
}
|
|
33
|
+
export declare class RateLimitError extends ApiError {
|
|
34
|
+
}
|
|
35
|
+
export declare class ServerError extends ApiError {
|
|
36
|
+
}
|
|
37
|
+
export declare class NetworkError extends ApiError {
|
|
38
|
+
}
|
|
39
|
+
export declare const isApiError: (error: unknown) => error is ApiError;
|
|
40
|
+
export declare const isValidationError: (error: unknown) => error is ValidationError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ApiErrorCode } from '@@/Enums/email-be';
|
|
2
|
+
import { type ApiError } from './ApiError';
|
|
3
|
+
export type OverrideOutcome = void | string | false;
|
|
4
|
+
export type ErrorOverride = (error: ApiError) => OverrideOutcome;
|
|
5
|
+
export interface HandleApiErrorOptions {
|
|
6
|
+
context: string;
|
|
7
|
+
silent?: boolean;
|
|
8
|
+
overrides?: Partial<Record<ApiErrorCode | number, ErrorOverride>>;
|
|
9
|
+
}
|
|
10
|
+
export declare const GENERIC_MESSAGE_KEY = "products.something-went-wrong";
|
|
11
|
+
export declare function handleApiError(error: unknown, options: HandleApiErrorOptions): ApiError;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HttpManager } from '@@/Services/emailBe/http/HttpManager';
|
|
2
|
+
import type { Result } from '@@/Services/emailBe/http/types';
|
|
3
|
+
import type { HtmlValidationResult, ValidateHtmlParams } from '@@/Types/email-be/html-validation';
|
|
4
|
+
export declare class HtmlValidationService {
|
|
5
|
+
private readonly http;
|
|
6
|
+
constructor(http: HttpManager);
|
|
7
|
+
validate({ html, syntax }: ValidateHtmlParams): Promise<Result<HtmlValidationResult>>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiEnvelope, HttpManagerDefaults, HttpTransport, RequestConfig } from './types';
|
|
2
|
+
export declare class HttpManager {
|
|
3
|
+
private readonly transport;
|
|
4
|
+
private readonly defaults;
|
|
5
|
+
private readonly inFlight;
|
|
6
|
+
constructor(transport: HttpTransport, defaults: HttpManagerDefaults);
|
|
7
|
+
request<T>(config: RequestConfig): Promise<T>;
|
|
8
|
+
requestEnvelope<T, M = never[]>(config: RequestConfig): Promise<ApiEnvelope<T, M>>;
|
|
9
|
+
private buildKey;
|
|
10
|
+
private shouldDedup;
|
|
11
|
+
private resolveRetry;
|
|
12
|
+
private executeWithRetry;
|
|
13
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HttpMethod, RetryPolicy } from './types';
|
|
2
|
+
import { type ApiError } from '@@/Services/emailBe/errors/ApiError';
|
|
3
|
+
export declare function defaultRetryFor(method: HttpMethod, fallback: RetryPolicy | null): RetryPolicy | null;
|
|
4
|
+
export declare function shouldRetry(error: ApiError, policy: RetryPolicy | null, attempt: number): boolean;
|
|
5
|
+
export declare function backoffDelay(policy: RetryPolicy, attempt: number): number;
|
|
6
|
+
export declare function delay(ms: number): Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class HttpStatusError extends Error {
|
|
2
|
+
readonly status: number;
|
|
3
|
+
readonly body: unknown;
|
|
4
|
+
readonly requestId: string;
|
|
5
|
+
readonly authReported: boolean;
|
|
6
|
+
constructor(status: number, body: unknown, requestId: string, authReported: boolean);
|
|
7
|
+
}
|
|
8
|
+
export declare class TransportNetworkError extends Error {
|
|
9
|
+
readonly isTimeout: boolean;
|
|
10
|
+
readonly cause: unknown;
|
|
11
|
+
constructor(isTimeout: boolean, cause: unknown);
|
|
12
|
+
}
|
|
13
|
+
export declare class SessionExpiredError extends Error {
|
|
14
|
+
constructor();
|
|
15
|
+
}
|