mirror of
https://github.com/dergigi/boris.git
synced 2025-12-23 09:34:19 +01:00
chore: upgrade applesauce packages to v4.0.0
- Update all applesauce packages from 3.1.0 to 4.0.0 - Add applesauce-factory dependency - Version 4.0.0 includes app-data helpers needed for NIP-78
This commit is contained in:
156
node_modules/nostr-tools/lib/esm/index.js
generated
vendored
156
node_modules/nostr-tools/lib/esm/index.js
generated
vendored
@@ -588,7 +588,10 @@ var AbstractRelay = class {
|
||||
baseEoseTimeout = 4400;
|
||||
connectionTimeout = 4400;
|
||||
publishTimeout = 4400;
|
||||
pingFrequency = 2e4;
|
||||
pingTimeout = 2e4;
|
||||
openSubs = /* @__PURE__ */ new Map();
|
||||
enablePing;
|
||||
connectionTimeoutHandle;
|
||||
connectionPromise;
|
||||
openCountRequests = /* @__PURE__ */ new Map();
|
||||
@@ -605,6 +608,7 @@ var AbstractRelay = class {
|
||||
this.url = normalizeURL(url);
|
||||
this.verifyEvent = opts.verifyEvent;
|
||||
this._WebSocket = opts.websocketImplementation || WebSocket;
|
||||
this.enablePing = opts.enablePing;
|
||||
}
|
||||
static async connect(url, opts) {
|
||||
const relay = new AbstractRelay(url, opts);
|
||||
@@ -650,7 +654,7 @@ var AbstractRelay = class {
|
||||
this.ws.onopen = () => {
|
||||
clearTimeout(this.connectionTimeoutHandle);
|
||||
this._connected = true;
|
||||
if (this.ws && this.ws.ping) {
|
||||
if (this.enablePing) {
|
||||
this.pingpong();
|
||||
}
|
||||
resolve();
|
||||
@@ -658,45 +662,54 @@ var AbstractRelay = class {
|
||||
this.ws.onerror = (ev) => {
|
||||
clearTimeout(this.connectionTimeoutHandle);
|
||||
reject(ev.message || "websocket error");
|
||||
if (this._connected) {
|
||||
this._connected = false;
|
||||
this.connectionPromise = void 0;
|
||||
this.onclose?.();
|
||||
this.closeAllSubscriptions("relay connection errored");
|
||||
}
|
||||
this._connected = false;
|
||||
this.connectionPromise = void 0;
|
||||
this.onclose?.();
|
||||
this.closeAllSubscriptions("relay connection errored");
|
||||
};
|
||||
this.ws.onclose = (ev) => {
|
||||
clearTimeout(this.connectionTimeoutHandle);
|
||||
reject(ev.message || "websocket closed");
|
||||
if (this._connected) {
|
||||
this._connected = false;
|
||||
this.connectionPromise = void 0;
|
||||
this.onclose?.();
|
||||
this.closeAllSubscriptions("relay connection closed");
|
||||
}
|
||||
this._connected = false;
|
||||
this.connectionPromise = void 0;
|
||||
this.onclose?.();
|
||||
this.closeAllSubscriptions("relay connection closed");
|
||||
};
|
||||
this.ws.onmessage = this._onmessage.bind(this);
|
||||
});
|
||||
return this.connectionPromise;
|
||||
}
|
||||
async receivePong() {
|
||||
async waitForPingPong() {
|
||||
return new Promise((res, err) => {
|
||||
;
|
||||
this.ws && this.ws.on && this.ws.on("pong", () => res(true)) || err("ws can't listen for pong");
|
||||
this.ws && this.ws.ping && this.ws.ping();
|
||||
});
|
||||
}
|
||||
async waitForDummyReq() {
|
||||
return new Promise((resolve, _) => {
|
||||
const sub = this.subscribe([{ ids: ["a".repeat(64)] }], {
|
||||
oneose: () => {
|
||||
sub.close();
|
||||
resolve(true);
|
||||
},
|
||||
eoseTimeout: this.pingTimeout + 1e3
|
||||
});
|
||||
});
|
||||
}
|
||||
async pingpong() {
|
||||
if (this.ws?.readyState == 1) {
|
||||
this.ws && this.ws.ping && this.ws.ping();
|
||||
if (this.ws?.readyState === 1) {
|
||||
const result = await Promise.any([
|
||||
this.receivePong(),
|
||||
new Promise((res) => setTimeout(() => res(false), 1e4))
|
||||
this.ws && this.ws.ping && this.ws.on ? this.waitForPingPong() : this.waitForDummyReq(),
|
||||
new Promise((res) => setTimeout(() => res(false), this.pingTimeout))
|
||||
]);
|
||||
console.error("pingpong result", result);
|
||||
if (result) {
|
||||
setTimeout(() => this.pingpong(), 1e4);
|
||||
setTimeout(() => this.pingpong(), this.pingFrequency);
|
||||
} else {
|
||||
this.ws && this.ws.close();
|
||||
this.closeAllSubscriptions("pingpong timed out");
|
||||
this._connected = false;
|
||||
this.onclose?.();
|
||||
this.ws?.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -861,8 +874,8 @@ var AbstractRelay = class {
|
||||
close() {
|
||||
this.closeAllSubscriptions("relay connection closed by us");
|
||||
this._connected = false;
|
||||
this.ws?.close();
|
||||
this.onclose?.();
|
||||
this.ws?.close();
|
||||
}
|
||||
_onmessage(ev) {
|
||||
this.incomingMessageQueue.enqueue(ev.data);
|
||||
@@ -951,11 +964,13 @@ var AbstractSimplePool = class {
|
||||
seenOn = /* @__PURE__ */ new Map();
|
||||
trackRelays = false;
|
||||
verifyEvent;
|
||||
enablePing;
|
||||
trustedRelayURLs = /* @__PURE__ */ new Set();
|
||||
_WebSocket;
|
||||
constructor(opts) {
|
||||
this.verifyEvent = opts.verifyEvent;
|
||||
this._WebSocket = opts.websocketImplementation;
|
||||
this.enablePing = opts.enablePing;
|
||||
}
|
||||
async ensureRelay(url, params) {
|
||||
url = normalizeURL(url);
|
||||
@@ -963,7 +978,8 @@ var AbstractSimplePool = class {
|
||||
if (!relay) {
|
||||
relay = new AbstractRelay(url, {
|
||||
verifyEvent: this.trustedRelayURLs.has(url) ? alwaysTrue : this.verifyEvent,
|
||||
websocketImplementation: this._WebSocket
|
||||
websocketImplementation: this._WebSocket,
|
||||
enablePing: this.enablePing
|
||||
});
|
||||
relay.onclose = () => {
|
||||
this.relays.delete(url);
|
||||
@@ -983,20 +999,38 @@ var AbstractSimplePool = class {
|
||||
}
|
||||
subscribe(relays, filter, params) {
|
||||
params.onauth = params.onauth || params.doauth;
|
||||
return this.subscribeMap(
|
||||
relays.map((url) => ({ url, filter })),
|
||||
params
|
||||
);
|
||||
const request = [];
|
||||
for (let i2 = 0; i2 < relays.length; i2++) {
|
||||
const url = normalizeURL(relays[i2]);
|
||||
if (!request.find((r) => r.url === url)) {
|
||||
request.push({ url, filter });
|
||||
}
|
||||
}
|
||||
return this.subscribeMap(request, params);
|
||||
}
|
||||
subscribeMany(relays, filters, params) {
|
||||
subscribeMany(relays, filter, params) {
|
||||
params.onauth = params.onauth || params.doauth;
|
||||
return this.subscribeMap(
|
||||
relays.flatMap((url) => filters.map((filter) => ({ url, filter }))),
|
||||
params
|
||||
);
|
||||
const request = [];
|
||||
const uniqUrls = [];
|
||||
for (let i2 = 0; i2 < relays.length; i2++) {
|
||||
const url = normalizeURL(relays[i2]);
|
||||
if (uniqUrls.indexOf(url) === -1) {
|
||||
uniqUrls.push(url);
|
||||
request.push({ url, filter });
|
||||
}
|
||||
}
|
||||
return this.subscribeMap(request, params);
|
||||
}
|
||||
subscribeMap(requests, params) {
|
||||
params.onauth = params.onauth || params.doauth;
|
||||
const grouped = /* @__PURE__ */ new Map();
|
||||
for (const req of requests) {
|
||||
const { url, filter } = req;
|
||||
if (!grouped.has(url))
|
||||
grouped.set(url, []);
|
||||
grouped.get(url).push(filter);
|
||||
}
|
||||
const groupedRequests = Array.from(grouped.entries()).map(([url, filters]) => ({ url, filters }));
|
||||
if (this.trackRelays) {
|
||||
params.receivedEvent = (relay, id) => {
|
||||
let set = this.seenOn.get(id);
|
||||
@@ -1041,8 +1075,7 @@ var AbstractSimplePool = class {
|
||||
return have;
|
||||
};
|
||||
const allOpened = Promise.all(
|
||||
requests.map(async ({ url, filter }, i2) => {
|
||||
url = normalizeURL(url);
|
||||
groupedRequests.map(async ({ url, filters }, i2) => {
|
||||
let relay;
|
||||
try {
|
||||
relay = await this.ensureRelay(url, {
|
||||
@@ -1052,13 +1085,13 @@ var AbstractSimplePool = class {
|
||||
handleClose(i2, err?.message || String(err));
|
||||
return;
|
||||
}
|
||||
let subscription = relay.subscribe([filter], {
|
||||
let subscription = relay.subscribe(filters, {
|
||||
...params,
|
||||
oneose: () => handleEose(i2),
|
||||
onclose: (reason) => {
|
||||
if (reason.startsWith("auth-required: ") && params.onauth) {
|
||||
relay.auth(params.onauth).then(() => {
|
||||
relay.subscribe([filter], {
|
||||
relay.subscribe(filters, {
|
||||
...params,
|
||||
oneose: () => handleEose(i2),
|
||||
onclose: (reason2) => {
|
||||
@@ -1099,9 +1132,9 @@ var AbstractSimplePool = class {
|
||||
});
|
||||
return subcloser;
|
||||
}
|
||||
subscribeManyEose(relays, filters, params) {
|
||||
subscribeManyEose(relays, filter, params) {
|
||||
params.onauth = params.onauth || params.doauth;
|
||||
const subcloser = this.subscribeMany(relays, filters, {
|
||||
const subcloser = this.subscribeMany(relays, filter, {
|
||||
...params,
|
||||
oneose() {
|
||||
subcloser.close("closed automatically on eose");
|
||||
@@ -1172,8 +1205,8 @@ try {
|
||||
} catch {
|
||||
}
|
||||
var SimplePool = class extends AbstractSimplePool {
|
||||
constructor() {
|
||||
super({ verifyEvent, websocketImplementation: _WebSocket2 });
|
||||
constructor(options) {
|
||||
super({ verifyEvent, websocketImplementation: _WebSocket2, ...options });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2158,19 +2191,19 @@ function* parse3(content) {
|
||||
if (prevIndex !== u - prefixLen) {
|
||||
yield { type: "text", text: content.substring(prevIndex, u - prefixLen) };
|
||||
}
|
||||
if (url.pathname.endsWith(".png") || url.pathname.endsWith(".jpg") || url.pathname.endsWith(".jpeg") || url.pathname.endsWith(".gif") || url.pathname.endsWith(".webp")) {
|
||||
if (/\.(png|jpe?g|gif|webp)$/i.test(url.pathname)) {
|
||||
yield { type: "image", url: url.toString() };
|
||||
index = end;
|
||||
prevIndex = index;
|
||||
continue;
|
||||
}
|
||||
if (url.pathname.endsWith(".mp4") || url.pathname.endsWith(".avi") || url.pathname.endsWith(".webm") || url.pathname.endsWith(".mkv")) {
|
||||
if (/\.(mp4|avi|webm|mkv)$/i.test(url.pathname)) {
|
||||
yield { type: "video", url: url.toString() };
|
||||
index = end;
|
||||
prevIndex = index;
|
||||
continue;
|
||||
}
|
||||
if (url.pathname.endsWith(".mp3") || url.pathname.endsWith(".aac") || url.pathname.endsWith(".ogg") || url.pathname.endsWith(".opus")) {
|
||||
if (/\.(mp3|aac|ogg|opus)$/i.test(url.pathname)) {
|
||||
yield { type: "audio", url: url.toString() };
|
||||
index = end;
|
||||
prevIndex = index;
|
||||
@@ -2463,41 +2496,30 @@ async function getZapEndpoint(metadata) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function makeZapRequest({
|
||||
profile,
|
||||
event,
|
||||
amount,
|
||||
relays,
|
||||
comment = ""
|
||||
}) {
|
||||
if (!amount)
|
||||
throw new Error("amount not given");
|
||||
if (!profile)
|
||||
throw new Error("profile not given");
|
||||
function makeZapRequest(params) {
|
||||
let zr = {
|
||||
kind: 9734,
|
||||
created_at: Math.round(Date.now() / 1e3),
|
||||
content: comment,
|
||||
content: params.comment || "",
|
||||
tags: [
|
||||
["p", profile],
|
||||
["amount", amount.toString()],
|
||||
["relays", ...relays]
|
||||
["p", "pubkey" in params ? params.pubkey : params.event.pubkey],
|
||||
["amount", params.amount.toString()],
|
||||
["relays", ...params.relays]
|
||||
]
|
||||
};
|
||||
if (event && typeof event === "string") {
|
||||
zr.tags.push(["e", event]);
|
||||
}
|
||||
if (event && typeof event === "object") {
|
||||
if (isReplaceableKind(event.kind)) {
|
||||
const a = ["a", `${event.kind}:${event.pubkey}:`];
|
||||
if ("event" in params) {
|
||||
zr.tags.push(["e", params.event.id]);
|
||||
if (isReplaceableKind(params.event.kind)) {
|
||||
const a = ["a", `${params.event.kind}:${params.event.pubkey}:`];
|
||||
zr.tags.push(a);
|
||||
} else if (isAddressableKind(event.kind)) {
|
||||
let d = event.tags.find(([t, v]) => t === "d" && v);
|
||||
} else if (isAddressableKind(params.event.kind)) {
|
||||
let d = params.event.tags.find(([t, v]) => t === "d" && v);
|
||||
if (!d)
|
||||
throw new Error("d tag not found or is empty");
|
||||
const a = ["a", `${event.kind}:${event.pubkey}:${d[1]}`];
|
||||
const a = ["a", `${params.event.kind}:${params.event.pubkey}:${d[1]}`];
|
||||
zr.tags.push(a);
|
||||
}
|
||||
zr.tags.push(["k", params.event.kind.toString()]);
|
||||
}
|
||||
return zr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user