mirror of
https://github.com/aljazceru/bakery.git
synced 2025-12-17 12:45:20 +01:00
move default relays to const
This commit is contained in:
@@ -10,8 +10,8 @@
|
|||||||
"prepack": "tsc",
|
"prepack": "tsc",
|
||||||
"start": "node .",
|
"start": "node .",
|
||||||
"dev": "DATA_PATH=./data nodemon --loader @swc-node/register/esm src/index.ts",
|
"dev": "DATA_PATH=./data nodemon --loader @swc-node/register/esm src/index.ts",
|
||||||
"mcp": "mcp-inspector node . --mcp",
|
"mcp": "mcp-inspector node . --mcp --port 8080",
|
||||||
"mcp-debug": "mcp-inspector node --inspect-brk . --mcp",
|
"mcp-debug": "mcp-inspector node --inspect-brk . --mcp --port 8080",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"format": "prettier -w .",
|
"format": "prettier -w .",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { normalizeURL } from "applesauce-core/helpers";
|
||||||
import { EncryptedDirectMessage } from "nostr-tools/kinds";
|
import { EncryptedDirectMessage } from "nostr-tools/kinds";
|
||||||
|
|
||||||
export const DEFAULT_PORT = 9272;
|
export const DEFAULT_PORT = 9272;
|
||||||
@@ -7,4 +8,8 @@ export const NIP_11_SOFTWARE_URL = "git+https://github.com/hzrd149/bakery.git";
|
|||||||
|
|
||||||
export const OUTBOUND_PROXY_TYPES = ["SOCKS5", "HTTP"];
|
export const OUTBOUND_PROXY_TYPES = ["SOCKS5", "HTTP"];
|
||||||
|
|
||||||
export const DEFAULT_NOSTR_CONNECT_RELAYS = ["wss://relay.nsec.app"];
|
export const DEFAULT_BOOTSTRAP_RELAYS = ["wss://nos.lol", "wss://relay.damus.io", "wss://relay.nostr.band"].map(
|
||||||
|
normalizeURL,
|
||||||
|
);
|
||||||
|
export const DEFAULT_LOOKUP_RELAYS = ["wss://purplepag.es/", "wss://user.kindpag.es/"].map(normalizeURL);
|
||||||
|
export const DEFAULT_NOSTR_CONNECT_RELAYS = ["wss://relay.nsec.app/"].map(normalizeURL);
|
||||||
|
|||||||
13
src/env.ts
13
src/env.ts
@@ -4,7 +4,7 @@ import { normalizeURL } from "applesauce-core/helpers";
|
|||||||
import { homedir } from "os";
|
import { homedir } from "os";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
|
||||||
import { DEFAULT_PORT, OUTBOUND_PROXY_TYPES } from "./const.js";
|
import { DEFAULT_BOOTSTRAP_RELAYS, DEFAULT_LOOKUP_RELAYS, DEFAULT_PORT, OUTBOUND_PROXY_TYPES } from "./const.js";
|
||||||
import { normalizeToHexPubkey } from "./helpers/nip19.js";
|
import { normalizeToHexPubkey } from "./helpers/nip19.js";
|
||||||
import args from "./args.js";
|
import args from "./args.js";
|
||||||
|
|
||||||
@@ -29,15 +29,14 @@ export const TOR_ADDRESS = process.env.TOR_ADDRESS;
|
|||||||
|
|
||||||
if (!OUTBOUND_PROXY_TYPES.includes(TOR_PROXY_TYPE)) throw new Error("Invalid TOR_PROXY_TYPE, must be SOCKS5 or HTTP");
|
if (!OUTBOUND_PROXY_TYPES.includes(TOR_PROXY_TYPE)) throw new Error("Invalid TOR_PROXY_TYPE, must be SOCKS5 or HTTP");
|
||||||
|
|
||||||
// Default relay config
|
// nostr network config
|
||||||
export const BOOTSTRAP_RELAYS = process.env.BOOTSTRAP_RELAYS
|
export const BOOTSTRAP_RELAYS = process.env.BOOTSTRAP_RELAYS
|
||||||
? process.env.BOOTSTRAP_RELAYS.split(",").map(normalizeURL)
|
? process.env.BOOTSTRAP_RELAYS.split(",").map(normalizeURL)
|
||||||
: ["wss://nos.lol", "wss://relay.damus.io", "wss://relay.nostr.band"].map(normalizeURL);
|
: DEFAULT_BOOTSTRAP_RELAYS;
|
||||||
|
|
||||||
export const COMMON_CONTACT_RELAYS = process.env.COMMON_CONTACT_RELAYS
|
export const LOOKUP_RELAYS = process.env.LOOKUP_RELAYS
|
||||||
? process.env.COMMON_CONTACT_RELAYS.split(",").map(normalizeURL)
|
? process.env.LOOKUP_RELAYS.split(",").map(normalizeURL)
|
||||||
: ["wss://purplepag.es", "wss://user.kindpag.es"].map(normalizeURL);
|
: DEFAULT_LOOKUP_RELAYS;
|
||||||
|
|
||||||
export const IS_DEV = process.env.NODE_ENV === "development";
|
export const IS_DEV = process.env.NODE_ENV === "development";
|
||||||
|
|
||||||
export const IS_MCP = args.values.mcp;
|
export const IS_MCP = args.values.mcp;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { getObservableValue, simpleTimeout } from "applesauce-core/observable";
|
|||||||
import { getInboxes, getOutboxes } from "applesauce-core/helpers";
|
import { getInboxes, getOutboxes } from "applesauce-core/helpers";
|
||||||
|
|
||||||
import { logger } from "../logger.js";
|
import { logger } from "../logger.js";
|
||||||
import { COMMON_CONTACT_RELAYS } from "../env.js";
|
import { LOOKUP_RELAYS } from "../env.js";
|
||||||
import { replaceableLoader } from "../services/loaders.js";
|
import { replaceableLoader } from "../services/loaders.js";
|
||||||
import { eventStore, queryStore } from "../services/stores.js";
|
import { eventStore, queryStore } from "../services/stores.js";
|
||||||
import { arrayFallback } from "../helpers/array.js";
|
import { arrayFallback } from "../helpers/array.js";
|
||||||
@@ -28,7 +28,7 @@ export default class AddressBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadMailboxes(pubkey: string, relays?: string[], force?: boolean) {
|
async loadMailboxes(pubkey: string, relays?: string[], force?: boolean) {
|
||||||
relays = arrayFallback(relays, COMMON_CONTACT_RELAYS);
|
relays = arrayFallback(relays, LOOKUP_RELAYS);
|
||||||
replaceableLoader.next({ kind: kinds.RelayList, pubkey, relays, force });
|
replaceableLoader.next({ kind: kinds.RelayList, pubkey, relays, force });
|
||||||
|
|
||||||
return getObservableValue(
|
return getObservableValue(
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ReplaceableQuery, UserContactsQuery } from "applesauce-core/queries";
|
|||||||
import { getObservableValue, simpleTimeout } from "applesauce-core/observable";
|
import { getObservableValue, simpleTimeout } from "applesauce-core/observable";
|
||||||
|
|
||||||
import { logger } from "../logger.js";
|
import { logger } from "../logger.js";
|
||||||
import { COMMON_CONTACT_RELAYS } from "../env.js";
|
import { LOOKUP_RELAYS } from "../env.js";
|
||||||
import { replaceableLoader } from "../services/loaders.js";
|
import { replaceableLoader } from "../services/loaders.js";
|
||||||
import { eventStore, queryStore } from "../services/stores.js";
|
import { eventStore, queryStore } from "../services/stores.js";
|
||||||
import { arrayFallback } from "../helpers/array.js";
|
import { arrayFallback } from "../helpers/array.js";
|
||||||
@@ -34,7 +34,7 @@ export default class ContactBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadContacts(pubkey: string, relays?: string[], force?: boolean) {
|
async loadContacts(pubkey: string, relays?: string[], force?: boolean) {
|
||||||
relays = arrayFallback(relays, COMMON_CONTACT_RELAYS);
|
relays = arrayFallback(relays, LOOKUP_RELAYS);
|
||||||
replaceableLoader.next({ kind: kinds.Contacts, pubkey, relays, force });
|
replaceableLoader.next({ kind: kinds.Contacts, pubkey, relays, force });
|
||||||
|
|
||||||
return getObservableValue(
|
return getObservableValue(
|
||||||
@@ -46,7 +46,7 @@ export default class ContactBook {
|
|||||||
|
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
async loadContactsEvent(pubkey: string, relays?: string[]) {
|
async loadContactsEvent(pubkey: string, relays?: string[]) {
|
||||||
relays = arrayFallback(relays, COMMON_CONTACT_RELAYS);
|
relays = arrayFallback(relays, LOOKUP_RELAYS);
|
||||||
replaceableLoader.next({ kind: kinds.Contacts, pubkey, relays });
|
replaceableLoader.next({ kind: kinds.Contacts, pubkey, relays });
|
||||||
|
|
||||||
return getObservableValue(
|
return getObservableValue(
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import type App from "../app/index.js";
|
|||||||
import { arrayFallback } from "../helpers/array.js";
|
import { arrayFallback } from "../helpers/array.js";
|
||||||
import { rxNostr } from "../services/rx-nostr.js";
|
import { rxNostr } from "../services/rx-nostr.js";
|
||||||
import { eventStore, queryStore } from "../services/stores.js";
|
import { eventStore, queryStore } from "../services/stores.js";
|
||||||
import { COMMON_CONTACT_RELAYS } from "../env.js";
|
import { LOOKUP_RELAYS } from "../env.js";
|
||||||
import { bufferAudit } from "../helpers/rxjs.js";
|
import { bufferAudit } from "../helpers/rxjs.js";
|
||||||
import { getRelaysFromContactList } from "../helpers/contacts.js";
|
import { getRelaysFromContactList } from "../helpers/contacts.js";
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ export default class DirectMessageManager extends EventEmitter<EventMap> {
|
|||||||
async watchInbox(pubkey: string) {
|
async watchInbox(pubkey: string) {
|
||||||
if (this.watching.has(pubkey)) return;
|
if (this.watching.has(pubkey)) return;
|
||||||
|
|
||||||
this.app.addressBook.loadMailboxes(pubkey, COMMON_CONTACT_RELAYS, true);
|
this.app.addressBook.loadMailboxes(pubkey, LOOKUP_RELAYS, true);
|
||||||
|
|
||||||
this.log(`Watching ${pubkey} inboxes for mail`);
|
this.log(`Watching ${pubkey} inboxes for mail`);
|
||||||
const subscription = queryStore
|
const subscription = queryStore
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { kinds } from "nostr-tools";
|
|||||||
import { getObservableValue, simpleTimeout } from "applesauce-core/observable";
|
import { getObservableValue, simpleTimeout } from "applesauce-core/observable";
|
||||||
import { ProfileQuery } from "applesauce-core/queries";
|
import { ProfileQuery } from "applesauce-core/queries";
|
||||||
|
|
||||||
import { COMMON_CONTACT_RELAYS } from "../env.js";
|
import { LOOKUP_RELAYS } from "../env.js";
|
||||||
import { logger } from "../logger.js";
|
import { logger } from "../logger.js";
|
||||||
import { replaceableLoader } from "../services/loaders.js";
|
import { replaceableLoader } from "../services/loaders.js";
|
||||||
import { eventStore, queryStore } from "../services/stores.js";
|
import { eventStore, queryStore } from "../services/stores.js";
|
||||||
@@ -19,7 +19,7 @@ export default class ProfileBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadProfile(pubkey: string, relays?: string[], force?: boolean) {
|
async loadProfile(pubkey: string, relays?: string[], force?: boolean) {
|
||||||
relays = arrayFallback(relays, COMMON_CONTACT_RELAYS);
|
relays = arrayFallback(relays, LOOKUP_RELAYS);
|
||||||
replaceableLoader.next({ kind: kinds.Metadata, pubkey, relays, force });
|
replaceableLoader.next({ kind: kinds.Metadata, pubkey, relays, force });
|
||||||
|
|
||||||
return getObservableValue(
|
return getObservableValue(
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { NostrEvent, SimplePool } from "nostr-tools";
|
|||||||
import { Subscription } from "nostr-tools/abstract-relay";
|
import { Subscription } from "nostr-tools/abstract-relay";
|
||||||
import { getRelaysFromContactsEvent } from "applesauce-core/helpers";
|
import { getRelaysFromContactsEvent } from "applesauce-core/helpers";
|
||||||
|
|
||||||
import { BOOTSTRAP_RELAYS, COMMON_CONTACT_RELAYS } from "../../env.js";
|
import { BOOTSTRAP_RELAYS, LOOKUP_RELAYS } from "../../env.js";
|
||||||
import { logger } from "../../logger.js";
|
import { logger } from "../../logger.js";
|
||||||
import App from "../../app/index.js";
|
import App from "../../app/index.js";
|
||||||
import { arrayFallback } from "../../helpers/array.js";
|
import { arrayFallback } from "../../helpers/array.js";
|
||||||
@@ -61,7 +61,7 @@ export default class Receiver extends EventEmitter<EventMap> {
|
|||||||
const owner = this.app.config.data.owner;
|
const owner = this.app.config.data.owner;
|
||||||
if (!owner) throw new Error("Missing owner");
|
if (!owner) throw new Error("Missing owner");
|
||||||
|
|
||||||
const commonMailboxesRelays = [...BOOTSTRAP_RELAYS, ...COMMON_CONTACT_RELAYS];
|
const commonMailboxesRelays = [...BOOTSTRAP_RELAYS, ...LOOKUP_RELAYS];
|
||||||
|
|
||||||
const ownerMailboxes = await requestLoader.mailboxes({ pubkey: owner, relays: commonMailboxesRelays }, true);
|
const ownerMailboxes = await requestLoader.mailboxes({ pubkey: owner, relays: commonMailboxesRelays }, true);
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Filter } from "nostr-tools";
|
|||||||
import { isFromCache, markFromCache } from "applesauce-core/helpers";
|
import { isFromCache, markFromCache } from "applesauce-core/helpers";
|
||||||
import { ReplaceableLoader, RequestLoader } from "applesauce-loaders/loaders";
|
import { ReplaceableLoader, RequestLoader } from "applesauce-loaders/loaders";
|
||||||
|
|
||||||
import { COMMON_CONTACT_RELAYS } from "../env.js";
|
import { LOOKUP_RELAYS } from "../env.js";
|
||||||
import { rxNostr } from "./rx-nostr.js";
|
import { rxNostr } from "./rx-nostr.js";
|
||||||
import eventCache from "./event-cache.js";
|
import eventCache from "./event-cache.js";
|
||||||
import { eventStore, queryStore } from "./stores.js";
|
import { eventStore, queryStore } from "./stores.js";
|
||||||
@@ -13,7 +13,7 @@ function cacheRequest(filters: Filter[]) {
|
|||||||
return from(events).pipe(tap(markFromCache));
|
return from(events).pipe(tap(markFromCache));
|
||||||
}
|
}
|
||||||
|
|
||||||
export const replaceableLoader = new ReplaceableLoader(rxNostr, { cacheRequest, lookupRelays: COMMON_CONTACT_RELAYS });
|
export const replaceableLoader = new ReplaceableLoader(rxNostr, { cacheRequest, lookupRelays: LOOKUP_RELAYS });
|
||||||
|
|
||||||
replaceableLoader.subscribe((packet) => {
|
replaceableLoader.subscribe((packet) => {
|
||||||
// add it to event store
|
// add it to event store
|
||||||
|
|||||||
Reference in New Issue
Block a user