@redsocs/spam-warden 1.3.2 → 1.3.3

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.
@@ -255,18 +255,41 @@ var SWModule = (() => {
255
255
  } catch (e) {
256
256
  }
257
257
  },
258
- _send: function(url, data) {
258
+ _send: async function(url, data) {
259
259
  if (!url) return;
260
260
  let finalUrl = url.indexOf("://") === -1 ? (/(^localhost|^127\.0\.0\.1)(:\d+)?(\/|$)/i.test(url) ? "http://" : "https://") + url : url;
261
261
  if (typeof navigator !== "undefined" && navigator.sendBeacon) {
262
262
  try {
263
- if (navigator.sendBeacon(finalUrl, new Blob([JSON.stringify(data)], { type: "application/json" }))) return;
263
+ const success = navigator.sendBeacon(finalUrl, new Blob([JSON.stringify(data)], { type: "application/json" }));
264
+ if (success) return;
264
265
  } catch (e) {
266
+ console.warn("[SpamWarden] Beacon failed, falling back to fetch.");
265
267
  }
266
268
  }
267
269
  if (typeof fetch !== "undefined") {
268
- fetch(finalUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data), keepalive: true }).catch(() => {
269
- });
270
+ try {
271
+ const response = await fetch(finalUrl, {
272
+ method: "POST",
273
+ headers: { "Content-Type": "application/json" },
274
+ body: JSON.stringify(data),
275
+ keepalive: true
276
+ });
277
+ if (!response.ok) {
278
+ throw new Error(`SIEM rejected payload: ${response.status}`);
279
+ }
280
+ } catch (err) {
281
+ console.error("[SpamWarden] \u26A0\uFE0F Critical: Telemetry delivery failed.", err);
282
+ this._persistToAuditQueue(data);
283
+ }
284
+ }
285
+ },
286
+ // Helper to ensure we have a record even if the network is dead
287
+ _persistToAuditQueue: function(data) {
288
+ try {
289
+ const queue = JSON.parse(localStorage.getItem("sw_audit_queue") || "[]");
290
+ queue.push({ timestamp: Date.now(), data });
291
+ localStorage.setItem("sw_audit_queue", JSON.stringify(queue.slice(-10)));
292
+ } catch (e) {
270
293
  }
271
294
  }
272
295
  };
@@ -291,23 +314,6 @@ var SWModule = (() => {
291
314
  e.stopImmediatePropagation();
292
315
  if (self._config.onSpam) self._config.onSpam(result);
293
316
  else alert("Submission Blocked: System detected malicious input.");
294
- } else {
295
- const guardEl = document.getElementById("sw-guard");
296
- if (guardEl) {
297
- const token = guardEl.getAttribute("data-sw-token") || "";
298
- const dynamicSeed = guardEl.getAttribute("data-sw-seed") || "";
299
- const payload = combinedText + token + dynamicSeed;
300
- let hash = 5381;
301
- for (let i = 0; i < payload.length; i++) {
302
- hash = (hash << 5) + hash + payload.charCodeAt(i);
303
- }
304
- const signature = Math.abs(hash).toString(16);
305
- const sigInput = document.createElement("input");
306
- sigInput.type = "hidden";
307
- sigInput.name = "sw_signature";
308
- sigInput.value = signature;
309
- e.target.appendChild(sigInput);
310
- }
311
317
  }
312
318
  }
313
319
  }, true);
@@ -385,11 +391,7 @@ var SWModule = (() => {
385
391
  window.spamwarden = SpamWarden;
386
392
  } else {
387
393
  window.spamwarden = {
388
- version: SpamWarden.version,
389
- spamcheck: do_pow(),
390
- isSpam: function() {
391
- return this.spamcheck().isSpam;
392
- }
394
+ version: SpamWarden.version
393
395
  };
394
396
  }
395
397
  }