Files
boris/node_modules/applesauce-actions/dist/actions/blossom.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

53 lines
2.7 KiB
JavaScript

import { BLOSSOM_SERVER_LIST_KIND } from "applesauce-core/helpers/blossom";
import { modifyPublicTags, modifyTags } from "applesauce-factory/operations";
import { addBlossomServerTag, removeBlossomServerTag } from "applesauce-factory/operations/tag/blossom";
/** An action that adds a server to the Blossom servers event */
export function AddBlossomServer(server) {
return async function* ({ events, factory, self }) {
const servers = events.getReplaceable(BLOSSOM_SERVER_LIST_KIND, self);
const operation = Array.isArray(server) ? server.map((s) => addBlossomServerTag(s)) : addBlossomServerTag(server);
// Modify or build new event
const draft = servers
? await factory.modifyTags(servers, operation)
: await factory.build({ kind: BLOSSOM_SERVER_LIST_KIND }, modifyTags(operation));
yield await factory.sign(draft);
};
}
/** An action that removes a server from the Blossom servers event */
export function RemoveBlossomServer(server) {
return async function* ({ events, factory, self }) {
const servers = events.getReplaceable(BLOSSOM_SERVER_LIST_KIND, self);
const operation = Array.isArray(server)
? server.map((s) => removeBlossomServerTag(s))
: removeBlossomServerTag(server);
// Modify or build new event
const draft = servers
? await factory.modifyTags(servers, operation)
: await factory.build({ kind: BLOSSOM_SERVER_LIST_KIND }, modifyTags(operation));
yield await factory.sign(draft);
};
}
/** Makes a specific Blossom server the default server (move it to the top of the list) */
export function SetDefaultBlossomServer(server) {
return async function* ({ events, factory, self }) {
const servers = events.getReplaceable(BLOSSOM_SERVER_LIST_KIND, self);
const prependTag = (tag) => (tags) => [tag, ...tags];
const operations = [removeBlossomServerTag(server), prependTag(["server", String(server)])];
const draft = servers
? await factory.modifyTags(servers, operations)
: await factory.build({ kind: BLOSSOM_SERVER_LIST_KIND }, modifyTags(...operations));
yield await factory.sign(draft);
};
}
/** Creates a new Blossom servers event */
export function NewBlossomServers(servers) {
return async function* ({ events, factory, self }) {
const existing = events.getReplaceable(BLOSSOM_SERVER_LIST_KIND, self);
if (existing)
throw new Error("Blossom servers event already exists");
const operations = servers ? servers.map((s) => addBlossomServerTag(s)) : [];
const draft = await factory.build({ kind: BLOSSOM_SERVER_LIST_KIND }, modifyPublicTags(...operations));
yield await factory.sign(draft);
};
}