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,26 @@
1
+ import { kinds } from "applesauce-core/helpers/event";
2
+ import { getCoordinateFromAddressPointer, isAddressPointer, } from "applesauce-core/helpers/pointers";
3
+ import { map } from "rxjs";
4
+ import { isValidZap } from "../helpers/zap.js";
5
+ /** A model that gets all zap events for an event */
6
+ export function EventZapsModel(id) {
7
+ return (events) => {
8
+ if (isAddressPointer(id)) {
9
+ return events
10
+ .timeline([{ kinds: [kinds.Zap], "#a": [getCoordinateFromAddressPointer(id)] }])
11
+ .pipe(map((events) => events.filter(isValidZap)));
12
+ }
13
+ else {
14
+ id = typeof id === "string" ? id : id.id;
15
+ return events.timeline([{ kinds: [kinds.Zap], "#e": [id] }]).pipe(map((events) => events.filter(isValidZap)));
16
+ }
17
+ };
18
+ }
19
+ /** A model that returns all zaps sent by a user */
20
+ export function SentZapsModel(pubkey) {
21
+ return (events) => events.timeline([{ kinds: [kinds.Zap], authors: [pubkey] }]).pipe(map((events) => events.filter(isValidZap)));
22
+ }
23
+ /** A model that returns all zaps received by a user */
24
+ export function ReceivedZapsModel(pubkey) {
25
+ return (events) => events.timeline([{ kinds: [kinds.Zap], "#p": [pubkey] }]).pipe(map((events) => events.filter(isValidZap)));
26
+ }
@@ -0,0 +1,6 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { EncryptionMethod } from "applesauce-core/helpers/encrypted-content";
3
+ /** Sets the app data identifier */
4
+ export declare function setIdentifier(identifier: string): EventOperation;
5
+ /** Sets the content of an application data event */
6
+ export declare function setContent<T>(data: T, encryption?: boolean | EncryptionMethod): EventOperation;
@@ -0,0 +1,21 @@
1
+ import { setContent as setPlaintextContent } from "applesauce-core/operations/content";
2
+ import { setHiddenContent } from "applesauce-core/operations/hidden-content";
3
+ import { includeSingletonTag } from "applesauce-core/operations/tags";
4
+ /** Sets the app data identifier */
5
+ export function setIdentifier(identifier) {
6
+ return includeSingletonTag(["d", identifier]);
7
+ }
8
+ /** Sets the content of an application data event */
9
+ export function setContent(data, encryption) {
10
+ const json = JSON.stringify(data);
11
+ switch (typeof encryption) {
12
+ case "boolean":
13
+ return encryption ? setHiddenContent(json) : setPlaintextContent(json);
14
+ case "string":
15
+ return setHiddenContent(json, encryption);
16
+ case "undefined":
17
+ return setPlaintextContent(json);
18
+ default:
19
+ throw new Error("Invalid encrypted type");
20
+ }
21
+ }
@@ -0,0 +1,5 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ /** Adds a server to a 10063 event */
3
+ export declare function addBlossomServer(url: string | URL, replace?: boolean): EventOperation;
4
+ /** Removes server matching the url from a 10063 event */
5
+ export declare function removeBlossomServer(url: string | URL): EventOperation;
@@ -0,0 +1,13 @@
1
+ import { normalizeURL } from "applesauce-core/helpers";
2
+ import { addNameValueTag } from "applesauce-core/operations/tag/common";
3
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
4
+ import { areBlossomServersEqual } from "../helpers/blossom.js";
5
+ /** Adds a server to a 10063 event */
6
+ export function addBlossomServer(url, replace = true) {
7
+ url = normalizeURL(url).toString();
8
+ return modifyPublicTags(addNameValueTag(["server", url], replace, (a, b) => areBlossomServersEqual(a, b)));
9
+ }
10
+ /** Removes server matching the url from a 10063 event */
11
+ export function removeBlossomServer(url) {
12
+ return modifyPublicTags((tags) => tags.filter((t) => !(t[0] === "server" && t[1] && areBlossomServersEqual(t[1], url))));
13
+ }
@@ -0,0 +1,34 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { CalendarEventParticipant } from "../helpers/calendar-event.js";
3
+ /** Sets the title of a calendar event */
4
+ export declare function setTitle(title: string): EventOperation;
5
+ /** Sets the summary of a calendar event */
6
+ export declare function setSummary(summary: string): EventOperation;
7
+ /** Sets the image for a calendar event */
8
+ export declare function setImage(image: string): EventOperation;
9
+ /** Adds a participant to a calendar event */
10
+ export declare function addParticipant(participant: CalendarEventParticipant): EventOperation;
11
+ /** Removes a participant from a calendar event */
12
+ export declare function removeParticipant(pubkey: string | CalendarEventParticipant): EventOperation;
13
+ /** Adds a location to a calendar event */
14
+ export declare function addLocation(location: string): EventOperation;
15
+ /** Removes a location from a calendar event */
16
+ export declare function removeLocation(location: string): EventOperation;
17
+ /** Adds a location to a calendar event */
18
+ export declare function addReferenceLink(link: string | URL): EventOperation;
19
+ /** Removes a location from a calendar event */
20
+ export declare function removeReferenceLink(link: string | URL): EventOperation;
21
+ /** Removes all locations from a calendar event */
22
+ export declare function clearLocations(): EventOperation;
23
+ /** Sets the geohash for a calendar event */
24
+ export declare function setGeohash(geohash: string): EventOperation;
25
+ /** Removes the geohash from a calendar event */
26
+ export declare function removeGeohash(): EventOperation;
27
+ /** Sets the start date for a date based calendar event */
28
+ export declare function setStartDate(start: string | Date): EventOperation;
29
+ /** Sets the start time for a time based calendar event */
30
+ export declare function setStartTime(start: number | Date, timezone?: string): EventOperation;
31
+ /** Sets the end date for a date based calendar event */
32
+ export declare function setEndDate(end: string | Date): EventOperation;
33
+ /** Sets the end time for a time based calendar event */
34
+ export declare function setEndTime(end: number | Date, timezone?: string): EventOperation;
@@ -0,0 +1,72 @@
1
+ import { addNameValueTag, removeNameValueTag, setSingletonTag } from "applesauce-core/operations/tag/common";
2
+ import { includeNameValueTag, includeSingletonTag, modifyPublicTags } from "applesauce-core/operations/tags";
3
+ import { createCalendarEventParticipantTag } from "../helpers/calendar-event.js";
4
+ import * as Geohash from "./geohash.js";
5
+ /** Sets the title of a calendar event */
6
+ export function setTitle(title) {
7
+ return includeSingletonTag(["title", title], true);
8
+ }
9
+ /** Sets the summary of a calendar event */
10
+ export function setSummary(summary) {
11
+ return includeSingletonTag(["summary", summary], true);
12
+ }
13
+ /** Sets the image for a calendar event */
14
+ export function setImage(image) {
15
+ return includeSingletonTag(["image", image], true);
16
+ }
17
+ /** Adds a participant to a calendar event */
18
+ export function addParticipant(participant) {
19
+ return includeNameValueTag(createCalendarEventParticipantTag(participant), true);
20
+ }
21
+ /** Removes a participant from a calendar event */
22
+ export function removeParticipant(pubkey) {
23
+ return modifyPublicTags(removeNameValueTag(["p", typeof pubkey === "string" ? pubkey : pubkey.pubkey]));
24
+ }
25
+ /** Adds a location to a calendar event */
26
+ export function addLocation(location) {
27
+ return modifyPublicTags(addNameValueTag(["location", location], true));
28
+ }
29
+ /** Removes a location from a calendar event */
30
+ export function removeLocation(location) {
31
+ return modifyPublicTags(removeNameValueTag(["location", location]));
32
+ }
33
+ /** Adds a location to a calendar event */
34
+ export function addReferenceLink(link) {
35
+ return modifyPublicTags(addNameValueTag(["r", new URL(link).toString()], true));
36
+ }
37
+ /** Removes a location from a calendar event */
38
+ export function removeReferenceLink(link) {
39
+ return modifyPublicTags(removeNameValueTag(["r", new URL(link).toString()]));
40
+ }
41
+ /** Removes all locations from a calendar event */
42
+ export function clearLocations() {
43
+ return modifyPublicTags((tags) => tags.filter((tag) => tag[0] !== "location"));
44
+ }
45
+ /** Sets the geohash for a calendar event */
46
+ export function setGeohash(geohash) {
47
+ return Geohash.setGeohash(geohash);
48
+ }
49
+ /** Removes the geohash from a calendar event */
50
+ export function removeGeohash() {
51
+ return Geohash.removeGeohash();
52
+ }
53
+ /** Sets the start date for a date based calendar event */
54
+ export function setStartDate(start) {
55
+ const date = new Date(start).toISOString().split("T")[0];
56
+ return includeSingletonTag(["start", date], true);
57
+ }
58
+ /** Sets the start time for a time based calendar event */
59
+ export function setStartTime(start, timezone) {
60
+ const timestamp = typeof start === "number" ? start : Math.round(new Date(start).valueOf() / 1000);
61
+ return modifyPublicTags(setSingletonTag(["start", String(timestamp)], true), timezone ? setSingletonTag(["start_tzid", timezone], true) : undefined);
62
+ }
63
+ /** Sets the end date for a date based calendar event */
64
+ export function setEndDate(end) {
65
+ const date = new Date(end).toISOString().split("T")[0];
66
+ return includeSingletonTag(["end", date], true);
67
+ }
68
+ /** Sets the end time for a time based calendar event */
69
+ export function setEndTime(end, timezone) {
70
+ const timestamp = typeof end === "number" ? end : Math.round(new Date(end).valueOf() / 1000);
71
+ return modifyPublicTags(setSingletonTag(["end", String(timestamp)], true), timezone ? setSingletonTag(["end_tzid", timezone], true) : undefined);
72
+ }
@@ -0,0 +1,10 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
4
+ import { RSVPFreeBusy, RSVPStatus } from "../helpers/calendar-rsvp.js";
5
+ /** Sets the RSVP status for a calendar event */
6
+ export declare function setStatus(status: RSVPStatus): EventOperation;
7
+ /** Sets the free busy status for a calendar event */
8
+ export declare function setFreeBusy(freeBusy: RSVPFreeBusy): EventOperation;
9
+ /** Sets the pointers to the calendar event for an RSVP event */
10
+ export declare function setCalendarEvent(pointer: NostrEvent | AddressPointer, relay?: string): EventOperation;
@@ -0,0 +1,35 @@
1
+ import { createATagFromAddressPointer, createETagFromEventPointer, createPTagFromProfilePointer, } from "applesauce-core/helpers";
2
+ import { addRelayHintsToPointer, getAddressPointerForEvent, isAddressPointer, } from "applesauce-core/helpers/pointers";
3
+ import { setSingletonTag } from "applesauce-core/operations/tag/common";
4
+ import { includeSingletonTag, modifyPublicTags } from "applesauce-core/operations/tags";
5
+ import { DATE_BASED_CALENDAR_EVENT_KIND, TIME_BASED_CALENDAR_EVENT_KIND } from "../helpers/calendar-event.js";
6
+ /** Sets the RSVP status for a calendar event */
7
+ export function setStatus(status) {
8
+ return includeSingletonTag(["status", status], true);
9
+ }
10
+ /** Sets the free busy status for a calendar event */
11
+ export function setFreeBusy(freeBusy) {
12
+ return includeSingletonTag(["fb", freeBusy], true);
13
+ }
14
+ /** Sets the pointers to the calendar event for an RSVP event */
15
+ export function setCalendarEvent(pointer, relay) {
16
+ if (pointer.kind !== DATE_BASED_CALENDAR_EVENT_KIND && pointer.kind !== TIME_BASED_CALENDAR_EVENT_KIND)
17
+ throw new Error("RSVP pointer must be to a calendar event");
18
+ let addressPointer = isAddressPointer(pointer) ? pointer : getAddressPointerForEvent(pointer);
19
+ let eventPointer = isAddressPointer(pointer)
20
+ ? undefined
21
+ : { id: pointer.id, kind: pointer.kind, author: pointer.pubkey };
22
+ let profilePointer = { pubkey: pointer.pubkey };
23
+ // Add relay hint if provided
24
+ if (relay) {
25
+ addressPointer = addRelayHintsToPointer(addressPointer, [relay]);
26
+ if (eventPointer)
27
+ eventPointer = addRelayHintsToPointer(eventPointer, [relay]);
28
+ profilePointer = addRelayHintsToPointer(profilePointer, [relay]);
29
+ }
30
+ return modifyPublicTags(
31
+ // Include "a" and "e" tags for calendar event
32
+ setSingletonTag(createATagFromAddressPointer(addressPointer)), eventPointer ? setSingletonTag(createETagFromEventPointer(eventPointer)) : undefined,
33
+ // Add a "p" tag for the event author
34
+ setSingletonTag(createPTagFromProfilePointer(profilePointer), true));
35
+ }
@@ -0,0 +1,9 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
4
+ /** Sets the title of a calendar */
5
+ export declare function setTitle(title: string): EventOperation;
6
+ /** Adds a calendar event tags to a calendar event */
7
+ export declare function addEvent(event: AddressPointer | NostrEvent): EventOperation;
8
+ /** Removes a calendar event tags from a calendar event */
9
+ export declare function removeEvent(event: AddressPointer | NostrEvent): EventOperation;
@@ -0,0 +1,15 @@
1
+ import { getAddressPointerForEvent, isAddressPointer } from "applesauce-core/helpers/pointers";
2
+ import { addAddressPointerTag, removeAddressPointerTag } from "applesauce-core/operations/tag/common";
3
+ import { includeSingletonTag, modifyPublicTags } from "applesauce-core/operations/tags";
4
+ /** Sets the title of a calendar */
5
+ export function setTitle(title) {
6
+ return includeSingletonTag(["title", title], true);
7
+ }
8
+ /** Adds a calendar event tags to a calendar event */
9
+ export function addEvent(event) {
10
+ return modifyPublicTags(addAddressPointerTag(isAddressPointer(event) ? event : getAddressPointerForEvent(event)));
11
+ }
12
+ /** Removes a calendar event tags from a calendar event */
13
+ export function removeEvent(event) {
14
+ return modifyPublicTags(removeAddressPointerTag(isAddressPointer(event) ? event : getAddressPointerForEvent(event)));
15
+ }
@@ -0,0 +1,4 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ /** Includes the "e" tag referencing the channel creating event */
4
+ export declare function includeChannelPointerTag(channel: NostrEvent): EventOperation;
@@ -0,0 +1,10 @@
1
+ import { ensureMarkedEventPointerTag } from "applesauce-core/helpers/factory";
2
+ import { getEventPointerForEvent } from "applesauce-core/helpers/pointers";
3
+ /** Includes the "e" tag referencing the channel creating event */
4
+ export function includeChannelPointerTag(channel) {
5
+ return (draft) => {
6
+ let tags = Array.from(draft.tags);
7
+ tags = ensureMarkedEventPointerTag(tags, getEventPointerForEvent(channel), "root");
8
+ return { ...draft, tags };
9
+ };
10
+ }
@@ -0,0 +1,4 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
3
+ /** Includes a NIP-89 client tag in an event*/
4
+ export declare function setClient(name: string, pointer?: Omit<AddressPointer, "kind" | "relays">, replace?: boolean): EventOperation;
@@ -0,0 +1,23 @@
1
+ import { kinds } from "applesauce-core/helpers/event";
2
+ import { getCoordinateFromAddressPointer } from "applesauce-core/helpers/pointers";
3
+ import { fillAndTrimTag } from "applesauce-core/helpers/tags";
4
+ import { includeSingletonTag } from "applesauce-core/operations/tags";
5
+ // A list of event kinds to never attach the "client" tag to
6
+ const NEVER_ATTACH_CLIENT_TAG = [kinds.EncryptedDirectMessage, kinds.GiftWrap, kinds.Seal];
7
+ /** Includes a NIP-89 client tag in an event*/
8
+ export function setClient(name, pointer, replace = true) {
9
+ return (draft, ctx) => {
10
+ if (NEVER_ATTACH_CLIENT_TAG.includes(draft.kind))
11
+ return draft;
12
+ else {
13
+ const coordinate = pointer
14
+ ? getCoordinateFromAddressPointer({
15
+ pubkey: pointer.pubkey,
16
+ identifier: pointer.identifier,
17
+ kind: kinds.Handlerinformation,
18
+ })
19
+ : undefined;
20
+ return includeSingletonTag(fillAndTrimTag(["client", name, coordinate]), replace)(draft, ctx);
21
+ }
22
+ };
23
+ }
@@ -0,0 +1,4 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ /** Sets the necessary tags for a NIP-22 comment event to point to a parent event */
4
+ export declare function setParent(parent: NostrEvent): EventOperation;
@@ -0,0 +1,11 @@
1
+ import { createCommentTagsForEvent } from "../helpers/comment.js";
2
+ /** Sets the necessary tags for a NIP-22 comment event to point to a parent event */
3
+ export function setParent(parent) {
4
+ return async (draft, ctx) => {
5
+ const relayHint = await ctx.getEventRelayHint?.(parent.id);
6
+ let tags = Array.from(draft.tags);
7
+ // add NIP-22 comment tags
8
+ tags.push(...createCommentTagsForEvent(parent, relayHint));
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
+ /** Sets all NIP-94 tags for {@link FileMetadata} */
4
+ export declare function setFileMetadata(metadata: FileMetadata): EventOperation;
@@ -0,0 +1,21 @@
1
+ import { ensureSingletonTag } from "applesauce-core/helpers";
2
+ import { createFileMetadataTags } from "../helpers/file-metadata.js";
3
+ /** Sets all NIP-94 tags for {@link FileMetadata} */
4
+ export function setFileMetadata(metadata) {
5
+ return (draft) => {
6
+ let tags = Array.from(draft.tags);
7
+ const fileTags = createFileMetadataTags(metadata);
8
+ for (const tag of fileTags) {
9
+ switch (tag[0]) {
10
+ case "fallback":
11
+ // support multiple fallback tags
12
+ tags.push(tag);
13
+ break;
14
+ default:
15
+ tags = ensureSingletonTag(tags, tag);
16
+ break;
17
+ }
18
+ }
19
+ return { ...draft, tags };
20
+ };
21
+ }
@@ -0,0 +1,5 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ /** Adds all "g" geohash tags for a given geohash or removes them if null */
3
+ export declare function setGeohash(geohash: string | null): EventOperation;
4
+ /** Removes all "g" geohash tags from an event */
5
+ export declare function removeGeohash(): EventOperation;
@@ -0,0 +1,17 @@
1
+ import { modifyPublicTags } from "applesauce-core/operations";
2
+ /** Adds all "g" geohash tags for a given geohash or removes them if null */
3
+ export function setGeohash(geohash) {
4
+ if (!geohash)
5
+ return removeGeohash();
6
+ return modifyPublicTags((tags) => {
7
+ tags = tags.filter((t) => t[0] !== "g" && t[1]);
8
+ for (let i = 0; i < geohash.length; i++) {
9
+ tags.push(["g", geohash.slice(0, i + 1)]);
10
+ }
11
+ return tags;
12
+ });
13
+ }
14
+ /** Removes all "g" geohash tags from an event */
15
+ export function removeGeohash() {
16
+ return modifyPublicTags((tags) => tags.filter((t) => t[0] !== "g" && t[1]));
17
+ }
@@ -0,0 +1,13 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { EventTemplate, NostrEvent, UnsignedEvent } from "applesauce-core/helpers/event";
3
+ import { MetaTagOptions } from "applesauce-core/operations/event";
4
+ import { Rumor } from "../helpers/gift-wrap.js";
5
+ /** Converts an event to a rumor. The first operation in the gift wrap pipeline */
6
+ export declare function toRumor(): EventOperation<EventTemplate | UnsignedEvent | NostrEvent, Rumor>;
7
+ /** Seals a rumor in a NIP-59 seal. The second operation in the gift wrap pipeline */
8
+ export declare function sealRumor(pubkey: string): EventOperation<Rumor, NostrEvent>;
9
+ export type GiftWrapOptions = MetaTagOptions;
10
+ /** Gift wraps a seal to a pubkey. The third operation in the gift wrap pipeline */
11
+ export declare function wrapSeal(pubkey: string, opts?: GiftWrapOptions): EventOperation<NostrEvent, NostrEvent>;
12
+ /** An operation that gift wraps an event to a pubkey */
13
+ export declare function giftWrap(pubkey: string, opts?: GiftWrapOptions): EventOperation<EventTemplate | UnsignedEvent | NostrEvent, NostrEvent>;
@@ -0,0 +1,93 @@
1
+ // Read https://github.com/nostr-protocol/nips/blob/master/59.md#overview for details on rumors and seals
2
+ // Gift wrap (signed random key) -> seal (signed sender key) -> rumor (unsigned)
3
+ import { buildEvent } from "applesauce-core/event-factory";
4
+ import { EncryptedContentSymbol } from "applesauce-core/helpers/encrypted-content";
5
+ import { nip44 } from "applesauce-core/helpers/encryption";
6
+ import { finalizeEvent, getEventHash, kinds, } from "applesauce-core/helpers/event";
7
+ import { generateSecretKey } from "applesauce-core/helpers/keys";
8
+ import { eventPipe, PRESERVE_EVENT_SYMBOLS } from "applesauce-core/helpers/pipeline";
9
+ import { unixNow } from "applesauce-core/helpers/time";
10
+ import { setEncryptedContent } from "applesauce-core/operations/encrypted-content";
11
+ import { setMetaTags, stamp } from "applesauce-core/operations/event";
12
+ import { GiftWrapSymbol, RumorSymbol, SealSymbol } from "../helpers/gift-wrap.js";
13
+ // Preserve gift-wrap and seal symbols when building gift-wrap events
14
+ PRESERVE_EVENT_SYMBOLS.add(GiftWrapSymbol);
15
+ PRESERVE_EVENT_SYMBOLS.add(SealSymbol);
16
+ PRESERVE_EVENT_SYMBOLS.add(RumorSymbol);
17
+ /** Create a timestamp with a random offset of an hour */
18
+ function randomNow() {
19
+ return unixNow() - Math.floor(Math.random() * 60 * 60);
20
+ }
21
+ /** Converts an event to a rumor. The first operation in the gift wrap pipeline */
22
+ export function toRumor() {
23
+ return async (draft, ctx) => {
24
+ // @ts-expect-error
25
+ const rumor = { ...draft };
26
+ // Ensure rumor has pubkey
27
+ if (!Reflect.has(rumor, "pubkey")) {
28
+ if (!ctx.signer)
29
+ throw new Error("A signer is required to create a rumor");
30
+ rumor.pubkey = await ctx.signer.getPublicKey();
31
+ }
32
+ // Ensure rumor has id
33
+ if (!Reflect.has(rumor, "id"))
34
+ rumor.id = getEventHash(rumor);
35
+ // Ensure rumor does not have signature
36
+ Reflect.deleteProperty(rumor, "sig");
37
+ return rumor;
38
+ };
39
+ }
40
+ /** Seals a rumor in a NIP-59 seal. The second operation in the gift wrap pipeline */
41
+ export function sealRumor(pubkey) {
42
+ return async (rumor, ctx) => {
43
+ if (!ctx.signer)
44
+ throw new Error("A signer is required to create a seal");
45
+ const plaintext = JSON.stringify(rumor);
46
+ const unsigned = await buildEvent({ kind: kinds.Seal, created_at: randomNow() }, ctx,
47
+ // Set the encrypted content
48
+ setEncryptedContent(pubkey, plaintext),
49
+ // Stamp the seal with the signers's pubkey
50
+ stamp());
51
+ const seal = await ctx.signer.signEvent(unsigned);
52
+ // Set the downstream reference on the seal
53
+ Reflect.set(seal, RumorSymbol, rumor);
54
+ // Add the upstream reference to the rumor
55
+ const seals = Reflect.get(rumor, SealSymbol);
56
+ if (seals)
57
+ seals.add(seal);
58
+ else
59
+ Reflect.set(rumor, SealSymbol, new Set([seal]));
60
+ return seal;
61
+ };
62
+ }
63
+ /** Gift wraps a seal to a pubkey. The third operation in the gift wrap pipeline */
64
+ export function wrapSeal(pubkey, opts) {
65
+ return async (seal) => {
66
+ const key = generateSecretKey();
67
+ const plaintext = JSON.stringify(seal);
68
+ const draft = await buildEvent({
69
+ kind: kinds.GiftWrap,
70
+ created_at: randomNow(),
71
+ content: nip44.encrypt(plaintext, nip44.getConversationKey(key, pubkey)),
72
+ tags: [["p", pubkey]],
73
+ },
74
+ // Pass an empty context here so here there is no chance to use the users pubkey
75
+ {},
76
+ // Set meta tags on the gift wrap
77
+ setMetaTags(opts));
78
+ const gift = finalizeEvent(draft, key);
79
+ // Set the upstream references on the seal
80
+ Reflect.set(seal, GiftWrapSymbol, gift);
81
+ // Set the downstream reference on the gift wrap
82
+ Reflect.set(gift, SealSymbol, seal);
83
+ // Set the encrypted content on the gift wrap
84
+ Reflect.set(gift, EncryptedContentSymbol, plaintext);
85
+ return gift;
86
+ };
87
+ }
88
+ /** An operation that gift wraps an event to a pubkey */
89
+ export function giftWrap(pubkey, opts) {
90
+ return eventPipe(toRumor(),
91
+ // @ts-expect-error
92
+ sealRumor(pubkey), wrapSeal(pubkey, opts));
93
+ }
@@ -0,0 +1,11 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { GroupPointer } from "../helpers/groups.js";
4
+ /** Adds a "group" tag to a list */
5
+ export declare function addGroupTag(group: GroupPointer): EventOperation;
6
+ /** Removes a "group" tag from a list */
7
+ export declare function removeGroupTag(group: GroupPointer): EventOperation;
8
+ /** Sets the "h" tag for NIP-29 group messages or other events */
9
+ export declare function setGroupPointer(group: GroupPointer): EventOperation;
10
+ /** Adds "previous" tags for group messages */
11
+ export declare function addPreviousRefs(previous: NostrEvent[], count?: number): EventOperation;
@@ -0,0 +1,34 @@
1
+ import { ensureNamedValueTag } from "applesauce-core/helpers";
2
+ import { includeSingletonTag, modifyPublicTags } from "applesauce-core/operations/tags";
3
+ import { createGroupHTagFromGroupPointer, createGroupTagFromGroupPointer } from "../helpers/groups-helper.js";
4
+ /** Adds a "group" tag to a list */
5
+ export function addGroupTag(group) {
6
+ return modifyPublicTags((tags) => {
7
+ // remove existing tag
8
+ tags = tags.filter((t) => !(t[0] === "group" && t[1] === group.id && t[2] === group.relay));
9
+ return [...tags, createGroupTagFromGroupPointer(group)];
10
+ });
11
+ }
12
+ /** Removes a "group" tag from a list */
13
+ export function removeGroupTag(group) {
14
+ return modifyPublicTags((tags) => tags.filter((tag) => tag[0] === "group" && tag[1] === group.id && tag[2] === group.relay));
15
+ }
16
+ /** Sets the "h" tag for NIP-29 group messages or other events */
17
+ export function setGroupPointer(group) {
18
+ return includeSingletonTag(createGroupHTagFromGroupPointer(group), true);
19
+ }
20
+ /** Adds "previous" tags for group messages */
21
+ export function addPreviousRefs(previous, count = 6) {
22
+ return (draft) => {
23
+ let tags = Array.from(draft.tags);
24
+ // sort previous events by date and limit to 50
25
+ const sorted = previous.sort((a, b) => b.created_at - a.created_at).slice(0, 50);
26
+ for (let i = 0; i < count; i++) {
27
+ const index = Math.round(Math.random() * (sorted.length - 1));
28
+ const event = sorted.splice(index, 1)[0];
29
+ if (event)
30
+ tags = ensureNamedValueTag(tags, ["previous", event.id.slice(0, 8)]);
31
+ }
32
+ return { ...draft, tags };
33
+ };
34
+ }
@@ -0,0 +1,7 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ /** Adds a hashtag to the live event */
3
+ export declare function addHashtag(hashtag: string): EventOperation;
4
+ /** Removes a hashtag from the live event */
5
+ export declare function removeHashtag(hashtag: string): EventOperation;
6
+ /** Adds "t" tags for an array of hashtags */
7
+ export declare function includeHashtags(hashtags: string[]): EventOperation;
@@ -0,0 +1,17 @@
1
+ import { modifyPublicTags } from "applesauce-core/operations";
2
+ import { addNameValueTag } from "applesauce-core/operations/tag/common";
3
+ /** Adds a hashtag to the live event */
4
+ export function addHashtag(hashtag) {
5
+ // Remove # if present at the beginning
6
+ const cleanTag = (hashtag.startsWith("#") ? hashtag.slice(1) : hashtag).toLocaleLowerCase();
7
+ return modifyPublicTags(addNameValueTag(["t", cleanTag], true));
8
+ }
9
+ /** Removes a hashtag from the live event */
10
+ export function removeHashtag(hashtag) {
11
+ const cleanTag = (hashtag.startsWith("#") ? hashtag.slice(1) : hashtag).toLocaleLowerCase();
12
+ return modifyPublicTags((tags) => tags.filter((t) => t[0] !== "t" || t[1].toLocaleLowerCase() !== cleanTag));
13
+ }
14
+ /** Adds "t" tags for an array of hashtags */
15
+ export function includeHashtags(hashtags) {
16
+ return modifyPublicTags(...hashtags.map((hashtag) => addNameValueTag(["t", hashtag.toLocaleLowerCase()])));
17
+ }
@@ -0,0 +1,18 @@
1
+ import { EventOperation } from "applesauce-core/event-factory";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { AddressPointer, EventPointer } from "applesauce-core/helpers/pointers";
4
+ import { HighlightAttribution } from "../helpers/highlight.js";
5
+ /** Sets the content (highlighted text) for a highlight event */
6
+ export declare function setHighlightContent(content: string): EventOperation;
7
+ /** Sets the source event that was highlighted using an 'e' tag */
8
+ export declare function setSource(source: NostrEvent | EventPointer | AddressPointer | string): EventOperation;
9
+ /** Attribution role types for highlight events */
10
+ export type AttributionRole = "author" | "editor" | "mention";
11
+ /** Sets attribution for a pubkey with optional role using 'p' tags */
12
+ export declare function addAttribution(attribution: HighlightAttribution): EventOperation;
13
+ /** Sets the context text for the highlight using a 'context' tag */
14
+ export declare function setContext(context: string): EventOperation;
15
+ /** Sets a comment for the highlight using a 'comment' tag to create a quote highlight */
16
+ export declare function setComment(comment: string): EventOperation;
17
+ /** Sets multiple attributions at once */
18
+ export declare function setAttributions(attributions: HighlightAttribution[]): EventOperation;
@@ -0,0 +1,47 @@
1
+ import { ensureMarkedProfilePointerTag } from "applesauce-core/helpers";
2
+ import { isEvent, isReplaceable } from "applesauce-core/helpers/event";
3
+ import { getAddressPointerForEvent, isAddressPointer, isEventPointer, } from "applesauce-core/helpers/pointers";
4
+ import { addAddressPointerTag, addEventPointerTag } from "applesauce-core/operations/tag/common";
5
+ import { includeSingletonTag, modifyPublicTags } from "applesauce-core/operations/tags";
6
+ /** Sets the content (highlighted text) for a highlight event */
7
+ export function setHighlightContent(content) {
8
+ return (draft) => ({ ...draft, content });
9
+ }
10
+ /** Sets the source event that was highlighted using an 'e' tag */
11
+ export function setSource(source) {
12
+ if (isEvent(source)) {
13
+ if (isReplaceable(source.kind))
14
+ return modifyPublicTags(addEventPointerTag(source, true), addAddressPointerTag(getAddressPointerForEvent(source), true));
15
+ else
16
+ return modifyPublicTags(addEventPointerTag(source, true));
17
+ }
18
+ else if (isAddressPointer(source)) {
19
+ return modifyPublicTags(addAddressPointerTag(source, true));
20
+ }
21
+ else if (isEventPointer(source))
22
+ return modifyPublicTags(addEventPointerTag(source, true));
23
+ else if (typeof source === "string")
24
+ return includeSingletonTag(["r", source]);
25
+ else
26
+ throw new Error("Invalid source");
27
+ }
28
+ /** Sets attribution for a pubkey with optional role using 'p' tags */
29
+ export function addAttribution(attribution) {
30
+ return modifyPublicTags((tags) => ensureMarkedProfilePointerTag(tags, attribution, attribution.role || "mention"));
31
+ }
32
+ /** Sets the context text for the highlight using a 'context' tag */
33
+ export function setContext(context) {
34
+ return includeSingletonTag(["context", context]);
35
+ }
36
+ /** Sets a comment for the highlight using a 'comment' tag to create a quote highlight */
37
+ export function setComment(comment) {
38
+ return includeSingletonTag(["comment", comment]);
39
+ }
40
+ /** Sets multiple attributions at once */
41
+ export function setAttributions(attributions) {
42
+ return modifyPublicTags(async (tags) => {
43
+ for (const attribution of attributions)
44
+ tags = ensureMarkedProfilePointerTag(tags, attribution, attribution.role || "mention");
45
+ return tags;
46
+ });
47
+ }