applesauce-common 6.2.0 → 7.1.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.
- package/README.md +1 -0
- package/dist/casts/_circular-import.d.ts +3 -0
- package/dist/casts/_circular-import.js +3 -0
- package/dist/casts/app-handler.d.ts +56 -0
- package/dist/casts/app-handler.js +105 -0
- package/dist/casts/app-recommendation.d.ts +26 -0
- package/dist/casts/app-recommendation.js +41 -0
- package/dist/casts/external-identities.d.ts +9 -0
- package/dist/casts/external-identities.js +14 -0
- package/dist/casts/forum-thread.d.ts +17 -0
- package/dist/casts/forum-thread.js +31 -0
- package/dist/casts/git-issue.d.ts +18 -0
- package/dist/casts/git-issue.js +26 -0
- package/dist/casts/git-patch.d.ts +49 -0
- package/dist/casts/git-patch.js +88 -0
- package/dist/casts/git-pull-request.d.ts +67 -0
- package/dist/casts/git-pull-request.js +122 -0
- package/dist/casts/git-repository.d.ts +9 -0
- package/dist/casts/git-repository.js +16 -0
- package/dist/casts/git-thread.d.ts +33 -0
- package/dist/casts/git-thread.js +65 -0
- package/dist/casts/index.d.ts +12 -0
- package/dist/casts/index.js +12 -0
- package/dist/casts/napplet-handlers.d.ts +39 -0
- package/dist/casts/napplet-handlers.js +91 -0
- package/dist/casts/napplet.d.ts +98 -0
- package/dist/casts/napplet.js +196 -0
- package/dist/casts/note.d.ts +8 -0
- package/dist/casts/note.js +21 -1
- package/dist/casts/nsite.d.ts +134 -0
- package/dist/casts/nsite.js +249 -0
- package/dist/casts/profile.d.ts +20 -0
- package/dist/casts/profile.js +30 -0
- package/dist/casts/reaction.d.ts +1 -1
- package/dist/casts/relay-discovery.d.ts +4 -0
- package/dist/casts/relay-discovery.js +9 -1
- package/dist/casts/report.d.ts +28 -15
- package/dist/casts/report.js +42 -19
- package/dist/casts/share.d.ts +1 -1
- package/dist/casts/torrent.d.ts +5 -0
- package/dist/casts/torrent.js +8 -1
- package/dist/casts/trusted-assertions.d.ts +2 -0
- package/dist/casts/trusted-assertions.js +19 -18
- package/dist/casts/user-status.d.ts +33 -0
- package/dist/casts/user-status.js +69 -0
- package/dist/casts/user.d.ts +7 -0
- package/dist/casts/user.js +20 -1
- package/dist/factories/app-handler.d.ts +31 -0
- package/dist/factories/app-handler.js +50 -0
- package/dist/factories/app-recommendation.d.ts +21 -0
- package/dist/factories/app-recommendation.js +28 -0
- package/dist/factories/chat-message.d.ts +37 -0
- package/dist/factories/chat-message.js +56 -0
- package/dist/factories/comment.d.ts +8 -7
- package/dist/factories/comment.js +2 -2
- package/dist/factories/external-identities.d.ts +17 -0
- package/dist/factories/external-identities.js +28 -0
- package/dist/factories/file-message.d.ts +24 -0
- package/dist/factories/file-message.js +37 -0
- package/dist/factories/forum-thread.d.ts +34 -0
- package/dist/factories/forum-thread.js +50 -0
- package/dist/factories/git-applied-status.d.ts +39 -0
- package/dist/factories/git-applied-status.js +53 -0
- package/dist/factories/git-closed-status.d.ts +18 -0
- package/dist/factories/git-closed-status.js +24 -0
- package/dist/factories/git-draft-status.d.ts +18 -0
- package/dist/factories/git-draft-status.js +24 -0
- package/dist/factories/git-issue.d.ts +19 -0
- package/dist/factories/git-issue.js +25 -0
- package/dist/factories/git-open-status.d.ts +18 -0
- package/dist/factories/git-open-status.js +22 -0
- package/dist/factories/git-patch.d.ts +59 -0
- package/dist/factories/git-patch.js +102 -0
- package/dist/factories/git-pull-request-update.d.ts +23 -0
- package/dist/factories/git-pull-request-update.js +33 -0
- package/dist/factories/git-pull-request.d.ts +39 -0
- package/dist/factories/git-pull-request.js +64 -0
- package/dist/factories/index.d.ts +24 -0
- package/dist/factories/index.js +24 -0
- package/dist/factories/internal/git-pull-request.d.ts +19 -0
- package/dist/factories/internal/git-pull-request.js +26 -0
- package/dist/factories/internal/git-status.d.ts +11 -0
- package/dist/factories/internal/git-status.js +12 -0
- package/dist/factories/internal/git-thread.d.ts +19 -0
- package/dist/factories/internal/git-thread.js +29 -0
- package/dist/factories/internal/napplet-manifest.d.ts +52 -0
- package/dist/factories/internal/napplet-manifest.js +85 -0
- package/dist/factories/internal/nsite-manifest.d.ts +45 -0
- package/dist/factories/internal/nsite-manifest.js +68 -0
- package/dist/factories/legacy-message.d.ts +2 -0
- package/dist/factories/legacy-message.js +9 -2
- package/dist/factories/named-napplet.d.ts +20 -0
- package/dist/factories/named-napplet.js +30 -0
- package/dist/factories/named-nsite.d.ts +28 -0
- package/dist/factories/named-nsite.js +53 -0
- package/dist/factories/napplet-handlers.d.ts +34 -0
- package/dist/factories/napplet-handlers.js +77 -0
- package/dist/factories/napplet-snapshot.d.ts +18 -0
- package/dist/factories/napplet-snapshot.js +38 -0
- package/dist/factories/nsite-snapshot.d.ts +18 -0
- package/dist/factories/nsite-snapshot.js +29 -0
- package/dist/factories/reaction.d.ts +3 -2
- package/dist/factories/report.d.ts +48 -0
- package/dist/factories/report.js +66 -0
- package/dist/factories/root-napplet.d.ts +18 -0
- package/dist/factories/root-napplet.js +24 -0
- package/dist/factories/root-nsite.d.ts +23 -0
- package/dist/factories/root-nsite.js +44 -0
- package/dist/factories/torrent.d.ts +24 -10
- package/dist/factories/torrent.js +48 -44
- package/dist/factories/trusted-provider-list.d.ts +23 -0
- package/dist/factories/trusted-provider-list.js +39 -0
- package/dist/factories/user-status.d.ts +26 -0
- package/dist/factories/user-status.js +52 -0
- package/dist/factories/wrapped-message.js +10 -4
- package/dist/helpers/app-data.js +15 -7
- package/dist/helpers/app-handler.d.ts +43 -6
- package/dist/helpers/app-handler.js +53 -3
- package/dist/helpers/app-recommendation.d.ts +24 -0
- package/dist/helpers/app-recommendation.js +30 -0
- package/dist/helpers/bookmark.js +5 -2
- package/dist/helpers/comment.d.ts +11 -5
- package/dist/helpers/comment.js +7 -1
- package/dist/helpers/content.d.ts +3 -1
- package/dist/helpers/emoji-pack.js +11 -6
- package/dist/helpers/emoji.d.ts +2 -2
- package/dist/helpers/encrypted-content-cache.d.ts +2 -11
- package/dist/helpers/encrypted-content-cache.js +6 -14
- package/dist/helpers/encrypted-file.d.ts +41 -0
- package/dist/helpers/encrypted-file.js +64 -0
- package/dist/helpers/external-id.js +13 -19
- package/dist/helpers/external-identities.d.ts +29 -0
- package/dist/helpers/external-identities.js +52 -0
- package/dist/helpers/file-message.d.ts +18 -0
- package/dist/helpers/file-message.js +44 -0
- package/dist/helpers/file-metadata.d.ts +9 -4
- package/dist/helpers/file-metadata.js +21 -6
- package/dist/helpers/forum-thread.d.ts +10 -0
- package/dist/helpers/forum-thread.js +10 -0
- package/dist/helpers/gift-wrap.d.ts +40 -15
- package/dist/helpers/gift-wrap.js +110 -33
- package/dist/helpers/git-issue.d.ts +13 -0
- package/dist/helpers/git-issue.js +19 -0
- package/dist/helpers/git-patch.d.ts +41 -0
- package/dist/helpers/git-patch.js +73 -0
- package/dist/helpers/git-pull-request.d.ts +57 -0
- package/dist/helpers/git-pull-request.js +111 -0
- package/dist/helpers/git-repository.d.ts +4 -0
- package/dist/helpers/git-repository.js +16 -0
- package/dist/helpers/git-status.d.ts +44 -0
- package/dist/helpers/git-status.js +93 -0
- package/dist/helpers/git.d.ts +2 -0
- package/dist/helpers/git.js +4 -0
- package/dist/helpers/groups.d.ts +5 -2
- package/dist/helpers/groups.js +40 -18
- package/dist/helpers/hashtag.d.ts +4 -2
- package/dist/helpers/index.d.ts +13 -0
- package/dist/helpers/index.js +13 -0
- package/dist/helpers/lists.js +14 -2
- package/dist/helpers/lnurl.js +1 -1
- package/dist/helpers/messages.js +3 -2
- package/dist/helpers/mute.js +20 -9
- package/dist/helpers/napplet-handlers.d.ts +79 -0
- package/dist/helpers/napplet-handlers.js +187 -0
- package/dist/helpers/napplet.d.ts +107 -0
- package/dist/helpers/napplet.js +177 -0
- package/dist/helpers/nsite.d.ts +90 -0
- package/dist/helpers/nsite.js +217 -0
- package/dist/helpers/relay-discovery.d.ts +4 -0
- package/dist/helpers/relay-discovery.js +8 -0
- package/dist/helpers/reports.d.ts +35 -0
- package/dist/helpers/reports.js +36 -5
- package/dist/helpers/threading.d.ts +4 -2
- package/dist/helpers/torrent.d.ts +9 -6
- package/dist/helpers/torrent.js +23 -15
- package/dist/helpers/trusted-assertions.d.ts +7 -0
- package/dist/helpers/trusted-assertions.js +41 -2
- package/dist/helpers/user-status.d.ts +13 -1
- package/dist/helpers/user-status.js +15 -0
- package/dist/helpers/wrapped-messages.d.ts +2 -0
- package/dist/helpers/wrapped-messages.js +6 -1
- package/dist/models/app-handler.d.ts +21 -0
- package/dist/models/app-handler.js +47 -0
- package/dist/models/git.d.ts +34 -0
- package/dist/models/git.js +144 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +4 -0
- package/dist/models/legacy-messages.js +6 -1
- package/dist/models/napplet-handlers.d.ts +16 -0
- package/dist/models/napplet-handlers.js +45 -0
- package/dist/models/nsite.d.ts +22 -0
- package/dist/models/nsite.js +67 -0
- package/dist/models/thread.d.ts +4 -1
- package/dist/models/thread.js +34 -5
- package/dist/models/user-status.d.ts +8 -4
- package/dist/models/user-status.js +16 -22
- package/dist/models/wrapped-messages.js +9 -7
- package/dist/observable/filter-timeline-by-mutes.d.ts +1 -1
- package/dist/observable/filter-timeline-by-mutes.js +6 -2
- package/dist/operations/app-handler.d.ts +24 -0
- package/dist/operations/app-handler.js +58 -0
- package/dist/operations/app-recommendation.d.ts +13 -0
- package/dist/operations/app-recommendation.js +40 -0
- package/dist/operations/calendar-event.js +3 -2
- package/dist/operations/chat-message.d.ts +9 -0
- package/dist/operations/chat-message.js +12 -0
- package/dist/operations/client.d.ts +1 -4
- package/dist/operations/client.js +1 -23
- package/dist/operations/comment.d.ts +9 -3
- package/dist/operations/comment.js +12 -9
- package/dist/operations/external-identities.d.ts +8 -0
- package/dist/operations/external-identities.js +23 -0
- package/dist/operations/file-message.d.ts +7 -0
- package/dist/operations/file-message.js +34 -0
- package/dist/operations/forum-thread.d.ts +3 -0
- package/dist/operations/forum-thread.js +6 -0
- package/dist/operations/gift-wrap.js +38 -14
- package/dist/operations/git-issue.d.ts +18 -0
- package/dist/operations/git-issue.js +31 -0
- package/dist/operations/git-patch.d.ts +30 -0
- package/dist/operations/git-patch.js +75 -0
- package/dist/operations/git-pull-request.d.ts +29 -0
- package/dist/operations/git-pull-request.js +74 -0
- package/dist/operations/git-repository.js +4 -4
- package/dist/operations/git-status.d.ts +28 -0
- package/dist/operations/git-status.js +116 -0
- package/dist/operations/git-thread.d.ts +13 -0
- package/dist/operations/git-thread.js +39 -0
- package/dist/operations/index.d.ts +17 -0
- package/dist/operations/index.js +17 -0
- package/dist/operations/internal/git-commits.d.ts +2 -0
- package/dist/operations/internal/git-commits.js +16 -0
- package/dist/operations/napplet-handlers.d.ts +47 -0
- package/dist/operations/napplet-handlers.js +161 -0
- package/dist/operations/napplet.d.ts +51 -0
- package/dist/operations/napplet.js +121 -0
- package/dist/operations/nsite.d.ts +51 -0
- package/dist/operations/nsite.js +112 -0
- package/dist/operations/reaction.d.ts +12 -2
- package/dist/operations/reaction.js +1 -1
- package/dist/operations/report.d.ts +33 -0
- package/dist/operations/report.js +60 -0
- package/dist/operations/stream.js +5 -4
- package/dist/operations/torrent.d.ts +1 -4
- package/dist/operations/torrent.js +24 -11
- package/dist/operations/trusted-providers.d.ts +14 -0
- package/dist/operations/trusted-providers.js +33 -0
- package/dist/operations/user-status.d.ts +11 -0
- package/dist/operations/user-status.js +29 -0
- package/dist/operations/wrapped-message.js +2 -2
- package/package.json +13 -17
|
@@ -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
|
+
}
|
package/dist/helpers/groups.d.ts
CHANGED
|
@@ -25,9 +25,12 @@ export type GroupPointer = {
|
|
|
25
25
|
/** The name of the group */
|
|
26
26
|
name?: string;
|
|
27
27
|
};
|
|
28
|
-
/**
|
|
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
|
|
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;
|
package/dist/helpers/groups.js
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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
|
|
47
|
+
/** Converts a group pointer into Applesauce's compatibility identifier. */
|
|
36
48
|
export function encodeGroupPointer(pointer) {
|
|
37
|
-
const
|
|
38
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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 {
|
|
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
|
|
3
|
+
export declare function getHashtagTag<E extends {
|
|
4
|
+
tags: string[][];
|
|
5
|
+
} = NostrEvent>(event: E, hashtag: string): ["t", string];
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -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,19 @@ 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";
|
|
20
|
+
export * from "./encrypted-file.js";
|
|
21
|
+
export * from "./file-message.js";
|
|
17
22
|
export * from "./file-metadata.js";
|
|
18
23
|
export * from "./gift-wrap.js";
|
|
19
24
|
export * from "./git-grasp-list.js";
|
|
25
|
+
export * from "./git-issue.js";
|
|
26
|
+
export * from "./git.js";
|
|
20
27
|
export * from "./git-lists.js";
|
|
28
|
+
export * from "./git-patch.js";
|
|
29
|
+
export * from "./git-pull-request.js";
|
|
21
30
|
export * from "./git-repository.js";
|
|
31
|
+
export * from "./git-status.js";
|
|
22
32
|
export * from "./groups.js";
|
|
23
33
|
export * from "./hashtag.js";
|
|
24
34
|
export * from "./highlight.js";
|
|
@@ -27,6 +37,8 @@ export * from "./lists.js";
|
|
|
27
37
|
export * from "./lnurl.js";
|
|
28
38
|
export * from "./messages.js";
|
|
29
39
|
export * from "./mute.js";
|
|
40
|
+
export * from "./napplet.js";
|
|
41
|
+
export * from "./napplet-handlers.js";
|
|
30
42
|
export * from "./nostr-web-token.js";
|
|
31
43
|
export * from "./picture-post.js";
|
|
32
44
|
export * from "./poll.js";
|
|
@@ -45,3 +57,4 @@ export * from "./user-status.js";
|
|
|
45
57
|
export * from "./wrapped-messages.js";
|
|
46
58
|
export * from "./zap-goal.js";
|
|
47
59
|
export * from "./zap.js";
|
|
60
|
+
export * from "./nsite.js";
|
package/dist/helpers/index.js
CHANGED
|
@@ -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,19 @@ 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";
|
|
20
|
+
export * from "./encrypted-file.js";
|
|
21
|
+
export * from "./file-message.js";
|
|
17
22
|
export * from "./file-metadata.js";
|
|
18
23
|
export * from "./gift-wrap.js";
|
|
19
24
|
export * from "./git-grasp-list.js";
|
|
25
|
+
export * from "./git-issue.js";
|
|
26
|
+
export * from "./git.js";
|
|
20
27
|
export * from "./git-lists.js";
|
|
28
|
+
export * from "./git-patch.js";
|
|
29
|
+
export * from "./git-pull-request.js";
|
|
21
30
|
export * from "./git-repository.js";
|
|
31
|
+
export * from "./git-status.js";
|
|
22
32
|
export * from "./groups.js";
|
|
23
33
|
export * from "./hashtag.js";
|
|
24
34
|
export * from "./highlight.js";
|
|
@@ -27,6 +37,8 @@ export * from "./lists.js";
|
|
|
27
37
|
export * from "./lnurl.js";
|
|
28
38
|
export * from "./messages.js";
|
|
29
39
|
export * from "./mute.js";
|
|
40
|
+
export * from "./napplet.js";
|
|
41
|
+
export * from "./napplet-handlers.js";
|
|
30
42
|
export * from "./nostr-web-token.js";
|
|
31
43
|
export * from "./picture-post.js";
|
|
32
44
|
export * from "./poll.js";
|
|
@@ -45,3 +57,4 @@ export * from "./user-status.js";
|
|
|
45
57
|
export * from "./wrapped-messages.js";
|
|
46
58
|
export * from "./zap-goal.js";
|
|
47
59
|
export * from "./zap.js";
|
|
60
|
+
export * from "./nsite.js";
|
package/dist/helpers/lists.js
CHANGED
|
@@ -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
|
-
|
|
20
|
-
|
|
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;
|
package/dist/helpers/lnurl.js
CHANGED
|
@@ -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");
|
package/dist/helpers/messages.js
CHANGED
|
@@ -33,8 +33,9 @@ export function getConversationParticipants(participants) {
|
|
|
33
33
|
participantList = participants;
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const kind = participants.kind;
|
|
37
|
+
if (kind !== kinds.EncryptedDirectMessage && kind !== kinds.PrivateDirectMessage && kind !== kinds.FileMessage)
|
|
38
|
+
throw new Error("Can only get participants from direct message event (4, 14, 15)");
|
|
38
39
|
participantList = [participants.pubkey, ...participants.tags.filter(isPTag).map((t) => t[1])];
|
|
39
40
|
}
|
|
40
41
|
return Array.from(new Set(participantList));
|
package/dist/helpers/mute.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
//
|
|
63
|
-
|
|
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 */
|
|
@@ -81,9 +82,11 @@ export async function unlockHiddenMutes(mute, signer) {
|
|
|
81
82
|
export function createMutedWordsRegExp(mutedWords) {
|
|
82
83
|
// Escape special characters and join with |
|
|
83
84
|
const escapedWords = mutedWords.map((word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
84
|
-
//
|
|
85
|
-
return new RegExp(
|
|
85
|
+
// Keep matches outside Unicode words, including combining marks and underscores
|
|
86
|
+
return new RegExp(`(?<![\\p{L}\\p{M}\\p{N}_])(${escapedWords.join("|")})(?![\\p{L}\\p{M}\\p{N}_])`, "giu");
|
|
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
|
-
|
|
111
|
-
if
|
|
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,79 @@
|
|
|
1
|
+
import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { Filter } from "applesauce-core/helpers/filter";
|
|
3
|
+
import { HiddenContentSigner } from "applesauce-core/helpers/hidden-content";
|
|
4
|
+
import { AddressPointer, EventPointer } from "applesauce-core/helpers/pointers";
|
|
5
|
+
/**
|
|
6
|
+
* The event kind for napplet handler preferences (addressable events)
|
|
7
|
+
* @see https://github.com/napplet/naps/blob/master/naps/NAP-INTENT.md
|
|
8
|
+
*/
|
|
9
|
+
export declare const NAPPLET_HANDLERS_KIND = 31129;
|
|
10
|
+
/** A validated napplet handler preferences event */
|
|
11
|
+
export type NappletHandlersEvent = KnownEvent<typeof NAPPLET_HANDLERS_KIND>;
|
|
12
|
+
/** A reference to a napplet that follows its latest manifest, or to a pinned snapshot */
|
|
13
|
+
export type NappletHandlerRef = {
|
|
14
|
+
type: "address";
|
|
15
|
+
pointer: AddressPointer;
|
|
16
|
+
} | {
|
|
17
|
+
type: "snapshot";
|
|
18
|
+
pointer: EventPointer;
|
|
19
|
+
};
|
|
20
|
+
/** The handler entries of one tag set (public or private), in preference order */
|
|
21
|
+
export type NappletHandlerEntries = {
|
|
22
|
+
/** Archetype-wide handlers from the `a` and `e` tags */
|
|
23
|
+
handlers: NappletHandlerRef[];
|
|
24
|
+
/** Intent-specific handlers from the `i` tags, keyed by convention identity */
|
|
25
|
+
intents: Map<string, NappletHandlerRef[]>;
|
|
26
|
+
};
|
|
27
|
+
/** A handler considered when resolving an intent */
|
|
28
|
+
export type NappletHandlerCandidate = {
|
|
29
|
+
/** The referenced napplet */
|
|
30
|
+
ref: NappletHandlerRef;
|
|
31
|
+
/** Whether the entry came from the private tags */
|
|
32
|
+
hidden: boolean;
|
|
33
|
+
/** Whether the entry is intent-specific (`i` tag) rather than archetype-wide */
|
|
34
|
+
intent: boolean;
|
|
35
|
+
};
|
|
36
|
+
/** Type for events with unlocked private handler entries */
|
|
37
|
+
export type UnlockedNappletHandlers = {
|
|
38
|
+
[NappletHandlersHiddenSymbol]: NappletHandlerEntries;
|
|
39
|
+
};
|
|
40
|
+
export declare const NappletHandlersPublicSymbol: unique symbol;
|
|
41
|
+
export declare const NappletHandlersHiddenSymbol: unique symbol;
|
|
42
|
+
/** Checks if an event is a valid napplet handler preferences event (kind 31129) */
|
|
43
|
+
export declare function isValidNappletHandlers(event?: NostrEvent): event is NappletHandlersEvent;
|
|
44
|
+
/** Returns the archetype from the `d` tag */
|
|
45
|
+
export declare function getNappletHandlersArchetype(event: NostrEvent): string;
|
|
46
|
+
/** Returns a relay filter for handler preferences of an archetype, optionally from a set of authors */
|
|
47
|
+
export declare function getNappletHandlersFilter(archetype: string, authors?: string[]): Filter;
|
|
48
|
+
/** Checks if an address points to a named (with an identifier) or root (without one) napplet manifest */
|
|
49
|
+
export declare function isNappletHandlerAddress(pointer: AddressPointer): boolean;
|
|
50
|
+
/** Returns the coordinate or snapshot id that identifies a handler reference, ignoring relay hints */
|
|
51
|
+
export declare function getNappletHandlerRefKey(ref: NappletHandlerRef): string;
|
|
52
|
+
/** Checks if two handler references name the same napplet or the same pinned snapshot */
|
|
53
|
+
export declare function isSameNappletHandlerRef(a: NappletHandlerRef, b: NappletHandlerRef): boolean;
|
|
54
|
+
/** Parses an `i` tag `<ref>`: a napplet coordinate or a snapshot id */
|
|
55
|
+
export declare function parseNappletHandlerRef(value: string): NappletHandlerRef | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Parses the handler entries from a set of tags, skipping malformed entries and unknown tags
|
|
58
|
+
* @param tags The public or private tags of the event
|
|
59
|
+
* @param archetype The archetype from the event's `d` tag
|
|
60
|
+
* @param hintTags Extra tags whose `a` and `e` entries provide relay hints and authors for `i` references
|
|
61
|
+
*/
|
|
62
|
+
export declare function parseNappletHandlerTags(tags: string[][], archetype: string, hintTags?: string[][]): NappletHandlerEntries;
|
|
63
|
+
/** Returns the public handler entries, which other users read as recommendations */
|
|
64
|
+
export declare function getPublicNappletHandlers(event: NostrEvent): NappletHandlerEntries;
|
|
65
|
+
/** Returns the private handler entries if the event is unlocked */
|
|
66
|
+
export declare function getHiddenNappletHandlers<T extends NostrEvent & UnlockedNappletHandlers>(event: T): NappletHandlerEntries;
|
|
67
|
+
export declare function getHiddenNappletHandlers<T extends NostrEvent>(event: T): NappletHandlerEntries | undefined;
|
|
68
|
+
/** Checks if the private handler entries are unlocked */
|
|
69
|
+
export declare function isHiddenNappletHandlersUnlocked<T extends NostrEvent>(event: T): event is T & UnlockedNappletHandlers;
|
|
70
|
+
/**
|
|
71
|
+
* Decrypts the private handler entries
|
|
72
|
+
* @throws if the content cannot be decrypted into a list of tags
|
|
73
|
+
*/
|
|
74
|
+
export declare function unlockHiddenNappletHandlers(event: NostrEvent, signer: HiddenContentSigner): Promise<NappletHandlerEntries>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns the handlers to try for a convention identity, in resolution order
|
|
77
|
+
* @note Private entries are only included once unlocked, and a shell must still check each candidate is usable
|
|
78
|
+
*/
|
|
79
|
+
export declare function getNappletHandlerCandidates(event: NostrEvent, identity: string): NappletHandlerCandidate[];
|