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
@@ -0,0 +1,28 @@
1
+ export * as AppData from "./app-data.js";
2
+ export * as Calendar from "./calendar.js";
3
+ export * as CalendarEvent from "./calendar-event.js";
4
+ export * as CalendarRsvp from "./calendar-rsvp.js";
5
+ export * as Channel from "./channel.js";
6
+ export * as Client from "./client.js";
7
+ export * as Comment from "./comment.js";
8
+ export * as FileMetadata from "./file-metadata.js";
9
+ export * as Geohash from "./geohash.js";
10
+ export * as GiftWrap from "./gift-wrap.js";
11
+ export * as Groups from "./group.js";
12
+ export * as Hashtags from "./hashtags.js";
13
+ export * as Highlight from "./highlight.js";
14
+ export * as LegacyMessage from "./legacy-message.js";
15
+ export * as List from "./list.js";
16
+ export * as LiveStream from "./live-stream.js";
17
+ export * as MediaAttachment from "./media-attachment.js";
18
+ export * as Note from "./note.js";
19
+ export * as PicturePost from "./picture-post.js";
20
+ export * as Poll from "./poll.js";
21
+ export * as PollResponse from "./poll-response.js";
22
+ export * as Reaction from "./reaction.js";
23
+ export * as Stream from "./stream.js";
24
+ export * as StreamChat from "./stream-chat.js";
25
+ export * as Torrent from "./torrent.js";
26
+ export * as WrappedMessage from "./wrapped-message.js";
27
+ export * as Zap from "./zap-split.js";
28
+ export * as TagOperations from "./tag/index.js";
@@ -0,0 +1,28 @@
1
+ export * as AppData from "./app-data.js";
2
+ export * as Calendar from "./calendar.js";
3
+ export * as CalendarEvent from "./calendar-event.js";
4
+ export * as CalendarRsvp from "./calendar-rsvp.js";
5
+ export * as Channel from "./channel.js";
6
+ export * as Client from "./client.js";
7
+ export * as Comment from "./comment.js";
8
+ export * as FileMetadata from "./file-metadata.js";
9
+ export * as Geohash from "./geohash.js";
10
+ export * as GiftWrap from "./gift-wrap.js";
11
+ export * as Groups from "./group.js";
12
+ export * as Hashtags from "./hashtags.js";
13
+ export * as Highlight from "./highlight.js";
14
+ export * as LegacyMessage from "./legacy-message.js";
15
+ export * as List from "./list.js";
16
+ export * as LiveStream from "./live-stream.js";
17
+ export * as MediaAttachment from "./media-attachment.js";
18
+ export * as Note from "./note.js";
19
+ export * as PicturePost from "./picture-post.js";
20
+ export * as Poll from "./poll.js";
21
+ export * as PollResponse from "./poll-response.js";
22
+ export * as Reaction from "./reaction.js";
23
+ export * as Stream from "./stream.js";
24
+ export * as StreamChat from "./stream-chat.js";
25
+ export * as Torrent from "./torrent.js";
26
+ export * as WrappedMessage from "./wrapped-message.js";
27
+ export * as Zap from "./zap-split.js";
28
+ export * as TagOperations from "./tag/index.js";
@@ -0,0 +1,6 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ /** Includes the nip-04 direct message "p" tag */
4
+ export declare function setMessageAddress(pubkey: string): EventOperation;
5
+ /** Includes the "e" tag for legacy message replies */
6
+ export declare function setMessageParent(parent: string | NostrEvent): EventOperation;
@@ -0,0 +1,13 @@
1
+ import { includeNameValueTag } from "applesauce-core/operations/tags";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ /** Includes the nip-04 direct message "p" tag */
4
+ export function setMessageAddress(pubkey) {
5
+ return includeNameValueTag(["p", pubkey]);
6
+ }
7
+ /** Includes the "e" tag for legacy message replies */
8
+ export function setMessageParent(parent) {
9
+ if (typeof parent !== "string" && parent.kind !== kinds.EncryptedDirectMessage)
10
+ throw new Error("Legacy messages can only reply to other legacy messages");
11
+ const id = typeof parent === "string" ? parent : parent.id;
12
+ return includeNameValueTag(["e", id]);
13
+ }
@@ -0,0 +1,7 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ /** Sets or removes the "title" tag on a NIP-51 list */
3
+ export declare function setTitle(title: string | null): EventOperation;
4
+ /** Sets or removes the "image" tag on a NIP-51 list */
5
+ export declare function setImage(image: string | null): EventOperation;
6
+ /** Sets or removes the "description" tag on a NIP-51 list */
7
+ export declare function setDescription(description: string | null): EventOperation;
@@ -0,0 +1,14 @@
1
+ import { removeSingletonTag, setSingletonTag } from "applesauce-core/operations/tag/common";
2
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
3
+ /** Sets or removes the "title" tag on a NIP-51 list */
4
+ export function setTitle(title) {
5
+ return modifyPublicTags(title === null ? removeSingletonTag("title") : setSingletonTag(["title", title], true));
6
+ }
7
+ /** Sets or removes the "image" tag on a NIP-51 list */
8
+ export function setImage(image) {
9
+ return modifyPublicTags(image === null ? removeSingletonTag("image") : setSingletonTag(["image", image], true));
10
+ }
11
+ /** Sets or removes the "description" tag on a NIP-51 list */
12
+ export function setDescription(description) {
13
+ return modifyPublicTags(description === null ? removeSingletonTag("description") : setSingletonTag(["description", description], true));
14
+ }
@@ -0,0 +1,4 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ /** Includes the "a" tag for live streams */
4
+ export declare function includeLiveStreamTag(stream: NostrEvent): EventOperation;
@@ -0,0 +1,11 @@
1
+ import { ensureMarkedAddressPointerTag } from "applesauce-core/helpers/factory";
2
+ import { getAddressPointerForEvent } from "applesauce-core/helpers/pointers";
3
+ /** Includes the "a" tag for live streams */
4
+ export function includeLiveStreamTag(stream) {
5
+ return async (draft, ctx) => {
6
+ let tags = Array.from(draft.tags);
7
+ const hint = await ctx.getEventRelayHint?.(stream.id);
8
+ tags = ensureMarkedAddressPointerTag(tags, getAddressPointerForEvent(stream, hint ? [hint] : undefined), "root");
9
+ return { ...draft, tags };
10
+ };
11
+ }
@@ -0,0 +1,4 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { FileMetadata } from "../helpers/file-metadata.js";
3
+ /** Adds "imeta" tags on to any event */
4
+ export declare function addMediaAttachments(attachments: FileMetadata[]): EventOperation;
@@ -0,0 +1,12 @@
1
+ import { createImetaTagForAttachment } from "../helpers/file-metadata.js";
2
+ /** Adds "imeta" tags on to any event */
3
+ export function addMediaAttachments(attachments) {
4
+ return (draft) => {
5
+ const tags = Array.from(draft.tags);
6
+ for (const attachment of attachments) {
7
+ // TODO: look for duplicates and merge them
8
+ tags.push(createImetaTagForAttachment(attachment));
9
+ }
10
+ return { ...draft, tags };
11
+ };
12
+ }
@@ -0,0 +1,9 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ /**
4
+ * Includes NIP-10 reply tags
5
+ * @throws {Error} if the parent is not a short text note
6
+ */
7
+ export declare function setThreadParent(parent: NostrEvent): EventOperation;
8
+ /** Copies "p" tags from parent event and adds new pubkeys */
9
+ export declare function includePubkeyNotificationTags(parent: NostrEvent): EventOperation;
@@ -0,0 +1,42 @@
1
+ import { kinds } from "applesauce-core/helpers/event";
2
+ import { ensureMarkedEventPointerTag, ensureProfilePointerTag } from "applesauce-core/helpers/factory";
3
+ import { isPTag } from "applesauce-core/helpers/tags";
4
+ import { getNip10References } from "../helpers/threading.js";
5
+ /**
6
+ * Includes NIP-10 reply tags
7
+ * @throws {Error} if the parent is not a short text note
8
+ */
9
+ export function setThreadParent(parent) {
10
+ if (parent.kind !== kinds.ShortTextNote)
11
+ throw new Error("Parent must be a short text note");
12
+ return async (draft, ctx) => {
13
+ let tags = Array.from(draft.tags);
14
+ const pointer = { id: parent.id, author: parent.pubkey, kind: parent.kind };
15
+ if (ctx.getEventRelayHint) {
16
+ const hint = await ctx.getEventRelayHint(parent.id);
17
+ if (hint)
18
+ pointer.relays = [hint];
19
+ }
20
+ const refs = getNip10References(parent);
21
+ const root = refs.root?.e ?? pointer;
22
+ const reply = pointer;
23
+ tags = ensureMarkedEventPointerTag(tags, root, "root");
24
+ tags = ensureMarkedEventPointerTag(tags, reply, "reply");
25
+ return { ...draft, tags };
26
+ };
27
+ }
28
+ /** Copies "p" tags from parent event and adds new pubkeys */
29
+ export function includePubkeyNotificationTags(parent) {
30
+ return async (draft, ctx) => {
31
+ let tags = Array.from(draft.tags);
32
+ // copy "p" tags from parent event that are not mentions
33
+ for (const tag of parent.tags) {
34
+ if (isPTag(tag) && tag[3] !== "mention")
35
+ tags.push(tag);
36
+ }
37
+ // add new "p" tag
38
+ const hint = await ctx.getPubkeyRelayHint?.(parent.pubkey);
39
+ tags = ensureProfilePointerTag(tags, { pubkey: parent.pubkey, relays: hint ? [hint] : undefined });
40
+ return { ...draft, tags };
41
+ };
42
+ }
@@ -0,0 +1,4 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { MediaAttachment } from "../helpers/file-metadata.js";
3
+ /** Includes the "x" and "m" tags for kind 20 picture posts */
4
+ export declare function setImageMetadata(pictures: MediaAttachment[]): EventOperation;
@@ -0,0 +1,14 @@
1
+ import { ensureNamedValueTag } from "applesauce-core/helpers/tags";
2
+ /** Includes the "x" and "m" tags for kind 20 picture posts */
3
+ export function setImageMetadata(pictures) {
4
+ return (draft) => {
5
+ let tags = Array.from(draft.tags);
6
+ for (const image of pictures) {
7
+ if (image.sha256)
8
+ tags = ensureNamedValueTag(tags, ["x", image.sha256]);
9
+ if (image.type)
10
+ tags = ensureNamedValueTag(tags, ["m", image.type]);
11
+ }
12
+ return { ...draft, tags };
13
+ };
14
+ }
@@ -0,0 +1,9 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { EventPointer } from "applesauce-core/helpers/pointers";
4
+ /** Sets the poll event that this response is for using an 'e' tag */
5
+ export declare function setPollEvent(poll: NostrEvent | EventPointer | string): EventOperation;
6
+ /** Sets multiple response options at once, replacing any existing response tags */
7
+ export declare function setChoices(optionIds: string[]): EventOperation;
8
+ /** Sets a single response option, replacing any existing response tags (for single choice polls) */
9
+ export declare function setChoice(optionId: string): EventOperation;
@@ -0,0 +1,20 @@
1
+ import { addEventPointerTag } from "applesauce-core/operations/tag/common";
2
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
3
+ /** Sets the poll event that this response is for using an 'e' tag */
4
+ export function setPollEvent(poll) {
5
+ return modifyPublicTags(addEventPointerTag(poll, true));
6
+ }
7
+ /** Sets multiple response options at once, replacing any existing response tags */
8
+ export function setChoices(optionIds) {
9
+ return modifyPublicTags((tags) => {
10
+ // Remove existing response tags
11
+ const filteredTags = tags.filter((tag) => tag[0] !== "response");
12
+ // Add new response tags
13
+ const responseTags = optionIds.map((id) => ["response", id]);
14
+ return [...filteredTags, ...responseTags];
15
+ });
16
+ }
17
+ /** Sets a single response option, replacing any existing response tags (for single choice polls) */
18
+ export function setChoice(optionId) {
19
+ return setChoices([optionId]);
20
+ }
@@ -0,0 +1,19 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { PollType } from "../helpers/poll.js";
3
+ /** Sets the content (poll question/label) for a poll event */
4
+ export declare function setQuestion(question: string): EventOperation;
5
+ /** Adds an option to a poll with an option ID and label */
6
+ export declare function addOption(optionId: string, label: string): EventOperation;
7
+ /** Sets multiple poll options at once, replacing any existing option tags */
8
+ export declare function setOptions(options: Array<{
9
+ id: string;
10
+ label: string;
11
+ }>): EventOperation;
12
+ /** Sets the poll type (singlechoice or multiplechoice) */
13
+ export declare function setType(pollType: PollType): EventOperation;
14
+ /** Sets the poll expiration timestamp */
15
+ export declare function setEndsAt(timestamp: number): EventOperation;
16
+ /** Adds a relay URL where poll responses should be published */
17
+ export declare function addRelay(relayUrl: string): EventOperation;
18
+ /** Sets multiple relay URLs at once, replacing any existing relay tags */
19
+ export declare function setRelays(relayUrls: string[]): EventOperation;
@@ -0,0 +1,42 @@
1
+ import { modifyPublicTags } from "applesauce-core/operations";
2
+ import { includeSingletonTag } from "applesauce-core/operations/tags";
3
+ /** Sets the content (poll question/label) for a poll event */
4
+ export function setQuestion(question) {
5
+ return (draft) => ({ ...draft, content: question });
6
+ }
7
+ /** Adds an option to a poll with an option ID and label */
8
+ export function addOption(optionId, label) {
9
+ return modifyPublicTags((tags) => [...tags, ["option", optionId, label]]);
10
+ }
11
+ /** Sets multiple poll options at once, replacing any existing option tags */
12
+ export function setOptions(options) {
13
+ return modifyPublicTags((tags) => {
14
+ // Remove existing option tags
15
+ const filteredTags = tags.filter((tag) => tag[0] !== "option");
16
+ // Add new option tags
17
+ const optionTags = options.map((option) => ["option", option.id, option.label]);
18
+ return [...filteredTags, ...optionTags];
19
+ });
20
+ }
21
+ /** Sets the poll type (singlechoice or multiplechoice) */
22
+ export function setType(pollType) {
23
+ return includeSingletonTag(["polltype", pollType]);
24
+ }
25
+ /** Sets the poll expiration timestamp */
26
+ export function setEndsAt(timestamp) {
27
+ return includeSingletonTag(["endsAt", timestamp.toString()]);
28
+ }
29
+ /** Adds a relay URL where poll responses should be published */
30
+ export function addRelay(relayUrl) {
31
+ return modifyPublicTags((tags) => [...tags, ["relay", relayUrl]]);
32
+ }
33
+ /** Sets multiple relay URLs at once, replacing any existing relay tags */
34
+ export function setRelays(relayUrls) {
35
+ return modifyPublicTags((tags) => {
36
+ // Remove existing relay tags
37
+ const filteredTags = tags.filter((tag) => tag[0] !== "relay");
38
+ // Add new relay tags
39
+ const relayTags = relayUrls.map((url) => ["relay", url]);
40
+ return [...filteredTags, ...relayTags];
41
+ });
42
+ }
@@ -0,0 +1,7 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { Emoji } from "../helpers/emoji.js";
4
+ /** Sets the content for a reaction event */
5
+ export declare function setReaction(emoji?: string | Emoji): EventOperation;
6
+ /** Includes NIP-25 "e", "p", "k", and "a" tags for a reaction event to point to a parent event */
7
+ export declare function setReactionParent(event: NostrEvent): EventOperation;
@@ -0,0 +1,39 @@
1
+ import { getTagValue, isAddressableKind } from "applesauce-core/helpers/event";
2
+ import { ensureAddressPointerTag, ensureEventPointerTag, ensureKTag, ensureProfilePointerTag, } from "applesauce-core/helpers/factory";
3
+ // TODO: some of these operations should be refactored to use "modifyPublicTags"
4
+ /** Sets the content for a reaction event */
5
+ export function setReaction(emoji = "+") {
6
+ return (draft) => ({ ...draft, content: typeof emoji === "string" ? emoji : `:${emoji.shortcode}:` });
7
+ }
8
+ /** Includes NIP-25 "e", "p", "k", and "a" tags for a reaction event to point to a parent event */
9
+ export function setReactionParent(event) {
10
+ return async (draft, ctx) => {
11
+ let tags = Array.from(draft.tags);
12
+ const eventHint = await ctx?.getEventRelayHint?.(event.id);
13
+ const pubkeyHint = await ctx?.getPubkeyRelayHint?.(event.pubkey);
14
+ // include "e" tag
15
+ tags = ensureEventPointerTag(tags, {
16
+ id: event.id,
17
+ relays: eventHint ? [eventHint] : undefined,
18
+ });
19
+ // include "p" tag
20
+ tags = ensureProfilePointerTag(tags, {
21
+ pubkey: event.pubkey,
22
+ relays: pubkeyHint ? [pubkeyHint] : undefined,
23
+ });
24
+ if (isAddressableKind(event.kind)) {
25
+ // include "a" tag
26
+ const identifier = getTagValue(event, "d");
27
+ if (identifier)
28
+ tags = ensureAddressPointerTag(tags, {
29
+ kind: event.kind,
30
+ pubkey: event.pubkey,
31
+ identifier,
32
+ relays: eventHint ? [eventHint] : undefined,
33
+ });
34
+ }
35
+ // include "k" tag
36
+ tags = ensureKTag(tags, event.kind);
37
+ return { ...draft, tags };
38
+ };
39
+ }
@@ -0,0 +1,8 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ /** Includes NIP-18 repost tags */
4
+ export declare function setShareTags(event: NostrEvent): EventOperation;
5
+ /** Sets the NIP-18 repost kind based on the kind of event being shared */
6
+ export declare function setShareKind(event: NostrEvent): EventOperation;
7
+ /** Sets the content of the event to a JSON string of the shared event */
8
+ export declare function embedSharedEvent(event: NostrEvent): EventOperation;
@@ -0,0 +1,34 @@
1
+ import { isAddressableKind, kinds } from "applesauce-core/helpers/event";
2
+ import { ensureAddressPointerTag, ensureEventPointerTag, ensureKTag, ensureProfilePointerTag, } from "applesauce-core/helpers/factory";
3
+ import { getAddressPointerForEvent, getEventPointerForEvent } from "applesauce-core/helpers/pointers";
4
+ import { setContent } from "applesauce-core/operations/content";
5
+ // TODO: some of these operations should be refactored to use "modifyPublicTags"
6
+ /** Includes NIP-18 repost tags */
7
+ export function setShareTags(event) {
8
+ return async (draft, ctx) => {
9
+ let tags = Array.from(draft.tags);
10
+ const hint = await ctx.getEventRelayHint?.(event.id);
11
+ // add "e" tag
12
+ tags = ensureEventPointerTag(tags, getEventPointerForEvent(event, hint ? [hint] : undefined));
13
+ // add "a" tag
14
+ if (isAddressableKind(event.kind)) {
15
+ tags = ensureAddressPointerTag(tags, getAddressPointerForEvent(event, hint ? [hint] : undefined));
16
+ }
17
+ // add "p" tag for notify
18
+ const pubkeyHint = await ctx.getPubkeyRelayHint?.(event.pubkey);
19
+ tags = ensureProfilePointerTag(tags, { pubkey: event.pubkey, relays: pubkeyHint ? [pubkeyHint] : undefined });
20
+ // add "k" tag
21
+ tags = ensureKTag(tags, event.kind);
22
+ return { ...draft, tags };
23
+ };
24
+ }
25
+ /** Sets the NIP-18 repost kind based on the kind of event being shared */
26
+ export function setShareKind(event) {
27
+ return (draft) => {
28
+ return { ...draft, kind: event.kind === kinds.ShortTextNote ? kinds.Repost : kinds.GenericRepost };
29
+ };
30
+ }
31
+ /** Sets the content of the event to a JSON string of the shared event */
32
+ export function embedSharedEvent(event) {
33
+ return setContent(JSON.stringify(event));
34
+ }
@@ -0,0 +1,7 @@
1
+ import { NostrEvent } from "applesauce-core/helpers/event";
2
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
3
+ import { TextContentOptions } from "applesauce-core/operations/content";
4
+ /** Sets the message content for a stream chat event */
5
+ export declare function setMessage(content: string, options?: TextContentOptions): import("applesauce-core").EventOperation;
6
+ /** Sets the stream for a stream chat event */
7
+ export declare function setStream(stream: AddressPointer | NostrEvent): import("applesauce-core").EventOperation<import("nostr-tools").Event | import("nostr-tools/core").UnsignedEvent | import("nostr-tools/core").EventTemplate, import("nostr-tools").Event | import("nostr-tools/core").UnsignedEvent | import("nostr-tools/core").EventTemplate>;
@@ -0,0 +1,27 @@
1
+ import { ensureAddressPointerTag } from "applesauce-core/helpers/factory";
2
+ import { eventPipe, skip } from "applesauce-core/helpers/pipeline";
3
+ import { getAddressPointerForEvent, isAddressPointer } from "applesauce-core/helpers/pointers";
4
+ import { includeEmojis, includeQuoteTags, repairNostrLinks, setContent, setContentWarning, tagPubkeyMentions, } from "applesauce-core/operations/content";
5
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
6
+ /** Sets the message content for a stream chat event */
7
+ export function setMessage(content, options) {
8
+ return eventPipe(
9
+ // set text content
10
+ setContent(content),
11
+ // fix @ mentions
12
+ repairNostrLinks(),
13
+ // include "p" tags for pubkeys mentioned
14
+ tagPubkeyMentions(),
15
+ // include event "q" tags
16
+ includeQuoteTags(),
17
+ // include "emoji" tags
18
+ options?.emojis ? includeEmojis(options.emojis) : skip(),
19
+ // set "content-warning" tag
20
+ options?.contentWarning !== undefined ? setContentWarning(options.contentWarning) : skip());
21
+ }
22
+ /** Sets the stream for a stream chat event */
23
+ export function setStream(stream) {
24
+ if (!isAddressPointer(stream))
25
+ stream = getAddressPointerForEvent(stream);
26
+ return modifyPublicTags((tags) => ensureAddressPointerTag(tags, stream));
27
+ }
@@ -0,0 +1,41 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { ProfilePointer } from "applesauce-core/helpers/pointers";
3
+ import { StreamRole } from "../helpers/stream.js";
4
+ /** Sets the title of a live event */
5
+ export declare function setTitle(title: string): EventOperation;
6
+ /** Sets the summary/description of a live event */
7
+ export declare function setSummary(summary: string): EventOperation;
8
+ /** Sets the preview image for a live event */
9
+ export declare function setImage(image: string): EventOperation;
10
+ /** Sets the streaming URL for a live event */
11
+ export declare function setStreamingUrl(url: string | URL): EventOperation;
12
+ /** Sets the recording URL for a live event (typically after the event ends) */
13
+ export declare function setRecordingUrl(url: string | URL): EventOperation;
14
+ /** Sets the start timestamp for a live event */
15
+ export declare function setStartTime(start: number | Date): EventOperation;
16
+ /** Sets the end timestamp for a live event */
17
+ export declare function setEndTime(end: number | Date): EventOperation;
18
+ /** Sets the status of a live event */
19
+ export declare function setStatus(status: "planned" | "live" | "ended"): EventOperation;
20
+ /** Sets the current number of participants */
21
+ export declare function setCurrentViewers(count: number): EventOperation;
22
+ /** Sets the total number of participants */
23
+ export declare function setMaxViewers(count: number): EventOperation;
24
+ /** Sets the host of the stream */
25
+ export declare function setHost(user: ProfilePointer): EventOperation;
26
+ /** Adds a participant to a live event with role and optional relay */
27
+ export declare function addParticipant(user: ProfilePointer, role: StreamRole): EventOperation;
28
+ /** Removes a participant from a live event */
29
+ export declare function removeParticipant(pubkey: string): EventOperation;
30
+ /** Adds a relay to the live event's relay list */
31
+ export declare function addRelay(relay: string | URL): EventOperation;
32
+ /** Removes a relay from the live event's relay list */
33
+ export declare function removeRelay(relay: string | URL): EventOperation;
34
+ /** Sets a pinned live chat message */
35
+ export declare function setPinnedMessage(eventId: string): EventOperation;
36
+ /** Removes the pinned live chat message */
37
+ export declare function removePinnedMessage(): EventOperation;
38
+ /** Adds a hashtag to the live event */
39
+ export declare function addHashtag(hashtag: string): EventOperation;
40
+ /** Removes a hashtag from the live event */
41
+ export declare function removeHashtag(hashtag: string): EventOperation;
@@ -0,0 +1,83 @@
1
+ import { ensureMarkedProfilePointerTag } from "applesauce-core/helpers/factory";
2
+ import { addNameValueTag, removeNameValueTag } from "applesauce-core/operations/tag/common";
3
+ import { includeSingletonTag, modifyPublicTags } from "applesauce-core/operations/tags";
4
+ import * as Hashtags from "./hashtags.js";
5
+ // Live Event (kind:30311) Operations
6
+ /** Sets the title of a live event */
7
+ export function setTitle(title) {
8
+ return includeSingletonTag(["title", title], true);
9
+ }
10
+ /** Sets the summary/description of a live event */
11
+ export function setSummary(summary) {
12
+ return includeSingletonTag(["summary", summary], true);
13
+ }
14
+ /** Sets the preview image for a live event */
15
+ export function setImage(image) {
16
+ return includeSingletonTag(["image", image], true);
17
+ }
18
+ /** Sets the streaming URL for a live event */
19
+ export function setStreamingUrl(url) {
20
+ return includeSingletonTag(["streaming", new URL(url).toString()], true);
21
+ }
22
+ /** Sets the recording URL for a live event (typically after the event ends) */
23
+ export function setRecordingUrl(url) {
24
+ return includeSingletonTag(["recording", new URL(url).toString()], true);
25
+ }
26
+ /** Sets the start timestamp for a live event */
27
+ export function setStartTime(start) {
28
+ const timestamp = typeof start === "number" ? start : Math.round(new Date(start).valueOf() / 1000);
29
+ return includeSingletonTag(["starts", String(timestamp)], true);
30
+ }
31
+ /** Sets the end timestamp for a live event */
32
+ export function setEndTime(end) {
33
+ const timestamp = typeof end === "number" ? end : Math.round(new Date(end).valueOf() / 1000);
34
+ return includeSingletonTag(["ends", String(timestamp)], true);
35
+ }
36
+ /** Sets the status of a live event */
37
+ export function setStatus(status) {
38
+ return includeSingletonTag(["status", status], true);
39
+ }
40
+ /** Sets the current number of participants */
41
+ export function setCurrentViewers(count) {
42
+ return includeSingletonTag(["current_participants", String(count)], true);
43
+ }
44
+ /** Sets the total number of participants */
45
+ export function setMaxViewers(count) {
46
+ return includeSingletonTag(["total_participants", String(count)], true);
47
+ }
48
+ /** Sets the host of the stream */
49
+ export function setHost(user) {
50
+ return modifyPublicTags((tags) => ensureMarkedProfilePointerTag(tags, user, "host"));
51
+ }
52
+ /** Adds a participant to a live event with role and optional relay */
53
+ export function addParticipant(user, role) {
54
+ return modifyPublicTags((tags) => ensureMarkedProfilePointerTag(tags, user, role));
55
+ }
56
+ /** Removes a participant from a live event */
57
+ export function removeParticipant(pubkey) {
58
+ return modifyPublicTags(removeNameValueTag(["p", pubkey]));
59
+ }
60
+ /** Adds a relay to the live event's relay list */
61
+ export function addRelay(relay) {
62
+ return modifyPublicTags(addNameValueTag(["relays", new URL(relay).toString()], true));
63
+ }
64
+ /** Removes a relay from the live event's relay list */
65
+ export function removeRelay(relay) {
66
+ return modifyPublicTags(removeNameValueTag(["relays", new URL(relay).toString()]));
67
+ }
68
+ /** Sets a pinned live chat message */
69
+ export function setPinnedMessage(eventId) {
70
+ return includeSingletonTag(["pinned", eventId], true);
71
+ }
72
+ /** Removes the pinned live chat message */
73
+ export function removePinnedMessage() {
74
+ return modifyPublicTags((tags) => tags.filter((tag) => tag[0] !== "pinned"));
75
+ }
76
+ /** Adds a hashtag to the live event */
77
+ export function addHashtag(hashtag) {
78
+ return Hashtags.addHashtag(hashtag);
79
+ }
80
+ /** Removes a hashtag from the live event */
81
+ export function removeHashtag(hashtag) {
82
+ return Hashtags.removeHashtag(hashtag);
83
+ }
@@ -0,0 +1,6 @@
1
+ import { TagOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ /** Adds an "e" or "a" tag to a bookmark list or set */
4
+ export declare function addEventBookmarkTag(event: NostrEvent): TagOperation;
5
+ /** Removes an "e" or "a" tag from a bookmark list or set */
6
+ export declare function removeEventBookmarkTag(event: NostrEvent): TagOperation;
@@ -0,0 +1,20 @@
1
+ import { isReplaceable } from "applesauce-core/helpers";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ import { getAddressPointerForEvent } from "applesauce-core/helpers/pointers";
4
+ import { addAddressPointerTag, addEventPointerTag, removeAddressPointerTag, removeEventPointerTag, } from "applesauce-core/operations/tag/common";
5
+ /** Adds an "e" or "a" tag to a bookmark list or set */
6
+ export function addEventBookmarkTag(event) {
7
+ if (event.kind !== kinds.ShortTextNote && event.kind !== kinds.LongFormArticle)
8
+ throw new Error(`Event kind (${event.kind}) cant not be added to bookmarks`);
9
+ return isReplaceable(event.kind)
10
+ ? addAddressPointerTag(getAddressPointerForEvent(event))
11
+ : addEventPointerTag(event.id);
12
+ }
13
+ /** Removes an "e" or "a" tag from a bookmark list or set */
14
+ export function removeEventBookmarkTag(event) {
15
+ if (event.kind !== kinds.ShortTextNote && event.kind !== kinds.LongFormArticle)
16
+ throw new Error(`Event kind (${event.kind}) cant not be added to bookmarks`);
17
+ return isReplaceable(event.kind)
18
+ ? removeAddressPointerTag(getAddressPointerForEvent(event))
19
+ : removeEventPointerTag(event.id);
20
+ }
@@ -0,0 +1 @@
1
+ export * from "./bookmarks.js";
@@ -0,0 +1 @@
1
+ export * from "./bookmarks.js";