apiblaze 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/dist/sidecar/index.d.mts +1 -1
- package/dist/sidecar/index.d.ts +1 -1
- package/dist/sidecar/index.js +41 -28
- package/dist/sidecar/index.mjs +41 -28
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var import_commander = require("commander");
|
|
|
28
28
|
var import_chalk30 = __toESM(require("chalk"));
|
|
29
29
|
|
|
30
30
|
// package.json
|
|
31
|
-
var version = "0.6.
|
|
31
|
+
var version = "0.6.1";
|
|
32
32
|
|
|
33
33
|
// src/types.ts
|
|
34
34
|
var ApiError = class extends Error {
|
|
@@ -3120,7 +3120,7 @@ export default async function Page() {
|
|
|
3120
3120
|
return (
|
|
3121
3121
|
<main style={{ fontFamily: "ui-monospace, monospace", padding: 24, lineHeight: 1.6 }}>
|
|
3122
3122
|
<h1>APIblaze sidecar inspector</h1>
|
|
3123
|
-
<p>Fetched httpbingo through the
|
|
3123
|
+
<p>Fetched httpbingo through the sidecar. If httpbingo.org is <b>not yet approved</b>, this went
|
|
3124
3124
|
<b> direct</b> and now appears as a candidate in your dashboard \u2014 approve it, wait ~5 min, reload,
|
|
3125
3125
|
and it will route through APIblaze (the echo below will show it arrived via your proxy).</p>
|
|
3126
3126
|
<pre>{JSON.stringify(r, null, 2)}</pre>
|
package/dist/sidecar/index.d.mts
CHANGED
package/dist/sidecar/index.d.ts
CHANGED
package/dist/sidecar/index.js
CHANGED
|
@@ -85,7 +85,7 @@ function register(opts) {
|
|
|
85
85
|
if (installed) return;
|
|
86
86
|
const token = opts?.token ?? process.env.APIBLAZE_TOKEN;
|
|
87
87
|
if (!token) {
|
|
88
|
-
if (!opts?.quiet) console.warn("[apiblaze/sidecar] APIBLAZE_TOKEN not set \u2014
|
|
88
|
+
if (!opts?.quiet) console.warn("[apiblaze/sidecar] APIBLAZE_TOKEN not set \u2014 sidecar OFF (fetches pass through unchanged).");
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
91
|
const original = globalThis.fetch;
|
|
@@ -121,42 +121,55 @@ function register(opts) {
|
|
|
121
121
|
if (include.length > 0 && !include.some((g) => hostMatchesGlob(host, g))) return false;
|
|
122
122
|
return true;
|
|
123
123
|
};
|
|
124
|
+
const urlOf = (input) => {
|
|
125
|
+
if (typeof input === "string") return input;
|
|
126
|
+
if (input instanceof URL) return input.href;
|
|
127
|
+
if (input && typeof input === "object" && typeof input.url === "string") return input.url;
|
|
128
|
+
return null;
|
|
129
|
+
};
|
|
124
130
|
const wrapped = async (input, init) => {
|
|
125
131
|
try {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
const urlStr = urlOf(input);
|
|
133
|
+
if (urlStr) {
|
|
134
|
+
const url = new URL(urlStr);
|
|
135
|
+
if (shouldConsider(url)) {
|
|
136
|
+
const origin = canonicalOrigin(url.origin);
|
|
137
|
+
if (origin) {
|
|
138
|
+
const base = routes[origin];
|
|
139
|
+
if (base) {
|
|
140
|
+
if (!seen.has(origin)) {
|
|
141
|
+
seen.add(origin);
|
|
142
|
+
if (!opts?.quiet) console.log(`[apiblaze/sidecar] routed \u2192 ${origin}`);
|
|
143
|
+
}
|
|
144
|
+
const isReq = input instanceof Request;
|
|
145
|
+
const headers = new Headers(isReq ? input.headers : void 0);
|
|
146
|
+
if (init?.headers) new Headers(init.headers).forEach((v, k) => headers.set(k, v));
|
|
147
|
+
const appKey = headers.get("x-api-key");
|
|
148
|
+
if (appKey) headers.set("x-abz-fwd-x-api-key", appKey);
|
|
149
|
+
headers.set("x-api-key", token);
|
|
150
|
+
const target = `${base}${url.pathname}${url.search}`;
|
|
151
|
+
const body = init?.body ?? (isReq ? input.body : void 0);
|
|
152
|
+
const nextInit = {
|
|
153
|
+
method: init?.method ?? (isReq ? input.method : "GET"),
|
|
154
|
+
headers,
|
|
155
|
+
body,
|
|
156
|
+
signal: init?.signal ?? (isReq ? input.signal : void 0),
|
|
157
|
+
redirect: init?.redirect ?? (isReq ? input.redirect : void 0),
|
|
158
|
+
credentials: init?.credentials ?? (isReq ? input.credentials : void 0)
|
|
159
|
+
};
|
|
160
|
+
if (body) nextInit.duplex = "half";
|
|
161
|
+
return original(target, nextInit);
|
|
162
|
+
}
|
|
133
163
|
if (!seen.has(origin)) {
|
|
134
164
|
seen.add(origin);
|
|
135
|
-
if (!opts?.quiet) console.log(`[apiblaze/sidecar]
|
|
165
|
+
if (!opts?.quiet) console.log(`[apiblaze/sidecar] direct (not approved) \u2192 ${origin} \xB7 approve to route it`);
|
|
166
|
+
reportObserved(origin);
|
|
136
167
|
}
|
|
137
|
-
const headers = new Headers(req.headers);
|
|
138
|
-
const appKey = headers.get("x-api-key");
|
|
139
|
-
if (appKey) headers.set("x-abz-fwd-x-api-key", appKey);
|
|
140
|
-
headers.set("x-api-key", token);
|
|
141
|
-
const target = `${base}${url.pathname}${url.search}`;
|
|
142
|
-
return original(target, {
|
|
143
|
-
method: req.method,
|
|
144
|
-
headers,
|
|
145
|
-
body: req.body,
|
|
146
|
-
redirect: "manual",
|
|
147
|
-
duplex: req.body ? "half" : void 0
|
|
148
|
-
// streaming request bodies
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
if (!seen.has(origin)) {
|
|
152
|
-
seen.add(origin);
|
|
153
|
-
if (!opts?.quiet) console.log(`[apiblaze/sidecar] direct (not approved) \u2192 ${origin} \xB7 approve at your dashboard to route it`);
|
|
154
|
-
reportObserved(origin);
|
|
155
168
|
}
|
|
156
169
|
}
|
|
157
170
|
}
|
|
158
171
|
} catch (err) {
|
|
159
|
-
if (!opts?.quiet) console.warn("[apiblaze/sidecar] passthrough after
|
|
172
|
+
if (!opts?.quiet) console.warn("[apiblaze/sidecar] passthrough after sidecar error:", err?.message);
|
|
160
173
|
}
|
|
161
174
|
return original(input, init);
|
|
162
175
|
};
|
package/dist/sidecar/index.mjs
CHANGED
|
@@ -59,7 +59,7 @@ function register(opts) {
|
|
|
59
59
|
if (installed) return;
|
|
60
60
|
const token = opts?.token ?? process.env.APIBLAZE_TOKEN;
|
|
61
61
|
if (!token) {
|
|
62
|
-
if (!opts?.quiet) console.warn("[apiblaze/sidecar] APIBLAZE_TOKEN not set \u2014
|
|
62
|
+
if (!opts?.quiet) console.warn("[apiblaze/sidecar] APIBLAZE_TOKEN not set \u2014 sidecar OFF (fetches pass through unchanged).");
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
const original = globalThis.fetch;
|
|
@@ -95,42 +95,55 @@ function register(opts) {
|
|
|
95
95
|
if (include.length > 0 && !include.some((g) => hostMatchesGlob(host, g))) return false;
|
|
96
96
|
return true;
|
|
97
97
|
};
|
|
98
|
+
const urlOf = (input) => {
|
|
99
|
+
if (typeof input === "string") return input;
|
|
100
|
+
if (input instanceof URL) return input.href;
|
|
101
|
+
if (input && typeof input === "object" && typeof input.url === "string") return input.url;
|
|
102
|
+
return null;
|
|
103
|
+
};
|
|
98
104
|
const wrapped = async (input, init) => {
|
|
99
105
|
try {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
const urlStr = urlOf(input);
|
|
107
|
+
if (urlStr) {
|
|
108
|
+
const url = new URL(urlStr);
|
|
109
|
+
if (shouldConsider(url)) {
|
|
110
|
+
const origin = canonicalOrigin(url.origin);
|
|
111
|
+
if (origin) {
|
|
112
|
+
const base = routes[origin];
|
|
113
|
+
if (base) {
|
|
114
|
+
if (!seen.has(origin)) {
|
|
115
|
+
seen.add(origin);
|
|
116
|
+
if (!opts?.quiet) console.log(`[apiblaze/sidecar] routed \u2192 ${origin}`);
|
|
117
|
+
}
|
|
118
|
+
const isReq = input instanceof Request;
|
|
119
|
+
const headers = new Headers(isReq ? input.headers : void 0);
|
|
120
|
+
if (init?.headers) new Headers(init.headers).forEach((v, k) => headers.set(k, v));
|
|
121
|
+
const appKey = headers.get("x-api-key");
|
|
122
|
+
if (appKey) headers.set("x-abz-fwd-x-api-key", appKey);
|
|
123
|
+
headers.set("x-api-key", token);
|
|
124
|
+
const target = `${base}${url.pathname}${url.search}`;
|
|
125
|
+
const body = init?.body ?? (isReq ? input.body : void 0);
|
|
126
|
+
const nextInit = {
|
|
127
|
+
method: init?.method ?? (isReq ? input.method : "GET"),
|
|
128
|
+
headers,
|
|
129
|
+
body,
|
|
130
|
+
signal: init?.signal ?? (isReq ? input.signal : void 0),
|
|
131
|
+
redirect: init?.redirect ?? (isReq ? input.redirect : void 0),
|
|
132
|
+
credentials: init?.credentials ?? (isReq ? input.credentials : void 0)
|
|
133
|
+
};
|
|
134
|
+
if (body) nextInit.duplex = "half";
|
|
135
|
+
return original(target, nextInit);
|
|
136
|
+
}
|
|
107
137
|
if (!seen.has(origin)) {
|
|
108
138
|
seen.add(origin);
|
|
109
|
-
if (!opts?.quiet) console.log(`[apiblaze/sidecar]
|
|
139
|
+
if (!opts?.quiet) console.log(`[apiblaze/sidecar] direct (not approved) \u2192 ${origin} \xB7 approve to route it`);
|
|
140
|
+
reportObserved(origin);
|
|
110
141
|
}
|
|
111
|
-
const headers = new Headers(req.headers);
|
|
112
|
-
const appKey = headers.get("x-api-key");
|
|
113
|
-
if (appKey) headers.set("x-abz-fwd-x-api-key", appKey);
|
|
114
|
-
headers.set("x-api-key", token);
|
|
115
|
-
const target = `${base}${url.pathname}${url.search}`;
|
|
116
|
-
return original(target, {
|
|
117
|
-
method: req.method,
|
|
118
|
-
headers,
|
|
119
|
-
body: req.body,
|
|
120
|
-
redirect: "manual",
|
|
121
|
-
duplex: req.body ? "half" : void 0
|
|
122
|
-
// streaming request bodies
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
if (!seen.has(origin)) {
|
|
126
|
-
seen.add(origin);
|
|
127
|
-
if (!opts?.quiet) console.log(`[apiblaze/sidecar] direct (not approved) \u2192 ${origin} \xB7 approve at your dashboard to route it`);
|
|
128
|
-
reportObserved(origin);
|
|
129
142
|
}
|
|
130
143
|
}
|
|
131
144
|
}
|
|
132
145
|
} catch (err) {
|
|
133
|
-
if (!opts?.quiet) console.warn("[apiblaze/sidecar] passthrough after
|
|
146
|
+
if (!opts?.quiet) console.warn("[apiblaze/sidecar] passthrough after sidecar error:", err?.message);
|
|
134
147
|
}
|
|
135
148
|
return original(input, init);
|
|
136
149
|
};
|
package/package.json
CHANGED