applesauce-common 6.1.0 → 7.0.0

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 (231) hide show
  1. package/README.md +1 -0
  2. package/dist/casts/_circular-import.d.ts +3 -0
  3. package/dist/casts/_circular-import.js +3 -0
  4. package/dist/casts/app-handler.d.ts +56 -0
  5. package/dist/casts/app-handler.js +105 -0
  6. package/dist/casts/app-recommendation.d.ts +26 -0
  7. package/dist/casts/app-recommendation.js +41 -0
  8. package/dist/casts/external-identities.d.ts +9 -0
  9. package/dist/casts/external-identities.js +14 -0
  10. package/dist/casts/forum-thread.d.ts +17 -0
  11. package/dist/casts/forum-thread.js +31 -0
  12. package/dist/casts/git-issue.d.ts +18 -0
  13. package/dist/casts/git-issue.js +26 -0
  14. package/dist/casts/git-patch.d.ts +49 -0
  15. package/dist/casts/git-patch.js +88 -0
  16. package/dist/casts/git-pull-request.d.ts +67 -0
  17. package/dist/casts/git-pull-request.js +122 -0
  18. package/dist/casts/git-repository.d.ts +9 -0
  19. package/dist/casts/git-repository.js +16 -0
  20. package/dist/casts/git-thread.d.ts +33 -0
  21. package/dist/casts/git-thread.js +65 -0
  22. package/dist/casts/index.d.ts +11 -0
  23. package/dist/casts/index.js +11 -0
  24. package/dist/casts/napplet.d.ts +98 -0
  25. package/dist/casts/napplet.js +196 -0
  26. package/dist/casts/note.d.ts +8 -0
  27. package/dist/casts/note.js +21 -1
  28. package/dist/casts/nsite.d.ts +134 -0
  29. package/dist/casts/nsite.js +249 -0
  30. package/dist/casts/profile.d.ts +20 -0
  31. package/dist/casts/profile.js +30 -0
  32. package/dist/casts/reaction.d.ts +1 -1
  33. package/dist/casts/relay-discovery.d.ts +4 -0
  34. package/dist/casts/relay-discovery.js +9 -1
  35. package/dist/casts/report.d.ts +28 -15
  36. package/dist/casts/report.js +42 -19
  37. package/dist/casts/share.d.ts +1 -1
  38. package/dist/casts/torrent.d.ts +5 -0
  39. package/dist/casts/torrent.js +8 -1
  40. package/dist/casts/trusted-assertions.d.ts +4 -2
  41. package/dist/casts/trusted-assertions.js +20 -19
  42. package/dist/casts/user-status.d.ts +33 -0
  43. package/dist/casts/user-status.js +69 -0
  44. package/dist/casts/user.d.ts +7 -0
  45. package/dist/casts/user.js +20 -1
  46. package/dist/factories/app-handler.d.ts +31 -0
  47. package/dist/factories/app-handler.js +50 -0
  48. package/dist/factories/app-recommendation.d.ts +21 -0
  49. package/dist/factories/app-recommendation.js +28 -0
  50. package/dist/factories/chat-message.d.ts +37 -0
  51. package/dist/factories/chat-message.js +56 -0
  52. package/dist/factories/comment.d.ts +8 -7
  53. package/dist/factories/comment.js +2 -2
  54. package/dist/factories/external-identities.d.ts +17 -0
  55. package/dist/factories/external-identities.js +28 -0
  56. package/dist/factories/forum-thread.d.ts +34 -0
  57. package/dist/factories/forum-thread.js +50 -0
  58. package/dist/factories/git-applied-status.d.ts +39 -0
  59. package/dist/factories/git-applied-status.js +53 -0
  60. package/dist/factories/git-closed-status.d.ts +18 -0
  61. package/dist/factories/git-closed-status.js +24 -0
  62. package/dist/factories/git-draft-status.d.ts +18 -0
  63. package/dist/factories/git-draft-status.js +24 -0
  64. package/dist/factories/git-issue.d.ts +19 -0
  65. package/dist/factories/git-issue.js +25 -0
  66. package/dist/factories/git-open-status.d.ts +18 -0
  67. package/dist/factories/git-open-status.js +22 -0
  68. package/dist/factories/git-patch.d.ts +59 -0
  69. package/dist/factories/git-patch.js +102 -0
  70. package/dist/factories/git-pull-request-update.d.ts +23 -0
  71. package/dist/factories/git-pull-request-update.js +33 -0
  72. package/dist/factories/git-pull-request.d.ts +39 -0
  73. package/dist/factories/git-pull-request.js +64 -0
  74. package/dist/factories/index.d.ts +23 -0
  75. package/dist/factories/index.js +23 -0
  76. package/dist/factories/internal/git-pull-request.d.ts +19 -0
  77. package/dist/factories/internal/git-pull-request.js +26 -0
  78. package/dist/factories/internal/git-status.d.ts +11 -0
  79. package/dist/factories/internal/git-status.js +12 -0
  80. package/dist/factories/internal/git-thread.d.ts +19 -0
  81. package/dist/factories/internal/git-thread.js +29 -0
  82. package/dist/factories/internal/napplet-manifest.d.ts +52 -0
  83. package/dist/factories/internal/napplet-manifest.js +85 -0
  84. package/dist/factories/internal/nsite-manifest.d.ts +45 -0
  85. package/dist/factories/internal/nsite-manifest.js +68 -0
  86. package/dist/factories/legacy-message.d.ts +2 -0
  87. package/dist/factories/legacy-message.js +9 -2
  88. package/dist/factories/named-napplet.d.ts +20 -0
  89. package/dist/factories/named-napplet.js +30 -0
  90. package/dist/factories/named-nsite.d.ts +28 -0
  91. package/dist/factories/named-nsite.js +53 -0
  92. package/dist/factories/napplet-snapshot.d.ts +18 -0
  93. package/dist/factories/napplet-snapshot.js +38 -0
  94. package/dist/factories/nostr-web-token.d.ts +39 -0
  95. package/dist/factories/nostr-web-token.js +95 -0
  96. package/dist/factories/nsite-snapshot.d.ts +18 -0
  97. package/dist/factories/nsite-snapshot.js +29 -0
  98. package/dist/factories/reaction.d.ts +3 -2
  99. package/dist/factories/report.d.ts +48 -0
  100. package/dist/factories/report.js +66 -0
  101. package/dist/factories/root-napplet.d.ts +18 -0
  102. package/dist/factories/root-napplet.js +24 -0
  103. package/dist/factories/root-nsite.d.ts +23 -0
  104. package/dist/factories/root-nsite.js +44 -0
  105. package/dist/factories/torrent.d.ts +24 -10
  106. package/dist/factories/torrent.js +48 -44
  107. package/dist/factories/trusted-provider-list.d.ts +23 -0
  108. package/dist/factories/trusted-provider-list.js +39 -0
  109. package/dist/factories/user-status.d.ts +26 -0
  110. package/dist/factories/user-status.js +52 -0
  111. package/dist/helpers/app-data.js +15 -7
  112. package/dist/helpers/app-handler.d.ts +43 -6
  113. package/dist/helpers/app-handler.js +53 -3
  114. package/dist/helpers/app-recommendation.d.ts +24 -0
  115. package/dist/helpers/app-recommendation.js +30 -0
  116. package/dist/helpers/bookmark.js +5 -2
  117. package/dist/helpers/comment.d.ts +11 -5
  118. package/dist/helpers/comment.js +7 -1
  119. package/dist/helpers/content.d.ts +3 -1
  120. package/dist/helpers/emoji-pack.js +11 -6
  121. package/dist/helpers/emoji.d.ts +2 -2
  122. package/dist/helpers/encrypted-content-cache.js +18 -1
  123. package/dist/helpers/external-id.d.ts +1 -0
  124. package/dist/helpers/external-id.js +21 -46
  125. package/dist/helpers/external-identities.d.ts +29 -0
  126. package/dist/helpers/external-identities.js +52 -0
  127. package/dist/helpers/file-metadata.js +5 -6
  128. package/dist/helpers/forum-thread.d.ts +10 -0
  129. package/dist/helpers/forum-thread.js +10 -0
  130. package/dist/helpers/gift-wrap.d.ts +40 -15
  131. package/dist/helpers/gift-wrap.js +110 -33
  132. package/dist/helpers/git-issue.d.ts +13 -0
  133. package/dist/helpers/git-issue.js +19 -0
  134. package/dist/helpers/git-patch.d.ts +41 -0
  135. package/dist/helpers/git-patch.js +73 -0
  136. package/dist/helpers/git-pull-request.d.ts +57 -0
  137. package/dist/helpers/git-pull-request.js +111 -0
  138. package/dist/helpers/git-repository.d.ts +4 -0
  139. package/dist/helpers/git-repository.js +16 -0
  140. package/dist/helpers/git-status.d.ts +44 -0
  141. package/dist/helpers/git-status.js +93 -0
  142. package/dist/helpers/git.d.ts +2 -0
  143. package/dist/helpers/git.js +4 -0
  144. package/dist/helpers/groups.d.ts +5 -2
  145. package/dist/helpers/groups.js +40 -18
  146. package/dist/helpers/hashtag.d.ts +4 -2
  147. package/dist/helpers/index.d.ts +11 -0
  148. package/dist/helpers/index.js +11 -0
  149. package/dist/helpers/lists.js +14 -2
  150. package/dist/helpers/lnurl.js +1 -1
  151. package/dist/helpers/mute.js +18 -7
  152. package/dist/helpers/napplet.d.ts +89 -0
  153. package/dist/helpers/napplet.js +144 -0
  154. package/dist/helpers/nostr-web-token.d.ts +54 -0
  155. package/dist/helpers/nostr-web-token.js +124 -0
  156. package/dist/helpers/nsite.d.ts +90 -0
  157. package/dist/helpers/nsite.js +217 -0
  158. package/dist/helpers/relay-discovery.d.ts +4 -0
  159. package/dist/helpers/relay-discovery.js +8 -0
  160. package/dist/helpers/reports.d.ts +35 -0
  161. package/dist/helpers/reports.js +36 -5
  162. package/dist/helpers/threading.d.ts +4 -2
  163. package/dist/helpers/torrent.d.ts +9 -6
  164. package/dist/helpers/torrent.js +23 -15
  165. package/dist/helpers/trusted-assertions.d.ts +7 -0
  166. package/dist/helpers/trusted-assertions.js +41 -2
  167. package/dist/helpers/user-status.d.ts +13 -1
  168. package/dist/helpers/user-status.js +15 -0
  169. package/dist/models/app-handler.d.ts +21 -0
  170. package/dist/models/app-handler.js +47 -0
  171. package/dist/models/git.d.ts +34 -0
  172. package/dist/models/git.js +144 -0
  173. package/dist/models/index.d.ts +3 -0
  174. package/dist/models/index.js +3 -0
  175. package/dist/models/nsite.d.ts +22 -0
  176. package/dist/models/nsite.js +67 -0
  177. package/dist/models/thread.d.ts +4 -1
  178. package/dist/models/thread.js +34 -5
  179. package/dist/models/user-status.d.ts +8 -4
  180. package/dist/models/user-status.js +16 -22
  181. package/dist/observable/filter-timeline-by-mutes.d.ts +1 -1
  182. package/dist/observable/filter-timeline-by-mutes.js +5 -1
  183. package/dist/operations/app-handler.d.ts +24 -0
  184. package/dist/operations/app-handler.js +58 -0
  185. package/dist/operations/app-recommendation.d.ts +13 -0
  186. package/dist/operations/app-recommendation.js +40 -0
  187. package/dist/operations/calendar-event.js +3 -2
  188. package/dist/operations/chat-message.d.ts +9 -0
  189. package/dist/operations/chat-message.js +12 -0
  190. package/dist/operations/client.d.ts +1 -4
  191. package/dist/operations/client.js +1 -23
  192. package/dist/operations/comment.d.ts +9 -3
  193. package/dist/operations/comment.js +12 -9
  194. package/dist/operations/external-identities.d.ts +8 -0
  195. package/dist/operations/external-identities.js +23 -0
  196. package/dist/operations/forum-thread.d.ts +3 -0
  197. package/dist/operations/forum-thread.js +6 -0
  198. package/dist/operations/gift-wrap.js +38 -14
  199. package/dist/operations/git-issue.d.ts +18 -0
  200. package/dist/operations/git-issue.js +31 -0
  201. package/dist/operations/git-patch.d.ts +30 -0
  202. package/dist/operations/git-patch.js +75 -0
  203. package/dist/operations/git-pull-request.d.ts +29 -0
  204. package/dist/operations/git-pull-request.js +74 -0
  205. package/dist/operations/git-repository.js +4 -4
  206. package/dist/operations/git-status.d.ts +28 -0
  207. package/dist/operations/git-status.js +116 -0
  208. package/dist/operations/git-thread.d.ts +13 -0
  209. package/dist/operations/git-thread.js +39 -0
  210. package/dist/operations/index.d.ts +16 -0
  211. package/dist/operations/index.js +16 -0
  212. package/dist/operations/internal/git-commits.d.ts +2 -0
  213. package/dist/operations/internal/git-commits.js +16 -0
  214. package/dist/operations/napplet.d.ts +51 -0
  215. package/dist/operations/napplet.js +121 -0
  216. package/dist/operations/nostr-web-token.d.ts +27 -0
  217. package/dist/operations/nostr-web-token.js +58 -0
  218. package/dist/operations/nsite.d.ts +51 -0
  219. package/dist/operations/nsite.js +112 -0
  220. package/dist/operations/reaction.d.ts +12 -2
  221. package/dist/operations/reaction.js +1 -1
  222. package/dist/operations/report.d.ts +33 -0
  223. package/dist/operations/report.js +60 -0
  224. package/dist/operations/stream.js +5 -4
  225. package/dist/operations/torrent.d.ts +1 -4
  226. package/dist/operations/torrent.js +24 -11
  227. package/dist/operations/trusted-providers.d.ts +14 -0
  228. package/dist/operations/trusted-providers.js +33 -0
  229. package/dist/operations/user-status.d.ts +11 -0
  230. package/dist/operations/user-status.js +29 -0
  231. package/package.json +10 -10
@@ -0,0 +1,93 @@
1
+ import { isHexKey } from "applesauce-core/helpers/string";
2
+ import { isGitCommitId } from "./git.js";
3
+ /** The NIP-34 open status event kind */
4
+ export const GIT_STATUS_OPEN_KIND = 1630;
5
+ /** The NIP-34 applied status event kind */
6
+ export const GIT_STATUS_APPLIED_KIND = 1631;
7
+ /** The NIP-34 closed status event kind */
8
+ export const GIT_STATUS_CLOSED_KIND = 1632;
9
+ /** The NIP-34 draft status event kind */
10
+ export const GIT_STATUS_DRAFT_KIND = 1633;
11
+ /** All NIP-34 status event kinds */
12
+ export const GIT_STATUS_KINDS = [
13
+ GIT_STATUS_OPEN_KIND,
14
+ GIT_STATUS_APPLIED_KIND,
15
+ GIT_STATUS_CLOSED_KIND,
16
+ GIT_STATUS_DRAFT_KIND,
17
+ ];
18
+ /** Map of status types to event kinds */
19
+ export const GIT_STATUS_KIND_MAP = {
20
+ open: GIT_STATUS_OPEN_KIND,
21
+ applied: GIT_STATUS_APPLIED_KIND,
22
+ closed: GIT_STATUS_CLOSED_KIND,
23
+ draft: GIT_STATUS_DRAFT_KIND,
24
+ };
25
+ /** Checks if an event is a valid NIP-34 status event with a root `e` tag */
26
+ export function isValidGitStatus(event) {
27
+ return !!event && GIT_STATUS_KINDS.includes(event.kind) && !!getGitStatusRootId(event);
28
+ }
29
+ export function getGitStatusType(event) {
30
+ switch (event.kind) {
31
+ case GIT_STATUS_OPEN_KIND:
32
+ return "open";
33
+ case GIT_STATUS_APPLIED_KIND:
34
+ return "applied";
35
+ case GIT_STATUS_CLOSED_KIND:
36
+ return "closed";
37
+ case GIT_STATUS_DRAFT_KIND:
38
+ return "draft";
39
+ default:
40
+ return undefined;
41
+ }
42
+ }
43
+ /** Returns the id of the issue, pull request or root patch a status event applies to */
44
+ export function getGitStatusRootId(event) {
45
+ const tag = event.tags.find((t) => t[0] === "e" && t[3] === "root") ?? event.tags.find((t) => t[0] === "e" && !t[3]);
46
+ return tag?.[1] && isHexKey(tag[1]) ? tag[1] : undefined;
47
+ }
48
+ /** Returns the ids of the patches applied or merged by a status event from the `q` tags */
49
+ export function getGitStatusAppliedPatchIds(event) {
50
+ return event.tags.filter((t) => t[0] === "q" && t[1] && isHexKey(t[1])).map((t) => t[1]);
51
+ }
52
+ /** Returns the merge commit id from the `merge-commit` tag */
53
+ export function getGitStatusMergeCommit(event) {
54
+ return event.tags.find((t) => t[0] === "merge-commit")?.[1] || undefined;
55
+ }
56
+ /**
57
+ * Returns the latest status event from the root author or a maintainer
58
+ * @param maintainers Pubkeys allowed to set the status in addition to the root author
59
+ */
60
+ export function getGitCurrentStatusEvent(root, statuses, maintainers = []) {
61
+ let latest;
62
+ for (const status of statuses) {
63
+ if (!isValidGitStatus(status) || getGitStatusRootId(status) !== root.id)
64
+ continue;
65
+ if (status.pubkey !== root.pubkey && !maintainers.includes(status.pubkey))
66
+ continue;
67
+ if (!latest ||
68
+ status.created_at > latest.created_at ||
69
+ (status.created_at === latest.created_at && status.id < latest.id))
70
+ latest = status;
71
+ }
72
+ return latest;
73
+ }
74
+ /**
75
+ * Returns the current status of an issue, patch or pull request, defaulting to "open"
76
+ * @param maintainers Pubkeys allowed to set the status in addition to the root author
77
+ */
78
+ export function getGitCurrentStatus(root, statuses, maintainers = []) {
79
+ const latest = getGitCurrentStatusEvent(root, statuses, maintainers);
80
+ return latest ? getGitStatusType(latest) : "open";
81
+ }
82
+ /** Returns the accepted revision root id from the marked reply tag */
83
+ export function getGitStatusAcceptedRevisionId(event) {
84
+ const id = event.tags.find((t) => t[0] === "e" && t[3] === "reply")?.[1];
85
+ return id && isHexKey(id) ? id : undefined;
86
+ }
87
+ /** Returns the commits produced by applying the patches */
88
+ export function getGitStatusAppliedCommits(event) {
89
+ return event.tags
90
+ .filter((t) => t[0] === "applied-as-commits")
91
+ .flatMap((t) => t.slice(1))
92
+ .filter(isGitCommitId);
93
+ }
@@ -0,0 +1,2 @@
1
+ /** Checks if a string is a SHA-1 or SHA-256 Git object id */
2
+ export declare function isGitCommitId(value: string | undefined): value is string;
@@ -0,0 +1,4 @@
1
+ /** Checks if a string is a SHA-1 or SHA-256 Git object id */
2
+ export function isGitCommitId(value) {
3
+ return !!value && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i.test(value);
4
+ }
@@ -25,9 +25,12 @@ export type GroupPointer = {
25
25
  /** The name of the group */
26
26
  name?: string;
27
27
  };
28
- /** decodes a group identifier into a group pointer object */
28
+ /**
29
+ * Decodes Applesauce's apostrophe-delimited compatibility identifier.
30
+ * NIP-29 references use kind-39000 `naddr` values with relay hints instead.
31
+ */
29
32
  export declare function decodeGroupPointer(str: string): GroupPointer | null;
30
- /** Converts a group pointer into a group identifier */
33
+ /** Converts a group pointer into Applesauce's compatibility identifier. */
31
34
  export declare function encodeGroupPointer(pointer: GroupPointer): string;
32
35
  export declare const GroupsPublicSymbol: unique symbol;
33
36
  export declare const GroupsHiddenSymbol: unique symbol;
@@ -20,22 +20,42 @@ export const DELETE_EVENT_KIND = 9005;
20
20
  export const CREATE_GROUP_KIND = 9007;
21
21
  export const DELETE_GROUP_KIND = 9008;
22
22
  export const CREATE_INVITE_KIND = 9009;
23
- /** decodes a group identifier into a group pointer object */
23
+ /**
24
+ * Decodes Applesauce's apostrophe-delimited compatibility identifier.
25
+ * NIP-29 references use kind-39000 `naddr` values with relay hints instead.
26
+ */
24
27
  export function decodeGroupPointer(str) {
25
- let [relay, id] = str.split("'");
28
+ const separator = str.indexOf("'");
29
+ let relay = separator === -1 ? str : str.slice(0, separator);
30
+ const id = separator === -1 ? "" : str.slice(separator + 1);
26
31
  if (!relay)
27
32
  return null;
28
33
  // Prepend wss:// if missing
29
34
  if (!relay.match(/^wss?:/))
30
35
  relay = `wss://${relay}`;
31
- // Normalize the relay url
32
- relay = normalizeURL(relay);
36
+ try {
37
+ relay = normalizeURL(relay);
38
+ const hash = relay.indexOf("#");
39
+ if (hash !== -1 && hash < relay.length - 1)
40
+ return null;
41
+ }
42
+ catch {
43
+ return null;
44
+ }
33
45
  return { relay, id: id || "_" };
34
46
  }
35
- /** Converts a group pointer into a group identifier */
47
+ /** Converts a group pointer into Applesauce's compatibility identifier. */
36
48
  export function encodeGroupPointer(pointer) {
37
- const hostname = URL.canParse(pointer.relay) ? new URL(pointer.relay).hostname : pointer.relay;
38
- return `${hostname}'${pointer.id}`;
49
+ const normalized = decodeGroupPointer(`${pointer.relay}'_`)?.relay;
50
+ if (!normalized)
51
+ return `${pointer.relay}'${pointer.id}`;
52
+ let relay = normalized;
53
+ if (normalized.startsWith("wss://")) {
54
+ const root = /^wss:\/\/([^/?#]+)\/(?:\?)?(?:#)?$/.exec(normalized);
55
+ // Native URL.host excludes credentials, even on root URLs.
56
+ relay = root ? root[1].slice(root[1].lastIndexOf("@") + 1) : normalized.slice("wss://".length);
57
+ }
58
+ return `${relay}'${pointer.id}`;
39
59
  }
40
60
  export const GroupsPublicSymbol = Symbol.for("groups-public");
41
61
  export const GroupsHiddenSymbol = Symbol.for("groups-hidden");
@@ -60,17 +80,19 @@ export function getPublicGroups(bookmark) {
60
80
  export function getHiddenGroups(bookmark) {
61
81
  if (GroupsHiddenSymbol in bookmark)
62
82
  return bookmark[GroupsHiddenSymbol];
63
- return getOrComputeCachedValue(bookmark, GroupsHiddenSymbol, () => {
64
- //get hidden tags
65
- const tags = getHiddenTags(bookmark);
66
- if (!tags)
67
- return undefined;
68
- // parse groups from hidden tags
69
- const groups = processTags(tags.filter((t) => t[0] === "group"), getGroupPointerFromGroupTag);
70
- // set cached value
71
- Reflect.set(bookmark, GroupsHiddenSymbol, groups);
72
- return groups;
73
- });
83
+ // get hidden tags
84
+ const tags = getHiddenTags(bookmark);
85
+ // D-02/D-03: don't memoize undefined. getOrComputeCachedValue unconditionally caches whatever
86
+ // its compute callback returns, so if we called it while the hidden tags are still locked
87
+ // (tags undefined) it would permanently poison GroupsHiddenSymbol with undefined — satisfying
88
+ // isHiddenGroupsUnlocked's presence check forever, even after the tags are later unlocked by
89
+ // some other path, and letting unlockHiddenGroups's short-circuit hand back that poisoned
90
+ // undefined instead of throwing or returning real groups. Returning here, before ever calling
91
+ // getOrComputeCachedValue, guarantees its callback only ever runs (and only ever caches) when
92
+ // the result is a real, defined GroupPointer[].
93
+ if (!tags)
94
+ return undefined;
95
+ return getOrComputeCachedValue(bookmark, GroupsHiddenSymbol, () => processTags(tags.filter((t) => t[0] === "group"), getGroupPointerFromGroupTag));
74
96
  }
75
97
  /** Checks if the hidden groups are unlocked */
76
98
  export function isHiddenGroupsUnlocked(bookmark) {
@@ -1,3 +1,5 @@
1
- import { EventTemplate, NostrEvent } from "applesauce-core/helpers/event";
1
+ import { NostrEvent } from "applesauce-core/helpers/event";
2
2
  /** Returns a matching ["t", string] tag for a hashtag in an event */
3
- export declare function getHashtagTag(event: NostrEvent | EventTemplate, hashtag: string): ["t", string];
3
+ export declare function getHashtagTag<E extends {
4
+ tags: string[][];
5
+ } = NostrEvent>(event: E, hashtag: string): ["t", string];
@@ -1,5 +1,7 @@
1
1
  export * from "./app-handler.js";
2
+ export * from "./app-recommendation.js";
2
3
  export * from "./article.js";
4
+ export * from "./forum-thread.js";
3
5
  export * from "./badge-award.js";
4
6
  export * from "./badge.js";
5
7
  export * from "./blossom.js";
@@ -14,11 +16,17 @@ export * from "./content.js";
14
16
  export * from "./emoji.js";
15
17
  export * from "./emoji-pack.js";
16
18
  export * from "./encrypted-content-cache.js";
19
+ export * from "./external-identities.js";
17
20
  export * from "./file-metadata.js";
18
21
  export * from "./gift-wrap.js";
19
22
  export * from "./git-grasp-list.js";
23
+ export * from "./git-issue.js";
24
+ export * from "./git.js";
20
25
  export * from "./git-lists.js";
26
+ export * from "./git-patch.js";
27
+ export * from "./git-pull-request.js";
21
28
  export * from "./git-repository.js";
29
+ export * from "./git-status.js";
22
30
  export * from "./groups.js";
23
31
  export * from "./hashtag.js";
24
32
  export * from "./highlight.js";
@@ -27,6 +35,8 @@ export * from "./lists.js";
27
35
  export * from "./lnurl.js";
28
36
  export * from "./messages.js";
29
37
  export * from "./mute.js";
38
+ export * from "./napplet.js";
39
+ export * from "./nostr-web-token.js";
30
40
  export * from "./picture-post.js";
31
41
  export * from "./poll.js";
32
42
  export * from "./profile-badges.js";
@@ -44,3 +54,4 @@ export * from "./user-status.js";
44
54
  export * from "./wrapped-messages.js";
45
55
  export * from "./zap-goal.js";
46
56
  export * from "./zap.js";
57
+ export * from "./nsite.js";
@@ -1,5 +1,7 @@
1
1
  export * from "./app-handler.js";
2
+ export * from "./app-recommendation.js";
2
3
  export * from "./article.js";
4
+ export * from "./forum-thread.js";
3
5
  export * from "./badge-award.js";
4
6
  export * from "./badge.js";
5
7
  export * from "./blossom.js";
@@ -14,11 +16,17 @@ export * from "./content.js";
14
16
  export * from "./emoji.js";
15
17
  export * from "./emoji-pack.js";
16
18
  export * from "./encrypted-content-cache.js";
19
+ export * from "./external-identities.js";
17
20
  export * from "./file-metadata.js";
18
21
  export * from "./gift-wrap.js";
19
22
  export * from "./git-grasp-list.js";
23
+ export * from "./git-issue.js";
24
+ export * from "./git.js";
20
25
  export * from "./git-lists.js";
26
+ export * from "./git-patch.js";
27
+ export * from "./git-pull-request.js";
21
28
  export * from "./git-repository.js";
29
+ export * from "./git-status.js";
22
30
  export * from "./groups.js";
23
31
  export * from "./hashtag.js";
24
32
  export * from "./highlight.js";
@@ -27,6 +35,8 @@ export * from "./lists.js";
27
35
  export * from "./lnurl.js";
28
36
  export * from "./messages.js";
29
37
  export * from "./mute.js";
38
+ export * from "./napplet.js";
39
+ export * from "./nostr-web-token.js";
30
40
  export * from "./picture-post.js";
31
41
  export * from "./poll.js";
32
42
  export * from "./profile-badges.js";
@@ -44,3 +54,4 @@ export * from "./user-status.js";
44
54
  export * from "./wrapped-messages.js";
45
55
  export * from "./zap-goal.js";
46
56
  export * from "./zap.js";
57
+ export * from "./nsite.js";
@@ -1,3 +1,4 @@
1
+ import { setCachedValue } from "applesauce-core/helpers/cache";
1
2
  import { getReplaceableIdentifier, isAddressableKind, isReplaceable, isReplaceableKind, } from "applesauce-core/helpers/event";
2
3
  import { getHiddenTags, isHiddenTagsUnlocked } from "applesauce-core/helpers/hidden-tags";
3
4
  import { getAddressPointerForEvent, getAddressPointerFromATag, getEventPointerFromETag, getProfilePointerFromPTag, getReplaceableAddressFromPointer, } from "applesauce-core/helpers/pointers";
@@ -16,8 +17,19 @@ function getOrComputeListCache(list, symbol, type, compute) {
16
17
  // Hidden/all results depend on unlocked hidden tags, so avoid caching until available
17
18
  if ((cacheType === "hidden" || cacheType === "all") && !isHiddenTagsUnlocked(list))
18
19
  return compute();
19
- const cache = Reflect.get(list, symbol) ?? {};
20
- Reflect.set(list, symbol, cache);
20
+ // Two-level cache (symbol -> cacheType -> value) derived from the list's own tags — identity
21
+ // memo (see cache.ts taxonomy). D-12 hot-path lift: this Phase 5 write site was deliberately
22
+ // deferred because this function runs on every getter call — unconditionally calling
23
+ // setCachedValue (Object.defineProperty) on every call would redefine the property descriptor
24
+ // every time instead of a plain assignment. That deferral is lifted here (05.1-09) by only
25
+ // calling setCachedValue once, when the cache object is first created; the returned cache is a
26
+ // mutable container that subsequent calls populate in place without touching the descriptor
27
+ // again (mirroring getOrComputeCachedValue's own once-only write).
28
+ let cache = Reflect.get(list, symbol);
29
+ if (!cache) {
30
+ cache = {};
31
+ setCachedValue(list, symbol, cache);
32
+ }
21
33
  const cached = cache[cacheType];
22
34
  if (cached !== undefined)
23
35
  return cached;
@@ -29,7 +29,7 @@ export function parseLNURLOrAddress(addressOrLNURL) {
29
29
  }
30
30
  /** Requests a bolt11 invoice from a LNURLp callback URL */
31
31
  export async function getInvoice(callback) {
32
- const { pr: payRequest } = await fetch(callback).then((res) => res.json());
32
+ const { pr: payRequest } = await fetch(callback, { signal: AbortSignal.timeout(10_000) }).then((res) => res.json());
33
33
  const amount = callback.searchParams.get("amount");
34
34
  if (!amount)
35
35
  throw new Error("Missing amount");
@@ -1,4 +1,4 @@
1
- import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
1
+ import { getOrComputeCachedValue, setCachedValue } from "applesauce-core/helpers/cache";
2
2
  import { kinds, notifyEventUpdate } from "applesauce-core/helpers/event";
3
3
  import { getIndexableTags } from "applesauce-core/helpers/filter";
4
4
  import { isETag, isPTag, isTTag } from "applesauce-core/helpers/tags";
@@ -47,8 +47,7 @@ export function getPublicMutedThings(mute) {
47
47
  }
48
48
  /** Checks if the hidden mutes are unlocked */
49
49
  export function isHiddenMutesUnlocked(mute) {
50
- // No need for try catch or proactivly parsing here since it only depends on hidden tags
51
- return MuteHiddenSymbol in mute || isHiddenTagsUnlocked(mute);
50
+ return isHiddenTagsUnlocked(mute) && (MuteHiddenSymbol in mute || getHiddenMutedThings(mute) !== undefined);
52
51
  }
53
52
  export function getHiddenMutedThings(mute) {
54
53
  if (MuteHiddenSymbol in mute)
@@ -59,8 +58,10 @@ export function getHiddenMutedThings(mute) {
59
58
  return undefined;
60
59
  // parse muted tags
61
60
  const mutes = parseMutedTags(tags);
62
- // set cached value
63
- Reflect.set(mute, MuteHiddenSymbol, mutes);
61
+ // Derived from the event's own hidden tags — identity memo (see applesauce-core's cache.ts
62
+ // taxonomy). Written non-enumerable via setCachedValue (05.1-09) so a plain spread drops it
63
+ // instead of carrying a stale derivation onto a copy whose hidden tags differ.
64
+ setCachedValue(mute, MuteHiddenSymbol, mutes);
64
65
  return mutes;
65
66
  }
66
67
  /** Unlocks the hidden mutes */
@@ -84,6 +85,8 @@ export function createMutedWordsRegExp(mutedWords) {
84
85
  // Create the RegExp with word boundaries and case insensitive flag
85
86
  return new RegExp(`\\b(${escapedWords.join("|")})\\b`, "gi");
86
87
  }
88
+ // Compiled muted word RegExps, keyed by the words set so matchMutes doesn't rebuild one per event
89
+ const mutedWordsRegExpCache = new WeakMap();
87
90
  /** Returns true if the event matches the mutes */
88
91
  export function matchMutes(mutes, event) {
89
92
  // Filter on muted pubkeys
@@ -107,8 +110,16 @@ export function matchMutes(mutes, event) {
107
110
  }
108
111
  // Filter on muted words
109
112
  if (mutes.words.size > 0) {
110
- const regExp = createMutedWordsRegExp(Array.from(mutes.words));
111
- if (regExp.test(event.content))
113
+ let cached = mutedWordsRegExpCache.get(mutes.words);
114
+ // Rebuild if the set was mutated after the RegExp was compiled
115
+ if (!cached || cached.words.length !== mutes.words.size || cached.words.some((word) => !mutes.words.has(word))) {
116
+ const words = Array.from(mutes.words);
117
+ cached = { words, regExp: createMutedWordsRegExp(words) };
118
+ mutedWordsRegExpCache.set(mutes.words, cached);
119
+ }
120
+ // The RegExp is global, so reset its position before reusing it
121
+ cached.regExp.lastIndex = 0;
122
+ if (cached.regExp.test(event.content))
112
123
  return true;
113
124
  }
114
125
  // Event does not match any mutes
@@ -0,0 +1,89 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
3
+ /**
4
+ * The event kind for NIP-5D napplet snapshots (regular events)
5
+ * @see https://github.com/nostr-protocol/nips/pull/2303
6
+ */
7
+ export declare const NAPPLET_SNAPSHOT_KIND = 5129;
8
+ /**
9
+ * The event kind for NIP-5D root napplets (replaceable events)
10
+ * @see https://github.com/nostr-protocol/nips/pull/2303
11
+ */
12
+ export declare const NAPPLET_ROOT_KIND = 15129;
13
+ /**
14
+ * The event kind for NIP-5D named napplets (addressable events)
15
+ * @see https://github.com/nostr-protocol/nips/pull/2303
16
+ */
17
+ export declare const NAPPLET_KIND = 35129;
18
+ /** The event kinds of a NIP-5D napplet manifest */
19
+ export type NappletKind = typeof NAPPLET_SNAPSHOT_KIND | typeof NAPPLET_ROOT_KIND | typeof NAPPLET_KIND;
20
+ /** All NIP-5D napplet manifest kinds */
21
+ export declare const NAPPLET_KINDS: NappletKind[];
22
+ /** The MIME types allowed for a napplet icon */
23
+ export declare const NAPPLET_ICON_TYPES: readonly ["image/png", "image/jpeg", "image/webp"];
24
+ /** A MIME type allowed for a napplet icon */
25
+ export type NappletIconType = (typeof NAPPLET_ICON_TYPES)[number];
26
+ /** A validated NIP-5D napplet manifest event */
27
+ export type NappletEvent = KnownEvent<NappletKind>;
28
+ /** A NIP-5D napplet snapshot event (kind 5129) */
29
+ export type NappletSnapshotEvent = KnownEvent<typeof NAPPLET_SNAPSHOT_KIND>;
30
+ /** A NIP-5D root napplet event (kind 15129) */
31
+ export type RootNappletEvent = KnownEvent<typeof NAPPLET_ROOT_KIND>;
32
+ /** A NIP-5D named napplet event (kind 35129) */
33
+ export type NamedNappletEvent = KnownEvent<typeof NAPPLET_KIND>;
34
+ /** An intent accepted by a napplet and its advertised parameter names */
35
+ export type NappletIntent = {
36
+ intent: string;
37
+ params: string[];
38
+ };
39
+ /** A content-addressed napplet icon */
40
+ export type NappletIcon = {
41
+ sha256: string;
42
+ type: NappletIconType;
43
+ };
44
+ /** Checks if a MIME type is allowed for a napplet icon */
45
+ export declare function isNappletIconType(type: string): type is NappletIconType;
46
+ /**
47
+ * Checks if an event is a valid NIP-5D napplet manifest
48
+ * @see https://github.com/nostr-protocol/nips/pull/2303
49
+ */
50
+ export declare function isValidNapplet(event?: NostrEvent): event is NappletEvent;
51
+ /** Checks if an event is a napplet snapshot (kind 5129) */
52
+ export declare function isNappletSnapshot(event?: NostrEvent): event is NappletSnapshotEvent;
53
+ /** Checks if an event is a root napplet (kind 15129) */
54
+ export declare function isRootNapplet(event?: NostrEvent): event is RootNappletEvent;
55
+ /** Checks if an event is a named napplet (kind 35129) */
56
+ export declare function isNamedNapplet(event?: NostrEvent): event is NamedNappletEvent;
57
+ /** Checks if an event is a valid napplet snapshot manifest */
58
+ export declare function isValidNappletSnapshot(event?: NostrEvent): event is NappletSnapshotEvent;
59
+ /** Checks if an event is a valid root napplet manifest */
60
+ export declare function isValidRootNapplet(event?: NostrEvent): event is RootNappletEvent;
61
+ /** Checks if an event is a valid named napplet manifest */
62
+ export declare function isValidNamedNapplet(event?: NostrEvent): event is NamedNappletEvent;
63
+ /** Returns the identifier from the `d` tag of a named napplet */
64
+ export declare function getNappletIdentifier(event: NostrEvent): string | undefined;
65
+ /** Returns the sha256 of the napplet `index.html` artifact from the `x` tag */
66
+ export declare function getNappletArtifactHash(event: NappletEvent): string;
67
+ export declare function getNappletArtifactHash(event: NostrEvent): string | undefined;
68
+ /** Returns the plain-text description of the napplet */
69
+ export declare function getNappletDescription(event: NostrEvent): string;
70
+ /** Returns the short display label from the `title` tag */
71
+ export declare function getNappletTitle(event: NostrEvent): string | undefined;
72
+ /** Returns the source URL from the `source` tag */
73
+ export declare function getNappletSource(event: NostrEvent): string | undefined;
74
+ /** Returns the Blossom server hints from the `server` tags */
75
+ export declare function getNappletServers(event: NostrEvent): string[];
76
+ /** Returns the archetypes from the `z` tags */
77
+ export declare function getNappletArchetypes(event: NostrEvent): string[];
78
+ /** Returns the accepted intents and their parameter names from the `i` tags */
79
+ export declare function getNappletIntents(event: NostrEvent): NappletIntent[];
80
+ /** Returns the NAP domains required for full functionality from the `R` tags */
81
+ export declare function getNappletRequiredDomains(event: NostrEvent): string[];
82
+ /** Returns the optional NAP domains from the `O` tags */
83
+ export declare function getNappletOptionalDomains(event: NostrEvent): string[];
84
+ /** Returns the icon from the `icon` tag, or undefined if the hash or MIME type is invalid */
85
+ export declare function getNappletIcon(event: NostrEvent): NappletIcon | undefined;
86
+ /** Returns the address of the napplet a snapshot derives from (`a` tag) */
87
+ export declare function getNappletParentPointer(event: NostrEvent): AddressPointer | undefined;
88
+ /** Returns the address of the root napplet a snapshot's lineage originates from (`A` tag) */
89
+ export declare function getNappletRootPointer(event: NostrEvent): AddressPointer | undefined;
@@ -0,0 +1,144 @@
1
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
+ import { getTagValue } from "applesauce-core/helpers/event";
3
+ import { getAddressPointerFromATag } from "applesauce-core/helpers/pointers";
4
+ import { processTags } from "applesauce-core/helpers/tags";
5
+ import { isSha256 } from "./blossom.js";
6
+ /**
7
+ * The event kind for NIP-5D napplet snapshots (regular events)
8
+ * @see https://github.com/nostr-protocol/nips/pull/2303
9
+ */
10
+ export const NAPPLET_SNAPSHOT_KIND = 5129;
11
+ /**
12
+ * The event kind for NIP-5D root napplets (replaceable events)
13
+ * @see https://github.com/nostr-protocol/nips/pull/2303
14
+ */
15
+ export const NAPPLET_ROOT_KIND = 15129;
16
+ /**
17
+ * The event kind for NIP-5D named napplets (addressable events)
18
+ * @see https://github.com/nostr-protocol/nips/pull/2303
19
+ */
20
+ export const NAPPLET_KIND = 35129;
21
+ /** All NIP-5D napplet manifest kinds */
22
+ export const NAPPLET_KINDS = [NAPPLET_SNAPSHOT_KIND, NAPPLET_ROOT_KIND, NAPPLET_KIND];
23
+ /** The MIME types allowed for a napplet icon */
24
+ export const NAPPLET_ICON_TYPES = ["image/png", "image/jpeg", "image/webp"];
25
+ const NappletArchetypesSymbol = Symbol.for("napplet-archetypes");
26
+ const NappletIntentsSymbol = Symbol.for("napplet-intents");
27
+ const NappletRequiredDomainsSymbol = Symbol.for("napplet-required-domains");
28
+ const NappletOptionalDomainsSymbol = Symbol.for("napplet-optional-domains");
29
+ const NappletServersSymbol = Symbol.for("napplet-servers");
30
+ /** Checks if a MIME type is allowed for a napplet icon */
31
+ export function isNappletIconType(type) {
32
+ return NAPPLET_ICON_TYPES.includes(type);
33
+ }
34
+ /** Returns the values of all tags with a name */
35
+ function getTagValues(event, name) {
36
+ return processTags(event.tags, (t) => (t[0] === name && t[1] ? t[1] : undefined));
37
+ }
38
+ /**
39
+ * Checks if an event is a valid NIP-5D napplet manifest
40
+ * @see https://github.com/nostr-protocol/nips/pull/2303
41
+ */
42
+ export function isValidNapplet(event) {
43
+ if (!event || !NAPPLET_KINDS.includes(event.kind))
44
+ return false;
45
+ if (event.content.trim().length === 0)
46
+ return false;
47
+ // The manifest must carry exactly one valid "x" tag
48
+ const x = event.tags.filter((t) => t[0] === "x");
49
+ if (x.length !== 1 || !x[0][1] || !isSha256(x[0][1]))
50
+ return false;
51
+ // Named napplets must have exactly one "d" tag, other kinds must have none
52
+ const d = event.tags.filter((t) => t[0] === "d");
53
+ if (event.kind === NAPPLET_KIND)
54
+ return d.length === 1 && !!d[0][1];
55
+ return d.length === 0;
56
+ }
57
+ /** Checks if an event is a napplet snapshot (kind 5129) */
58
+ export function isNappletSnapshot(event) {
59
+ return event?.kind === NAPPLET_SNAPSHOT_KIND;
60
+ }
61
+ /** Checks if an event is a root napplet (kind 15129) */
62
+ export function isRootNapplet(event) {
63
+ return event?.kind === NAPPLET_ROOT_KIND;
64
+ }
65
+ /** Checks if an event is a named napplet (kind 35129) */
66
+ export function isNamedNapplet(event) {
67
+ return event?.kind === NAPPLET_KIND;
68
+ }
69
+ /** Checks if an event is a valid napplet snapshot manifest */
70
+ export function isValidNappletSnapshot(event) {
71
+ return isNappletSnapshot(event) && isValidNapplet(event);
72
+ }
73
+ /** Checks if an event is a valid root napplet manifest */
74
+ export function isValidRootNapplet(event) {
75
+ return isRootNapplet(event) && isValidNapplet(event);
76
+ }
77
+ /** Checks if an event is a valid named napplet manifest */
78
+ export function isValidNamedNapplet(event) {
79
+ return isNamedNapplet(event) && isValidNapplet(event);
80
+ }
81
+ /** Returns the identifier from the `d` tag of a named napplet */
82
+ export function getNappletIdentifier(event) {
83
+ if (!isNamedNapplet(event))
84
+ return undefined;
85
+ return getTagValue(event, "d") || undefined;
86
+ }
87
+ export function getNappletArtifactHash(event) {
88
+ return getTagValue(event, "x");
89
+ }
90
+ /** Returns the plain-text description of the napplet */
91
+ export function getNappletDescription(event) {
92
+ return event.content;
93
+ }
94
+ /** Returns the short display label from the `title` tag */
95
+ export function getNappletTitle(event) {
96
+ return getTagValue(event, "title") || undefined;
97
+ }
98
+ /** Returns the source URL from the `source` tag */
99
+ export function getNappletSource(event) {
100
+ return getTagValue(event, "source") || undefined;
101
+ }
102
+ /** Returns the Blossom server hints from the `server` tags */
103
+ export function getNappletServers(event) {
104
+ return getOrComputeCachedValue(event, NappletServersSymbol, () => getTagValues(event, "server"));
105
+ }
106
+ /** Returns the archetypes from the `z` tags */
107
+ export function getNappletArchetypes(event) {
108
+ return getOrComputeCachedValue(event, NappletArchetypesSymbol, () => getTagValues(event, "z"));
109
+ }
110
+ /** Returns the accepted intents and their parameter names from the `i` tags */
111
+ export function getNappletIntents(event) {
112
+ return getOrComputeCachedValue(event, NappletIntentsSymbol, () => processTags(event.tags, (t) => t[0] === "i" && t[1] ? { intent: t[1], params: t.slice(2).filter((p) => p.length > 0) } : undefined));
113
+ }
114
+ /** Returns the NAP domains required for full functionality from the `R` tags */
115
+ export function getNappletRequiredDomains(event) {
116
+ return getOrComputeCachedValue(event, NappletRequiredDomainsSymbol, () => getTagValues(event, "R"));
117
+ }
118
+ /** Returns the optional NAP domains from the `O` tags */
119
+ export function getNappletOptionalDomains(event) {
120
+ return getOrComputeCachedValue(event, NappletOptionalDomainsSymbol, () => getTagValues(event, "O"));
121
+ }
122
+ /** Returns the icon from the `icon` tag, or undefined if the hash or MIME type is invalid */
123
+ export function getNappletIcon(event) {
124
+ const tag = event.tags.find((t) => t[0] === "icon");
125
+ if (!tag || !tag[1] || !tag[2])
126
+ return undefined;
127
+ if (!isSha256(tag[1]) || !isNappletIconType(tag[2]))
128
+ return undefined;
129
+ return { sha256: tag[1], type: tag[2] };
130
+ }
131
+ /** Returns the address of the napplet a snapshot derives from (`a` tag) */
132
+ export function getNappletParentPointer(event) {
133
+ if (!isNappletSnapshot(event))
134
+ return undefined;
135
+ const tag = event.tags.find((t) => t[0] === "a" && t[1]);
136
+ return (tag && getAddressPointerFromATag(tag)) || undefined;
137
+ }
138
+ /** Returns the address of the root napplet a snapshot's lineage originates from (`A` tag) */
139
+ export function getNappletRootPointer(event) {
140
+ if (!isNappletSnapshot(event))
141
+ return undefined;
142
+ const tag = event.tags.find((t) => t[0] === "A" && t[1]);
143
+ return (tag && getAddressPointerFromATag(tag)) || undefined;
144
+ }