applesauce-common 0.0.0-next-20251203172109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/dist/blueprints/app-data.d.ts +5 -0
  4. package/dist/blueprints/app-data.js +10 -0
  5. package/dist/blueprints/calendar.d.ts +5 -0
  6. package/dist/blueprints/calendar.js +7 -0
  7. package/dist/blueprints/channels.d.ts +6 -0
  8. package/dist/blueprints/channels.js +13 -0
  9. package/dist/blueprints/comment.d.ts +12 -0
  10. package/dist/blueprints/comment.js +15 -0
  11. package/dist/blueprints/delete.d.ts +9 -0
  12. package/dist/blueprints/delete.js +14 -0
  13. package/dist/blueprints/file-metadata.d.ts +8 -0
  14. package/dist/blueprints/file-metadata.js +11 -0
  15. package/dist/blueprints/follow-set.d.ts +11 -0
  16. package/dist/blueprints/follow-set.js +21 -0
  17. package/dist/blueprints/gift-wrap.d.ts +5 -0
  18. package/dist/blueprints/gift-wrap.js +6 -0
  19. package/dist/blueprints/group.d.ts +9 -0
  20. package/dist/blueprints/group.js +17 -0
  21. package/dist/blueprints/highlight.d.ts +20 -0
  22. package/dist/blueprints/highlight.js +12 -0
  23. package/dist/blueprints/index.d.ts +23 -0
  24. package/dist/blueprints/index.js +24 -0
  25. package/dist/blueprints/legacy-message.d.ts +7 -0
  26. package/dist/blueprints/legacy-message.js +29 -0
  27. package/dist/blueprints/live-stream.d.ts +6 -0
  28. package/dist/blueprints/live-stream.js +9 -0
  29. package/dist/blueprints/note.d.ts +16 -0
  30. package/dist/blueprints/note.js +30 -0
  31. package/dist/blueprints/picture-post.d.ts +12 -0
  32. package/dist/blueprints/picture-post.js +17 -0
  33. package/dist/blueprints/poll.d.ts +41 -0
  34. package/dist/blueprints/poll.js +33 -0
  35. package/dist/blueprints/profile.d.ts +3 -0
  36. package/dist/blueprints/profile.js +7 -0
  37. package/dist/blueprints/reaction.d.ts +10 -0
  38. package/dist/blueprints/reaction.js +14 -0
  39. package/dist/blueprints/share.d.ts +12 -0
  40. package/dist/blueprints/share.js +25 -0
  41. package/dist/blueprints/stream.d.ts +6 -0
  42. package/dist/blueprints/stream.js +7 -0
  43. package/dist/blueprints/torrent.d.ts +23 -0
  44. package/dist/blueprints/torrent.js +25 -0
  45. package/dist/blueprints/wrapped-message.d.ts +20 -0
  46. package/dist/blueprints/wrapped-message.js +64 -0
  47. package/dist/helpers/app-data.d.ts +39 -0
  48. package/dist/helpers/app-data.js +68 -0
  49. package/dist/helpers/app-handler.d.ts +22 -0
  50. package/dist/helpers/app-handler.js +67 -0
  51. package/dist/helpers/article.d.ts +14 -0
  52. package/dist/helpers/article.js +24 -0
  53. package/dist/helpers/blossom.d.ts +11 -0
  54. package/dist/helpers/blossom.js +40 -0
  55. package/dist/helpers/bolt11.d.ts +10 -0
  56. package/dist/helpers/bolt11.js +17 -0
  57. package/dist/helpers/bookmark.d.ts +30 -0
  58. package/dist/helpers/bookmark.js +96 -0
  59. package/dist/helpers/calendar-event.d.ts +39 -0
  60. package/dist/helpers/calendar-event.js +121 -0
  61. package/dist/helpers/calendar-rsvp.d.ts +15 -0
  62. package/dist/helpers/calendar-rsvp.js +38 -0
  63. package/dist/helpers/calendar.d.ts +6 -0
  64. package/dist/helpers/calendar.js +11 -0
  65. package/dist/helpers/channels.d.ts +13 -0
  66. package/dist/helpers/channels.js +27 -0
  67. package/dist/helpers/comment.d.ts +47 -0
  68. package/dist/helpers/comment.js +185 -0
  69. package/dist/helpers/content.d.ts +3 -0
  70. package/dist/helpers/content.js +8 -0
  71. package/dist/helpers/emoji.d.ts +21 -0
  72. package/dist/helpers/emoji.js +34 -0
  73. package/dist/helpers/encrypted-content-cache.d.ts +22 -0
  74. package/dist/helpers/encrypted-content-cache.js +138 -0
  75. package/dist/helpers/file-metadata.d.ts +55 -0
  76. package/dist/helpers/file-metadata.js +130 -0
  77. package/dist/helpers/gift-wrap.d.ts +66 -0
  78. package/dist/helpers/gift-wrap.js +204 -0
  79. package/dist/helpers/groups-helper.d.ts +6 -0
  80. package/dist/helpers/groups-helper.js +9 -0
  81. package/dist/helpers/groups.d.ts +26 -0
  82. package/dist/helpers/groups.js +49 -0
  83. package/dist/helpers/hashtag.d.ts +2 -0
  84. package/dist/helpers/hashtag.js +7 -0
  85. package/dist/helpers/highlight.d.ts +45 -0
  86. package/dist/helpers/highlight.js +76 -0
  87. package/dist/helpers/index.d.ts +37 -0
  88. package/dist/helpers/index.js +37 -0
  89. package/dist/helpers/legacy-messages.d.ts +31 -0
  90. package/dist/helpers/legacy-messages.js +49 -0
  91. package/dist/helpers/lists.d.ts +58 -0
  92. package/dist/helpers/lists.js +110 -0
  93. package/dist/helpers/lnurl.d.ts +8 -0
  94. package/dist/helpers/lnurl.js +44 -0
  95. package/dist/helpers/mailboxes.d.ts +7 -0
  96. package/dist/helpers/mailboxes.js +49 -0
  97. package/dist/helpers/messages.d.ts +31 -0
  98. package/dist/helpers/messages.js +57 -0
  99. package/dist/helpers/mute.d.ts +33 -0
  100. package/dist/helpers/mute.js +111 -0
  101. package/dist/helpers/picture-post.d.ts +5 -0
  102. package/dist/helpers/picture-post.js +6 -0
  103. package/dist/helpers/poll.d.ts +46 -0
  104. package/dist/helpers/poll.js +78 -0
  105. package/dist/helpers/reaction.d.ts +8 -0
  106. package/dist/helpers/reaction.js +56 -0
  107. package/dist/helpers/relay-discovery.d.ts +87 -0
  108. package/dist/helpers/relay-discovery.js +126 -0
  109. package/dist/helpers/reports.d.ts +28 -0
  110. package/dist/helpers/reports.js +38 -0
  111. package/dist/helpers/share.d.ts +19 -0
  112. package/dist/helpers/share.js +58 -0
  113. package/dist/helpers/stream-chat.d.ts +4 -0
  114. package/dist/helpers/stream-chat.js +9 -0
  115. package/dist/helpers/stream.d.ts +31 -0
  116. package/dist/helpers/stream.js +81 -0
  117. package/dist/helpers/threading.d.ts +55 -0
  118. package/dist/helpers/threading.js +94 -0
  119. package/dist/helpers/torrent.d.ts +55 -0
  120. package/dist/helpers/torrent.js +270 -0
  121. package/dist/helpers/user-status.d.ts +18 -0
  122. package/dist/helpers/user-status.js +22 -0
  123. package/dist/helpers/wrapped-messages.d.ts +14 -0
  124. package/dist/helpers/wrapped-messages.js +23 -0
  125. package/dist/helpers/zap.d.ts +46 -0
  126. package/dist/helpers/zap.js +125 -0
  127. package/dist/index.d.ts +5 -0
  128. package/dist/index.js +6 -0
  129. package/dist/models/blossom.d.ts +11 -0
  130. package/dist/models/blossom.js +18 -0
  131. package/dist/models/bookmarks.d.ts +8 -0
  132. package/dist/models/bookmarks.js +24 -0
  133. package/dist/models/calendar.d.ts +6 -0
  134. package/dist/models/calendar.js +15 -0
  135. package/dist/models/channels.d.ts +11 -0
  136. package/dist/models/channels.js +61 -0
  137. package/dist/models/comments.d.ts +11 -0
  138. package/dist/models/comments.js +17 -0
  139. package/dist/models/gift-wrap.d.ts +7 -0
  140. package/dist/models/gift-wrap.js +20 -0
  141. package/dist/models/index.d.ts +15 -0
  142. package/dist/models/index.js +16 -0
  143. package/dist/models/legacy-messages.d.ts +14 -0
  144. package/dist/models/legacy-messages.js +64 -0
  145. package/dist/models/mutes.d.ts +16 -0
  146. package/dist/models/mutes.js +34 -0
  147. package/dist/models/pins.d.ts +4 -0
  148. package/dist/models/pins.js +10 -0
  149. package/dist/models/reactions.d.ts +11 -0
  150. package/dist/models/reactions.js +21 -0
  151. package/dist/models/thread.d.ts +33 -0
  152. package/dist/models/thread.js +93 -0
  153. package/dist/models/user-status.d.ts +11 -0
  154. package/dist/models/user-status.js +32 -0
  155. package/dist/models/wrapped-messages.d.ts +31 -0
  156. package/dist/models/wrapped-messages.js +76 -0
  157. package/dist/models/zaps.d.ts +9 -0
  158. package/dist/models/zaps.js +26 -0
  159. package/dist/operations/app-data.d.ts +6 -0
  160. package/dist/operations/app-data.js +21 -0
  161. package/dist/operations/blossom.d.ts +5 -0
  162. package/dist/operations/blossom.js +13 -0
  163. package/dist/operations/calendar-event.d.ts +34 -0
  164. package/dist/operations/calendar-event.js +72 -0
  165. package/dist/operations/calendar-rsvp.d.ts +10 -0
  166. package/dist/operations/calendar-rsvp.js +35 -0
  167. package/dist/operations/calendar.d.ts +9 -0
  168. package/dist/operations/calendar.js +15 -0
  169. package/dist/operations/channel.d.ts +4 -0
  170. package/dist/operations/channel.js +10 -0
  171. package/dist/operations/client.d.ts +4 -0
  172. package/dist/operations/client.js +23 -0
  173. package/dist/operations/comment.d.ts +4 -0
  174. package/dist/operations/comment.js +11 -0
  175. package/dist/operations/file-metadata.d.ts +4 -0
  176. package/dist/operations/file-metadata.js +21 -0
  177. package/dist/operations/geohash.d.ts +5 -0
  178. package/dist/operations/geohash.js +17 -0
  179. package/dist/operations/gift-wrap.d.ts +13 -0
  180. package/dist/operations/gift-wrap.js +93 -0
  181. package/dist/operations/group.d.ts +11 -0
  182. package/dist/operations/group.js +34 -0
  183. package/dist/operations/hashtags.d.ts +7 -0
  184. package/dist/operations/hashtags.js +17 -0
  185. package/dist/operations/highlight.d.ts +18 -0
  186. package/dist/operations/highlight.js +47 -0
  187. package/dist/operations/index.d.ts +28 -0
  188. package/dist/operations/index.js +28 -0
  189. package/dist/operations/legacy-message.d.ts +6 -0
  190. package/dist/operations/legacy-message.js +13 -0
  191. package/dist/operations/list.d.ts +7 -0
  192. package/dist/operations/list.js +14 -0
  193. package/dist/operations/live-stream.d.ts +4 -0
  194. package/dist/operations/live-stream.js +11 -0
  195. package/dist/operations/media-attachment.d.ts +4 -0
  196. package/dist/operations/media-attachment.js +12 -0
  197. package/dist/operations/note.d.ts +9 -0
  198. package/dist/operations/note.js +42 -0
  199. package/dist/operations/picture-post.d.ts +4 -0
  200. package/dist/operations/picture-post.js +14 -0
  201. package/dist/operations/poll-response.d.ts +9 -0
  202. package/dist/operations/poll-response.js +20 -0
  203. package/dist/operations/poll.d.ts +19 -0
  204. package/dist/operations/poll.js +42 -0
  205. package/dist/operations/reaction.d.ts +7 -0
  206. package/dist/operations/reaction.js +39 -0
  207. package/dist/operations/share.d.ts +8 -0
  208. package/dist/operations/share.js +34 -0
  209. package/dist/operations/stream-chat.d.ts +7 -0
  210. package/dist/operations/stream-chat.js +27 -0
  211. package/dist/operations/stream.d.ts +41 -0
  212. package/dist/operations/stream.js +83 -0
  213. package/dist/operations/tag/bookmarks.d.ts +6 -0
  214. package/dist/operations/tag/bookmarks.js +20 -0
  215. package/dist/operations/tag/index.d.ts +1 -0
  216. package/dist/operations/tag/index.js +1 -0
  217. package/dist/operations/torrent.d.ts +33 -0
  218. package/dist/operations/torrent.js +66 -0
  219. package/dist/operations/wrapped-message.d.ts +12 -0
  220. package/dist/operations/wrapped-message.js +28 -0
  221. package/dist/operations/zap-split.d.ts +10 -0
  222. package/dist/operations/zap-split.js +20 -0
  223. package/dist/register.d.ts +11 -0
  224. package/dist/register.js +13 -0
  225. package/package.json +91 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 hzrd149
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # applesauce-common
2
+
3
+ AppleSauce is a collection of utilities for building reactive nostr applications. The common package provides NIP-specific helpers and models for working with various Nostr Improvement Proposals (NIPs).
4
+
5
+ ## Key Components
6
+
7
+ - **Helpers**: NIP-specific utility methods for parsing and extracting data from nostr events
8
+ - **Models**: Complex subscriptions for NIP-specific nostr data patterns
9
+
10
+ ## Documentation
11
+
12
+ For detailed documentation and guides, visit:
13
+
14
+ - [Getting Started](https://hzrd149.github.io/applesauce/introduction/getting-started)
15
+ - [API Reference](https://hzrd149.github.io/applesauce/typedoc/)
16
+
17
+ ## Example
18
+
19
+ ```js
20
+ import { EventStore } from "applesauce-core";
21
+ import { ThreadModel } from "applesauce-common/models";
22
+ import { getNip10References } from "applesauce-common/helpers/threading";
23
+ import { Relay } from "nostr-tools/relay";
24
+
25
+ // Create a single EventStore instance for your app
26
+ const eventStore = new EventStore();
27
+
28
+ // Use any nostr library for relay connections (nostr-tools, ndk, nostrify, etc...)
29
+ const relay = await Relay.connect("wss://relay.example.com");
30
+
31
+ // Subscribe to events and add them to the store
32
+ const sub = relay.subscribe([{ ids: ["event-id"] }], {
33
+ onevent(event) {
34
+ eventStore.add(event);
35
+ },
36
+ });
37
+
38
+ // Get NIP-10 thread references
39
+ const refs = getNip10References(event);
40
+
41
+ // Subscribe to a thread using ThreadModel
42
+ const thread = eventStore.model(ThreadModel, "event-id");
43
+
44
+ thread.subscribe((thread) => {
45
+ console.log(thread);
46
+ });
47
+ ```
48
+
49
+ ## Supported NIPs
50
+
51
+ This package includes helpers and models for various NIPs including:
52
+
53
+ - NIP-10 (Threading)
54
+ - NIP-22 (Comments)
55
+ - NIP-53 (Streams)
56
+ - NIP-23 (Articles)
57
+ - NIP-52 (Calendar Events)
58
+ - NIP-88 (Polls)
59
+ - And many more...
@@ -0,0 +1,5 @@
1
+ import { EventBlueprint } from "applesauce-core/event-factory";
2
+ import { EncryptionMethod } from "applesauce-core/helpers/encrypted-content";
3
+ import { MetaTagOptions } from "applesauce-core/operations/event";
4
+ /** A blueprint for creating kind 30078 application data events */
5
+ export declare function AppDataBlueprint<T>(identifier: string, data: T, encryption?: boolean | EncryptionMethod, options?: MetaTagOptions): EventBlueprint;
@@ -0,0 +1,10 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { setMetaTags } from "applesauce-core/operations/event";
3
+ import { APP_DATA_KIND } from "../helpers/app-data.js";
4
+ import * as AppData from "../operations/app-data.js";
5
+ /** A blueprint for creating kind 30078 application data events */
6
+ export function AppDataBlueprint(identifier, data, encryption, options) {
7
+ return blueprint(APP_DATA_KIND, AppData.setIdentifier(identifier),
8
+ // Set the content as either encrypted or plaintext
9
+ AppData.setContent(data, encryption), setMetaTags(options));
10
+ }
@@ -0,0 +1,5 @@
1
+ import { EventBlueprint } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
4
+ /** Creates a calendar event with a title and optional events */
5
+ export declare function CalendarBlueprint(title: string, events?: (NostrEvent | AddressPointer)[]): EventBlueprint;
@@ -0,0 +1,7 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ import { addEvent, setTitle } from "../operations/calendar.js";
4
+ /** Creates a calendar event with a title and optional events */
5
+ export function CalendarBlueprint(title, events) {
6
+ return blueprint(kinds.Calendar, setTitle(title), ...(events?.map((event) => addEvent(event)) ?? []));
7
+ }
@@ -0,0 +1,6 @@
1
+ import { NostrEvent } from "applesauce-core/helpers/event";
2
+ import { TextContentOptions } from "applesauce-core/operations";
3
+ /** Creates a NIP-28 channel message */
4
+ export declare function ChannelMessageBlueprint(channel: NostrEvent, message: string, options?: TextContentOptions): import("applesauce-core/event-factory").EventBlueprint;
5
+ /** Creates a NIP-28 channel message reply */
6
+ export declare function ChannelMessageReplyBlueprint(parent: NostrEvent, message: string, options?: TextContentOptions): import("applesauce-core/event-factory").EventBlueprint;
@@ -0,0 +1,13 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ import { setShortTextContent } from "applesauce-core/operations";
4
+ import { includeChannelPointerTag } from "../operations/channel.js";
5
+ import { includePubkeyNotificationTags, setThreadParent } from "../operations/note.js";
6
+ /** Creates a NIP-28 channel message */
7
+ export function ChannelMessageBlueprint(channel, message, options) {
8
+ return blueprint(kinds.ChannelMessage, includeChannelPointerTag(channel), setShortTextContent(message, options));
9
+ }
10
+ /** Creates a NIP-28 channel message reply */
11
+ export function ChannelMessageReplyBlueprint(parent, message, options) {
12
+ return blueprint(kinds.ChannelMessage, setThreadParent(parent), includePubkeyNotificationTags(parent), setShortTextContent(message, options));
13
+ }
@@ -0,0 +1,12 @@
1
+ import { NostrEvent, EventTemplate } from "applesauce-core/helpers/event";
2
+ import { TextContentOptions } from "applesauce-core/operations/content";
3
+ import { MetaTagOptions } from "applesauce-core/operations/event";
4
+ export type CommentBlueprintOptions = TextContentOptions & MetaTagOptions;
5
+ /** A blueprint to create a NIP-22 comment event */
6
+ export declare function CommentBlueprint(parent: NostrEvent, content: string, options?: CommentBlueprintOptions): import("applesauce-core/event-factory").EventBlueprint;
7
+ declare module "applesauce-core/event-factory" {
8
+ interface EventFactory {
9
+ /** Create a NIP-22 comment event */
10
+ comment(parent: NostrEvent, content: string, options?: CommentBlueprintOptions): Promise<EventTemplate>;
11
+ }
12
+ }
@@ -0,0 +1,15 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { setShortTextContent } from "applesauce-core/operations/content";
3
+ import { setMetaTags } from "applesauce-core/operations/event";
4
+ import { COMMENT_KIND } from "../helpers/comment.js";
5
+ import { setParent } from "../operations/comment.js";
6
+ // Import EventFactory as a value (class) to modify its prototype
7
+ import { EventFactory } from "applesauce-core/event-factory";
8
+ /** A blueprint to create a NIP-22 comment event */
9
+ export function CommentBlueprint(parent, content, options) {
10
+ return blueprint(COMMENT_KIND, setParent(parent), setShortTextContent(content, options), setMetaTags(options));
11
+ }
12
+ // Register this blueprint with EventFactory
13
+ EventFactory.prototype.comment = function (parent, content, options) {
14
+ return this.create(CommentBlueprint, parent, content, options);
15
+ };
@@ -0,0 +1,9 @@
1
+ import { EventTemplate, NostrEvent } from "applesauce-core/helpers/event";
2
+ /** A blueprint for a NIP-09 delete event */
3
+ export declare function DeleteBlueprint(events: NostrEvent[], reason?: string): import("applesauce-core/event-factory").EventBlueprint;
4
+ declare module "applesauce-core/event-factory" {
5
+ interface EventFactory {
6
+ /** Create a NIP-09 delete event */
7
+ delete(events: NostrEvent[], reason?: string): Promise<EventTemplate>;
8
+ }
9
+ }
@@ -0,0 +1,14 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ import { setContent } from "applesauce-core/operations";
4
+ import { setDeleteEvents } from "applesauce-core/operations/delete";
5
+ // Import EventFactory as a value (class) to modify its prototype
6
+ import { EventFactory } from "applesauce-core/event-factory";
7
+ /** A blueprint for a NIP-09 delete event */
8
+ export function DeleteBlueprint(events, reason) {
9
+ return blueprint(kinds.EventDeletion, reason ? setContent(reason) : undefined, setDeleteEvents(events));
10
+ }
11
+ // Register this blueprint with EventFactory
12
+ EventFactory.prototype.delete = function (events, reason) {
13
+ return this.create(DeleteBlueprint, events, reason);
14
+ };
@@ -0,0 +1,8 @@
1
+ import { TextContentOptions } from "applesauce-core/operations/content";
2
+ import { MetaTagOptions } from "applesauce-core/operations/event";
3
+ import { FileMetadata } from "../helpers/file-metadata.js";
4
+ export type FileMetadataBlueprintOptions = TextContentOptions & MetaTagOptions & {
5
+ hashtags?: string[];
6
+ };
7
+ /** Blueprint to create a NIP-94 file metadata event */
8
+ export declare function FileMetadataBlueprint(metadata: FileMetadata, description?: string, options?: FileMetadataBlueprintOptions): import("applesauce-core/event-factory").EventBlueprint;
@@ -0,0 +1,11 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ import { skip } from "applesauce-core/helpers/pipeline";
4
+ import { setShortTextContent } from "applesauce-core/operations/content";
5
+ import { setMetaTags } from "applesauce-core/operations/event";
6
+ import { setFileMetadata } from "../operations/file-metadata.js";
7
+ import { includeHashtags } from "../operations/hashtags.js";
8
+ /** Blueprint to create a NIP-94 file metadata event */
9
+ export function FileMetadataBlueprint(metadata, description, options) {
10
+ return blueprint(kinds.FileMetadata, setFileMetadata(metadata), description ? setShortTextContent(description, options) : skip(), options?.hashtags ? includeHashtags(options.hashtags) : skip(), setMetaTags(options));
11
+ }
@@ -0,0 +1,11 @@
1
+ import { EventBlueprint } from "applesauce-core/event-factory";
2
+ import { ProfilePointer } from "applesauce-core/helpers/pointers";
3
+ /** Creates a new kind 30000 follow set */
4
+ export declare function FollowSetBlueprint(list?: {
5
+ title?: string;
6
+ description?: string;
7
+ image?: string;
8
+ }, users?: {
9
+ public?: ProfilePointer[];
10
+ hidden?: ProfilePointer[];
11
+ } | ProfilePointer[]): EventBlueprint;
@@ -0,0 +1,21 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ import { addProfilePointerTag } from "applesauce-core/operations/tag/common";
4
+ import { modifyHiddenTags, modifyPublicTags } from "applesauce-core/operations/tags";
5
+ import { setDescription, setImage, setTitle } from "../operations/list.js";
6
+ /** Creates a new kind 30000 follow set */
7
+ export function FollowSetBlueprint(list, users) {
8
+ const userOperations = users
9
+ ? Array.isArray(users)
10
+ ? [modifyPublicTags(...users.map((p) => addProfilePointerTag(p)))]
11
+ : [
12
+ users?.public ? modifyPublicTags(...users.public.map((p) => addProfilePointerTag(p))) : undefined,
13
+ users?.hidden ? modifyHiddenTags(...users.hidden.map((p) => addProfilePointerTag(p))) : undefined,
14
+ ]
15
+ : [];
16
+ return blueprint(kinds.Followsets,
17
+ // set list info tags
18
+ list?.title ? setTitle(list.title) : undefined, list?.description ? setDescription(list.description) : undefined, list?.image ? setImage(list.image) : undefined,
19
+ // add users to the list
20
+ ...userOperations);
21
+ }
@@ -0,0 +1,5 @@
1
+ import { EventBlueprint } from "applesauce-core/event-factory";
2
+ import { EventTemplate, NostrEvent, UnsignedEvent } from "applesauce-core/helpers/event";
3
+ import { MetaTagOptions } from "applesauce-core/operations/event";
4
+ /** Creates a gift wrapped event based on a blueprint */
5
+ export declare function GiftWrapBlueprint(pubkey: string, blueprint: EventBlueprint | EventTemplate | UnsignedEvent | NostrEvent, opts?: MetaTagOptions): EventBlueprint<NostrEvent>;
@@ -0,0 +1,6 @@
1
+ import { buildEvent } from "applesauce-core/event-factory";
2
+ import { giftWrap } from "../operations/gift-wrap.js";
3
+ /** Creates a gift wrapped event based on a blueprint */
4
+ export function GiftWrapBlueprint(pubkey, blueprint, opts) {
5
+ return async (ctx) => (await buildEvent(typeof blueprint === "function" ? await blueprint(ctx) : blueprint, ctx, giftWrap(pubkey, opts)));
6
+ }
@@ -0,0 +1,9 @@
1
+ import { NostrEvent } from "applesauce-core/helpers/event";
2
+ import { TextContentOptions } from "applesauce-core/operations/content";
3
+ import { MetaTagOptions } from "applesauce-core/operations/event";
4
+ import { GroupPointer } from "../helpers/groups.js";
5
+ export type GroupMessageBlueprintOptions = {
6
+ previous: NostrEvent[];
7
+ } & TextContentOptions & MetaTagOptions;
8
+ /** A blueprint for a NIP-29 group message */
9
+ export declare function GroupMessageBlueprint(group: GroupPointer, content: string, options?: GroupMessageBlueprintOptions): import("applesauce-core/event-factory").EventBlueprint;
@@ -0,0 +1,17 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { setShortTextContent } from "applesauce-core/operations/content";
3
+ import { setMetaTags } from "applesauce-core/operations/event";
4
+ import { GROUP_MESSAGE_KIND } from "../helpers/groups.js";
5
+ import { addPreviousRefs, setGroupPointer } from "../operations/group.js";
6
+ /** A blueprint for a NIP-29 group message */
7
+ export function GroupMessageBlueprint(group, content, options) {
8
+ return blueprint(GROUP_MESSAGE_KIND,
9
+ // include group id "h" tag
10
+ setGroupPointer(group),
11
+ // include "previous" events tags
12
+ options?.previous && addPreviousRefs(options.previous),
13
+ // Set text content
14
+ setShortTextContent(content, options),
15
+ // Add common meta tags
16
+ setMetaTags(options));
17
+ }
@@ -0,0 +1,20 @@
1
+ import { NostrEvent } from "applesauce-core/helpers/event";
2
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
3
+ import { MetaTagOptions } from "applesauce-core/operations/event";
4
+ import { HighlightAttribution } from "../helpers/index.js";
5
+ import { ZapOptions } from "../operations/zap-split.js";
6
+ export type HighlightBlueprintOptions = MetaTagOptions & ZapOptions & {
7
+ /** Additional context surrounding the highlight */
8
+ context?: string;
9
+ /** Comment to create a quote highlight */
10
+ comment?: string;
11
+ /** Attribution information for the original content */
12
+ attributions?: HighlightAttribution[];
13
+ /** Alt description for clients that can't render the event */
14
+ alt?: string;
15
+ };
16
+ /**
17
+ * NIP-84 Highlight event (kind 9802) blueprint
18
+ * Creates a highlight event that references content from nostr events or external URLs
19
+ */
20
+ export declare function HighlightBlueprint(content: string, source: NostrEvent | AddressPointer | string, options?: HighlightBlueprintOptions): import("applesauce-core/event-factory").EventBlueprint;
@@ -0,0 +1,12 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ import { includeAltTag, setMetaTags } from "applesauce-core/operations/event";
4
+ import { setAttributions, setComment, setContext, setHighlightContent, setSource } from "../operations/highlight.js";
5
+ import { setZapSplit } from "../operations/zap-split.js";
6
+ /**
7
+ * NIP-84 Highlight event (kind 9802) blueprint
8
+ * Creates a highlight event that references content from nostr events or external URLs
9
+ */
10
+ export function HighlightBlueprint(content, source, options) {
11
+ return blueprint(kinds.Highlights, setHighlightContent(content), setSource(source), options?.attributions ? setAttributions(options.attributions) : undefined, options?.context ? setContext(options.context) : undefined, options?.comment ? setComment(options.comment) : undefined, setZapSplit(options), setMetaTags(options), includeAltTag(options?.alt ?? "A text highlight"));
12
+ }
@@ -0,0 +1,23 @@
1
+ export * from "./app-data.js";
2
+ export * from "./calendar.js";
3
+ export * from "./channels.js";
4
+ export * from "./comment.js";
5
+ export * from "./delete.js";
6
+ export * from "./file-metadata.js";
7
+ export * from "./follow-set.js";
8
+ export * from "./gift-wrap.js";
9
+ export * from "./group.js";
10
+ export * from "./delete.js";
11
+ export * from "./highlight.js";
12
+ export * from "./legacy-message.js";
13
+ export * from "./live-stream.js";
14
+ export * from "./note.js";
15
+ export * from "./picture-post.js";
16
+ export * from "./poll.js";
17
+ export * from "./profile.js";
18
+ export * from "./reaction.js";
19
+ export * from "./share.js";
20
+ export * from "./stream.js";
21
+ export * from "./torrent.js";
22
+ export * from "./wrapped-message.js";
23
+ import "../register.js";
@@ -0,0 +1,24 @@
1
+ export * from "./app-data.js";
2
+ export * from "./calendar.js";
3
+ export * from "./channels.js";
4
+ export * from "./comment.js";
5
+ export * from "./delete.js";
6
+ export * from "./file-metadata.js";
7
+ export * from "./follow-set.js";
8
+ export * from "./gift-wrap.js";
9
+ export * from "./group.js";
10
+ export * from "./delete.js";
11
+ export * from "./highlight.js";
12
+ export * from "./legacy-message.js";
13
+ export * from "./live-stream.js";
14
+ export * from "./note.js";
15
+ export * from "./picture-post.js";
16
+ export * from "./poll.js";
17
+ export * from "./profile.js";
18
+ export * from "./reaction.js";
19
+ export * from "./share.js";
20
+ export * from "./stream.js";
21
+ export * from "./torrent.js";
22
+ export * from "./wrapped-message.js";
23
+ // Register the common blueprints with the event factory
24
+ import "../register.js";
@@ -0,0 +1,7 @@
1
+ import { NostrEvent } from "applesauce-core/helpers/event";
2
+ import { MetaTagOptions } from "applesauce-core/operations/event";
3
+ export type LegacyMessageBlueprintOptions = MetaTagOptions;
4
+ /** A blueprint to create a nip-04 encrypted direct message */
5
+ export declare function LegacyMessageBlueprint(recipient: string, message: string, opts?: LegacyMessageBlueprintOptions): import("applesauce-core/event-factory").EventBlueprint;
6
+ /** Creates a reply to a legacy message */
7
+ export declare function LegacyMessageReplyBlueprint(parent: NostrEvent, message: string, opts?: LegacyMessageBlueprintOptions): import("applesauce-core/event-factory").EventBlueprint;
@@ -0,0 +1,29 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ import { setEncryptedContent } from "applesauce-core/operations/encrypted-content";
4
+ import { setMetaTags } from "applesauce-core/operations/event";
5
+ import { setMessageAddress, setMessageParent } from "../operations/legacy-message.js";
6
+ /** A blueprint to create a nip-04 encrypted direct message */
7
+ export function LegacyMessageBlueprint(recipient, message, opts) {
8
+ return blueprint(kinds.EncryptedDirectMessage,
9
+ // Encrypt the contents of the message to the recipient
10
+ setEncryptedContent(recipient, message),
11
+ // Include the necessary "p" tag of the recipient
12
+ setMessageAddress(recipient),
13
+ // Include the meta tags
14
+ setMetaTags(opts));
15
+ }
16
+ /** Creates a reply to a legacy message */
17
+ export function LegacyMessageReplyBlueprint(parent, message, opts) {
18
+ if (parent.kind !== kinds.EncryptedDirectMessage)
19
+ throw new Error("Parent message must be a legacy message (kind 4)");
20
+ return blueprint(kinds.EncryptedDirectMessage,
21
+ // Encrypt the contents of the message to the recipient
22
+ setEncryptedContent(parent.pubkey, message),
23
+ // Include the necessary "p" tag of the recipient
24
+ setMessageAddress(parent.pubkey),
25
+ // Include the parent message id
26
+ setMessageParent(parent),
27
+ // Include the meta tags
28
+ setMetaTags(opts));
29
+ }
@@ -0,0 +1,6 @@
1
+ import { NostrEvent } from "applesauce-core/helpers/event";
2
+ import { TextContentOptions } from "applesauce-core/operations/content";
3
+ import { MetaTagOptions } from "applesauce-core/operations/event";
4
+ export type LiveChatMessageBlueprintOptions = TextContentOptions & MetaTagOptions;
5
+ /** A blueprint for creating a live stream message */
6
+ export declare function LiveChatMessageBlueprint(stream: NostrEvent, message: string, options?: LiveChatMessageBlueprintOptions): import("applesauce-core/event-factory").EventBlueprint;
@@ -0,0 +1,9 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ import { setShortTextContent } from "applesauce-core/operations/content";
4
+ import { setMetaTags } from "applesauce-core/operations/event";
5
+ import { includeLiveStreamTag } from "../operations/live-stream.js";
6
+ /** A blueprint for creating a live stream message */
7
+ export function LiveChatMessageBlueprint(stream, message, options) {
8
+ return blueprint(kinds.LiveChatMessage, includeLiveStreamTag(stream), setShortTextContent(message, options), setMetaTags(options));
9
+ }
@@ -0,0 +1,16 @@
1
+ import { EventTemplate, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { MetaTagOptions, TextContentOptions } from "applesauce-core/operations";
3
+ import { ZapOptions } from "../operations/zap-split.js";
4
+ export type NoteBlueprintOptions = TextContentOptions & MetaTagOptions & ZapOptions;
5
+ /** Short text note (kind 1) blueprint */
6
+ export declare function NoteBlueprint(content: string, options?: NoteBlueprintOptions): import("applesauce-core/event-factory").EventBlueprint;
7
+ /** Short text note reply (kind 1) blueprint */
8
+ export declare function NoteReplyBlueprint(parent: NostrEvent, content: string, options?: TextContentOptions): import("applesauce-core/event-factory").EventBlueprint;
9
+ declare module "applesauce-core/event-factory" {
10
+ interface EventFactory {
11
+ /** Create a short text note (kind 1) */
12
+ note(content: string, options?: NoteBlueprintOptions): Promise<EventTemplate>;
13
+ /** Create a short text note reply (kind 1) */
14
+ noteReply(parent: NostrEvent, content: string, options?: TextContentOptions): Promise<EventTemplate>;
15
+ }
16
+ }
@@ -0,0 +1,30 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ import { setMetaTags, setShortTextContent } from "applesauce-core/operations";
4
+ import { setZapSplit } from "../operations/zap-split.js";
5
+ import { includePubkeyNotificationTags, setThreadParent } from "../operations/note.js";
6
+ // Import EventFactory as a value (class) to modify its prototype
7
+ import { EventFactory } from "applesauce-core/event-factory";
8
+ /** Short text note (kind 1) blueprint */
9
+ export function NoteBlueprint(content, options) {
10
+ return blueprint(kinds.ShortTextNote, setShortTextContent(content, options), setZapSplit(options), setMetaTags(options));
11
+ }
12
+ /** Short text note reply (kind 1) blueprint */
13
+ export function NoteReplyBlueprint(parent, content, options) {
14
+ if (parent.kind !== kinds.ShortTextNote)
15
+ throw new Error("Kind 1 replies should only be used to reply to kind 1 notes");
16
+ return blueprint(kinds.ShortTextNote,
17
+ // add NIP-10 tags
18
+ setThreadParent(parent),
19
+ // copy "p" tags from parent
20
+ includePubkeyNotificationTags(parent),
21
+ // set default text content
22
+ setShortTextContent(content, options));
23
+ }
24
+ // Register these blueprints with EventFactory
25
+ EventFactory.prototype.note = function (content, options) {
26
+ return this.create(NoteBlueprint, content, options);
27
+ };
28
+ EventFactory.prototype.noteReply = function (parent, content, options) {
29
+ return this.create(NoteReplyBlueprint, parent, content, options);
30
+ };
@@ -0,0 +1,12 @@
1
+ import { TextContentOptions } from "applesauce-core/operations/content";
2
+ import { MetaTagOptions } from "applesauce-core/operations/event";
3
+ import { MediaAttachment } from "../helpers/index.js";
4
+ export type PicturePostBlueprintOptions = TextContentOptions & MetaTagOptions & {
5
+ hashtags?: string[];
6
+ };
7
+ /**
8
+ * A blueprint to create a kind 20 picture post
9
+ * @see https://github.com/nostr-protocol/nips/blob/master/68.md
10
+ * @throws {Error} if the pictures are not image/* types
11
+ */
12
+ export declare function PicturePostBlueprint(pictures: MediaAttachment[], content: string, options?: PicturePostBlueprintOptions): import("applesauce-core/event-factory").EventBlueprint;
@@ -0,0 +1,17 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { setShortTextContent } from "applesauce-core/operations/content";
3
+ import { setMetaTags } from "applesauce-core/operations/event";
4
+ import { PICTURE_POST_KIND } from "../helpers/index.js";
5
+ import { includeHashtags } from "../operations/hashtags.js";
6
+ import { addMediaAttachments } from "../operations/media-attachment.js";
7
+ import { setImageMetadata } from "../operations/picture-post.js";
8
+ /**
9
+ * A blueprint to create a kind 20 picture post
10
+ * @see https://github.com/nostr-protocol/nips/blob/master/68.md
11
+ * @throws {Error} if the pictures are not image/* types
12
+ */
13
+ export function PicturePostBlueprint(pictures, content, options) {
14
+ if (pictures.some((m) => !m.type?.includes("image/")))
15
+ throw new Error("Only image/* types can be added to a picture post");
16
+ return blueprint(PICTURE_POST_KIND, addMediaAttachments(pictures), setImageMetadata(pictures), setShortTextContent(content, options), setMetaTags(options), options?.hashtags ? includeHashtags(options.hashtags) : undefined);
17
+ }
@@ -0,0 +1,41 @@
1
+ import { EventTemplate, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { EventPointer } from "applesauce-core/helpers/pointers";
3
+ import { MetaTagOptions } from "applesauce-core/operations";
4
+ import { PollType } from "../helpers/poll.js";
5
+ import { ZapOptions } from "../operations/zap-split.js";
6
+ export interface PollOption {
7
+ id: string;
8
+ label: string;
9
+ }
10
+ export type PollBlueprintOptions = MetaTagOptions & ZapOptions & {
11
+ /** Poll type - singlechoice or multiplechoice. Defaults to singlechoice */
12
+ pollType?: PollType;
13
+ /** Unix timestamp when the poll ends */
14
+ endsAt?: number;
15
+ /** Relay URLs where responses should be published */
16
+ relays?: string[];
17
+ };
18
+ /**
19
+ * NIP-88 Poll event (kind 1068) blueprint
20
+ * Creates a poll event with question and options
21
+ */
22
+ export declare function PollBlueprint(question: string, options: PollOption[], opts?: PollBlueprintOptions): import("applesauce-core").EventBlueprint;
23
+ export type PollResponseBlueprintOptions = MetaTagOptions & {
24
+ comment?: string;
25
+ };
26
+ /**
27
+ * NIP-88 Poll Response event (kind 1018) blueprint
28
+ * Creates a response to a poll event
29
+ */
30
+ export declare function PollResponseBlueprint(poll: NostrEvent | EventPointer | string, optionIds: string[], opts?: PollResponseBlueprintOptions): import("applesauce-core").EventBlueprint;
31
+ /**
32
+ * Convenience blueprint for single-choice poll responses
33
+ * Creates a response to a poll event with a single option
34
+ */
35
+ export declare function SingleChoicePollResponseBlueprint(poll: NostrEvent | EventPointer | string, optionId: string, opts?: PollResponseBlueprintOptions): import("applesauce-core").EventBlueprint;
36
+ declare module "applesauce-core/event-factory" {
37
+ interface EventFactory {
38
+ /** Create a NIP-88 poll event */
39
+ poll(question: string, options: PollOption[], opts?: PollBlueprintOptions): Promise<EventTemplate>;
40
+ }
41
+ }
@@ -0,0 +1,33 @@
1
+ import { blueprint } from "applesauce-core";
2
+ import { setContent, setMetaTags } from "applesauce-core/operations";
3
+ import { POLL_KIND, POLL_RESPONSE_KIND } from "../helpers/poll.js";
4
+ import * as PollResponse from "../operations/poll-response.js";
5
+ import * as Poll from "../operations/poll.js";
6
+ import { setZapSplit } from "../operations/zap-split.js";
7
+ // Import EventFactory as a value (class) to modify its prototype
8
+ import { EventFactory } from "applesauce-core/event-factory";
9
+ /**
10
+ * NIP-88 Poll event (kind 1068) blueprint
11
+ * Creates a poll event with question and options
12
+ */
13
+ export function PollBlueprint(question, options, opts) {
14
+ return blueprint(POLL_KIND, Poll.setQuestion(question), Poll.setOptions(options), opts?.pollType ? Poll.setType(opts.pollType) : undefined, opts?.endsAt ? Poll.setEndsAt(opts.endsAt) : undefined, opts?.relays ? Poll.setRelays(opts.relays) : undefined, setZapSplit(opts), setMetaTags({ ...opts, alt: opts?.alt ?? `Poll: ${question}` }));
15
+ }
16
+ /**
17
+ * NIP-88 Poll Response event (kind 1018) blueprint
18
+ * Creates a response to a poll event
19
+ */
20
+ export function PollResponseBlueprint(poll, optionIds, opts) {
21
+ return blueprint(POLL_RESPONSE_KIND, PollResponse.setPollEvent(poll), PollResponse.setChoices(optionIds), opts?.comment ? setContent(opts.comment) : undefined, setMetaTags({ ...opts, alt: opts?.alt ?? "Poll response" }));
22
+ }
23
+ /**
24
+ * Convenience blueprint for single-choice poll responses
25
+ * Creates a response to a poll event with a single option
26
+ */
27
+ export function SingleChoicePollResponseBlueprint(poll, optionId, opts) {
28
+ return blueprint(POLL_RESPONSE_KIND, PollResponse.setPollEvent(poll), PollResponse.setChoice(optionId), opts?.comment ? setContent(opts.comment) : undefined, setMetaTags({ ...opts, alt: opts?.alt ?? "Poll response" }));
29
+ }
30
+ // Register this blueprint with EventFactory
31
+ EventFactory.prototype.poll = function (question, options, opts) {
32
+ return this.create(PollBlueprint, question, options, opts);
33
+ };
@@ -0,0 +1,3 @@
1
+ import { ProfileContent } from "applesauce-core/helpers/profile";
2
+ /** User Profile (kind 0) blueprint */
3
+ export declare function ProfileBlueprint(content: ProfileContent): import("applesauce-core/event-factory").EventBlueprint;
@@ -0,0 +1,7 @@
1
+ import { blueprint } from "applesauce-core/event-factory";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ import { setProfile } from "applesauce-core/operations/profile";
4
+ /** User Profile (kind 0) blueprint */
5
+ export function ProfileBlueprint(content) {
6
+ return blueprint(kinds.Metadata, setProfile(content));
7
+ }
@@ -0,0 +1,10 @@
1
+ import { Emoji } from "applesauce-core/event-factory";
2
+ import { EventTemplate, NostrEvent } from "applesauce-core/helpers/event";
3
+ /** blueprint for kind 7 reaction event */
4
+ export declare function ReactionBlueprint(event: NostrEvent, emoji?: string | Emoji): import("applesauce-core/event-factory").EventBlueprint;
5
+ declare module "applesauce-core/event-factory" {
6
+ interface EventFactory {
7
+ /** Create a kind 7 reaction event */
8
+ reaction(event: NostrEvent, emoji?: string | Emoji): Promise<EventTemplate>;
9
+ }
10
+ }