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/app-data
- applesauce-factory/blueprints/calendar
- applesauce-factory/blueprints/channels
- applesauce-factory/blueprints/comment
- applesauce-factory/blueprints/comment.test
- applesauce-factory/blueprints/delete
- applesauce-factory/blueprints/file-metadata
- applesauce-factory/blueprints/follow-sets
- applesauce-factory/blueprints/gift-wrap
- applesauce-factory/blueprints/group
- applesauce-factory/blueprints/groups
- applesauce-factory/blueprints/highlight
- 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/note.test
- applesauce-factory/blueprints/picture-post
- applesauce-factory/blueprints/picture-post.test
- applesauce-factory/blueprints/poll
- applesauce-factory/blueprints/reaction
- applesauce-factory/blueprints/reaction.test
- applesauce-factory/blueprints/reply
- applesauce-factory/blueprints/reply.test
- applesauce-factory/blueprints/share
- applesauce-factory/blueprints/share.test
- applesauce-factory/blueprints/stream
- 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/calendar-event
- applesauce-factory/helpers/comment
- applesauce-factory/helpers/comment.test
- applesauce-factory/helpers/common-tags
- applesauce-factory/helpers/common-tags.test
- 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/pointer.test
- applesauce-factory/helpers/quote
- applesauce-factory/helpers/quote.test
- applesauce-factory/helpers/reaction
- applesauce-factory/helpers/tag
- applesauce-factory/operations
- applesauce-factory/operations/__tests__/exports.test
- applesauce-factory/operations/app-data
- applesauce-factory/operations/blossom
- applesauce-factory/operations/calendar
- applesauce-factory/operations/calendar-event
- applesauce-factory/operations/calendar-rsvp
- applesauce-factory/operations/channel
- applesauce-factory/operations/channels
- applesauce-factory/operations/client
- applesauce-factory/operations/comment
- applesauce-factory/operations/common
- applesauce-factory/operations/common.test
- applesauce-factory/operations/content
- applesauce-factory/operations/content.test
- applesauce-factory/operations/delete
- applesauce-factory/operations/emojis
- 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/hidden-tags
- 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/file-metadata
- applesauce-factory/operations/geohash
- applesauce-factory/operations/gift-wrap
- applesauce-factory/operations/group
- applesauce-factory/operations/groups
- applesauce-factory/operations/groups.test
- applesauce-factory/operations/hashtags
- applesauce-factory/operations/hashtags.test
- applesauce-factory/operations/highlight
- applesauce-factory/operations/index
- applesauce-factory/operations/legacy-message
- applesauce-factory/operations/list
- applesauce-factory/operations/list/common
- applesauce-factory/operations/list/common.test
- applesauce-factory/operations/list/groups
- applesauce-factory/operations/list/groups.test
- applesauce-factory/operations/list/index
- applesauce-factory/operations/list/list
- applesauce-factory/operations/list/list.test
- applesauce-factory/operations/list/relay
- applesauce-factory/operations/live-stream
- applesauce-factory/operations/mailboxes
- applesauce-factory/operations/media-attachment
- applesauce-factory/operations/note
- applesauce-factory/operations/picture-post
- applesauce-factory/operations/poll
- applesauce-factory/operations/poll-response
- applesauce-factory/operations/profile
- applesauce-factory/operations/quote
- applesauce-factory/operations/reaction
- applesauce-factory/operations/share
- applesauce-factory/operations/signer
- applesauce-factory/operations/stream
- applesauce-factory/operations/stream-chat
- 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/hashtags
- applesauce-factory/operations/tag/hidden-tags
- applesauce-factory/operations/tag/index
- applesauce-factory/operations/tag/mailboxes
- applesauce-factory/operations/tag/relay
- applesauce-factory/operations/tags
- applesauce-factory/operations/wrapped-message
- applesauce-factory/operations/zap
- applesauce-factory/operations/zap-split
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 propertiesEventFactory.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