Files
boris/node_modules/applesauce-actions/dist/actions/mailboxes.js
Gigi 5d53a827e0 feat: initialize markr nostr bookmark client
- Add project structure with TypeScript, React, and Vite
- Implement nostr authentication using browser extension (NIP-07)
- Add NIP-51 compliant bookmark fetching and display
- Create minimal UI with login and bookmark components
- Integrate applesauce-core and applesauce-react libraries
- Add responsive styling with dark/light mode support
- Include comprehensive README with setup instructions

This is a minimal MVP for a nostr bookmark client that allows users to
view their bookmarks according to NIP-51 specification.
2025-10-02 07:17:07 +02:00

67 lines
3.0 KiB
JavaScript

import { kinds } from "nostr-tools";
import { addInboxRelay, addOutboxRelay, removeInboxRelay, removeOutboxRelay } from "applesauce-factory/operations/tag";
import { modifyPublicTags } from "applesauce-factory/operations";
/** An action to create a new kind 10002 relay list event */
export function CreateMailboxes(inboxes, outboxes) {
return async function* ({ events, factory, self }) {
const mailboxes = events.getReplaceable(kinds.RelayList, self);
if (mailboxes)
throw new Error("Mailbox event already exists");
const draft = await factory.build({ kind: kinds.RelayList }, modifyPublicTags(...inboxes.map(addInboxRelay), ...outboxes.map(addOutboxRelay)));
const signed = await factory.sign(draft);
yield signed;
};
}
/** An action to add an inbox relay to the kind 10002 relay list */
export function AddInboxRelay(relay) {
return async function* ({ events, factory, self }) {
if (typeof relay === "string")
relay = [relay];
const mailboxes = events.getReplaceable(kinds.RelayList, self);
const draft = mailboxes
? await factory.modifyTags(mailboxes, ...relay.map(addInboxRelay))
: await factory.build({ kind: kinds.RelayList }, modifyPublicTags(...relay.map(addInboxRelay)));
const signed = await factory.sign(draft);
yield signed;
};
}
/** An action to remove an inbox relay from the kind 10002 relay list */
export function RemoveInboxRelay(relay) {
return async function* ({ events, factory, self }) {
if (typeof relay === "string")
relay = [relay];
const mailboxes = events.getReplaceable(kinds.RelayList, self);
if (!mailboxes)
return;
const draft = await factory.modifyTags(mailboxes, ...relay.map(removeInboxRelay));
const signed = await factory.sign(draft);
yield signed;
};
}
/** An action to add an outbox relay to the kind 10002 relay list */
export function AddOutboxRelay(relay) {
return async function* ({ events, factory, self }) {
if (typeof relay === "string")
relay = [relay];
const mailboxes = events.getReplaceable(kinds.RelayList, self);
const draft = mailboxes
? await factory.modifyTags(mailboxes, ...relay.map(addOutboxRelay))
: await factory.build({ kind: kinds.RelayList }, modifyPublicTags(...relay.map(addOutboxRelay)));
const signed = await factory.sign(draft);
yield signed;
};
}
/** An action to remove an outbox relay from the kind 10002 relay list */
export function RemoveOutboxRelay(relay) {
return async function* ({ events, factory, self }) {
if (typeof relay === "string")
relay = [relay];
const mailboxes = events.getReplaceable(kinds.RelayList, self);
if (!mailboxes)
return;
const draft = await factory.modifyTags(mailboxes, ...relay.map(removeOutboxRelay));
const signed = await factory.sign(draft);
yield signed;
};
}