applesauce-common 6.2.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.
- 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 +11 -0
- package/dist/casts/index.js +11 -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/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 +22 -0
- package/dist/factories/index.js +22 -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-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/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.js +18 -1
- 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-metadata.js +5 -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 +10 -0
- package/dist/helpers/index.js +10 -0
- package/dist/helpers/lists.js +14 -2
- package/dist/helpers/lnurl.js +1 -1
- package/dist/helpers/mute.js +18 -7
- package/dist/helpers/napplet.d.ts +89 -0
- package/dist/helpers/napplet.js +144 -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/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 +3 -0
- package/dist/models/index.js +3 -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/observable/filter-timeline-by-mutes.d.ts +1 -1
- package/dist/observable/filter-timeline-by-mutes.js +5 -1
- 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/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 +15 -0
- package/dist/operations/index.js +15 -0
- package/dist/operations/internal/git-commits.d.ts +2 -0
- package/dist/operations/internal/git-commits.js +16 -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/package.json +9 -9
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,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,7 @@ 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";
|
|
30
39
|
export * from "./nostr-web-token.js";
|
|
31
40
|
export * from "./picture-post.js";
|
|
32
41
|
export * from "./poll.js";
|
|
@@ -45,3 +54,4 @@ export * from "./user-status.js";
|
|
|
45
54
|
export * from "./wrapped-messages.js";
|
|
46
55
|
export * from "./zap-goal.js";
|
|
47
56
|
export * from "./zap.js";
|
|
57
|
+
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/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 */
|
|
@@ -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
|
-
|
|
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,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
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { AddressPointer, EventPointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
/** The event kind for NIP-5A manifest snapshots */
|
|
4
|
+
export declare const NSITE_SNAPSHOT_KIND = 5128;
|
|
5
|
+
/** The event kind for NIP-5A root sites */
|
|
6
|
+
export declare const NSITE_ROOT_KIND = 15128;
|
|
7
|
+
/** The event kind for NIP-5A named sites */
|
|
8
|
+
export declare const NSITE_KIND = 35128;
|
|
9
|
+
/** The event kinds of an nsite manifest */
|
|
10
|
+
export type NsiteKind = typeof NSITE_SNAPSHOT_KIND | typeof NSITE_ROOT_KIND | typeof NSITE_KIND;
|
|
11
|
+
/** All NIP-5A manifest kinds */
|
|
12
|
+
export declare const NSITE_KINDS: NsiteKind[];
|
|
13
|
+
/** A validated nsite manifest */
|
|
14
|
+
export type NsiteEvent = KnownEvent<NsiteKind>;
|
|
15
|
+
/** A root site manifest */
|
|
16
|
+
export type RootNsiteEvent = KnownEvent<typeof NSITE_ROOT_KIND>;
|
|
17
|
+
/** A named site manifest */
|
|
18
|
+
export type NamedNsiteEvent = KnownEvent<typeof NSITE_KIND>;
|
|
19
|
+
/** A manifest snapshot */
|
|
20
|
+
export type NsiteSnapshotEvent = KnownEvent<typeof NSITE_SNAPSHOT_KIND>;
|
|
21
|
+
/** A file in an nsite manifest */
|
|
22
|
+
export interface NsiteFile {
|
|
23
|
+
/** The absolute path to the file */
|
|
24
|
+
path: string;
|
|
25
|
+
/** The lowercase hexadecimal SHA-256 of the file */
|
|
26
|
+
sha256: string;
|
|
27
|
+
}
|
|
28
|
+
/** Checks if an identifier fits the canonical named-site DNS label */
|
|
29
|
+
export declare function isValidNsiteIdentifier(identifier: string): boolean;
|
|
30
|
+
/** Checks if a path is absolute and ends in a filename with an extension */
|
|
31
|
+
export declare function isValidNsitePath(path: string): boolean;
|
|
32
|
+
/** Checks if an address pointer references a root or named site */
|
|
33
|
+
export declare function isNsiteAddressPointer(pointer: AddressPointer): boolean;
|
|
34
|
+
/** Checks if an event is a root site */
|
|
35
|
+
export declare function isRootNsite(event?: NostrEvent): event is RootNsiteEvent;
|
|
36
|
+
/** Checks if an event is a named site */
|
|
37
|
+
export declare function isNamedNsite(event?: NostrEvent): event is NamedNsiteEvent;
|
|
38
|
+
/** Checks if an event is a manifest snapshot */
|
|
39
|
+
export declare function isNsiteSnapshot(event?: NostrEvent): event is NsiteSnapshotEvent;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if an event is a valid NIP-5A manifest
|
|
42
|
+
* @see https://github.com/nostr-protocol/nips/blob/master/5A.md
|
|
43
|
+
*/
|
|
44
|
+
export declare function isValidNsite(event?: NostrEvent): event is NsiteEvent;
|
|
45
|
+
/** Checks if an event is a valid root site */
|
|
46
|
+
export declare function isValidRootNsite(event?: NostrEvent): event is RootNsiteEvent;
|
|
47
|
+
/** Checks if an event is a valid named site */
|
|
48
|
+
export declare function isValidNamedNsite(event?: NostrEvent): event is NamedNsiteEvent;
|
|
49
|
+
/** Checks if an event is a valid manifest snapshot */
|
|
50
|
+
export declare function isValidNsiteSnapshot(event?: NostrEvent): event is NsiteSnapshotEvent;
|
|
51
|
+
/** Returns the named site's identifier */
|
|
52
|
+
export declare function getNsiteIdentifier(event: NostrEvent): string | undefined;
|
|
53
|
+
/** Returns the site's display title */
|
|
54
|
+
export declare function getNsiteTitle(event: NostrEvent): string | undefined;
|
|
55
|
+
/** Returns the site's description tag */
|
|
56
|
+
export declare function getNsiteDescription(event: NostrEvent): string | undefined;
|
|
57
|
+
/** Returns the site's source repository or archive URL */
|
|
58
|
+
export declare function getNsiteSource(event: NostrEvent): string | undefined;
|
|
59
|
+
/** Returns the valid file mappings from the manifest */
|
|
60
|
+
export declare function getNsiteFiles(event: NostrEvent): NsiteFile[];
|
|
61
|
+
/** Returns the Blossom server hints */
|
|
62
|
+
export declare function getNsiteServers(event: NostrEvent): string[];
|
|
63
|
+
/** Returns the upstream addressable app descriptor pointers */
|
|
64
|
+
export declare function getNsiteAppPointers(event: NostrEvent): AddressPointer[];
|
|
65
|
+
/** Returns the immediate parent site address */
|
|
66
|
+
export declare function getNsiteParentPointer(event: NostrEvent): AddressPointer | undefined;
|
|
67
|
+
/** Returns the origin site address of a copy lineage */
|
|
68
|
+
export declare function getNsiteRootPointer(event: NostrEvent): AddressPointer | undefined;
|
|
69
|
+
/** Returns the advertised aggregate hash */
|
|
70
|
+
export declare function getNsiteAggregateHash(event: NostrEvent): string | undefined;
|
|
71
|
+
/** Returns the deterministic SHA-256 of all path tags, including duplicates */
|
|
72
|
+
export declare function computeNsiteAggregateHash(manifest: Pick<NostrEvent, "tags">): string;
|
|
73
|
+
/** Returns the cached computed aggregate hash of a manifest */
|
|
74
|
+
export declare function getComputedNsiteAggregateHash(event: NostrEvent): string;
|
|
75
|
+
/** Checks if the advertised aggregate hash matches the manifest's path tags */
|
|
76
|
+
export declare function verifyNsiteAggregateHash(event: NostrEvent): boolean;
|
|
77
|
+
/** Resolves a request path with index.html and 404.html fallbacks */
|
|
78
|
+
export declare function resolveNsitePath(event: NostrEvent, path: string): NsiteFile | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the canonical DNS label for an nsite manifest
|
|
81
|
+
* @throws if the manifest is invalid
|
|
82
|
+
*/
|
|
83
|
+
export declare function getNsiteHostLabel(event: NostrEvent): string;
|
|
84
|
+
/** Parses a canonical nsite DNS label into a site or snapshot pointer */
|
|
85
|
+
export declare function parseNsiteHostLabel(label: string): AddressPointer | EventPointer | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Returns a site's URL on an nsite host
|
|
88
|
+
* @throws if the manifest or host URL is invalid
|
|
89
|
+
*/
|
|
90
|
+
export declare function getNsiteURL(event: NostrEvent, host: string | URL): URL;
|