@voltro/integration-http 0.84.0 → 0.86.0
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/CHANGELOG.md +1215 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/client.js +32 -0
- package/dist/core.js +175 -0
- package/dist/index.js +3 -203
- package/package.json +2 -2
package/THIRD-PARTY-NOTICES.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Third-Party Notices — @voltro/integration-http
|
|
2
2
|
|
|
3
|
-
This package
|
|
3
|
+
This package uses the open-source software listed below. Each is the
|
|
4
4
|
property of its respective copyright holders and is used under the terms of
|
|
5
5
|
its license. This file is provided for attribution; it grants no rights in
|
|
6
6
|
@voltro/integration-http itself, which is proprietary (see LICENSE).
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DEFAULT_POLICY as e, request as t, requestJson as n } from "./core.js";
|
|
2
|
+
//#region src/client.ts
|
|
3
|
+
var r = (r) => {
|
|
4
|
+
let i = {
|
|
5
|
+
...e,
|
|
6
|
+
...r.policy
|
|
7
|
+
}, a = (e, t, n) => {
|
|
8
|
+
let a = n?.ctx ?? void 0, o = n?.body;
|
|
9
|
+
return {
|
|
10
|
+
fetchImpl: r.fetchImpl,
|
|
11
|
+
baseUrl: r.baseUrl,
|
|
12
|
+
method: e,
|
|
13
|
+
path: t,
|
|
14
|
+
headers: r.auth(a),
|
|
15
|
+
...o === void 0 ? {} : { body: JSON.stringify(o) },
|
|
16
|
+
policy: i,
|
|
17
|
+
makeError: r.makeError,
|
|
18
|
+
...r.now ? { now: r.now } : {}
|
|
19
|
+
};
|
|
20
|
+
}, o = (e, n, r) => t(a(e, n, r)), s = (e, t, r) => n(a(e, t, r));
|
|
21
|
+
return {
|
|
22
|
+
get: (e, t) => o("GET", e, t),
|
|
23
|
+
getJson: (e, t) => s("GET", e, t),
|
|
24
|
+
postJson: (e, t) => s("POST", e, t),
|
|
25
|
+
putJson: (e, t) => s("PUT", e, t),
|
|
26
|
+
deleteJson: (e, t) => s("DELETE", e, t),
|
|
27
|
+
request: (e, t, n) => o(e, t, n),
|
|
28
|
+
policy: i
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { r as makeHttpClient };
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { Duration as e, Effect as t, Metric as n } from "effect";
|
|
2
|
+
//#region src/core.ts
|
|
3
|
+
var r = /* @__PURE__ */ new Set([
|
|
4
|
+
408,
|
|
5
|
+
425,
|
|
6
|
+
429,
|
|
7
|
+
500,
|
|
8
|
+
502,
|
|
9
|
+
503,
|
|
10
|
+
504
|
|
11
|
+
]), i = [
|
|
12
|
+
"GET",
|
|
13
|
+
"PUT",
|
|
14
|
+
"DELETE"
|
|
15
|
+
], a = {
|
|
16
|
+
ratio: .2,
|
|
17
|
+
minRetriesPerWindow: 10,
|
|
18
|
+
windowMs: 1e4
|
|
19
|
+
}, o = {
|
|
20
|
+
maxAttempts: 4,
|
|
21
|
+
initialDelayMs: 500,
|
|
22
|
+
maxDelayMs: 1e4,
|
|
23
|
+
timeoutMs: 2e4,
|
|
24
|
+
honourRetryAfter: !0,
|
|
25
|
+
retryMethods: i,
|
|
26
|
+
retryBudget: a
|
|
27
|
+
}, s = /* @__PURE__ */ new Map(), c = (e, t, n) => {
|
|
28
|
+
let r = t - n;
|
|
29
|
+
for (; e.head < e.events.length && e.events[e.head][0] < r;) e.events[e.head][1] === 0 ? --e.requests : --e.retries, e.head += 1;
|
|
30
|
+
e.head > 0 && e.head * 2 >= e.events.length && (e.events = e.events.slice(e.head), e.head = 0);
|
|
31
|
+
}, l = (e) => {
|
|
32
|
+
let t = s.get(e);
|
|
33
|
+
return t === void 0 && (t = {
|
|
34
|
+
events: [],
|
|
35
|
+
head: 0,
|
|
36
|
+
requests: 0,
|
|
37
|
+
retries: 0
|
|
38
|
+
}, s.set(e, t)), t;
|
|
39
|
+
}, u = (e) => ({
|
|
40
|
+
requests: e.requests,
|
|
41
|
+
retries: e.retries
|
|
42
|
+
}), d = (e, t, n) => {
|
|
43
|
+
let r = l(e);
|
|
44
|
+
c(r, t, n.windowMs), r.events.push([t, 0]), r.requests += 1;
|
|
45
|
+
}, f = n.counter("voltro_http_retries_total"), p = n.counter("voltro_http_retry_budget_exhausted_total"), m = (e, r, i) => {
|
|
46
|
+
let a = l(e);
|
|
47
|
+
c(a, r, i.windowMs);
|
|
48
|
+
let { requests: o, retries: s } = u(a);
|
|
49
|
+
return s >= Math.max(i.minRetriesPerWindow, Math.floor(o * i.ratio)) ? (t.runSync(n.update(n.withAttributes(p, { host: e }), 1)), !1) : (a.events.push([r, 1]), a.retries += 1, t.runSync(n.update(n.withAttributes(f, { host: e }), 1)), !0);
|
|
50
|
+
}, h = (e, t = Date.now(), n = a.windowMs) => {
|
|
51
|
+
let r = s.get(e);
|
|
52
|
+
return r === void 0 ? {
|
|
53
|
+
requests: 0,
|
|
54
|
+
retries: 0
|
|
55
|
+
} : (c(r, t, n), u(r));
|
|
56
|
+
}, g = () => {
|
|
57
|
+
s.clear();
|
|
58
|
+
}, _ = (e, t) => Math.min(t.initialDelayMs * 2 ** (e - 1), t.maxDelayMs), v = (e, t) => {
|
|
59
|
+
if (!e) return null;
|
|
60
|
+
let n = Number(e);
|
|
61
|
+
if (Number.isFinite(n)) return Math.max(0, n * 1e3);
|
|
62
|
+
let r = Date.parse(e);
|
|
63
|
+
return Number.isNaN(r) ? null : Math.max(0, r - t);
|
|
64
|
+
}, y = (e, t) => {
|
|
65
|
+
try {
|
|
66
|
+
return new URL(e).host === new URL(t).host;
|
|
67
|
+
} catch {
|
|
68
|
+
return !1;
|
|
69
|
+
}
|
|
70
|
+
}, b = (e, t) => e === 127 || e === 10 || e === 172 && t >= 16 && t <= 31 || e === 192 && t === 168 || e === 169 && t === 254 || e === 0 || e === 100 && t >= 64 && t <= 127 || e >= 224, x = (e) => {
|
|
71
|
+
let t;
|
|
72
|
+
try {
|
|
73
|
+
t = new URL(e);
|
|
74
|
+
} catch {
|
|
75
|
+
throw Error("SSRF: malformed url");
|
|
76
|
+
}
|
|
77
|
+
if (t.protocol !== "http:" && t.protocol !== "https:") throw Error(`SSRF: blocked url scheme "${t.protocol}"`);
|
|
78
|
+
let n = t.hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
79
|
+
if (n === "localhost" || n.endsWith(".localhost") || n.endsWith(".internal") || n.endsWith(".local")) throw Error(`SSRF: blocked host "${n}"`);
|
|
80
|
+
let r = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(n);
|
|
81
|
+
if (r) {
|
|
82
|
+
let e = r.slice(1).map(Number);
|
|
83
|
+
if (e.some((e) => e > 255) || b(e[0], e[1])) throw Error(`SSRF: blocked address "${n}"`);
|
|
84
|
+
} else if (n.includes(":") && (n === "::1" || n === "::" || n.startsWith("::ffff:") || /^fe[89ab]/.test(n) || n.startsWith("fc") || n.startsWith("fd"))) throw Error(`SSRF: blocked address "${n}"`);
|
|
85
|
+
}, S = (e) => typeof e == "object" && !!e && e._transient === !0, C = (n) => {
|
|
86
|
+
let { fetchImpl: o, baseUrl: s, method: c, path: l, headers: u, body: f, policy: p, makeError: h } = n, g = n.now ?? Date.now, b = `${s.replace(/\/$/, "")}${l.startsWith("/") ? l : `/${l}`}`;
|
|
87
|
+
if (!y(s, b)) return t.fail(h({
|
|
88
|
+
message: `blocked off-host request to ${b}`,
|
|
89
|
+
transient: !1
|
|
90
|
+
}));
|
|
91
|
+
let x = t.tryPromise({
|
|
92
|
+
try: async (e) => {
|
|
93
|
+
let t = await o(b, {
|
|
94
|
+
method: c,
|
|
95
|
+
headers: u,
|
|
96
|
+
...f === void 0 ? {} : { body: f },
|
|
97
|
+
signal: e
|
|
98
|
+
}), n = new Uint8Array(await t.arrayBuffer()), i = t.headers.get("content-type"), a = () => new TextDecoder().decode(n);
|
|
99
|
+
if (t.status >= 200 && t.status < 300) return {
|
|
100
|
+
status: t.status,
|
|
101
|
+
bytes: n,
|
|
102
|
+
contentType: i,
|
|
103
|
+
text: a
|
|
104
|
+
};
|
|
105
|
+
throw t.status === 401 ? h({
|
|
106
|
+
status: 401,
|
|
107
|
+
message: "unauthorized — the upstream refused this credential (401). The reason is not in the response: expired, revoked, insufficient scope and malformed are all this status.",
|
|
108
|
+
transient: !1,
|
|
109
|
+
code: "unauthorized"
|
|
110
|
+
}) : r.has(t.status) ? {
|
|
111
|
+
_transient: !0,
|
|
112
|
+
status: t.status,
|
|
113
|
+
message: `HTTP ${t.status}: ${a().slice(0, 500)}`,
|
|
114
|
+
retryAfterMs: p.honourRetryAfter ? v(t.headers.get("retry-after"), g()) : null
|
|
115
|
+
} : h({
|
|
116
|
+
status: t.status,
|
|
117
|
+
message: `HTTP ${t.status}: ${a().slice(0, 500)}`,
|
|
118
|
+
transient: !1
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
catch: (e) => S(e) || typeof e == "object" && e && "_tag" in e ? e : {
|
|
122
|
+
_transient: !0,
|
|
123
|
+
message: `network error: ${String(e)}`,
|
|
124
|
+
retryAfterMs: null
|
|
125
|
+
}
|
|
126
|
+
}).pipe(t.timeoutOrElse({
|
|
127
|
+
duration: e.millis(p.timeoutMs),
|
|
128
|
+
orElse: () => t.fail({
|
|
129
|
+
_transient: !0,
|
|
130
|
+
message: `request timed out after ${p.timeoutMs}ms`,
|
|
131
|
+
retryAfterMs: null
|
|
132
|
+
})
|
|
133
|
+
})), C = n.retry ?? (p.retryMethods ?? i).includes(c), w = p.retryBudget === void 0 ? a : p.retryBudget, T = (() => {
|
|
134
|
+
try {
|
|
135
|
+
return new URL(s).host;
|
|
136
|
+
} catch {
|
|
137
|
+
return "invalid";
|
|
138
|
+
}
|
|
139
|
+
})(), E = (e, n) => t.fail(h({
|
|
140
|
+
message: `${e.message} (not retried: ${n})`,
|
|
141
|
+
transient: !0,
|
|
142
|
+
...e.status === void 0 ? {} : { status: e.status }
|
|
143
|
+
})), D = (n) => x.pipe(t.catch((r) => {
|
|
144
|
+
if (S(r) && n < p.maxAttempts && !C) return E(r, `${c} is not idempotent — pass \`retry: true\` for a call you have made so`);
|
|
145
|
+
if (S(r) && n < p.maxAttempts && w !== !1 && !m(T, g(), w)) return E(r, `the retry budget for ${T} is exhausted`);
|
|
146
|
+
if (S(r) && n < p.maxAttempts) {
|
|
147
|
+
let i = r.retryAfterMs ?? _(n, p), a = r.retryAfterMs == null ? i / 2 + i / 2 * Math.random() : i, o = Math.min(a, p.maxDelayMs);
|
|
148
|
+
return t.sleep(e.millis(o)).pipe(t.flatMap(() => D(n + 1)));
|
|
149
|
+
}
|
|
150
|
+
return S(r) ? t.fail(h({
|
|
151
|
+
message: r.message,
|
|
152
|
+
transient: !0,
|
|
153
|
+
...r.status === void 0 ? {} : { status: r.status }
|
|
154
|
+
})) : t.fail(r);
|
|
155
|
+
})), O = (() => {
|
|
156
|
+
try {
|
|
157
|
+
return new URL(s).host;
|
|
158
|
+
} catch {
|
|
159
|
+
return "invalid";
|
|
160
|
+
}
|
|
161
|
+
})();
|
|
162
|
+
return t.suspend(() => (w !== !1 && d(T, g(), w), D(1))).pipe(t.withSpan("integration-http.request", { attributes: {
|
|
163
|
+
"http.request.method": c,
|
|
164
|
+
"server.address": O
|
|
165
|
+
} }));
|
|
166
|
+
}, w = (e) => C(e).pipe(t.flatMap((n) => n.bytes.length === 0 ? t.succeed(null) : t.try({
|
|
167
|
+
try: () => JSON.parse(n.text()),
|
|
168
|
+
catch: () => e.makeError({
|
|
169
|
+
status: n.status,
|
|
170
|
+
message: "invalid JSON in response",
|
|
171
|
+
transient: !1
|
|
172
|
+
})
|
|
173
|
+
})));
|
|
174
|
+
//#endregion
|
|
175
|
+
export { o as DEFAULT_POLICY, a as DEFAULT_RETRY_BUDGET, i as DEFAULT_RETRY_METHODS, r as RETRYABLE_STATUS, x as assertPublicUrl, y as assertSameHost, _ as backoffMs, v as parseRetryAfter, C as request, w as requestJson, g as resetRetryBudgets, h as retryBudgetSnapshot };
|
package/dist/index.js
CHANGED
|
@@ -1,203 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
408,
|
|
5
|
-
425,
|
|
6
|
-
429,
|
|
7
|
-
500,
|
|
8
|
-
502,
|
|
9
|
-
503,
|
|
10
|
-
504
|
|
11
|
-
]), i = [
|
|
12
|
-
"GET",
|
|
13
|
-
"PUT",
|
|
14
|
-
"DELETE"
|
|
15
|
-
], a = {
|
|
16
|
-
ratio: .2,
|
|
17
|
-
minRetriesPerWindow: 10,
|
|
18
|
-
windowMs: 1e4
|
|
19
|
-
}, o = {
|
|
20
|
-
maxAttempts: 4,
|
|
21
|
-
initialDelayMs: 500,
|
|
22
|
-
maxDelayMs: 1e4,
|
|
23
|
-
timeoutMs: 2e4,
|
|
24
|
-
honourRetryAfter: !0,
|
|
25
|
-
retryMethods: i,
|
|
26
|
-
retryBudget: a
|
|
27
|
-
}, s = /* @__PURE__ */ new Map(), c = (e, t, n) => {
|
|
28
|
-
let r = t - n, i = 0;
|
|
29
|
-
for (; i < e.events.length && e.events[i][0] < r;) i += 1;
|
|
30
|
-
i > 0 && e.events.splice(0, i);
|
|
31
|
-
}, l = (e) => {
|
|
32
|
-
let t = s.get(e);
|
|
33
|
-
return t === void 0 && (t = { events: [] }, s.set(e, t)), t;
|
|
34
|
-
}, u = (e) => {
|
|
35
|
-
let t = 0, n = 0;
|
|
36
|
-
for (let [, r] of e.events) r === 0 ? t += 1 : n += 1;
|
|
37
|
-
return {
|
|
38
|
-
requests: t,
|
|
39
|
-
retries: n
|
|
40
|
-
};
|
|
41
|
-
}, d = (e, t, n) => {
|
|
42
|
-
let r = l(e);
|
|
43
|
-
c(r, t, n.windowMs), r.events.push([t, 0]);
|
|
44
|
-
}, f = n.counter("voltro_http_retries_total"), p = n.counter("voltro_http_retry_budget_exhausted_total"), m = (e, r, i) => {
|
|
45
|
-
let a = l(e);
|
|
46
|
-
c(a, r, i.windowMs);
|
|
47
|
-
let { requests: o, retries: s } = u(a);
|
|
48
|
-
return s >= Math.max(i.minRetriesPerWindow, Math.floor(o * i.ratio)) ? (t.runSync(n.increment(n.tagged(p, "host", e))), !1) : (a.events.push([r, 1]), t.runSync(n.increment(n.tagged(f, "host", e))), !0);
|
|
49
|
-
}, h = (e, t = Date.now(), n = a.windowMs) => {
|
|
50
|
-
let r = s.get(e);
|
|
51
|
-
return r === void 0 ? {
|
|
52
|
-
requests: 0,
|
|
53
|
-
retries: 0
|
|
54
|
-
} : (c(r, t, n), u(r));
|
|
55
|
-
}, g = () => {
|
|
56
|
-
s.clear();
|
|
57
|
-
}, _ = (e, t) => Math.min(t.initialDelayMs * 2 ** (e - 1), t.maxDelayMs), v = (e, t) => {
|
|
58
|
-
if (!e) return null;
|
|
59
|
-
let n = Number(e);
|
|
60
|
-
if (Number.isFinite(n)) return Math.max(0, n * 1e3);
|
|
61
|
-
let r = Date.parse(e);
|
|
62
|
-
return Number.isNaN(r) ? null : Math.max(0, r - t);
|
|
63
|
-
}, y = (e, t) => {
|
|
64
|
-
try {
|
|
65
|
-
return new URL(e).host === new URL(t).host;
|
|
66
|
-
} catch {
|
|
67
|
-
return !1;
|
|
68
|
-
}
|
|
69
|
-
}, b = (e, t) => e === 127 || e === 10 || e === 172 && t >= 16 && t <= 31 || e === 192 && t === 168 || e === 169 && t === 254 || e === 0 || e === 100 && t >= 64 && t <= 127 || e >= 224, x = (e) => {
|
|
70
|
-
let t;
|
|
71
|
-
try {
|
|
72
|
-
t = new URL(e);
|
|
73
|
-
} catch {
|
|
74
|
-
throw Error("SSRF: malformed url");
|
|
75
|
-
}
|
|
76
|
-
if (t.protocol !== "http:" && t.protocol !== "https:") throw Error(`SSRF: blocked url scheme "${t.protocol}"`);
|
|
77
|
-
let n = t.hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
78
|
-
if (n === "localhost" || n.endsWith(".localhost") || n.endsWith(".internal") || n.endsWith(".local")) throw Error(`SSRF: blocked host "${n}"`);
|
|
79
|
-
let r = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(n);
|
|
80
|
-
if (r) {
|
|
81
|
-
let e = r.slice(1).map(Number);
|
|
82
|
-
if (e.some((e) => e > 255) || b(e[0], e[1])) throw Error(`SSRF: blocked address "${n}"`);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (n.includes(":") && (n === "::1" || n === "::" || n.startsWith("::ffff:") || /^fe[89ab]/.test(n) || n.startsWith("fc") || n.startsWith("fd"))) throw Error(`SSRF: blocked address "${n}"`);
|
|
86
|
-
}, S = (e) => typeof e == "object" && !!e && e._transient === !0, C = (n) => {
|
|
87
|
-
let { fetchImpl: o, baseUrl: s, method: c, path: l, headers: u, body: f, policy: p, makeError: h } = n, g = n.now ?? Date.now, b = `${s.replace(/\/$/, "")}${l.startsWith("/") ? l : `/${l}`}`;
|
|
88
|
-
if (!y(s, b)) return t.fail(h({
|
|
89
|
-
message: `blocked off-host request to ${b}`,
|
|
90
|
-
transient: !1
|
|
91
|
-
}));
|
|
92
|
-
let x = t.tryPromise({
|
|
93
|
-
try: async (e) => {
|
|
94
|
-
let t = await o(b, {
|
|
95
|
-
method: c,
|
|
96
|
-
headers: u,
|
|
97
|
-
...f === void 0 ? {} : { body: f },
|
|
98
|
-
signal: e
|
|
99
|
-
}), n = new Uint8Array(await t.arrayBuffer()), i = t.headers.get("content-type"), a = () => new TextDecoder().decode(n);
|
|
100
|
-
if (t.status >= 200 && t.status < 300) return {
|
|
101
|
-
status: t.status,
|
|
102
|
-
bytes: n,
|
|
103
|
-
contentType: i,
|
|
104
|
-
text: a
|
|
105
|
-
};
|
|
106
|
-
throw t.status === 401 ? h({
|
|
107
|
-
status: 401,
|
|
108
|
-
message: "unauthorized — the upstream refused this credential (401). The reason is not in the response: expired, revoked, insufficient scope and malformed are all this status.",
|
|
109
|
-
transient: !1,
|
|
110
|
-
code: "unauthorized"
|
|
111
|
-
}) : r.has(t.status) ? {
|
|
112
|
-
_transient: !0,
|
|
113
|
-
status: t.status,
|
|
114
|
-
message: `HTTP ${t.status}: ${a().slice(0, 500)}`,
|
|
115
|
-
retryAfterMs: p.honourRetryAfter ? v(t.headers.get("retry-after"), g()) : null
|
|
116
|
-
} : h({
|
|
117
|
-
status: t.status,
|
|
118
|
-
message: `HTTP ${t.status}: ${a().slice(0, 500)}`,
|
|
119
|
-
transient: !1
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
catch: (e) => S(e) || typeof e == "object" && e && "_tag" in e ? e : {
|
|
123
|
-
_transient: !0,
|
|
124
|
-
message: `network error: ${String(e)}`,
|
|
125
|
-
retryAfterMs: null
|
|
126
|
-
}
|
|
127
|
-
}).pipe(t.timeoutFail({
|
|
128
|
-
duration: e.millis(p.timeoutMs),
|
|
129
|
-
onTimeout: () => ({
|
|
130
|
-
_transient: !0,
|
|
131
|
-
message: `request timed out after ${p.timeoutMs}ms`,
|
|
132
|
-
retryAfterMs: null
|
|
133
|
-
})
|
|
134
|
-
})), C = n.retry ?? (p.retryMethods ?? i).includes(c), w = p.retryBudget === void 0 ? a : p.retryBudget, T = (() => {
|
|
135
|
-
try {
|
|
136
|
-
return new URL(s).host;
|
|
137
|
-
} catch {
|
|
138
|
-
return "invalid";
|
|
139
|
-
}
|
|
140
|
-
})(), E = (e, n) => t.fail(h({
|
|
141
|
-
message: `${e.message} (not retried: ${n})`,
|
|
142
|
-
transient: !0,
|
|
143
|
-
...e.status === void 0 ? {} : { status: e.status }
|
|
144
|
-
})), D = (n) => x.pipe(t.catchAll((r) => {
|
|
145
|
-
if (S(r) && n < p.maxAttempts && !C) return E(r, `${c} is not idempotent — pass \`retry: true\` for a call you have made so`);
|
|
146
|
-
if (S(r) && n < p.maxAttempts && w !== !1 && !m(T, g(), w)) return E(r, `the retry budget for ${T} is exhausted`);
|
|
147
|
-
if (S(r) && n < p.maxAttempts) {
|
|
148
|
-
let i = r.retryAfterMs ?? _(n, p), a = r.retryAfterMs == null ? i / 2 + i / 2 * Math.random() : i, o = Math.min(a, p.maxDelayMs);
|
|
149
|
-
return t.sleep(e.millis(o)).pipe(t.flatMap(() => D(n + 1)));
|
|
150
|
-
}
|
|
151
|
-
return S(r) ? t.fail(h({
|
|
152
|
-
message: r.message,
|
|
153
|
-
transient: !0,
|
|
154
|
-
...r.status === void 0 ? {} : { status: r.status }
|
|
155
|
-
})) : t.fail(r);
|
|
156
|
-
})), O = (() => {
|
|
157
|
-
try {
|
|
158
|
-
return new URL(s).host;
|
|
159
|
-
} catch {
|
|
160
|
-
return "invalid";
|
|
161
|
-
}
|
|
162
|
-
})();
|
|
163
|
-
return t.suspend(() => (w !== !1 && d(T, g(), w), D(1))).pipe(t.withSpan("integration-http.request", { attributes: {
|
|
164
|
-
"http.request.method": c,
|
|
165
|
-
"server.address": O
|
|
166
|
-
} }));
|
|
167
|
-
}, w = (e) => C(e).pipe(t.flatMap((n) => n.bytes.length === 0 ? t.succeed(null) : t.try({
|
|
168
|
-
try: () => JSON.parse(n.text()),
|
|
169
|
-
catch: () => e.makeError({
|
|
170
|
-
status: n.status,
|
|
171
|
-
message: "invalid JSON in response",
|
|
172
|
-
transient: !1
|
|
173
|
-
})
|
|
174
|
-
}))), T = (e) => {
|
|
175
|
-
let t = {
|
|
176
|
-
...o,
|
|
177
|
-
...e.policy
|
|
178
|
-
}, n = (n, r, i) => {
|
|
179
|
-
let a = i?.ctx ?? void 0, o = i?.body;
|
|
180
|
-
return {
|
|
181
|
-
fetchImpl: e.fetchImpl,
|
|
182
|
-
baseUrl: e.baseUrl,
|
|
183
|
-
method: n,
|
|
184
|
-
path: r,
|
|
185
|
-
headers: e.auth(a),
|
|
186
|
-
...o === void 0 ? {} : { body: JSON.stringify(o) },
|
|
187
|
-
policy: t,
|
|
188
|
-
makeError: e.makeError,
|
|
189
|
-
...e.now ? { now: e.now } : {}
|
|
190
|
-
};
|
|
191
|
-
}, r = (e, t, r) => C(n(e, t, r)), i = (e, t, r) => w(n(e, t, r));
|
|
192
|
-
return {
|
|
193
|
-
get: (e, t) => r("GET", e, t),
|
|
194
|
-
getJson: (e, t) => i("GET", e, t),
|
|
195
|
-
postJson: (e, t) => i("POST", e, t),
|
|
196
|
-
putJson: (e, t) => i("PUT", e, t),
|
|
197
|
-
deleteJson: (e, t) => i("DELETE", e, t),
|
|
198
|
-
request: (e, t, n) => r(e, t, n),
|
|
199
|
-
policy: t
|
|
200
|
-
};
|
|
201
|
-
};
|
|
202
|
-
//#endregion
|
|
203
|
-
export { o as DEFAULT_POLICY, a as DEFAULT_RETRY_BUDGET, i as DEFAULT_RETRY_METHODS, r as RETRYABLE_STATUS, x as assertPublicUrl, y as assertSameHost, _ as backoffMs, T as makeHttpClient, v as parseRetryAfter, C as request, w as requestJson, g as resetRetryBudgets, h as retryBudgetSnapshot };
|
|
1
|
+
import { DEFAULT_POLICY as e, DEFAULT_RETRY_BUDGET as t, DEFAULT_RETRY_METHODS as n, RETRYABLE_STATUS as r, assertPublicUrl as i, assertSameHost as a, backoffMs as o, parseRetryAfter as s, request as c, requestJson as l, resetRetryBudgets as u, retryBudgetSnapshot as d } from "./core.js";
|
|
2
|
+
import { makeHttpClient as f } from "./client.js";
|
|
3
|
+
export { e as DEFAULT_POLICY, t as DEFAULT_RETRY_BUDGET, n as DEFAULT_RETRY_METHODS, r as RETRYABLE_STATUS, i as assertPublicUrl, a as assertSameHost, o as backoffMs, f as makeHttpClient, s as parseRetryAfter, c as request, l as requestJson, u as resetRetryBudgets, d as retryBudgetSnapshot };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/integration-http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.86.0",
|
|
4
4
|
"description": "Server-side HTTP transport core for integration plugins: token auth, transient retry with Retry-After, per-request timeout, and an SSRF host-allowlist guard — over an injectable fetch seam, Effect-first with typed errors.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"node": ">=24.0.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"effect": "
|
|
36
|
+
"effect": "4.0.1"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|