@profullstack/threatcrush 0.13.51 → 0.13.52

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/daemon.js CHANGED
@@ -20128,7 +20128,43 @@ async function runDaemon() {
20128
20128
  }, 1 << 30);
20129
20129
  }
20130
20130
 
20131
+ // src/core/user-agent.ts
20132
+ var USER_AGENT = `threatcrush/${PKG_VERSION} (node ${process.version}; ${process.platform})`;
20133
+ function isOurHost(url, api = apiUrl()) {
20134
+ let host;
20135
+ try {
20136
+ host = new URL(url).hostname.toLowerCase();
20137
+ } catch {
20138
+ return false;
20139
+ }
20140
+ let apiHost = "";
20141
+ try {
20142
+ apiHost = new URL(api).hostname.toLowerCase();
20143
+ } catch {
20144
+ }
20145
+ return host === apiHost || host === "threatcrush.com" || host.endsWith(".threatcrush.com");
20146
+ }
20147
+ function urlOf(input) {
20148
+ if (typeof input === "string") return input;
20149
+ if (input instanceof URL) return input.href;
20150
+ return input.url;
20151
+ }
20152
+ function installUserAgent(target = globalThis) {
20153
+ const base = target.fetch;
20154
+ if (!base || base.__threatcrushUA) return;
20155
+ const wrapped = ((input, init) => {
20156
+ if (!isOurHost(urlOf(input))) return base(input, init);
20157
+ const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
20158
+ if (headers.has("user-agent")) return base(input, init);
20159
+ headers.set("user-agent", USER_AGENT);
20160
+ return base(input, { ...init, headers });
20161
+ });
20162
+ wrapped.__threatcrushUA = true;
20163
+ target.fetch = wrapped;
20164
+ }
20165
+
20131
20166
  // src/daemon-entry.ts
20167
+ installUserAgent();
20132
20168
  runDaemon().catch((err) => {
20133
20169
  console.error("threatcrushd failed to start:", err);
20134
20170
  process.exit(1);