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.
- 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 +4 -2
- package/dist/casts/trusted-assertions.js +20 -19
- 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 +23 -0
- package/dist/factories/index.js +23 -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/nostr-web-token.d.ts +39 -0
- package/dist/factories/nostr-web-token.js +95 -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.d.ts +1 -0
- package/dist/helpers/external-id.js +21 -46
- 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 +11 -0
- package/dist/helpers/index.js +11 -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/nostr-web-token.d.ts +54 -0
- package/dist/helpers/nostr-web-token.js +124 -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 +16 -0
- package/dist/operations/index.js +16 -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/nostr-web-token.d.ts +27 -0
- package/dist/operations/nostr-web-token.js +58 -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 +10 -10
package/dist/operations/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * as AppData from "./app-data.js";
|
|
2
|
+
export * as AppHandler from "./app-handler.js";
|
|
3
|
+
export * as AppRecommendation from "./app-recommendation.js";
|
|
2
4
|
export * as Badge from "./badge.js";
|
|
3
5
|
export * as BadgeAward from "./badge-award.js";
|
|
4
6
|
export * as CodeSnippet from "./code-snippet.js";
|
|
@@ -6,13 +8,21 @@ export * as Calendar from "./calendar.js";
|
|
|
6
8
|
export * as CalendarEvent from "./calendar-event.js";
|
|
7
9
|
export * as CalendarRsvp from "./calendar-rsvp.js";
|
|
8
10
|
export * as Channel from "./channel.js";
|
|
11
|
+
export * as ChatMessage from "./chat-message.js";
|
|
12
|
+
export * as ForumThread from "./forum-thread.js";
|
|
9
13
|
export * as Client from "./client.js";
|
|
10
14
|
export * as Comment from "./comment.js";
|
|
15
|
+
export * as ExternalIdentities from "./external-identities.js";
|
|
11
16
|
export * as FileMetadata from "./file-metadata.js";
|
|
12
17
|
export * as Geohash from "./geohash.js";
|
|
13
18
|
export * as GiftWrap from "./gift-wrap.js";
|
|
14
19
|
export * as GitGraspList from "./git-grasp-list.js";
|
|
20
|
+
export * as GitIssue from "./git-issue.js";
|
|
21
|
+
export * as GitThread from "./git-thread.js";
|
|
22
|
+
export * as GitPatch from "./git-patch.js";
|
|
23
|
+
export * as GitPullRequest from "./git-pull-request.js";
|
|
15
24
|
export * as GitRepository from "./git-repository.js";
|
|
25
|
+
export * as GitStatus from "./git-status.js";
|
|
16
26
|
export * as Group from "./group.js";
|
|
17
27
|
export * as Hashtags from "./hashtags.js";
|
|
18
28
|
export * as Highlight from "./highlight.js";
|
|
@@ -20,7 +30,9 @@ export * as LegacyMessage from "./legacy-message.js";
|
|
|
20
30
|
export * as List from "./list.js";
|
|
21
31
|
export * as LiveStream from "./live-stream.js";
|
|
22
32
|
export * as MediaAttachment from "./media-attachment.js";
|
|
33
|
+
export * as Napplet from "./napplet.js";
|
|
23
34
|
export * as Note from "./note.js";
|
|
35
|
+
export * as NostrWebToken from "./nostr-web-token.js";
|
|
24
36
|
export * as PicturePost from "./picture-post.js";
|
|
25
37
|
export * as Poll from "./poll.js";
|
|
26
38
|
export * as PollResponse from "./poll-response.js";
|
|
@@ -29,9 +41,13 @@ export * as ProfileBadges from "./profile-badges.js";
|
|
|
29
41
|
export * as Stream from "./stream.js";
|
|
30
42
|
export * as StreamChat from "./stream-chat.js";
|
|
31
43
|
export * as Torrent from "./torrent.js";
|
|
44
|
+
export * as TrustedProviders from "./trusted-providers.js";
|
|
45
|
+
export * as UserStatus from "./user-status.js";
|
|
32
46
|
export * as WrappedMessage from "./wrapped-message.js";
|
|
33
47
|
export * as Zap from "./zap.js";
|
|
34
48
|
export * as ZapGoal from "./zap-goal.js";
|
|
35
49
|
export * as ZapRequest from "./zap-request.js";
|
|
36
50
|
export * as ZapSplit from "./zap-split.js";
|
|
37
51
|
export * as TagOperations from "./tag/index.js";
|
|
52
|
+
export * from "./nsite.js";
|
|
53
|
+
export * from "./report.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Replaces commit metadata and the discovery tags owned by that metadata */
|
|
2
|
+
export function replaceGitCommitReferences(tags, name, commits) {
|
|
3
|
+
const old = new Set(tags.filter((tag) => tag[0] === name).flatMap((tag) => tag.slice(1)));
|
|
4
|
+
const next = tags.filter((tag) => tag[0] !== name);
|
|
5
|
+
// Each generated role owns one discovery tag; the same id may also identify the repository.
|
|
6
|
+
for (const commit of old) {
|
|
7
|
+
for (let index = next.length - 1; index >= 0; index--) {
|
|
8
|
+
if (next[index][0] === "r" && next[index][1] === commit) {
|
|
9
|
+
next.splice(index, 1);
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const ids = [...new Set(commits)];
|
|
15
|
+
return [...next, ...(ids.length ? [[name, ...ids], ...ids.map((id) => ["r", id])] : [])];
|
|
16
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
|
+
import { AddressPointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
import { NappletIconType } from "../helpers/napplet.js";
|
|
4
|
+
/** Sets the `d` tag identifier of a named napplet */
|
|
5
|
+
export declare function setNappletIdentifier(identifier: string): EventOperation;
|
|
6
|
+
/**
|
|
7
|
+
* Sets the sha256 of the napplet `index.html` artifact (`x` tag)
|
|
8
|
+
* @throws if the hash is not a 64 character lowercase hex string
|
|
9
|
+
*/
|
|
10
|
+
export declare function setNappletArtifactHash(sha256: string): EventOperation;
|
|
11
|
+
/** Sets the plain-text description of the napplet */
|
|
12
|
+
export declare function setNappletDescription(description: string): EventOperation;
|
|
13
|
+
/** Sets or removes the short display label (`title` tag) */
|
|
14
|
+
export declare function setNappletTitle(title: string | null): EventOperation;
|
|
15
|
+
/** Sets or removes the source URL (`source` tag) */
|
|
16
|
+
export declare function setNappletSource(url: string | null): EventOperation;
|
|
17
|
+
/** Adds an archetype (`z` tag) */
|
|
18
|
+
export declare function addNappletArchetype(archetype: string): EventOperation;
|
|
19
|
+
/** Removes an archetype (`z` tag) */
|
|
20
|
+
export declare function removeNappletArchetype(archetype: string): EventOperation;
|
|
21
|
+
/** Adds or replaces an accepted intent and its parameter names (`i` tag) */
|
|
22
|
+
export declare function addNappletIntent(intent: string, params?: string[]): EventOperation;
|
|
23
|
+
/** Removes an accepted intent (`i` tag) */
|
|
24
|
+
export declare function removeNappletIntent(intent: string): EventOperation;
|
|
25
|
+
/** Adds a NAP domain required for full functionality (`R` tag) */
|
|
26
|
+
export declare function addNappletRequiredDomain(domain: string): EventOperation;
|
|
27
|
+
/** Removes a required NAP domain (`R` tag) */
|
|
28
|
+
export declare function removeNappletRequiredDomain(domain: string): EventOperation;
|
|
29
|
+
/** Adds an optional NAP domain (`O` tag) */
|
|
30
|
+
export declare function addNappletOptionalDomain(domain: string): EventOperation;
|
|
31
|
+
/** Removes an optional NAP domain (`O` tag) */
|
|
32
|
+
export declare function removeNappletOptionalDomain(domain: string): EventOperation;
|
|
33
|
+
/** Adds a Blossom server hint (`server` tag) */
|
|
34
|
+
export declare function addNappletServer(url: string): EventOperation;
|
|
35
|
+
/** Removes a Blossom server hint (`server` tag) */
|
|
36
|
+
export declare function removeNappletServer(url: string): EventOperation;
|
|
37
|
+
/**
|
|
38
|
+
* Sets or removes the content-addressed icon (`icon` tag)
|
|
39
|
+
* @throws if the hash is not a lowercase hex sha256 or the MIME type is not png, jpeg or webp
|
|
40
|
+
*/
|
|
41
|
+
export declare function setNappletIcon(sha256: string | null, type?: NappletIconType): EventOperation;
|
|
42
|
+
/**
|
|
43
|
+
* Sets or removes the address of the napplet a snapshot derives from (`a` tag)
|
|
44
|
+
* @throws if the address cannot be parsed
|
|
45
|
+
*/
|
|
46
|
+
export declare function setNappletParent(parent: AddressPointer | string | null): EventOperation;
|
|
47
|
+
/**
|
|
48
|
+
* Sets or removes the address of the root napplet a snapshot's lineage originates from (`A` tag)
|
|
49
|
+
* @throws if the address cannot be parsed
|
|
50
|
+
*/
|
|
51
|
+
export declare function setNappletRoot(root: AddressPointer | string | null): EventOperation;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { getReplaceableAddressFromPointer, parseReplaceableAddress, } from "applesauce-core/helpers/pointers";
|
|
2
|
+
import { isSafeRelayURL } from "applesauce-core/helpers/relays";
|
|
3
|
+
import { normalizeURL } from "applesauce-core/helpers/url";
|
|
4
|
+
import { setContent } from "applesauce-core/operations/content";
|
|
5
|
+
import { addNameValueTag, removeNameValueTag, removeSingletonTag, setSingletonTag, } from "applesauce-core/operations/tag/common";
|
|
6
|
+
import { includeSingletonTag, modifyPublicTags } from "applesauce-core/operations/tags";
|
|
7
|
+
import { isSha256 } from "../helpers/blossom.js";
|
|
8
|
+
import { isNappletIconType } from "../helpers/napplet.js";
|
|
9
|
+
/** Builds a lineage tag (`a` or `A`) for a napplet address */
|
|
10
|
+
function createLineageTag(name, input) {
|
|
11
|
+
const pointer = typeof input === "string" ? parseReplaceableAddress(input) : input;
|
|
12
|
+
if (!pointer)
|
|
13
|
+
throw new Error(`Invalid napplet address: ${input}`);
|
|
14
|
+
const hint = pointer.relays?.find((url) => isSafeRelayURL(url));
|
|
15
|
+
const address = getReplaceableAddressFromPointer(pointer);
|
|
16
|
+
return hint ? [name, address, normalizeURL(hint)] : [name, address];
|
|
17
|
+
}
|
|
18
|
+
/** Removes all but the first tag with a name */
|
|
19
|
+
function keepFirstTag(name) {
|
|
20
|
+
return (tags) => {
|
|
21
|
+
const first = tags.findIndex((t) => t[0] === name);
|
|
22
|
+
return tags.filter((t, i) => t[0] !== name || i === first);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Sets the `d` tag identifier of a named napplet */
|
|
26
|
+
export function setNappletIdentifier(identifier) {
|
|
27
|
+
return includeSingletonTag(["d", identifier], true);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sets the sha256 of the napplet `index.html` artifact (`x` tag)
|
|
31
|
+
* @throws if the hash is not a 64 character lowercase hex string
|
|
32
|
+
*/
|
|
33
|
+
export function setNappletArtifactHash(sha256) {
|
|
34
|
+
if (!isSha256(sha256))
|
|
35
|
+
throw new Error("Napplet artifact hash must be a lowercase hex sha256");
|
|
36
|
+
// Drop duplicate "x" tags since a manifest must carry exactly one
|
|
37
|
+
return modifyPublicTags(keepFirstTag("x"), setSingletonTag(["x", sha256], true));
|
|
38
|
+
}
|
|
39
|
+
/** Sets the plain-text description of the napplet */
|
|
40
|
+
export function setNappletDescription(description) {
|
|
41
|
+
return setContent(description);
|
|
42
|
+
}
|
|
43
|
+
/** Sets or removes the short display label (`title` tag) */
|
|
44
|
+
export function setNappletTitle(title) {
|
|
45
|
+
return modifyPublicTags(title === null ? removeSingletonTag("title") : setSingletonTag(["title", title], true));
|
|
46
|
+
}
|
|
47
|
+
/** Sets or removes the source URL (`source` tag) */
|
|
48
|
+
export function setNappletSource(url) {
|
|
49
|
+
return modifyPublicTags(url === null ? removeSingletonTag("source") : setSingletonTag(["source", url], true));
|
|
50
|
+
}
|
|
51
|
+
/** Adds an archetype (`z` tag) */
|
|
52
|
+
export function addNappletArchetype(archetype) {
|
|
53
|
+
return modifyPublicTags(addNameValueTag(["z", archetype]));
|
|
54
|
+
}
|
|
55
|
+
/** Removes an archetype (`z` tag) */
|
|
56
|
+
export function removeNappletArchetype(archetype) {
|
|
57
|
+
return modifyPublicTags(removeNameValueTag(["z", archetype]));
|
|
58
|
+
}
|
|
59
|
+
/** Adds or replaces an accepted intent and its parameter names (`i` tag) */
|
|
60
|
+
export function addNappletIntent(intent, params = []) {
|
|
61
|
+
return modifyPublicTags(addNameValueTag(["i", intent, ...params]));
|
|
62
|
+
}
|
|
63
|
+
/** Removes an accepted intent (`i` tag) */
|
|
64
|
+
export function removeNappletIntent(intent) {
|
|
65
|
+
return modifyPublicTags(removeNameValueTag(["i", intent]));
|
|
66
|
+
}
|
|
67
|
+
/** Adds a NAP domain required for full functionality (`R` tag) */
|
|
68
|
+
export function addNappletRequiredDomain(domain) {
|
|
69
|
+
return modifyPublicTags(addNameValueTag(["R", domain]));
|
|
70
|
+
}
|
|
71
|
+
/** Removes a required NAP domain (`R` tag) */
|
|
72
|
+
export function removeNappletRequiredDomain(domain) {
|
|
73
|
+
return modifyPublicTags(removeNameValueTag(["R", domain]));
|
|
74
|
+
}
|
|
75
|
+
/** Adds an optional NAP domain (`O` tag) */
|
|
76
|
+
export function addNappletOptionalDomain(domain) {
|
|
77
|
+
return modifyPublicTags(addNameValueTag(["O", domain]));
|
|
78
|
+
}
|
|
79
|
+
/** Removes an optional NAP domain (`O` tag) */
|
|
80
|
+
export function removeNappletOptionalDomain(domain) {
|
|
81
|
+
return modifyPublicTags(removeNameValueTag(["O", domain]));
|
|
82
|
+
}
|
|
83
|
+
/** Adds a Blossom server hint (`server` tag) */
|
|
84
|
+
export function addNappletServer(url) {
|
|
85
|
+
return modifyPublicTags(addNameValueTag(["server", url]));
|
|
86
|
+
}
|
|
87
|
+
/** Removes a Blossom server hint (`server` tag) */
|
|
88
|
+
export function removeNappletServer(url) {
|
|
89
|
+
return modifyPublicTags(removeNameValueTag(["server", url]));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Sets or removes the content-addressed icon (`icon` tag)
|
|
93
|
+
* @throws if the hash is not a lowercase hex sha256 or the MIME type is not png, jpeg or webp
|
|
94
|
+
*/
|
|
95
|
+
export function setNappletIcon(sha256, type) {
|
|
96
|
+
if (sha256 === null)
|
|
97
|
+
return modifyPublicTags(removeSingletonTag("icon"));
|
|
98
|
+
if (!isSha256(sha256))
|
|
99
|
+
throw new Error("Napplet icon hash must be a lowercase hex sha256");
|
|
100
|
+
if (!type || !isNappletIconType(type))
|
|
101
|
+
throw new Error(`Unsupported napplet icon type: ${type}`);
|
|
102
|
+
return modifyPublicTags(setSingletonTag(["icon", sha256, type], true));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Sets or removes the address of the napplet a snapshot derives from (`a` tag)
|
|
106
|
+
* @throws if the address cannot be parsed
|
|
107
|
+
*/
|
|
108
|
+
export function setNappletParent(parent) {
|
|
109
|
+
if (parent === null)
|
|
110
|
+
return modifyPublicTags(removeSingletonTag("a"));
|
|
111
|
+
return modifyPublicTags(setSingletonTag(createLineageTag("a", parent), true));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Sets or removes the address of the root napplet a snapshot's lineage originates from (`A` tag)
|
|
115
|
+
* @throws if the address cannot be parsed
|
|
116
|
+
*/
|
|
117
|
+
export function setNappletRoot(root) {
|
|
118
|
+
if (root === null)
|
|
119
|
+
return modifyPublicTags(removeSingletonTag("A"));
|
|
120
|
+
return modifyPublicTags(setSingletonTag(createLineageTag("A", root), true));
|
|
121
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
|
+
/** Sets or removes the issuer claim. */
|
|
3
|
+
export declare function setIssuer(value: string | null): EventOperation;
|
|
4
|
+
/** Sets or removes the subject claim. */
|
|
5
|
+
export declare function setSubject(value: string | null): EventOperation;
|
|
6
|
+
/** Sets or removes the issued-at claim. */
|
|
7
|
+
export declare function setIssuedAt(value: number | null): EventOperation;
|
|
8
|
+
/** Sets or removes the expiration claim. */
|
|
9
|
+
export declare function setExpiration(value: number | null): EventOperation;
|
|
10
|
+
/** Sets or removes the not-before claim. */
|
|
11
|
+
export declare function setNotBefore(value: number | null): EventOperation;
|
|
12
|
+
/** Adds an audience claim. */
|
|
13
|
+
export declare function addAudience(value: string, replace?: boolean): EventOperation;
|
|
14
|
+
/** Removes a matching audience claim. */
|
|
15
|
+
export declare function removeAudience(value: string): EventOperation;
|
|
16
|
+
/** Removes all audience claims. */
|
|
17
|
+
export declare function clearAudiences(): EventOperation;
|
|
18
|
+
/** Replaces all audience claims. */
|
|
19
|
+
export declare function setAudiences(values: string[]): EventOperation;
|
|
20
|
+
/** Sets or removes a singleton claim. */
|
|
21
|
+
export declare function setClaim(name: string, value: string | number | null): EventOperation;
|
|
22
|
+
/** Adds an application-defined claim. */
|
|
23
|
+
export declare function addClaim(name: string, value: string | number, replace?: boolean): EventOperation;
|
|
24
|
+
/** Removes matching values for a claim, or all tags with the claim name when value is omitted. */
|
|
25
|
+
export declare function removeClaim(name: string, value?: string | number): EventOperation;
|
|
26
|
+
/** Removes all tags with the claim name. */
|
|
27
|
+
export declare function clearClaim(name: string): EventOperation;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { eventPipe } from "applesauce-core/helpers";
|
|
2
|
+
import { addNameValueTag, removeSingletonTag, setSingletonTag } from "applesauce-core/operations/tag/common";
|
|
3
|
+
import { modifyPublicTags } from "applesauce-core/operations/tags";
|
|
4
|
+
function setNullableSingletonTag(name, value) {
|
|
5
|
+
return modifyPublicTags(value === null ? removeSingletonTag(name) : setSingletonTag([name, String(value)], true));
|
|
6
|
+
}
|
|
7
|
+
/** Sets or removes the issuer claim. */
|
|
8
|
+
export function setIssuer(value) {
|
|
9
|
+
return setNullableSingletonTag("iss", value);
|
|
10
|
+
}
|
|
11
|
+
/** Sets or removes the subject claim. */
|
|
12
|
+
export function setSubject(value) {
|
|
13
|
+
return setNullableSingletonTag("sub", value);
|
|
14
|
+
}
|
|
15
|
+
/** Sets or removes the issued-at claim. */
|
|
16
|
+
export function setIssuedAt(value) {
|
|
17
|
+
return setNullableSingletonTag("iat", value);
|
|
18
|
+
}
|
|
19
|
+
/** Sets or removes the expiration claim. */
|
|
20
|
+
export function setExpiration(value) {
|
|
21
|
+
return setNullableSingletonTag("exp", value);
|
|
22
|
+
}
|
|
23
|
+
/** Sets or removes the not-before claim. */
|
|
24
|
+
export function setNotBefore(value) {
|
|
25
|
+
return setNullableSingletonTag("nbf", value);
|
|
26
|
+
}
|
|
27
|
+
/** Adds an audience claim. */
|
|
28
|
+
export function addAudience(value, replace = true) {
|
|
29
|
+
return modifyPublicTags(addNameValueTag(["aud", value], replace));
|
|
30
|
+
}
|
|
31
|
+
/** Removes a matching audience claim. */
|
|
32
|
+
export function removeAudience(value) {
|
|
33
|
+
return modifyPublicTags((tags) => tags.filter((tag) => !(tag[0] === "aud" && tag[1] === value)));
|
|
34
|
+
}
|
|
35
|
+
/** Removes all audience claims. */
|
|
36
|
+
export function clearAudiences() {
|
|
37
|
+
return modifyPublicTags((tags) => tags.filter((tag) => tag[0] !== "aud"));
|
|
38
|
+
}
|
|
39
|
+
/** Replaces all audience claims. */
|
|
40
|
+
export function setAudiences(values) {
|
|
41
|
+
return eventPipe(clearAudiences(), ...values.map((value) => addAudience(value, false)));
|
|
42
|
+
}
|
|
43
|
+
/** Sets or removes a singleton claim. */
|
|
44
|
+
export function setClaim(name, value) {
|
|
45
|
+
return setNullableSingletonTag(name, value);
|
|
46
|
+
}
|
|
47
|
+
/** Adds an application-defined claim. */
|
|
48
|
+
export function addClaim(name, value, replace = true) {
|
|
49
|
+
return modifyPublicTags(addNameValueTag([name, String(value)], replace));
|
|
50
|
+
}
|
|
51
|
+
/** Removes matching values for a claim, or all tags with the claim name when value is omitted. */
|
|
52
|
+
export function removeClaim(name, value) {
|
|
53
|
+
return modifyPublicTags((tags) => tags.filter((tag) => (value === undefined ? tag[0] !== name : !(tag[0] === name && tag[1] === String(value)))));
|
|
54
|
+
}
|
|
55
|
+
/** Removes all tags with the claim name. */
|
|
56
|
+
export function clearClaim(name) {
|
|
57
|
+
return removeClaim(name);
|
|
58
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
|
+
import { AddressPointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
/**
|
|
4
|
+
* Sets the identifier of a named site
|
|
5
|
+
* @throws if the identifier is invalid or the draft is not a named site
|
|
6
|
+
*/
|
|
7
|
+
export declare function setNsiteIdentifier(identifier: string): EventOperation;
|
|
8
|
+
/** Sets or removes the site's title */
|
|
9
|
+
export declare function setNsiteTitle(title: string | null): EventOperation;
|
|
10
|
+
/** Sets or removes the site's description tag */
|
|
11
|
+
export declare function setNsiteDescription(description: string | null): EventOperation;
|
|
12
|
+
/** Sets or removes the site's source repository or archive URL */
|
|
13
|
+
export declare function setNsiteSource(source: string | null): EventOperation;
|
|
14
|
+
/** Adds a Blossom server hint */
|
|
15
|
+
export declare function addNsiteServer(server: string): EventOperation;
|
|
16
|
+
/** Removes a Blossom server hint */
|
|
17
|
+
export declare function removeNsiteServer(server: string): EventOperation;
|
|
18
|
+
/**
|
|
19
|
+
* Adds or replaces an upstream app descriptor reference
|
|
20
|
+
* @throws if the address is not addressable
|
|
21
|
+
*/
|
|
22
|
+
export declare function addNsiteApp(app: AddressPointer | string): EventOperation;
|
|
23
|
+
/**
|
|
24
|
+
* Removes an upstream app descriptor reference
|
|
25
|
+
* @throws if the address is not addressable
|
|
26
|
+
*/
|
|
27
|
+
export declare function removeNsiteApp(app: AddressPointer | string): EventOperation;
|
|
28
|
+
/**
|
|
29
|
+
* Sets or removes the immediate parent site address
|
|
30
|
+
* @throws if the address does not reference a root or named site
|
|
31
|
+
*/
|
|
32
|
+
export declare function setNsiteParent(parent: AddressPointer | string | null): EventOperation;
|
|
33
|
+
/**
|
|
34
|
+
* Sets or removes the origin site address of the copy lineage
|
|
35
|
+
* @throws if the address does not reference a root or named site
|
|
36
|
+
*/
|
|
37
|
+
export declare function setNsiteRoot(root: AddressPointer | string | null): EventOperation;
|
|
38
|
+
/**
|
|
39
|
+
* Sets or removes the advertised aggregate hash
|
|
40
|
+
* @throws if the hash is not lowercase hexadecimal SHA-256
|
|
41
|
+
*/
|
|
42
|
+
export declare function setNsiteAggregateHash(hash: string | null): EventOperation;
|
|
43
|
+
/** Updates the aggregate hash from all current path tags */
|
|
44
|
+
export declare function updateNsiteAggregateHash(): EventOperation;
|
|
45
|
+
/**
|
|
46
|
+
* Adds or replaces a file mapping and updates the aggregate hash
|
|
47
|
+
* @throws if the path or hash is invalid
|
|
48
|
+
*/
|
|
49
|
+
export declare function setNsiteFile(path: string, hash: string): EventOperation;
|
|
50
|
+
/** Removes a file mapping and updates the aggregate hash */
|
|
51
|
+
export declare function removeNsiteFile(path: string): EventOperation;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { getReplaceableAddressFromPointer, parseReplaceableAddress, } from "applesauce-core/helpers/pointers";
|
|
2
|
+
import { isSafeRelayURL } from "applesauce-core/helpers/relays";
|
|
3
|
+
import { normalizeURL } from "applesauce-core/helpers/url";
|
|
4
|
+
import { addNameValueTag, removeNameValueTag } from "applesauce-core/operations/tag/common";
|
|
5
|
+
import { modifyPublicTags } from "applesauce-core/operations/tags";
|
|
6
|
+
import { isSha256 } from "../helpers/blossom.js";
|
|
7
|
+
import { computeNsiteAggregateHash, isNsiteAddressPointer, isValidNsiteIdentifier, isValidNsitePath, NSITE_KIND, } from "../helpers/nsite.js";
|
|
8
|
+
function singleton(name, value) {
|
|
9
|
+
return modifyPublicTags((tags) => [...tags.filter((t) => t[0] !== name), ...(value ? [[name, ...value]] : [])]);
|
|
10
|
+
}
|
|
11
|
+
function pointerTag(name, input) {
|
|
12
|
+
const pointer = typeof input === "string" ? parseReplaceableAddress(input) : input;
|
|
13
|
+
if (!pointer ||
|
|
14
|
+
!isSha256(pointer.pubkey) ||
|
|
15
|
+
(name === "app" ? pointer.kind < 30000 || pointer.kind >= 40000 : !isNsiteAddressPointer(pointer)))
|
|
16
|
+
throw new Error(`Invalid ${name === "app" ? "app descriptor" : "nsite"} address`);
|
|
17
|
+
const relay = pointer.relays?.find(isSafeRelayURL);
|
|
18
|
+
return [name, getReplaceableAddressFromPointer(pointer), ...(relay ? [normalizeURL(relay)] : [])];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sets the identifier of a named site
|
|
22
|
+
* @throws if the identifier is invalid or the draft is not a named site
|
|
23
|
+
*/
|
|
24
|
+
export function setNsiteIdentifier(identifier) {
|
|
25
|
+
if (!isValidNsiteIdentifier(identifier))
|
|
26
|
+
throw new Error("Invalid nsite identifier");
|
|
27
|
+
return (draft) => {
|
|
28
|
+
if (draft.kind !== NSITE_KIND)
|
|
29
|
+
throw new Error("Only named nsites have identifiers");
|
|
30
|
+
return singleton("d", [identifier])(draft);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Sets or removes the site's title */
|
|
34
|
+
export function setNsiteTitle(title) {
|
|
35
|
+
return singleton("title", title === null ? null : [title]);
|
|
36
|
+
}
|
|
37
|
+
/** Sets or removes the site's description tag */
|
|
38
|
+
export function setNsiteDescription(description) {
|
|
39
|
+
return singleton("description", description === null ? null : [description]);
|
|
40
|
+
}
|
|
41
|
+
/** Sets or removes the site's source repository or archive URL */
|
|
42
|
+
export function setNsiteSource(source) {
|
|
43
|
+
return singleton("source", source === null ? null : [source]);
|
|
44
|
+
}
|
|
45
|
+
/** Adds a Blossom server hint */
|
|
46
|
+
export function addNsiteServer(server) {
|
|
47
|
+
return modifyPublicTags(addNameValueTag(["server", server]));
|
|
48
|
+
}
|
|
49
|
+
/** Removes a Blossom server hint */
|
|
50
|
+
export function removeNsiteServer(server) {
|
|
51
|
+
return modifyPublicTags(removeNameValueTag(["server", server]));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Adds or replaces an upstream app descriptor reference
|
|
55
|
+
* @throws if the address is not addressable
|
|
56
|
+
*/
|
|
57
|
+
export function addNsiteApp(app) {
|
|
58
|
+
return modifyPublicTags(addNameValueTag(pointerTag("app", app)));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Removes an upstream app descriptor reference
|
|
62
|
+
* @throws if the address is not addressable
|
|
63
|
+
*/
|
|
64
|
+
export function removeNsiteApp(app) {
|
|
65
|
+
return modifyPublicTags(removeNameValueTag(pointerTag("app", app).slice(0, 2)));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Sets or removes the immediate parent site address
|
|
69
|
+
* @throws if the address does not reference a root or named site
|
|
70
|
+
*/
|
|
71
|
+
export function setNsiteParent(parent) {
|
|
72
|
+
return singleton("a", parent === null ? null : pointerTag("a", parent).slice(1));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Sets or removes the origin site address of the copy lineage
|
|
76
|
+
* @throws if the address does not reference a root or named site
|
|
77
|
+
*/
|
|
78
|
+
export function setNsiteRoot(root) {
|
|
79
|
+
return singleton("A", root === null ? null : pointerTag("A", root).slice(1));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Sets or removes the advertised aggregate hash
|
|
83
|
+
* @throws if the hash is not lowercase hexadecimal SHA-256
|
|
84
|
+
*/
|
|
85
|
+
export function setNsiteAggregateHash(hash) {
|
|
86
|
+
if (hash !== null && !isSha256(hash))
|
|
87
|
+
throw new Error("Invalid nsite aggregate hash");
|
|
88
|
+
return singleton("x", hash === null ? null : [hash, "aggregate"]);
|
|
89
|
+
}
|
|
90
|
+
/** Updates the aggregate hash from all current path tags */
|
|
91
|
+
export function updateNsiteAggregateHash() {
|
|
92
|
+
return (draft) => setNsiteAggregateHash(computeNsiteAggregateHash(draft))(draft);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Adds or replaces a file mapping and updates the aggregate hash
|
|
96
|
+
* @throws if the path or hash is invalid
|
|
97
|
+
*/
|
|
98
|
+
export function setNsiteFile(path, hash) {
|
|
99
|
+
if (!isValidNsitePath(path) || !isSha256(hash))
|
|
100
|
+
throw new Error("Invalid nsite file path or hash");
|
|
101
|
+
return modifyPublicTags((tags) => {
|
|
102
|
+
const next = [...tags.filter((t) => !(t[0] === "path" && t[1] === path) && t[0] !== "x"), ["path", path, hash]];
|
|
103
|
+
return [...next, ["x", computeNsiteAggregateHash({ tags: next }), "aggregate"]];
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/** Removes a file mapping and updates the aggregate hash */
|
|
107
|
+
export function removeNsiteFile(path) {
|
|
108
|
+
return modifyPublicTags((tags) => {
|
|
109
|
+
const next = tags.filter((t) => !(t[0] === "path" && t[1] === path) && t[0] !== "x");
|
|
110
|
+
return [...next, ["x", computeNsiteAggregateHash({ tags: next }), "aggregate"]];
|
|
111
|
+
});
|
|
112
|
+
}
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { EventOperation } from "applesauce-core/factories";
|
|
2
|
-
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { NostrEvent, Rumor } from "applesauce-core/helpers/event";
|
|
3
3
|
import { Emoji } from "../helpers/emoji.js";
|
|
4
4
|
/** Sets the content for a reaction event */
|
|
5
5
|
export declare function setReaction(emoji?: string | Emoji): EventOperation;
|
|
6
|
+
/**
|
|
7
|
+
* The event a reaction points to. A full event/rumor carries its tags (so an
|
|
8
|
+
* addressable target can be resolved to an "a" tag), or a lightweight
|
|
9
|
+
* `{ id, pubkey, kind }` pointer for cases where only the identity is known.
|
|
10
|
+
*/
|
|
11
|
+
export type ReactionParent = NostrEvent | Rumor | {
|
|
12
|
+
id: string;
|
|
13
|
+
pubkey: string;
|
|
14
|
+
kind: number;
|
|
15
|
+
};
|
|
6
16
|
/**
|
|
7
17
|
* Includes NIP-25 "e", "p", "k", and "a" tags for a reaction event to point to a parent event
|
|
8
18
|
* @param event - Event being reacted to
|
|
9
19
|
* @param getEventRelayHint - Optional function to get relay hint for event ID
|
|
10
20
|
* @param getPubkeyRelayHint - Optional function to get relay hint for pubkey
|
|
11
21
|
*/
|
|
12
|
-
export declare function setReactionParent(event:
|
|
22
|
+
export declare function setReactionParent(event: ReactionParent, getEventRelayHint?: (eventId: string) => Promise<string | undefined>, getPubkeyRelayHint?: (pubkey: string) => Promise<string | undefined>): EventOperation;
|
|
@@ -26,7 +26,7 @@ export function setReactionParent(event, getEventRelayHint, getPubkeyRelayHint)
|
|
|
26
26
|
pubkey: event.pubkey,
|
|
27
27
|
relays: pubkeyHint ? [pubkeyHint] : undefined,
|
|
28
28
|
});
|
|
29
|
-
if (isAddressableKind(event.kind)) {
|
|
29
|
+
if (isAddressableKind(event.kind) && "tags" in event) {
|
|
30
30
|
// include "a" tag
|
|
31
31
|
const identifier = getTagValue(event, "d");
|
|
32
32
|
if (identifier)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
|
+
import { ReportReason, ReportTarget } from "../helpers/reports.js";
|
|
3
|
+
/** An event identity required when reporting an event or its media */
|
|
4
|
+
export type ReportEventTarget = {
|
|
5
|
+
/** The event ID */
|
|
6
|
+
id: string;
|
|
7
|
+
/** The event author's public key */
|
|
8
|
+
pubkey: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Adds or updates a reported user
|
|
12
|
+
* @throws if the public key or reason is invalid
|
|
13
|
+
*/
|
|
14
|
+
export declare function addReportUser(pubkey: string, reason: ReportReason): EventOperation;
|
|
15
|
+
/**
|
|
16
|
+
* Adds or updates a reported event and includes its author
|
|
17
|
+
* @throws if the event identity or reason is invalid
|
|
18
|
+
*/
|
|
19
|
+
export declare function addReportEvent(event: ReportEventTarget, reason: ReportReason): EventOperation;
|
|
20
|
+
/**
|
|
21
|
+
* Adds or updates a reported blob and includes its containing event and author
|
|
22
|
+
* @throws if the hash, event identity, or reason is invalid
|
|
23
|
+
*/
|
|
24
|
+
export declare function addReportBlob(hash: string, event: ReportEventTarget, reason: ReportReason): EventOperation;
|
|
25
|
+
/** Removes matching target tags and preserves all other tags */
|
|
26
|
+
export declare function removeReportTarget(type: ReportTarget["type"], value: string): EventOperation;
|
|
27
|
+
/**
|
|
28
|
+
* Adds a media server or direct media URL without rewriting its path
|
|
29
|
+
* @throws if the URL is invalid or does not use HTTP or HTTPS
|
|
30
|
+
*/
|
|
31
|
+
export declare function addReportServer(server: string): EventOperation;
|
|
32
|
+
/** Removes a media server or direct media URL */
|
|
33
|
+
export declare function removeReportServer(server: string): EventOperation;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { modifyPublicTags } from "applesauce-core/operations/tags";
|
|
2
|
+
import { isReportIdentifier, ReportReason } from "../helpers/reports.js";
|
|
3
|
+
function check(value, reason) {
|
|
4
|
+
if (!isReportIdentifier(value))
|
|
5
|
+
throw new Error("Expected a 32-byte lowercase hex report target");
|
|
6
|
+
if (reason !== undefined && !Object.values(ReportReason).includes(reason))
|
|
7
|
+
throw new Error("Invalid report reason");
|
|
8
|
+
}
|
|
9
|
+
function put(tags, name, value, reason) {
|
|
10
|
+
const existing = tags.find((t) => t[0] === name && t[1] === value);
|
|
11
|
+
if (existing && reason === undefined)
|
|
12
|
+
return tags;
|
|
13
|
+
return [...tags.filter((t) => t[0] !== name || t[1] !== value), reason ? [name, value, reason] : [name, value]];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Adds or updates a reported user
|
|
17
|
+
* @throws if the public key or reason is invalid
|
|
18
|
+
*/
|
|
19
|
+
export function addReportUser(pubkey, reason) {
|
|
20
|
+
check(pubkey, reason);
|
|
21
|
+
return modifyPublicTags((tags) => put(tags, "p", pubkey, reason));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Adds or updates a reported event and includes its author
|
|
25
|
+
* @throws if the event identity or reason is invalid
|
|
26
|
+
*/
|
|
27
|
+
export function addReportEvent(event, reason) {
|
|
28
|
+
check(event.id, reason);
|
|
29
|
+
check(event.pubkey);
|
|
30
|
+
return modifyPublicTags((tags) => put(put(tags, "p", event.pubkey), "e", event.id, reason));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Adds or updates a reported blob and includes its containing event and author
|
|
34
|
+
* @throws if the hash, event identity, or reason is invalid
|
|
35
|
+
*/
|
|
36
|
+
export function addReportBlob(hash, event, reason) {
|
|
37
|
+
check(hash, reason);
|
|
38
|
+
check(event.id);
|
|
39
|
+
check(event.pubkey);
|
|
40
|
+
return modifyPublicTags((tags) => put(put(put(tags, "p", event.pubkey), "e", event.id), "x", hash, reason));
|
|
41
|
+
}
|
|
42
|
+
/** Removes matching target tags and preserves all other tags */
|
|
43
|
+
export function removeReportTarget(type, value) {
|
|
44
|
+
const name = { user: "p", event: "e", blob: "x" }[type];
|
|
45
|
+
return modifyPublicTags((tags) => tags.filter((t) => t[0] !== name || t[1] !== value));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Adds a media server or direct media URL without rewriting its path
|
|
49
|
+
* @throws if the URL is invalid or does not use HTTP or HTTPS
|
|
50
|
+
*/
|
|
51
|
+
export function addReportServer(server) {
|
|
52
|
+
const url = new URL(server);
|
|
53
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
54
|
+
throw new Error("Expected an HTTP media URL");
|
|
55
|
+
return modifyPublicTags((tags) => tags.some((t) => t[0] === "server" && t[1] === server) ? tags : [...tags, ["server", server]]);
|
|
56
|
+
}
|
|
57
|
+
/** Removes a media server or direct media URL */
|
|
58
|
+
export function removeReportServer(server) {
|
|
59
|
+
return modifyPublicTags((tags) => tags.filter((t) => t[0] !== "server" || t[1] !== server));
|
|
60
|
+
}
|