JSPM

applesauce-factory

0.0.0-next-20250609183606
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 100
    • Score
      100M100P100Q88147F
    • License MIT

    Package Exports

    • applesauce-factory
    • applesauce-factory/blueprints
    • applesauce-factory/blueprints/__tests__/comment.test
    • applesauce-factory/blueprints/__tests__/exports.test
    • applesauce-factory/blueprints/__tests__/follow-sets.test
    • applesauce-factory/blueprints/__tests__/gift-wrap.test
    • applesauce-factory/blueprints/__tests__/note.test
    • applesauce-factory/blueprints/__tests__/picture-post.test
    • applesauce-factory/blueprints/__tests__/reaction.test
    • applesauce-factory/blueprints/__tests__/reply.test
    • applesauce-factory/blueprints/__tests__/share.test
    • applesauce-factory/blueprints/channels
    • applesauce-factory/blueprints/comment
    • applesauce-factory/blueprints/delete
    • applesauce-factory/blueprints/file-metadata
    • applesauce-factory/blueprints/follow-sets
    • applesauce-factory/blueprints/gift-wrap
    • applesauce-factory/blueprints/groups
    • applesauce-factory/blueprints/index
    • applesauce-factory/blueprints/legacy-message
    • applesauce-factory/blueprints/live-stream
    • applesauce-factory/blueprints/message
    • applesauce-factory/blueprints/note
    • applesauce-factory/blueprints/picture-post
    • applesauce-factory/blueprints/reaction
    • applesauce-factory/blueprints/reply
    • applesauce-factory/blueprints/share
    • applesauce-factory/blueprints/wrapped-messages
    • applesauce-factory/event-factory
    • applesauce-factory/helpers
    • applesauce-factory/helpers/__tests__/comment.test
    • applesauce-factory/helpers/__tests__/common-tags.test
    • applesauce-factory/helpers/__tests__/exports.test
    • applesauce-factory/helpers/__tests__/pipeline.test
    • applesauce-factory/helpers/__tests__/pointer.test
    • applesauce-factory/helpers/__tests__/quote.test
    • applesauce-factory/helpers/__tests__/tags.test
    • applesauce-factory/helpers/blueprint
    • applesauce-factory/helpers/comment
    • applesauce-factory/helpers/common-tags
    • applesauce-factory/helpers/content
    • applesauce-factory/helpers/file-metadata
    • applesauce-factory/helpers/groups
    • applesauce-factory/helpers/index
    • applesauce-factory/helpers/pipeline
    • applesauce-factory/helpers/pointer
    • applesauce-factory/helpers/quote
    • applesauce-factory/helpers/tag
    • applesauce-factory/operations
    • applesauce-factory/operations/event
    • applesauce-factory/operations/event/__tests__/common.test
    • applesauce-factory/operations/event/__tests__/content.test
    • applesauce-factory/operations/event/__tests__/encryption.test
    • applesauce-factory/operations/event/__tests__/exports.test
    • applesauce-factory/operations/event/__tests__/gift-wrap.test
    • applesauce-factory/operations/event/__tests__/groups.test
    • applesauce-factory/operations/event/__tests__/hashtags.test
    • applesauce-factory/operations/event/__tests__/list.test
    • applesauce-factory/operations/event/__tests__/note.test
    • applesauce-factory/operations/event/__tests__/tags.test
    • applesauce-factory/operations/event/channels
    • applesauce-factory/operations/event/client
    • applesauce-factory/operations/event/comment
    • applesauce-factory/operations/event/common
    • applesauce-factory/operations/event/content
    • applesauce-factory/operations/event/delete
    • applesauce-factory/operations/event/emojis
    • applesauce-factory/operations/event/encryption
    • applesauce-factory/operations/event/expiration
    • applesauce-factory/operations/event/file-metadata
    • applesauce-factory/operations/event/gift-wrap
    • applesauce-factory/operations/event/groups
    • applesauce-factory/operations/event/hashtags
    • applesauce-factory/operations/event/index
    • applesauce-factory/operations/event/legacy-message
    • applesauce-factory/operations/event/list
    • applesauce-factory/operations/event/live-stream
    • applesauce-factory/operations/event/media-attachment
    • applesauce-factory/operations/event/message
    • applesauce-factory/operations/event/note
    • applesauce-factory/operations/event/picture-post
    • applesauce-factory/operations/event/profile
    • applesauce-factory/operations/event/protected
    • applesauce-factory/operations/event/quote
    • applesauce-factory/operations/event/reaction
    • applesauce-factory/operations/event/share
    • applesauce-factory/operations/event/signer
    • applesauce-factory/operations/event/tags
    • applesauce-factory/operations/event/wrapped-message
    • applesauce-factory/operations/event/zap
    • applesauce-factory/operations/tag
    • applesauce-factory/operations/tag/__tests__/common.test
    • applesauce-factory/operations/tag/__tests__/exports.test
    • applesauce-factory/operations/tag/__tests__/groups.test
    • applesauce-factory/operations/tag/__tests__/mailboxes.test
    • applesauce-factory/operations/tag/__tests__/relay.test
    • applesauce-factory/operations/tag/blossom
    • applesauce-factory/operations/tag/bookmarks
    • applesauce-factory/operations/tag/common
    • applesauce-factory/operations/tag/groups
    • applesauce-factory/operations/tag/index
    • applesauce-factory/operations/tag/mailboxes
    • applesauce-factory/operations/tag/relay

    Readme

    applesauce-factory

    applesauce event factory is a package for easily creating or modifying nostr events

    Documentation

    For detailed documentation and guides, visit:

    Creating a Factory

    When creating a new event factory you can pass a context object that is used by all blueprints:

    const signer = new SimpleSigner();
    
    const factory = new EventFactory({
      // optionally pass a signer in (required for encryption)
      signer: signer, // or pass NIP-07 window.nostr if it exists
      // optionally set a NIP-89 client
      client: {
        name: "My Awesome Client",
        address: {
          pubkey: "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d",
          identifier: "awesome-client",
        },
      },
    });

    Creating a short text note

    import { EventFactory } from "applesauce-factory";
    import { NoteBlueprint } from "applesauce-factory/blueprints";
    
    const factory = new EventFactory({
      // config options,
      // see https://hzrd149.github.io/applesauce/typedoc/types/applesauce-factory.EventFactoryContext.html
    });
    
    const unsignedEvent = await factory.create(
      NoteBlueprint,
      "hello nostr:npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6 #introductions",
    );
    
    console.log(unsignedEvent);
    {
      kind: 1,
      content: "hello nostr:npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6 #introductions",
      created_at: 0,
      tags: [['p', '3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d'], ['t', 'introductions']]
    }

    Relay Hints

    Relay hints can be added to all event tags that support them by passing in getEventRelayHint and getPubkeyRelayHint methods into the context:

    const factory = new EventFactory({
      getEventRelayHint: async (event) => {
        // an async process to find the best relay hint for this event
        try {
          return await calculateRelayHint(event)
        }
        catch(){
          return undefined
        }
      },
      getPubkeyRelayHint: async (pubkey) => {
        // an async process to find a relay hint for this pubkey
        return loadPubkeyMailboxes(pubkey).then((mailboxes) => getOutboxes(mailboxes)[0]);
      },
    });

    Modifying Events

    The factory provides methods to modify existing events:

    • EventFactory.modify - Takes a list of EventOperations to modify common properties
    • EventFactory.modifyTags - Takes a list of TagOperations to modify the tags array

    Example of modifying a list:

    const list = {
      kind: 30003,
      content: "",
      tags: [
        ["title", "read later"],
        ["description", "notes ill read later"],
      ],
    };
    
    const modified = await factory.modify(
      list,
      setListTitle("read never"),
      setListDescription("I will never get around to reading these notes"),
    );

    Prebuilt Blueprints

    The applesauce-factory package comes with common event blueprints for social clients. you can find them in the typescript docs