Validate url in fetch, rework some hints
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@welshman",
|
||||
"private": true,
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/app",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "A collection of svelte stores for use in building nostr client applications.",
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import {INBOX_RELAYS, asDecryptedEvent, readList} from "@welshman/util"
|
||||
import {TrustedEvent, PublishedList} from "@welshman/util"
|
||||
import {deriveEventsMapped, collection} from "@welshman/store"
|
||||
import {repository} from "./core.js"
|
||||
import {makeOutboxLoader} from "./relaySelections.js"
|
||||
|
||||
export const inboxRelaySelections = deriveEventsMapped<PublishedList>(repository, {
|
||||
filters: [{kinds: [INBOX_RELAYS]}],
|
||||
itemToEvent: item => item.event,
|
||||
eventToItem: (event: TrustedEvent) => readList(asDecryptedEvent(event)),
|
||||
})
|
||||
|
||||
export const {
|
||||
indexStore: inboxRelaySelectionsByPubkey,
|
||||
deriveItem: deriveInboxRelaySelections,
|
||||
loadItem: loadInboxRelaySelections,
|
||||
} = collection({
|
||||
name: "inboxRelaySelections",
|
||||
store: inboxRelaySelections,
|
||||
getKey: inboxRelaySelections => inboxRelaySelections.event.pubkey,
|
||||
load: makeOutboxLoader(INBOX_RELAYS),
|
||||
})
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/content",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "A collection of utilities for parsing nostr note content.",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/editor",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "A batteries-included nostr editor.",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/feeds",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "Utilities for building dynamic nostr feeds.",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/lib",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "A collection of utilities.",
|
||||
|
||||
@@ -1291,6 +1291,9 @@ type FetchOpts = {
|
||||
* @returns Promise of parsed JSON response
|
||||
*/
|
||||
export const fetchJson = async (url: string, opts: FetchOpts = {}) => {
|
||||
// Make sure the url is valid, this will throw if not
|
||||
url = String(new URL(url))
|
||||
|
||||
if (!opts.headers) {
|
||||
opts.headers = {}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/net",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "Utilities for connecting with nostr relays.",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/relay",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "An in-memory nostr relay implementation.",
|
||||
|
||||
@@ -56,7 +56,7 @@ export class Repository<E extends HashedEvent = TrustedEvent> extends Emitter {
|
||||
constructor() {
|
||||
super()
|
||||
|
||||
this.setMaxListeners(100)
|
||||
this.setMaxListeners(1000)
|
||||
}
|
||||
|
||||
// Dump/load/clear
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/router",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "A collection of utilities for nostr relay selection.",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
nth,
|
||||
uniq,
|
||||
intersection,
|
||||
mergeLeft,
|
||||
@@ -31,6 +32,7 @@ import {
|
||||
getAncestorTags,
|
||||
asDecryptedEvent,
|
||||
getRelaysFromList,
|
||||
getPubkeyTags,
|
||||
RelayMode,
|
||||
} from "@welshman/util"
|
||||
import {Repository} from "@welshman/relay"
|
||||
@@ -212,32 +214,33 @@ export class Router {
|
||||
return this.merge(scenarios)
|
||||
}
|
||||
|
||||
EventAncestors = (event: TrustedEvent, type: "mentions" | "replies" | "roots") => {
|
||||
const ancestorTags = getAncestorTags(event)
|
||||
EventParents = (event: TrustedEvent) => {
|
||||
const {replies} = getAncestorTags(event)
|
||||
const mentions = getPubkeyTags(event.tags)
|
||||
const authors = replies.map(nth(3)).filter(p => p?.length === 64)
|
||||
const others = mentions.map(nth(1)).filter(p => p?.length === 64)
|
||||
const relays = uniq([...replies, ...mentions].map(nth(2)).filter(r => r && isRelayUrl(r)))
|
||||
|
||||
const tags: string[][] = (ancestorTags as any)[type] || []
|
||||
|
||||
return this.scenario(
|
||||
tags.flatMap(([_, value, relay, ...pubkeys]) => {
|
||||
const selections = [
|
||||
makeSelection(this.ForUser().getUrls(), 0.5),
|
||||
makeSelection(this.FromPubkeys(pubkeys).getUrls()),
|
||||
]
|
||||
|
||||
if (relay) {
|
||||
selections.push(makeSelection([relay], 0.9))
|
||||
}
|
||||
|
||||
return selections
|
||||
}),
|
||||
)
|
||||
return this.merge([
|
||||
this.FromPubkeys(authors).weight(10),
|
||||
this.FromPubkeys(others),
|
||||
this.FromRelays(relays),
|
||||
])
|
||||
}
|
||||
|
||||
EventMentions = (event: TrustedEvent) => this.EventAncestors(event, "mentions")
|
||||
EventRoots = (event: TrustedEvent) => {
|
||||
const {roots} = getAncestorTags(event)
|
||||
const mentions = getPubkeyTags(event.tags)
|
||||
const authors = roots.map(nth(3)).filter(p => p?.length === 64)
|
||||
const others = mentions.map(nth(1)).filter(p => p?.length === 64)
|
||||
const relays = uniq([...roots, ...mentions].map(nth(2)).filter(r => r && isRelayUrl(r)))
|
||||
|
||||
EventParents = (event: TrustedEvent) => this.EventAncestors(event, "replies")
|
||||
|
||||
EventRoots = (event: TrustedEvent) => this.EventAncestors(event, "roots")
|
||||
return this.merge([
|
||||
this.FromPubkeys(authors).weight(10),
|
||||
this.FromPubkeys(others),
|
||||
this.FromRelays(relays),
|
||||
])
|
||||
}
|
||||
|
||||
PublishEvent = (event: TrustedEvent) => {
|
||||
const pubkeys = getPubkeyTagValues(event.tags)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/signer",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "A nostr signer implemenation supporting several login methods.",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/store",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "A collection of utilities based on svelte/store for use with welshman",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/util",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "A collection of nostr-related utilities.",
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
set -e
|
||||
|
||||
# Run the TypeScript script using ts-node
|
||||
pnpm exec ts-node scripts/apply_version.ts
|
||||
pnpm exec ts-node scripts/bump.ts
|
||||
|
||||
Reference in New Issue
Block a user