wireweave 0.3.8 → 0.3.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wireweave",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "nostr + webrtc voice + data SDK. networking layer for 247420 projects.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/bans.js CHANGED
@@ -55,13 +55,16 @@ export class Bans extends EventTarget {
55
55
  if (!creator) return;
56
56
  this.sub = 'bans-' + serverId;
57
57
  this.pool.subscribe(this.sub,
58
- [{ kinds: [30078], authors: [creator], '#d': ['zellous-ban:' + serverId, 'zellous-timeout:' + serverId] }],
58
+ [{ kinds: [30078], authors: [creator], '#server': [serverId] }],
59
59
  (event) => {
60
60
  if (event.pubkey !== creator) return;
61
61
  try {
62
62
  const dTag = event.tags.find(t => t[0] === 'd');
63
63
  if (!dTag?.[1]) return;
64
- const [prefix, , pubkey] = dTag[1].split(':');
64
+ const parts = dTag[1].split(':');
65
+ const prefix = parts[0];
66
+ const pubkey = parts[parts.length - 1];
67
+ if (prefix !== 'zellous-ban' && prefix !== 'zellous-timeout') return;
65
68
  const data = this.store.get(serverId) || { banned: [], timeouts: {} };
66
69
  if (prefix === 'zellous-ban' && pubkey && !data.banned.includes(pubkey)) data.banned.push(pubkey);
67
70
  else if (prefix === 'zellous-timeout' && pubkey) {
package/src/debug.js CHANGED
@@ -3,15 +3,15 @@ const registry = new Map();
3
3
  export const register = (key, obj) => {
4
4
  registry.set(key, obj);
5
5
  if (typeof window !== 'undefined') {
6
- window.__magicwand = window.__magicwand || {};
7
- window.__magicwand[key] = obj;
6
+ window.__wireweave = window.__wireweave || {};
7
+ window.__wireweave[key] = obj;
8
8
  }
9
9
  };
10
10
 
11
11
  export const deregister = (key) => {
12
12
  registry.delete(key);
13
- if (typeof window !== 'undefined' && window.__magicwand) {
14
- delete window.__magicwand[key];
13
+ if (typeof window !== 'undefined' && window.__wireweave) {
14
+ delete window.__wireweave[key];
15
15
  }
16
16
  };
17
17
 
package/src/media.js CHANGED
@@ -94,8 +94,8 @@ export class Media {
94
94
 
95
95
  isMedia(url) {
96
96
  if (typeof url !== 'string') return null;
97
- if (/\.(png|jpe?g|gif|webp|svg|avif)(\?|$)/i.test(url)) return 'image';
98
- if (/\.(mp4|webm|mov|ogg)(\?|$)/i.test(url)) return 'video';
97
+ if (/\.(png|jpe?g|gif|webp|svg|avif|heic|heif|tiff?|bmp)(\?|$)/i.test(url)) return 'image';
98
+ if (/\.(mp4|webm|mov|ogg|ogv|mkv|m4v|avi)(\?|$)/i.test(url)) return 'video';
99
99
  return null;
100
100
  }
101
101
 
package/src/pages.js CHANGED
@@ -1,7 +1,17 @@
1
+ const stripTags = (html) => html
2
+ .replace(/<\s*(script|iframe|object|embed|form|input|button)\b[^>]*>[\s\S]*?<\s*\/\s*\1\s*>/gi, '')
3
+ .replace(/<\s*(script|iframe|object|embed|form|input|button)\b[^>]*\/?\s*>/gi, '')
4
+ .replace(/\son[a-z]+\s*=\s*"[^"]*"/gi, '')
5
+ .replace(/\son[a-z]+\s*=\s*'[^']*'/gi, '')
6
+ .replace(/\son[a-z]+\s*=\s*[^\s>]+/gi, '')
7
+ .replace(/(href|src)\s*=\s*"\s*javascript:[^"]*"/gi, '$1="#"')
8
+ .replace(/(href|src)\s*=\s*'\s*javascript:[^']*'/gi, "$1='#'");
9
+
1
10
  const sanitize = (html) => {
2
- if (typeof document === 'undefined') return html;
11
+ const stripped = stripTags(html);
12
+ if (typeof document === 'undefined') return stripped;
3
13
  const el = document.createElement('div');
4
- el.innerHTML = html;
14
+ el.innerHTML = stripped;
5
15
  el.querySelectorAll('script,iframe,object,embed,form,input,button').forEach(n => n.remove());
6
16
  el.querySelectorAll('*').forEach(n => {
7
17
  [...n.attributes].forEach(a => {
package/src/relay-pool.js CHANGED
@@ -36,7 +36,12 @@ export class RelayPool extends EventTarget {
36
36
 
37
37
  disconnect() {
38
38
  for (const [, r] of this.relays) {
39
- if (r.ws) { r.ws.onclose = null; r.ws.onerror = null; try { r.ws.close(); } catch {} }
39
+ if (r.ws) {
40
+ r.ws.onclose = null; r.ws.onerror = null; r.ws.onopen = null; r.ws.onmessage = null;
41
+ if (typeof r.ws.removeAllListeners === 'function') r.ws.removeAllListeners();
42
+ if (typeof r.ws.on === 'function') r.ws.on('error', () => {});
43
+ try { r.ws.close(); } catch {}
44
+ }
40
45
  }
41
46
  this.relays.clear();
42
47
  }
package/src/wireweave.js CHANGED
@@ -24,6 +24,7 @@ export const createWireweave = ({
24
24
  } = {}) => {
25
25
  if (!nostrTools) throw new Error('wireweave: nostrTools required');
26
26
  if (!xstate) throw new Error('wireweave: xstate required');
27
+ if (!storage) throw new Error('wireweave: storage required (no localStorage in this env — pass a {getItem,setItem,removeItem} adapter)');
27
28
 
28
29
  const fsm = createFSM(xstate);
29
30
  const pool = createRelayPool({ relays, verifyEvent: nostrTools.verifyEvent, WebSocketImpl });