applesauce-common 0.0.0-next-20251209200210 → 0.0.0-next-20251231055351

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 (116) hide show
  1. package/README.md +45 -4
  2. package/dist/blueprints/__register__.d.ts +7 -0
  3. package/dist/blueprints/__register__.js +8 -0
  4. package/dist/blueprints/comment.d.ts +3 -2
  5. package/dist/blueprints/group-mangement.d.ts +25 -0
  6. package/dist/blueprints/group-mangement.js +40 -0
  7. package/dist/blueprints/index.d.ts +1 -0
  8. package/dist/blueprints/index.js +1 -0
  9. package/dist/blueprints/torrent.d.ts +7 -0
  10. package/dist/blueprints/torrent.js +5 -1
  11. package/dist/casts/article.d.ts +19 -0
  12. package/dist/casts/article.js +47 -0
  13. package/dist/casts/bookmarks.d.ts +35 -0
  14. package/dist/casts/bookmarks.js +91 -0
  15. package/dist/casts/cast.d.ts +30 -0
  16. package/dist/casts/cast.js +67 -0
  17. package/dist/casts/comment.d.ts +18 -0
  18. package/dist/casts/comment.js +54 -0
  19. package/dist/casts/groups.d.ts +19 -0
  20. package/dist/casts/groups.js +43 -0
  21. package/dist/casts/index.d.ts +18 -0
  22. package/dist/casts/index.js +18 -0
  23. package/dist/casts/mutes.d.ts +23 -0
  24. package/dist/casts/mutes.js +54 -0
  25. package/dist/casts/note.d.ts +25 -0
  26. package/dist/casts/note.js +76 -0
  27. package/dist/casts/profile.d.ts +24 -0
  28. package/dist/casts/profile.js +52 -0
  29. package/dist/casts/reaction.d.ts +17 -0
  30. package/dist/casts/reaction.js +46 -0
  31. package/dist/casts/relay-discovery.d.ts +29 -0
  32. package/dist/casts/relay-discovery.js +54 -0
  33. package/dist/casts/relay-lists.d.ts +33 -0
  34. package/dist/casts/relay-lists.js +72 -0
  35. package/dist/casts/relay-monitor.d.ts +21 -0
  36. package/dist/casts/relay-monitor.js +41 -0
  37. package/dist/casts/report.d.ts +31 -0
  38. package/dist/casts/report.js +74 -0
  39. package/dist/casts/share.d.ts +15 -0
  40. package/dist/casts/share.js +34 -0
  41. package/dist/casts/stream.d.ts +43 -0
  42. package/dist/casts/stream.js +116 -0
  43. package/dist/casts/torrent.d.ts +31 -0
  44. package/dist/casts/torrent.js +62 -0
  45. package/dist/casts/user.d.ts +40 -0
  46. package/dist/casts/user.js +181 -0
  47. package/dist/casts/zap.d.ts +17 -0
  48. package/dist/casts/zap.js +47 -0
  49. package/dist/helpers/bookmark.d.ts +18 -17
  50. package/dist/helpers/bookmark.js +36 -49
  51. package/dist/helpers/calendar-event.d.ts +7 -1
  52. package/dist/helpers/calendar-event.js +8 -10
  53. package/dist/helpers/channels.d.ts +1 -1
  54. package/dist/helpers/channels.js +5 -8
  55. package/dist/helpers/comment.d.ts +3 -1
  56. package/dist/helpers/comment.js +12 -2
  57. package/dist/helpers/encrypted-content-cache.js +23 -25
  58. package/dist/helpers/external-id.d.ts +32 -0
  59. package/dist/helpers/external-id.js +85 -0
  60. package/dist/helpers/file-metadata.d.ts +1 -4
  61. package/dist/helpers/file-metadata.js +1 -4
  62. package/dist/helpers/gift-wrap.js +11 -5
  63. package/dist/helpers/groups.d.ts +129 -7
  64. package/dist/helpers/groups.js +317 -15
  65. package/dist/helpers/index.d.ts +1 -1
  66. package/dist/helpers/index.js +1 -1
  67. package/dist/helpers/lists.d.ts +0 -1
  68. package/dist/helpers/lists.js +4 -5
  69. package/dist/helpers/mute.d.ts +14 -11
  70. package/dist/helpers/mute.js +9 -4
  71. package/dist/helpers/relay-list.d.ts +14 -0
  72. package/dist/helpers/relay-list.js +18 -0
  73. package/dist/helpers/reports.d.ts +4 -1
  74. package/dist/helpers/reports.js +14 -10
  75. package/dist/helpers/stream-chat.d.ts +4 -1
  76. package/dist/helpers/stream-chat.js +4 -1
  77. package/dist/index.d.ts +1 -0
  78. package/dist/index.js +1 -0
  79. package/dist/models/__register__.d.ts +5 -0
  80. package/dist/models/__register__.js +6 -0
  81. package/dist/models/blossom.d.ts +2 -2
  82. package/dist/models/blossom.js +1 -1
  83. package/dist/models/bookmarks.d.ts +3 -5
  84. package/dist/models/bookmarks.js +2 -10
  85. package/dist/models/channels.js +3 -9
  86. package/dist/models/comments.d.ts +3 -2
  87. package/dist/models/comments.js +19 -1
  88. package/dist/models/index.d.ts +3 -1
  89. package/dist/models/index.js +4 -1
  90. package/dist/models/mutes.d.ts +5 -5
  91. package/dist/models/{relays.js → relay-lists.js} +2 -1
  92. package/dist/models/shares.d.ts +3 -0
  93. package/dist/models/shares.js +5 -0
  94. package/dist/models/thread.js +30 -24
  95. package/dist/observable/cast-stream.d.ts +8 -0
  96. package/dist/observable/cast-stream.js +29 -0
  97. package/dist/observable/chainable.d.ts +50 -0
  98. package/dist/observable/chainable.js +79 -0
  99. package/dist/observable/index.d.ts +2 -0
  100. package/dist/observable/index.js +2 -0
  101. package/dist/operations/comment.d.ts +3 -2
  102. package/dist/operations/comment.js +19 -5
  103. package/dist/operations/group.d.ts +14 -1
  104. package/dist/operations/group.js +42 -4
  105. package/dist/operations/index.d.ts +1 -1
  106. package/dist/operations/index.js +1 -1
  107. package/dist/operations/tag/bookmarks.d.ts +3 -2
  108. package/dist/operations/tag/bookmarks.js +34 -14
  109. package/dist/operations/torrent.d.ts +2 -0
  110. package/dist/operations/torrent.js +4 -0
  111. package/dist/register.d.ts +2 -11
  112. package/dist/register.js +2 -11
  113. package/package.json +12 -2
  114. package/dist/helpers/mailboxes.d.ts +0 -7
  115. package/dist/helpers/mailboxes.js +0 -49
  116. /package/dist/models/{relays.d.ts → relay-lists.d.ts} +0 -0
@@ -1,11 +1,25 @@
1
- import { createCommentTagsForEvent } from "../helpers/comment.js";
2
- /** Sets the necessary tags for a NIP-22 comment event to point to a parent event */
1
+ import { isEvent } from "applesauce-core/helpers/event";
2
+ import { COMMENT_KIND, createCommentTagsForEvent, createCommentTagsFromCommentPointer, } from "../helpers/comment.js";
3
+ /** Sets the necessary tags for a NIP-22 comment event to point to a parent event or pointer */
3
4
  export function setParent(parent) {
4
5
  return async (draft, ctx) => {
5
- const relayHint = await ctx.getEventRelayHint?.(parent.id);
6
6
  let tags = Array.from(draft.tags);
7
- // add NIP-22 comment tags
8
- tags.push(...createCommentTagsForEvent(parent, relayHint));
7
+ // If parent is a CommentPointer (not a NostrEvent), handle it directly
8
+ if (!isEvent(parent)) {
9
+ if (parent.kind === COMMENT_KIND)
10
+ throw new Error("Comment pointer cannot be a comment kind. please pass the full nip-22 comment event");
11
+ // For CommentPointer, treat as root comment: both root and reply tags point to the same pointer
12
+ // Note: relay hints are already included in the pointer if available
13
+ // Add root tags (capitalized)
14
+ tags.push(...createCommentTagsFromCommentPointer(parent, true));
15
+ // Add reply tags (lowercase)
16
+ tags.push(...createCommentTagsFromCommentPointer(parent, false));
17
+ }
18
+ else {
19
+ // If parent is a NostrEvent, use existing logic
20
+ const relayHint = await ctx.getEventRelayHint?.(parent.id);
21
+ tags.push(...createCommentTagsForEvent(parent, relayHint));
22
+ }
9
23
  return { ...draft, tags };
10
24
  };
11
25
  }
@@ -1,6 +1,7 @@
1
1
  import { EventOperation } from "applesauce-core/event-factory";
2
+ import { EventPointer, ProfilePointer } from "applesauce-core/helpers";
2
3
  import { NostrEvent } from "applesauce-core/helpers/event";
3
- import { GroupPointer } from "../helpers/groups.js";
4
+ import { GroupMetadata, GroupPointer } from "../helpers/groups.js";
4
5
  /** Adds a "group" tag to a list */
5
6
  export declare function addGroupTag(group: GroupPointer): EventOperation;
6
7
  /** Removes a "group" tag from a list */
@@ -9,3 +10,15 @@ export declare function removeGroupTag(group: GroupPointer): EventOperation;
9
10
  export declare function setGroupPointer(group: GroupPointer): EventOperation;
10
11
  /** Adds "previous" tags for group messages */
11
12
  export declare function addPreviousRefs(previous: NostrEvent[], count?: number): EventOperation;
13
+ /** Sets tags for a join request (kind 9021) */
14
+ export declare function setJoinRequestTags(group: GroupPointer, inviteCode?: string): EventOperation;
15
+ /** Sets tags for a leave request (kind 9022) */
16
+ export declare function setLeaveRequestTags(group: GroupPointer): EventOperation;
17
+ /** Sets tags for put user (kind 9000) */
18
+ export declare function setPutUserTags(user: string | ProfilePointer, roles?: string[]): EventOperation;
19
+ /** Sets tags for remove user (kind 9001) */
20
+ export declare function setRemoveUserTags(user: string | ProfilePointer): EventOperation;
21
+ /** Sets tags for edit metadata (kind 9002) */
22
+ export declare function setEditMetadataTags(fields: Partial<GroupMetadata>): EventOperation;
23
+ /** Sets tags for delete event (kind 9005) */
24
+ export declare function setDeleteEventTags(event: string | EventPointer | NostrEvent): EventOperation;
@@ -1,6 +1,18 @@
1
- import { ensureNamedValueTag } from "applesauce-core/helpers";
2
- import { includeSingletonTag, modifyPublicTags } from "applesauce-core/operations/tags";
3
- import { createGroupHTagFromGroupPointer, createGroupTagFromGroupPointer } from "../helpers/groups.js";
1
+ import { ensureNamedValueTag, ensureWebSocketURL, fillAndTrimTag, } from "applesauce-core/helpers";
2
+ import { addEventPointerTag, addNameValueTag, addProfilePointerTag, setSingletonTag, } from "applesauce-core/operations/tag/common";
3
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
4
+ /** Creates a "h" tag for chat messages from a {@link GroupPointer} */
5
+ function createGroupHTagFromGroupPointer(group) {
6
+ return fillAndTrimTag(["h", group.id, ensureWebSocketURL(group.relay)]);
7
+ }
8
+ /** Creates a "group" tag from a {@link GroupPointer} */
9
+ function createGroupTagFromGroupPointer(group) {
10
+ return fillAndTrimTag(["group", group.id, ensureWebSocketURL(group.relay), group.name], 3);
11
+ }
12
+ /** A tag operation for setting the "h" tag for a group */
13
+ function setGroupHTag(group) {
14
+ return setSingletonTag(createGroupHTagFromGroupPointer(group));
15
+ }
4
16
  /** Adds a "group" tag to a list */
5
17
  export function addGroupTag(group) {
6
18
  return modifyPublicTags((tags) => {
@@ -15,7 +27,7 @@ export function removeGroupTag(group) {
15
27
  }
16
28
  /** Sets the "h" tag for NIP-29 group messages or other events */
17
29
  export function setGroupPointer(group) {
18
- return includeSingletonTag(createGroupHTagFromGroupPointer(group), true);
30
+ return modifyPublicTags(setGroupHTag(group));
19
31
  }
20
32
  /** Adds "previous" tags for group messages */
21
33
  export function addPreviousRefs(previous, count = 6) {
@@ -32,3 +44,29 @@ export function addPreviousRefs(previous, count = 6) {
32
44
  return { ...draft, tags };
33
45
  };
34
46
  }
47
+ /** Sets tags for a join request (kind 9021) */
48
+ export function setJoinRequestTags(group, inviteCode) {
49
+ return modifyPublicTags(setGroupHTag(group), inviteCode ? addNameValueTag(["code", inviteCode]) : undefined);
50
+ }
51
+ /** Sets tags for a leave request (kind 9022) */
52
+ export function setLeaveRequestTags(group) {
53
+ return modifyPublicTags(setGroupHTag(group));
54
+ }
55
+ /** Sets tags for put user (kind 9000) */
56
+ export function setPutUserTags(user, roles) {
57
+ const pubkey = typeof user === "string" ? user : user.pubkey;
58
+ const tag = roles && roles.length > 0 ? ["p", pubkey, ...roles] : ["p", pubkey];
59
+ return modifyPublicTags(addNameValueTag(tag));
60
+ }
61
+ /** Sets tags for remove user (kind 9001) */
62
+ export function setRemoveUserTags(user) {
63
+ return modifyPublicTags(addProfilePointerTag(user));
64
+ }
65
+ /** Sets tags for edit metadata (kind 9002) */
66
+ export function setEditMetadataTags(fields) {
67
+ return modifyPublicTags(fields.name !== undefined ? setSingletonTag(["name", fields.name]) : undefined, fields.picture !== undefined ? setSingletonTag(["picture", fields.picture]) : undefined, fields.about !== undefined ? setSingletonTag(["about", fields.about]) : undefined, fields.isPublic ? setSingletonTag(["public"]) : undefined, fields.isPrivate ? setSingletonTag(["private"]) : undefined, fields.isOpen ? setSingletonTag(["open"]) : undefined, fields.isClosed ? setSingletonTag(["closed"]) : undefined);
68
+ }
69
+ /** Sets tags for delete event (kind 9005) */
70
+ export function setDeleteEventTags(event) {
71
+ return modifyPublicTags(addEventPointerTag(event));
72
+ }
@@ -8,7 +8,7 @@ export * as Comment from "./comment.js";
8
8
  export * as FileMetadata from "./file-metadata.js";
9
9
  export * as Geohash from "./geohash.js";
10
10
  export * as GiftWrap from "./gift-wrap.js";
11
- export * as Groups from "./group.js";
11
+ export * as Group from "./group.js";
12
12
  export * as Hashtags from "./hashtags.js";
13
13
  export * as Highlight from "./highlight.js";
14
14
  export * as LegacyMessage from "./legacy-message.js";
@@ -8,7 +8,7 @@ export * as Comment from "./comment.js";
8
8
  export * as FileMetadata from "./file-metadata.js";
9
9
  export * as Geohash from "./geohash.js";
10
10
  export * as GiftWrap from "./gift-wrap.js";
11
- export * as Groups from "./group.js";
11
+ export * as Group from "./group.js";
12
12
  export * as Hashtags from "./hashtags.js";
13
13
  export * as Highlight from "./highlight.js";
14
14
  export * as LegacyMessage from "./legacy-message.js";
@@ -1,6 +1,7 @@
1
1
  import { TagOperation } from "applesauce-core/event-factory";
2
2
  import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { AddressPointer, EventPointer } from "applesauce-core/helpers/pointers";
3
4
  /** Adds an "e" or "a" tag to a bookmark list or set */
4
- export declare function addEventBookmarkTag(event: NostrEvent): TagOperation;
5
+ export declare function addEventBookmarkTag(event: NostrEvent | EventPointer | AddressPointer): TagOperation;
5
6
  /** Removes an "e" or "a" tag from a bookmark list or set */
6
- export declare function removeEventBookmarkTag(event: NostrEvent): TagOperation;
7
+ export declare function removeEventBookmarkTag(event: NostrEvent | EventPointer | AddressPointer): TagOperation;
@@ -1,22 +1,42 @@
1
- import { tagPipe } from "applesauce-core/helpers";
2
- import { kinds } from "applesauce-core/helpers/event";
3
- import { getAddressPointerForEvent } from "applesauce-core/helpers/pointers";
1
+ import { isEvent, isReplaceable, kinds } from "applesauce-core/helpers/event";
2
+ import { isAddressPointer, isEventPointer } from "applesauce-core/helpers/pointers";
4
3
  import { addAddressPointerTag, addEventPointerTag, removeAddressPointerTag, removeEventPointerTag, } from "applesauce-core/operations/tag/common";
5
4
  /** Adds an "e" or "a" tag to a bookmark list or set */
6
5
  export function addEventBookmarkTag(event) {
7
- if (event.kind !== kinds.ShortTextNote && event.kind !== kinds.LongFormArticle)
6
+ // Validate event kind if event or address pointer
7
+ if ((isEvent(event) || isAddressPointer(event)) &&
8
+ event.kind !== kinds.ShortTextNote &&
9
+ event.kind !== kinds.LongFormArticle)
8
10
  throw new Error(`Event kind (${event.kind}) cant not be added to bookmarks`);
9
- const address = getAddressPointerForEvent(event);
10
- return address ? addAddressPointerTag(address) : addEventPointerTag(event.id);
11
+ if (isEvent(event)) {
12
+ // Add "a" tag for replaceable articles
13
+ if (isReplaceable(event.kind))
14
+ return addAddressPointerTag(event);
15
+ // Add "e" tag for non-replaceable notes
16
+ else
17
+ return addEventPointerTag(event);
18
+ }
19
+ // "e" tags for note event pointers
20
+ else if (isEventPointer(event))
21
+ return addEventPointerTag(event);
22
+ // "a" tags for address pointers
23
+ else
24
+ return addAddressPointerTag(event);
11
25
  }
12
26
  /** Removes an "e" or "a" tag from a bookmark list or set */
13
27
  export function removeEventBookmarkTag(event) {
14
- if (event.kind !== kinds.ShortTextNote && event.kind !== kinds.LongFormArticle)
15
- throw new Error(`Event kind (${event.kind}) cant not be added to bookmarks`);
16
- const address = getAddressPointerForEvent(event);
17
- return tagPipe(
18
- // Remove address pointer if it exists
19
- address ? removeAddressPointerTag(address) : undefined,
20
- // Always remove event pointer
21
- removeEventPointerTag(event.id));
28
+ if (isEvent(event)) {
29
+ // Remove "a" tag for replaceable articles
30
+ if (isReplaceable(event.kind))
31
+ return removeAddressPointerTag(event);
32
+ // Remove "e" tag for non-replaceable notes
33
+ else
34
+ return removeEventPointerTag(event);
35
+ }
36
+ // "e" tags for note event pointers
37
+ else if (isEventPointer(event))
38
+ return removeEventPointerTag(event);
39
+ // "a" tags for address pointers
40
+ else
41
+ return removeAddressPointerTag(event);
22
42
  }
@@ -22,6 +22,8 @@ export declare function addTorrentSearchTag(tag: string): EventOperation;
22
22
  export declare function removeTorrentSearchTag(tag: string): EventOperation;
23
23
  /** Sets the category path (tcat) */
24
24
  export declare function setTorrentCategoryPath(categoryPath: string): EventOperation;
25
+ /** Removes the category path (tcat) */
26
+ export declare function removeTorrentCategoryPath(): EventOperation;
25
27
  /** Adds an external identifier */
26
28
  export declare function addTorrentExternalIdentifier(identifier: TorrentExternalIdentifier): EventOperation;
27
29
  /**
@@ -48,6 +48,10 @@ export function removeTorrentSearchTag(tag) {
48
48
  export function setTorrentCategoryPath(categoryPath) {
49
49
  return modifyPublicTags(setSingletonTag(["i", `tcat:${categoryPath}`]));
50
50
  }
51
+ /** Removes the category path (tcat) */
52
+ export function removeTorrentCategoryPath() {
53
+ return modifyPublicTags((tags) => tags.filter((t) => !(t[0] === "i" && t[1]?.startsWith("tcat:"))));
54
+ }
51
55
  /** Adds an external identifier */
52
56
  export function addTorrentExternalIdentifier(identifier) {
53
57
  return modifyPublicTags(addNameValueTag(["i", identifier.identifier], false));
@@ -1,11 +1,2 @@
1
- import "./models/blossom.js";
2
- import "./models/mutes.js";
3
- import "./models/reactions.js";
4
- import "./models/comments.js";
5
- import "./models/thread.js";
6
- import "./blueprints/comment.js";
7
- import "./blueprints/delete.js";
8
- import "./blueprints/note.js";
9
- import "./blueprints/reaction.js";
10
- import "./blueprints/share.js";
11
- import "./blueprints/poll.js";
1
+ import "./models/__register__.js";
2
+ import "./blueprints/__register__.js";
package/dist/register.js CHANGED
@@ -1,13 +1,4 @@
1
1
  // Import models that should register with the event store
2
- import "./models/blossom.js";
3
- import "./models/mutes.js";
4
- import "./models/reactions.js";
5
- import "./models/comments.js";
6
- import "./models/thread.js";
2
+ import "./models/__register__.js";
7
3
  // Import blueprints that should register with the event factory
8
- import "./blueprints/comment.js";
9
- import "./blueprints/delete.js";
10
- import "./blueprints/note.js";
11
- import "./blueprints/reaction.js";
12
- import "./blueprints/share.js";
13
- import "./blueprints/poll.js";
4
+ import "./blueprints/__register__.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-common",
3
- "version": "0.0.0-next-20251209200210",
3
+ "version": "0.0.0-next-20251231055351",
4
4
  "description": "Common NIP-specific helpers and models for applesauce",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -69,11 +69,21 @@
69
69
  "import": "./dist/observable/*.js",
70
70
  "require": "./dist/observable/*.js",
71
71
  "types": "./dist/observable/*.d.ts"
72
+ },
73
+ "./casts": {
74
+ "import": "./dist/casts/index.js",
75
+ "require": "./dist/casts/index.js",
76
+ "types": "./dist/casts/index.d.ts"
77
+ },
78
+ "./casts/*": {
79
+ "import": "./dist/casts/*.js",
80
+ "require": "./dist/casts/*.js",
81
+ "types": "./dist/casts/*.d.ts"
72
82
  }
73
83
  },
74
84
  "dependencies": {
75
85
  "@scure/base": "^1.2.4",
76
- "applesauce-core": "0.0.0-next-20251209200210",
86
+ "applesauce-core": "0.0.0-next-20251231055351",
77
87
  "hash-sum": "^2.0.0",
78
88
  "light-bolt11-decoder": "^3.2.0",
79
89
  "rxjs": "^7.8.1"
@@ -1,7 +0,0 @@
1
- import { NostrEvent } from "applesauce-core/helpers/event";
2
- export declare const MailboxesInboxesSymbol: unique symbol;
3
- export declare const MailboxesOutboxesSymbol: unique symbol;
4
- /** Parses a 10002 event and stores the inboxes in the event using the {@link MailboxesInboxesSymbol} symbol */
5
- export declare function getInboxes(event: NostrEvent): string[];
6
- /** Parses a 10002 event and stores the outboxes in the event using the {@link MailboxesOutboxesSymbol} symbol */
7
- export declare function getOutboxes(event: NostrEvent): string[];
@@ -1,49 +0,0 @@
1
- import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
- import { isSafeRelayURL } from "applesauce-core/helpers/relays";
3
- import { isRTag } from "applesauce-core/helpers/tags";
4
- import { normalizeURL } from "applesauce-core/helpers/url";
5
- export const MailboxesInboxesSymbol = Symbol.for("mailboxes-inboxes");
6
- export const MailboxesOutboxesSymbol = Symbol.for("mailboxes-outboxes");
7
- /** Parses a 10002 event and stores the inboxes in the event using the {@link MailboxesInboxesSymbol} symbol */
8
- export function getInboxes(event) {
9
- return getOrComputeCachedValue(event, MailboxesInboxesSymbol, () => {
10
- const inboxes = [];
11
- for (const tag of event.tags) {
12
- if (!isRTag(tag))
13
- continue;
14
- try {
15
- const [, url, mode] = tag;
16
- if (url && isSafeRelayURL(url) && !inboxes.includes(url) && (mode === "read" || mode === undefined)) {
17
- inboxes.push(normalizeURL(url));
18
- }
19
- }
20
- catch {
21
- // Ignore invalid url tags
22
- }
23
- }
24
- return inboxes;
25
- });
26
- }
27
- /** Parses a 10002 event and stores the outboxes in the event using the {@link MailboxesOutboxesSymbol} symbol */
28
- export function getOutboxes(event) {
29
- return getOrComputeCachedValue(event, MailboxesOutboxesSymbol, () => {
30
- const outboxes = [];
31
- for (const tag of event.tags) {
32
- if (!isRTag(tag))
33
- continue;
34
- try {
35
- const [name, url, mode] = tag;
36
- if (name === "r" &&
37
- isSafeRelayURL(url) &&
38
- !outboxes.includes(url) &&
39
- (mode === "write" || mode === undefined)) {
40
- outboxes.push(normalizeURL(url));
41
- }
42
- }
43
- catch {
44
- // Ignore invalid url tags
45
- }
46
- }
47
- return outboxes;
48
- });
49
- }
File without changes