apiblaze 0.9.0 → 0.11.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/dist/index.js +1079 -207
- package/dist/sidecar/index.js +7 -6
- package/dist/sidecar/index.mjs +7 -6
- package/package.json +1 -1
package/dist/sidecar/index.js
CHANGED
|
@@ -84,14 +84,15 @@ function isPrivateOrLocal(host) {
|
|
|
84
84
|
}
|
|
85
85
|
function register(opts) {
|
|
86
86
|
if (installed) return;
|
|
87
|
+
const quiet = opts?.quiet ?? (process.env.APIBLAZE_SIDECAR_VERBOSE ?? "true").trim().toLowerCase() === "false";
|
|
87
88
|
const off = opts?.enabled === false || opts?.enabled === void 0 && OFF_VALUES.has((process.env.APIBLAZE_SIDECAR ?? "").trim().toLowerCase());
|
|
88
89
|
if (off) {
|
|
89
|
-
if (!
|
|
90
|
+
if (!quiet) console.log("[apiblaze/sidecar] off (APIBLAZE_SIDECAR=off) \u2014 fetches go direct.");
|
|
90
91
|
return;
|
|
91
92
|
}
|
|
92
93
|
const token = opts?.token ?? process.env.APIBLAZE_API_KEY ?? process.env.APIBLAZE_TOKEN;
|
|
93
94
|
if (!token) {
|
|
94
|
-
if (!
|
|
95
|
+
if (!quiet) console.log("[apiblaze/sidecar] off (no APIBLAZE_API_KEY set) \u2014 fetches go direct.");
|
|
95
96
|
return;
|
|
96
97
|
}
|
|
97
98
|
const original = globalThis.fetch;
|
|
@@ -145,7 +146,7 @@ function register(opts) {
|
|
|
145
146
|
if (base) {
|
|
146
147
|
if (!seen.has(origin)) {
|
|
147
148
|
seen.add(origin);
|
|
148
|
-
if (!
|
|
149
|
+
if (!quiet) console.log(`[apiblaze/sidecar] routed \u2192 ${origin}`);
|
|
149
150
|
}
|
|
150
151
|
const isReq = input instanceof Request;
|
|
151
152
|
const headers = new Headers(isReq ? input.headers : void 0);
|
|
@@ -168,21 +169,21 @@ function register(opts) {
|
|
|
168
169
|
}
|
|
169
170
|
if (!seen.has(origin)) {
|
|
170
171
|
seen.add(origin);
|
|
171
|
-
if (!
|
|
172
|
+
if (!quiet) console.log(`[apiblaze/sidecar] direct (not approved) \u2192 ${origin} \xB7 approve to route it: npx apiblaze sidecar approve ${url.hostname}`);
|
|
172
173
|
reportObserved(origin);
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
} catch (err) {
|
|
178
|
-
if (!
|
|
179
|
+
if (!quiet) console.warn("[apiblaze/sidecar] passthrough after sidecar error:", err?.message);
|
|
179
180
|
}
|
|
180
181
|
return original(input, init);
|
|
181
182
|
};
|
|
182
183
|
wrapped.__apiblaze = true;
|
|
183
184
|
globalThis.fetch = wrapped;
|
|
184
185
|
installed = true;
|
|
185
|
-
if (!
|
|
186
|
+
if (!quiet) console.log("[apiblaze/sidecar] active \u2014 approved origins route through APIblaze; the rest go direct.");
|
|
186
187
|
}
|
|
187
188
|
function withApiblaze(nextConfig = {}) {
|
|
188
189
|
register();
|
package/dist/sidecar/index.mjs
CHANGED
|
@@ -58,14 +58,15 @@ function isPrivateOrLocal(host) {
|
|
|
58
58
|
}
|
|
59
59
|
function register(opts) {
|
|
60
60
|
if (installed) return;
|
|
61
|
+
const quiet = opts?.quiet ?? (process.env.APIBLAZE_SIDECAR_VERBOSE ?? "true").trim().toLowerCase() === "false";
|
|
61
62
|
const off = opts?.enabled === false || opts?.enabled === void 0 && OFF_VALUES.has((process.env.APIBLAZE_SIDECAR ?? "").trim().toLowerCase());
|
|
62
63
|
if (off) {
|
|
63
|
-
if (!
|
|
64
|
+
if (!quiet) console.log("[apiblaze/sidecar] off (APIBLAZE_SIDECAR=off) \u2014 fetches go direct.");
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
66
67
|
const token = opts?.token ?? process.env.APIBLAZE_API_KEY ?? process.env.APIBLAZE_TOKEN;
|
|
67
68
|
if (!token) {
|
|
68
|
-
if (!
|
|
69
|
+
if (!quiet) console.log("[apiblaze/sidecar] off (no APIBLAZE_API_KEY set) \u2014 fetches go direct.");
|
|
69
70
|
return;
|
|
70
71
|
}
|
|
71
72
|
const original = globalThis.fetch;
|
|
@@ -119,7 +120,7 @@ function register(opts) {
|
|
|
119
120
|
if (base) {
|
|
120
121
|
if (!seen.has(origin)) {
|
|
121
122
|
seen.add(origin);
|
|
122
|
-
if (!
|
|
123
|
+
if (!quiet) console.log(`[apiblaze/sidecar] routed \u2192 ${origin}`);
|
|
123
124
|
}
|
|
124
125
|
const isReq = input instanceof Request;
|
|
125
126
|
const headers = new Headers(isReq ? input.headers : void 0);
|
|
@@ -142,21 +143,21 @@ function register(opts) {
|
|
|
142
143
|
}
|
|
143
144
|
if (!seen.has(origin)) {
|
|
144
145
|
seen.add(origin);
|
|
145
|
-
if (!
|
|
146
|
+
if (!quiet) console.log(`[apiblaze/sidecar] direct (not approved) \u2192 ${origin} \xB7 approve to route it: npx apiblaze sidecar approve ${url.hostname}`);
|
|
146
147
|
reportObserved(origin);
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
} catch (err) {
|
|
152
|
-
if (!
|
|
153
|
+
if (!quiet) console.warn("[apiblaze/sidecar] passthrough after sidecar error:", err?.message);
|
|
153
154
|
}
|
|
154
155
|
return original(input, init);
|
|
155
156
|
};
|
|
156
157
|
wrapped.__apiblaze = true;
|
|
157
158
|
globalThis.fetch = wrapped;
|
|
158
159
|
installed = true;
|
|
159
|
-
if (!
|
|
160
|
+
if (!quiet) console.log("[apiblaze/sidecar] active \u2014 approved origins route through APIblaze; the rest go direct.");
|
|
160
161
|
}
|
|
161
162
|
function withApiblaze(nextConfig = {}) {
|
|
162
163
|
register();
|
package/package.json
CHANGED