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
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isValidRootNapplet, NAPPLET_ROOT_KIND } from "../helpers/napplet.js";
|
|
3
|
+
import { NappletManifestFactory } from "./internal/napplet-manifest.js";
|
|
4
|
+
/** A factory for root napplet manifests (kind 15129) */
|
|
5
|
+
export class RootNappletFactory extends NappletManifestFactory {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a root napplet manifest
|
|
8
|
+
* @throws if the artifact hash is invalid
|
|
9
|
+
*/
|
|
10
|
+
static create(artifactHash, description) {
|
|
11
|
+
return new RootNappletFactory((res) => res(blankEventTemplate(NAPPLET_ROOT_KIND)))
|
|
12
|
+
.artifact(artifactHash)
|
|
13
|
+
.description(description);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a factory for modifying a root napplet manifest
|
|
17
|
+
* @throws if the event is not a valid root napplet manifest
|
|
18
|
+
*/
|
|
19
|
+
static modify(event) {
|
|
20
|
+
if (!isValidRootNapplet(event))
|
|
21
|
+
throw new Error("Expected a root napplet manifest");
|
|
22
|
+
return new RootNappletFactory((res) => res(toEventTemplate(event)));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { NSITE_ROOT_KIND, NsiteFile } from "../helpers/nsite.js";
|
|
3
|
+
import { NsiteManifestFactory } from "./internal/nsite-manifest.js";
|
|
4
|
+
/** An event template for a root nsite manifest */
|
|
5
|
+
export type RootNsiteTemplate = KnownEventTemplate<typeof NSITE_ROOT_KIND>;
|
|
6
|
+
/** A factory for root nsite manifests (kind 15128) */
|
|
7
|
+
export declare class RootNsiteFactory extends NsiteManifestFactory<typeof NSITE_ROOT_KIND> {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a root nsite manifest
|
|
10
|
+
* @throws if the manifest is empty or a path or hash is invalid
|
|
11
|
+
*/
|
|
12
|
+
static create(files: NsiteFile[]): RootNsiteFactory;
|
|
13
|
+
/**
|
|
14
|
+
* Copies a root or named site into a new root manifest with copy lineage
|
|
15
|
+
* @throws if the source is invalid or is a snapshot
|
|
16
|
+
*/
|
|
17
|
+
static copy(site: NostrEvent): RootNsiteFactory;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a factory for modifying a root nsite manifest
|
|
20
|
+
* @throws if the event is not a valid root nsite manifest
|
|
21
|
+
*/
|
|
22
|
+
static modify(event: NostrEvent): RootNsiteFactory;
|
|
23
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isValidRootNsite, NSITE_ROOT_KIND } from "../helpers/nsite.js";
|
|
3
|
+
import { NsiteManifestFactory } from "./internal/nsite-manifest.js";
|
|
4
|
+
import { getReplaceableAddressForEvent } from "applesauce-core/helpers/pointers";
|
|
5
|
+
import { unixNow } from "applesauce-core/helpers/time";
|
|
6
|
+
import { isValidNsite, isNsiteSnapshot, getNsiteRootPointer } from "../helpers/nsite.js";
|
|
7
|
+
/** A factory for root nsite manifests (kind 15128) */
|
|
8
|
+
export class RootNsiteFactory extends NsiteManifestFactory {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a root nsite manifest
|
|
11
|
+
* @throws if the manifest is empty or a path or hash is invalid
|
|
12
|
+
*/
|
|
13
|
+
static create(files) {
|
|
14
|
+
if (!files.length)
|
|
15
|
+
throw new Error("An nsite must include at least one file");
|
|
16
|
+
let factory = new RootNsiteFactory((res) => res(blankEventTemplate(NSITE_ROOT_KIND)));
|
|
17
|
+
for (const file of files)
|
|
18
|
+
factory = factory.file(file.path, file.sha256);
|
|
19
|
+
return factory;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Copies a root or named site into a new root manifest with copy lineage
|
|
23
|
+
* @throws if the source is invalid or is a snapshot
|
|
24
|
+
*/
|
|
25
|
+
static copy(site) {
|
|
26
|
+
if (!isValidNsite(site) || isNsiteSnapshot(site))
|
|
27
|
+
throw new Error("Expected a root or named nsite");
|
|
28
|
+
const kind = NSITE_ROOT_KIND;
|
|
29
|
+
const tags = site.tags.filter((t) => t[0] !== "d" && t[0] !== "a").map((t) => [...t]);
|
|
30
|
+
let factory = new RootNsiteFactory((res) => res({ kind, created_at: unixNow(), content: site.content, tags })).parent(getReplaceableAddressForEvent(site));
|
|
31
|
+
if (!getNsiteRootPointer(site))
|
|
32
|
+
factory = factory.root(getReplaceableAddressForEvent(site));
|
|
33
|
+
return factory;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a factory for modifying a root nsite manifest
|
|
37
|
+
* @throws if the event is not a valid root nsite manifest
|
|
38
|
+
*/
|
|
39
|
+
static modify(event) {
|
|
40
|
+
if (!isValidRootNsite(event))
|
|
41
|
+
throw new Error("Expected a root nsite manifest");
|
|
42
|
+
return new RootNsiteFactory((res) => res(toEventTemplate(event)));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
-
import { KnownEventTemplate } from "applesauce-core/helpers";
|
|
2
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
3
|
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
4
4
|
import { TORRENT_KIND, TorrentExternalIdentifier, TorrentFile } from "../helpers/torrent.js";
|
|
5
|
+
/** An unsigned NIP-35 torrent event template */
|
|
5
6
|
export type TorrentTemplate = KnownEventTemplate<typeof TORRENT_KIND>;
|
|
7
|
+
/** @deprecated Use the TorrentFactory builder methods instead */
|
|
6
8
|
export type TorrentBlueprintOptions = MetaTagOptions & {
|
|
7
9
|
/** Torrent title */
|
|
8
10
|
title?: string;
|
|
@@ -21,35 +23,47 @@ export type TorrentBlueprintOptions = MetaTagOptions & {
|
|
|
21
23
|
};
|
|
22
24
|
/** A factory class for building NIP-35 torrent events (kind 2003) */
|
|
23
25
|
export declare class TorrentFactory extends EventFactory<typeof TORRENT_KIND, TorrentTemplate> {
|
|
26
|
+
/** Creates a new torrent factory with an info hash and optional description */
|
|
27
|
+
static create(infoHash: string, content?: string): TorrentFactory;
|
|
24
28
|
/**
|
|
25
|
-
* Creates a
|
|
26
|
-
* @
|
|
27
|
-
* @param content - Optional description
|
|
28
|
-
* @returns A new torrent factory
|
|
29
|
+
* Creates a factory for modifying an existing torrent event
|
|
30
|
+
* @throws if the event is not a kind 2003 torrent
|
|
29
31
|
*/
|
|
30
|
-
static
|
|
32
|
+
static modify(event: NostrEvent): TorrentFactory;
|
|
31
33
|
/** Sets the torrent info hash */
|
|
32
34
|
infoHash(hash: string): this;
|
|
33
35
|
/** Sets the torrent title */
|
|
34
36
|
title(title: string): this;
|
|
35
37
|
/** Sets the category path */
|
|
36
38
|
categoryPath(path: string): this;
|
|
39
|
+
/** Removes the category path */
|
|
40
|
+
clearCategoryPath(): this;
|
|
37
41
|
/** Sets the newznab category */
|
|
38
42
|
category(id: number): this;
|
|
43
|
+
/** Removes the newznab category */
|
|
44
|
+
clearCategory(): this;
|
|
39
45
|
/** Adds a file to the torrent */
|
|
40
46
|
addFile(file: TorrentFile): this;
|
|
47
|
+
/** Removes a file from the torrent by name */
|
|
48
|
+
removeFile(name: string): this;
|
|
41
49
|
/** Adds files to the torrent */
|
|
42
|
-
files(files: TorrentFile[]):
|
|
50
|
+
files(files: TorrentFile[]): TorrentFactory;
|
|
43
51
|
/** Adds a tracker URL */
|
|
44
52
|
addTracker(url: string): this;
|
|
53
|
+
/** Removes a tracker URL */
|
|
54
|
+
removeTracker(url: string): this;
|
|
45
55
|
/** Adds tracker URLs */
|
|
46
|
-
trackers(urls: string[]):
|
|
56
|
+
trackers(urls: string[]): TorrentFactory;
|
|
47
57
|
/** Adds a search tag */
|
|
48
58
|
addSearchTag(tag: string): this;
|
|
59
|
+
/** Removes a search tag */
|
|
60
|
+
removeSearchTag(tag: string): this;
|
|
49
61
|
/** Adds search tags */
|
|
50
|
-
searchTags(tags: string[]):
|
|
62
|
+
searchTags(tags: string[]): TorrentFactory;
|
|
51
63
|
/** Adds an external identifier */
|
|
52
64
|
addExternalId(id: TorrentExternalIdentifier): this;
|
|
65
|
+
/** Removes an external identifier by its full identifier string (e.g., "imdb:tt15239678") */
|
|
66
|
+
removeExternalId(identifier: string): this;
|
|
53
67
|
/** Adds external identifiers */
|
|
54
|
-
externalIds(ids: TorrentExternalIdentifier[]):
|
|
68
|
+
externalIds(ids: TorrentExternalIdentifier[]): TorrentFactory;
|
|
55
69
|
}
|
|
@@ -1,88 +1,92 @@
|
|
|
1
|
-
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
1
|
+
import { EventFactory, blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
2
2
|
import { TORRENT_KIND } from "../helpers/torrent.js";
|
|
3
|
-
import { addTorrentExternalIdentifier, addTorrentFile, addTorrentSearchTag, addTorrentTracker, setTorrentCategory, setTorrentCategoryPath, setTorrentInfoHash, setTorrentTitle, } from "../operations/torrent.js";
|
|
3
|
+
import { addTorrentExternalIdentifier, addTorrentFile, addTorrentSearchTag, addTorrentTracker, removeTorrentCategory, removeTorrentCategoryPath, removeTorrentExternalIdentifier, removeTorrentFile, removeTorrentSearchTag, removeTorrentTracker, setTorrentCategory, setTorrentCategoryPath, setTorrentInfoHash, setTorrentTitle, } from "../operations/torrent.js";
|
|
4
4
|
/** A factory class for building NIP-35 torrent events (kind 2003) */
|
|
5
5
|
export class TorrentFactory extends EventFactory {
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new torrent factory
|
|
8
|
-
* @param infoHash - The torrent info hash
|
|
9
|
-
* @param content - Optional description
|
|
10
|
-
* @returns A new torrent factory
|
|
11
|
-
*/
|
|
6
|
+
/** Creates a new torrent factory with an info hash and optional description */
|
|
12
7
|
static create(infoHash, content) {
|
|
13
8
|
const factory = new TorrentFactory((res) => res(blankEventTemplate(TORRENT_KIND))).infoHash(infoHash);
|
|
14
9
|
return content ? factory.content(content) : factory;
|
|
15
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a factory for modifying an existing torrent event
|
|
13
|
+
* @throws if the event is not a kind 2003 torrent
|
|
14
|
+
*/
|
|
15
|
+
static modify(event) {
|
|
16
|
+
if (event.kind !== TORRENT_KIND)
|
|
17
|
+
throw new Error("Expected a torrent event");
|
|
18
|
+
return new TorrentFactory((res) => res(toEventTemplate(event)));
|
|
19
|
+
}
|
|
16
20
|
/** Sets the torrent info hash */
|
|
17
21
|
infoHash(hash) {
|
|
18
|
-
return this.chain(
|
|
22
|
+
return this.chain(setTorrentInfoHash(hash));
|
|
19
23
|
}
|
|
20
24
|
/** Sets the torrent title */
|
|
21
25
|
title(title) {
|
|
22
|
-
return this.chain(
|
|
26
|
+
return this.chain(setTorrentTitle(title));
|
|
23
27
|
}
|
|
24
28
|
/** Sets the category path */
|
|
25
29
|
categoryPath(path) {
|
|
26
|
-
return this.chain(
|
|
30
|
+
return this.chain(setTorrentCategoryPath(path));
|
|
31
|
+
}
|
|
32
|
+
/** Removes the category path */
|
|
33
|
+
clearCategoryPath() {
|
|
34
|
+
return this.chain(removeTorrentCategoryPath());
|
|
27
35
|
}
|
|
28
36
|
/** Sets the newznab category */
|
|
29
37
|
category(id) {
|
|
30
|
-
return this.chain(
|
|
38
|
+
return this.chain(setTorrentCategory(id));
|
|
39
|
+
}
|
|
40
|
+
/** Removes the newznab category */
|
|
41
|
+
clearCategory() {
|
|
42
|
+
return this.chain(removeTorrentCategory());
|
|
31
43
|
}
|
|
32
44
|
/** Adds a file to the torrent */
|
|
33
45
|
addFile(file) {
|
|
34
|
-
return this.chain(
|
|
46
|
+
return this.chain(addTorrentFile(file));
|
|
47
|
+
}
|
|
48
|
+
/** Removes a file from the torrent by name */
|
|
49
|
+
removeFile(name) {
|
|
50
|
+
return this.chain(removeTorrentFile(name));
|
|
35
51
|
}
|
|
36
52
|
/** Adds files to the torrent */
|
|
37
53
|
files(files) {
|
|
38
|
-
return
|
|
39
|
-
let result = draft;
|
|
40
|
-
for (const file of files) {
|
|
41
|
-
result = await addTorrentFile(file)(result);
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
44
|
-
});
|
|
54
|
+
return files.reduce((factory, file) => factory.addFile(file), this);
|
|
45
55
|
}
|
|
46
56
|
/** Adds a tracker URL */
|
|
47
57
|
addTracker(url) {
|
|
48
|
-
return this.chain(
|
|
58
|
+
return this.chain(addTorrentTracker(url));
|
|
59
|
+
}
|
|
60
|
+
/** Removes a tracker URL */
|
|
61
|
+
removeTracker(url) {
|
|
62
|
+
return this.chain(removeTorrentTracker(url));
|
|
49
63
|
}
|
|
50
64
|
/** Adds tracker URLs */
|
|
51
65
|
trackers(urls) {
|
|
52
|
-
return
|
|
53
|
-
let result = draft;
|
|
54
|
-
for (const url of urls) {
|
|
55
|
-
result = await addTorrentTracker(url)(result);
|
|
56
|
-
}
|
|
57
|
-
return result;
|
|
58
|
-
});
|
|
66
|
+
return urls.reduce((factory, url) => factory.addTracker(url), this);
|
|
59
67
|
}
|
|
60
68
|
/** Adds a search tag */
|
|
61
69
|
addSearchTag(tag) {
|
|
62
|
-
return this.chain(
|
|
70
|
+
return this.chain(addTorrentSearchTag(tag));
|
|
71
|
+
}
|
|
72
|
+
/** Removes a search tag */
|
|
73
|
+
removeSearchTag(tag) {
|
|
74
|
+
return this.chain(removeTorrentSearchTag(tag));
|
|
63
75
|
}
|
|
64
76
|
/** Adds search tags */
|
|
65
77
|
searchTags(tags) {
|
|
66
|
-
return
|
|
67
|
-
let result = draft;
|
|
68
|
-
for (const tag of tags) {
|
|
69
|
-
result = await addTorrentSearchTag(tag)(result);
|
|
70
|
-
}
|
|
71
|
-
return result;
|
|
72
|
-
});
|
|
78
|
+
return tags.reduce((factory, tag) => factory.addSearchTag(tag), this);
|
|
73
79
|
}
|
|
74
80
|
/** Adds an external identifier */
|
|
75
81
|
addExternalId(id) {
|
|
76
|
-
return this.chain(
|
|
82
|
+
return this.chain(addTorrentExternalIdentifier(id));
|
|
83
|
+
}
|
|
84
|
+
/** Removes an external identifier by its full identifier string (e.g., "imdb:tt15239678") */
|
|
85
|
+
removeExternalId(identifier) {
|
|
86
|
+
return this.chain(removeTorrentExternalIdentifier(identifier));
|
|
77
87
|
}
|
|
78
88
|
/** Adds external identifiers */
|
|
79
89
|
externalIds(ids) {
|
|
80
|
-
return
|
|
81
|
-
let result = draft;
|
|
82
|
-
for (const id of ids) {
|
|
83
|
-
result = await addTorrentExternalIdentifier(id)(result);
|
|
84
|
-
}
|
|
85
|
-
return result;
|
|
86
|
-
});
|
|
90
|
+
return ids.reduce((factory, id) => factory.addExternalId(id), this);
|
|
87
91
|
}
|
|
88
92
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { TRUSTED_PROVIDER_LIST_KIND, TrustedProvider } from "../helpers/trusted-assertions.js";
|
|
4
|
+
import { TrustedProviderSelector } from "../operations/trusted-providers.js";
|
|
5
|
+
export type TrustedProviderListTemplate = KnownEventTemplate<typeof TRUSTED_PROVIDER_LIST_KIND>;
|
|
6
|
+
/** A factory class for building NIP-85 kind 10040 trusted provider list events */
|
|
7
|
+
export declare class TrustedProviderListFactory extends EventFactory<typeof TRUSTED_PROVIDER_LIST_KIND, TrustedProviderListTemplate> {
|
|
8
|
+
/** Creates a new trusted provider list factory */
|
|
9
|
+
static create(): TrustedProviderListFactory;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new trusted provider list factory from an existing kind 10040 event
|
|
12
|
+
* @throws if the event is not a trusted provider list
|
|
13
|
+
*/
|
|
14
|
+
static modify(event: NostrEvent | KnownEvent<typeof TRUSTED_PROVIDER_LIST_KIND>): TrustedProviderListFactory;
|
|
15
|
+
/** Adds a provider to the list, or updates its relay hint if it already exists */
|
|
16
|
+
addProvider(provider: TrustedProvider, hidden?: boolean): this;
|
|
17
|
+
/** Removes a provider, or every provider in the `kind:tag` slot if no pubkey is given */
|
|
18
|
+
removeProvider(selector: TrustedProviderSelector, hidden?: boolean): this;
|
|
19
|
+
/** Replaces every provider in the `kind:tag` slot with a single provider */
|
|
20
|
+
setProvider(provider: TrustedProvider, hidden?: boolean): this;
|
|
21
|
+
/** Removes a service pubkey from every slot */
|
|
22
|
+
removeService(servicePubkey: string, hidden?: boolean): this;
|
|
23
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { TRUSTED_PROVIDER_LIST_KIND } from "../helpers/trusted-assertions.js";
|
|
3
|
+
import { addProviderTag, removeProviderTag, removeServiceTags, setProviderTag, } from "../operations/trusted-providers.js";
|
|
4
|
+
/** A factory class for building NIP-85 kind 10040 trusted provider list events */
|
|
5
|
+
export class TrustedProviderListFactory extends EventFactory {
|
|
6
|
+
/** Creates a new trusted provider list factory */
|
|
7
|
+
static create() {
|
|
8
|
+
return new TrustedProviderListFactory((res) => res(blankEventTemplate(TRUSTED_PROVIDER_LIST_KIND)));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new trusted provider list factory from an existing kind 10040 event
|
|
12
|
+
* @throws if the event is not a trusted provider list
|
|
13
|
+
*/
|
|
14
|
+
static modify(event) {
|
|
15
|
+
if (event.kind !== TRUSTED_PROVIDER_LIST_KIND)
|
|
16
|
+
throw new Error("Event is not a trusted provider list event");
|
|
17
|
+
return new TrustedProviderListFactory((res) => res(toEventTemplate(event)));
|
|
18
|
+
}
|
|
19
|
+
/** Adds a provider to the list, or updates its relay hint if it already exists */
|
|
20
|
+
addProvider(provider, hidden = false) {
|
|
21
|
+
const op = addProviderTag(provider);
|
|
22
|
+
return hidden ? this.modifyHiddenTags(op) : this.modifyPublicTags(op);
|
|
23
|
+
}
|
|
24
|
+
/** Removes a provider, or every provider in the `kind:tag` slot if no pubkey is given */
|
|
25
|
+
removeProvider(selector, hidden = false) {
|
|
26
|
+
const op = removeProviderTag(selector);
|
|
27
|
+
return hidden ? this.modifyHiddenTags(op) : this.modifyPublicTags(op);
|
|
28
|
+
}
|
|
29
|
+
/** Replaces every provider in the `kind:tag` slot with a single provider */
|
|
30
|
+
setProvider(provider, hidden = false) {
|
|
31
|
+
const op = setProviderTag(provider);
|
|
32
|
+
return hidden ? this.modifyHiddenTags(op) : this.modifyPublicTags(op);
|
|
33
|
+
}
|
|
34
|
+
/** Removes a service pubkey from every slot */
|
|
35
|
+
removeService(servicePubkey, hidden = false) {
|
|
36
|
+
const op = removeServiceTags(servicePubkey);
|
|
37
|
+
return hidden ? this.modifyHiddenTags(op) : this.modifyPublicTags(op);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
3
|
+
import { Emoji } from "../helpers/emoji.js";
|
|
4
|
+
import { UserStatusPointer, UserStatusType } from "../helpers/user-status.js";
|
|
5
|
+
export type UserStatusTemplate = KnownEventTemplate<typeof kinds.UserStatuses>;
|
|
6
|
+
/** A factory class for building NIP-38 user status events (kind 30315) */
|
|
7
|
+
export declare class UserStatusFactory extends EventFactory<typeof kinds.UserStatuses, UserStatusTemplate> {
|
|
8
|
+
/** Creates a new user status factory for a status type */
|
|
9
|
+
static create(type?: UserStatusType, content?: string): UserStatusFactory;
|
|
10
|
+
/** Creates a "music" status that expires when the track stops playing */
|
|
11
|
+
static music(content: string, expiration?: number, link?: string | UserStatusPointer): UserStatusFactory;
|
|
12
|
+
/** Creates a factory configured to modify an existing user status */
|
|
13
|
+
static modify(event: NostrEvent): UserStatusFactory;
|
|
14
|
+
/** Sets the status type ("d" tag) */
|
|
15
|
+
type(type: UserStatusType): this;
|
|
16
|
+
/** Sets the status text and includes any NIP-30 custom emojis used in it */
|
|
17
|
+
status(content: string, emojis?: Emoji[]): this;
|
|
18
|
+
/** Sets the URL, profile, event, or address the status links to */
|
|
19
|
+
link(link: string | UserStatusPointer): this;
|
|
20
|
+
/** Removes the status link */
|
|
21
|
+
clearLink(): this;
|
|
22
|
+
/** Removes the expiration timestamp */
|
|
23
|
+
clearExpiration(): this;
|
|
24
|
+
/** Clears the status by removing the content, link, emojis, and expiration */
|
|
25
|
+
clear(): this;
|
|
26
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { kinds } from "applesauce-core/helpers/event";
|
|
3
|
+
import { includeEmojis, setContent } from "applesauce-core/operations/content";
|
|
4
|
+
import { removeSingletonTag } from "applesauce-core/operations/tag/common";
|
|
5
|
+
import { clearStatusLink, setStatusLink, setStatusType } from "../operations/user-status.js";
|
|
6
|
+
const removeEmojiTags = (tags) => tags.filter((t) => t[0] !== "emoji");
|
|
7
|
+
/** A factory class for building NIP-38 user status events (kind 30315) */
|
|
8
|
+
export class UserStatusFactory extends EventFactory {
|
|
9
|
+
/** Creates a new user status factory for a status type */
|
|
10
|
+
static create(type = "general", content = "") {
|
|
11
|
+
return new UserStatusFactory((res) => res(blankEventTemplate(kinds.UserStatuses))).type(type).status(content);
|
|
12
|
+
}
|
|
13
|
+
/** Creates a "music" status that expires when the track stops playing */
|
|
14
|
+
static music(content, expiration, link) {
|
|
15
|
+
let factory = UserStatusFactory.create("music", content);
|
|
16
|
+
if (expiration)
|
|
17
|
+
factory = factory.expiration(expiration);
|
|
18
|
+
if (link)
|
|
19
|
+
factory = factory.link(link);
|
|
20
|
+
return factory;
|
|
21
|
+
}
|
|
22
|
+
/** Creates a factory configured to modify an existing user status */
|
|
23
|
+
static modify(event) {
|
|
24
|
+
if (event.kind !== kinds.UserStatuses)
|
|
25
|
+
throw new Error("Expected a user status event");
|
|
26
|
+
return new UserStatusFactory((res) => res(toEventTemplate(event)));
|
|
27
|
+
}
|
|
28
|
+
/** Sets the status type ("d" tag) */
|
|
29
|
+
type(type) {
|
|
30
|
+
return this.chain(setStatusType(type));
|
|
31
|
+
}
|
|
32
|
+
/** Sets the status text and includes any NIP-30 custom emojis used in it */
|
|
33
|
+
status(content, emojis) {
|
|
34
|
+
return this.modifyPublicTags(removeEmojiTags).chain(setContent(content)).chain(includeEmojis(emojis));
|
|
35
|
+
}
|
|
36
|
+
/** Sets the URL, profile, event, or address the status links to */
|
|
37
|
+
link(link) {
|
|
38
|
+
return this.chain(setStatusLink(link));
|
|
39
|
+
}
|
|
40
|
+
/** Removes the status link */
|
|
41
|
+
clearLink() {
|
|
42
|
+
return this.chain(clearStatusLink());
|
|
43
|
+
}
|
|
44
|
+
/** Removes the expiration timestamp */
|
|
45
|
+
clearExpiration() {
|
|
46
|
+
return this.modifyPublicTags(removeSingletonTag("expiration"));
|
|
47
|
+
}
|
|
48
|
+
/** Clears the status by removing the content, link, emojis, and expiration */
|
|
49
|
+
clear() {
|
|
50
|
+
return this.status("").clearLink().clearExpiration();
|
|
51
|
+
}
|
|
52
|
+
}
|
package/dist/helpers/app-data.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setCachedValue } from "applesauce-core/helpers/cache";
|
|
1
2
|
import { isNIP04Encrypted } from "applesauce-core/helpers/encryption";
|
|
2
3
|
import { getHiddenContent, isHiddenContentUnlocked, lockHiddenContent, setHiddenContentEncryptionMethod, unlockHiddenContent, } from "applesauce-core/helpers/hidden-content";
|
|
3
4
|
import { safeParse } from "applesauce-core/helpers/json";
|
|
@@ -28,21 +29,24 @@ export function isAppDataUnlocked(event) {
|
|
|
28
29
|
}
|
|
29
30
|
/** Returns the parsed application data for an event if it's unlocked */
|
|
30
31
|
export function getAppDataContent(event) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return cached;
|
|
32
|
+
if (Reflect.has(event, AppDataContentSymbol))
|
|
33
|
+
return Reflect.get(event, AppDataContentSymbol);
|
|
34
34
|
// If content is empty, return undefined
|
|
35
35
|
if (event.content.length === 0)
|
|
36
36
|
return undefined;
|
|
37
37
|
let data = getAppDataEncryption(event) ? undefined : safeParse(event.content);
|
|
38
|
-
if (
|
|
38
|
+
if (data === undefined) {
|
|
39
39
|
const decrypted = getHiddenContent(event);
|
|
40
|
-
if (decrypted)
|
|
40
|
+
if (decrypted !== undefined)
|
|
41
41
|
data = safeParse(decrypted);
|
|
42
42
|
}
|
|
43
|
-
if (
|
|
43
|
+
if (data === undefined)
|
|
44
44
|
return undefined;
|
|
45
|
-
|
|
45
|
+
// Derived from the event's own (possibly encrypted) content — identity memo (see
|
|
46
|
+
// applesauce-core's cache.ts taxonomy). Written non-enumerable via setCachedValue (05.1-09) so
|
|
47
|
+
// a plain spread drops it instead of carrying a stale derivation onto a copy whose content
|
|
48
|
+
// differs. lockAppData's Reflect.deleteProperty still clears it (CR-03).
|
|
49
|
+
setCachedValue(event, AppDataContentSymbol, data);
|
|
46
50
|
return data;
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
@@ -64,5 +68,9 @@ export async function unlockAppData(event, signer, override) {
|
|
|
64
68
|
}
|
|
65
69
|
/** Removes the unencrypted application data cache on an event */
|
|
66
70
|
export function lockAppData(event) {
|
|
71
|
+
// Two-delete lock (mirrors lockHiddenTags): drop the parsed-plaintext memo first, then lock the
|
|
72
|
+
// underlying hidden content. Without this, AppDataContentSymbol's cached-read early return in
|
|
73
|
+
// getAppDataContent survives the lock and keeps handing back decrypted plaintext (CR-03).
|
|
74
|
+
Reflect.deleteProperty(event, AppDataContentSymbol);
|
|
67
75
|
lockHiddenContent(event);
|
|
68
76
|
}
|
|
@@ -1,7 +1,44 @@
|
|
|
1
|
-
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
1
|
+
import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { Filter } from "applesauce-core/helpers/filter";
|
|
2
3
|
import { AddressPointer, DecodeResult, EventPointer, ProfilePointer } from "applesauce-core/helpers/pointers";
|
|
4
|
+
/** The event kind for NIP-89 handler information */
|
|
5
|
+
export declare const APP_HANDLER_KIND = 31990;
|
|
6
|
+
/** A validated NIP-89 handler information event */
|
|
7
|
+
export type AppHandlerEvent = KnownEvent<typeof APP_HANDLER_KIND>;
|
|
3
8
|
export type HandlerLinkPlatform = "web" | "ios" | "android";
|
|
4
9
|
export type HandlerLinkType = DecodeResult["type"];
|
|
10
|
+
/** A URL template for opening NIP-19 entities in a handler */
|
|
11
|
+
export interface HandlerLink {
|
|
12
|
+
/** The URL with a `<bech32>` placeholder */
|
|
13
|
+
url: string;
|
|
14
|
+
/** The NIP-19 entity type the URL handles, or undefined for any type */
|
|
15
|
+
type?: HandlerLinkType;
|
|
16
|
+
}
|
|
17
|
+
/** A parsed NIP-89 `client` tag */
|
|
18
|
+
export interface ClientTag {
|
|
19
|
+
/** The client's display name */
|
|
20
|
+
name: string;
|
|
21
|
+
/** The client's handler information address */
|
|
22
|
+
pointer?: AddressPointer;
|
|
23
|
+
}
|
|
24
|
+
/** Checks if an event is a valid NIP-89 handler information event (kind 31990) */
|
|
25
|
+
export declare function isValidAppHandler(event?: NostrEvent): event is AppHandlerEvent;
|
|
26
|
+
/** Returns the handler's `d` tag identifier */
|
|
27
|
+
export declare function getHandlerIdentifier(handler: NostrEvent): string;
|
|
28
|
+
/** Returns the named nsite (kind 35128) the handler currently serves from its `latest` tag */
|
|
29
|
+
export declare function getHandlerLatestPointer(handler: NostrEvent): AddressPointer | undefined;
|
|
30
|
+
/** Returns the named nsite (kind 35128) the handler is rolling out from its `next` tag */
|
|
31
|
+
export declare function getHandlerNextPointer(handler: NostrEvent): AddressPointer | undefined;
|
|
32
|
+
/** An event or draft with tags, for helpers that only read handler link tags */
|
|
33
|
+
export type HandlerTags = Pick<NostrEvent, "tags">;
|
|
34
|
+
/** Returns a relay filter for handlers that support an event kind */
|
|
35
|
+
export declare function getAppHandlersFilter(kind: number): Filter;
|
|
36
|
+
/** Returns all URL templates the handler advertises for a platform */
|
|
37
|
+
export declare function getHandlerLinks(handler: HandlerTags, platform?: HandlerLinkPlatform): HandlerLink[];
|
|
38
|
+
/** Returns the platforms the handler has at least one URL template for */
|
|
39
|
+
export declare function getHandlerPlatforms(handler: HandlerTags): HandlerLinkPlatform[];
|
|
40
|
+
/** Returns the NIP-89 `client` tag of an event */
|
|
41
|
+
export declare function getClientTag(event: NostrEvent): ClientTag | undefined;
|
|
5
42
|
/** Returns an array of supported kinds for a given handler */
|
|
6
43
|
export declare function getHandlerSupportedKinds(handler: NostrEvent): number[];
|
|
7
44
|
/** Returns the name of the handler */
|
|
@@ -11,12 +48,12 @@ export declare function getHandlerPicture(handler: NostrEvent, fallback?: string
|
|
|
11
48
|
/** Returns the description of the handler */
|
|
12
49
|
export declare function getHandlerDescription(handler: NostrEvent): string | undefined;
|
|
13
50
|
/** Returns the web link template for a handler and type */
|
|
14
|
-
export declare function getHandlerLinkTemplate(handler:
|
|
51
|
+
export declare function getHandlerLinkTemplate(handler: HandlerTags, platform?: HandlerLinkPlatform, type?: HandlerLinkType): string | undefined;
|
|
15
52
|
/** Returns a link for a Profile Pointer */
|
|
16
|
-
export declare function createHandlerProfileLink(handler:
|
|
53
|
+
export declare function createHandlerProfileLink(handler: HandlerTags, pointer: ProfilePointer, platform?: HandlerLinkPlatform): string | undefined;
|
|
17
54
|
/** Returns a link for an Event Pointer */
|
|
18
|
-
export declare function createHandlerEventLink(handler:
|
|
55
|
+
export declare function createHandlerEventLink(handler: HandlerTags, pointer: EventPointer, platform?: HandlerLinkPlatform): string | undefined;
|
|
19
56
|
/** Returns a link for an Address Pointer */
|
|
20
|
-
export declare function createHandlerAddressLink(handler:
|
|
57
|
+
export declare function createHandlerAddressLink(handler: HandlerTags, pointer: AddressPointer, platform?: HandlerLinkPlatform): string | undefined;
|
|
21
58
|
/** Creates a handler link for a pointer and optionally fallsback to a web link */
|
|
22
|
-
export declare function createHandlerLink(handler:
|
|
59
|
+
export declare function createHandlerLink(handler: HandlerTags, pointer: AddressPointer | EventPointer | ProfilePointer, platform?: HandlerLinkPlatform, webFallback?: boolean): string | undefined;
|
|
@@ -1,9 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
|
|
2
|
+
import { getReplaceableIdentifier, kinds } from "applesauce-core/helpers/event";
|
|
3
|
+
import { getAddressPointerFromATag, isAddressPointer, isEventPointer, naddrEncode, neventEncode, noteEncode, nprofileEncode, npubEncode, } from "applesauce-core/helpers/pointers";
|
|
2
4
|
import { getDisplayName, getProfileContent, getProfilePicture, isValidProfile } from "applesauce-core/helpers/profile";
|
|
3
5
|
import { processTags } from "applesauce-core/helpers/tags";
|
|
6
|
+
import { NSITE_KIND } from "./nsite.js";
|
|
7
|
+
/** The event kind for NIP-89 handler information */
|
|
8
|
+
export const APP_HANDLER_KIND = kinds.Handlerinformation;
|
|
9
|
+
const LatestSymbol = Symbol.for("app-handler-latest");
|
|
10
|
+
const NextSymbol = Symbol.for("app-handler-next");
|
|
11
|
+
const KindsSymbol = Symbol.for("app-handler-kinds");
|
|
12
|
+
/** Checks if an event is a valid NIP-89 handler information event (kind 31990) */
|
|
13
|
+
export function isValidAppHandler(event) {
|
|
14
|
+
return !!event && event.kind === APP_HANDLER_KIND && !!getReplaceableIdentifier(event);
|
|
15
|
+
}
|
|
16
|
+
/** Returns the handler's `d` tag identifier */
|
|
17
|
+
export function getHandlerIdentifier(handler) {
|
|
18
|
+
return getReplaceableIdentifier(handler);
|
|
19
|
+
}
|
|
20
|
+
function nsiteTagPointer(handler, name) {
|
|
21
|
+
const tag = handler.tags.find((t) => t[0] === name);
|
|
22
|
+
const pointer = tag && getAddressPointerFromATag(tag);
|
|
23
|
+
return pointer && pointer.kind === NSITE_KIND ? pointer : undefined;
|
|
24
|
+
}
|
|
25
|
+
/** Returns the named nsite (kind 35128) the handler currently serves from its `latest` tag */
|
|
26
|
+
export function getHandlerLatestPointer(handler) {
|
|
27
|
+
return getOrComputeCachedValue(handler, LatestSymbol, () => nsiteTagPointer(handler, "latest"));
|
|
28
|
+
}
|
|
29
|
+
/** Returns the named nsite (kind 35128) the handler is rolling out from its `next` tag */
|
|
30
|
+
export function getHandlerNextPointer(handler) {
|
|
31
|
+
return getOrComputeCachedValue(handler, NextSymbol, () => nsiteTagPointer(handler, "next"));
|
|
32
|
+
}
|
|
33
|
+
const PLATFORMS = ["web", "ios", "android"];
|
|
34
|
+
/** Returns a relay filter for handlers that support an event kind */
|
|
35
|
+
export function getAppHandlersFilter(kind) {
|
|
36
|
+
return { kinds: [APP_HANDLER_KIND], "#k": [String(kind)] };
|
|
37
|
+
}
|
|
38
|
+
/** Returns all URL templates the handler advertises for a platform */
|
|
39
|
+
export function getHandlerLinks(handler, platform = "web") {
|
|
40
|
+
return processTags(handler.tags, (t) => t[0] === platform && t[1] ? { url: t[1], type: (t[2] || undefined) } : undefined);
|
|
41
|
+
}
|
|
42
|
+
/** Returns the platforms the handler has at least one URL template for */
|
|
43
|
+
export function getHandlerPlatforms(handler) {
|
|
44
|
+
return PLATFORMS.filter((platform) => handler.tags.some((t) => t[0] === platform && t[1]));
|
|
45
|
+
}
|
|
46
|
+
/** Returns the NIP-89 `client` tag of an event */
|
|
47
|
+
export function getClientTag(event) {
|
|
48
|
+
const tag = event.tags.find((t) => t[0] === "client" && t[1]);
|
|
49
|
+
if (!tag)
|
|
50
|
+
return undefined;
|
|
51
|
+
const pointer = tag[2] ? getAddressPointerFromATag(tag.slice(1)) : null;
|
|
52
|
+
return pointer?.kind === APP_HANDLER_KIND ? { name: tag[1], pointer } : { name: tag[1] };
|
|
53
|
+
}
|
|
4
54
|
/** Returns an array of supported kinds for a given handler */
|
|
5
55
|
export function getHandlerSupportedKinds(handler) {
|
|
6
|
-
return processTags(handler.tags, (t) => (t[0] === "k" && t[1] ? parseInt(t[1]) : undefined));
|
|
56
|
+
return getOrComputeCachedValue(handler, KindsSymbol, () => processTags(handler.tags, (t) => (t[0] === "k" && /^\d+$/.test(t[1] ?? "") ? parseInt(t[1]) : undefined)));
|
|
7
57
|
}
|
|
8
58
|
/** Returns the name of the handler */
|
|
9
59
|
export function getHandlerName(handler) {
|
|
@@ -47,7 +97,7 @@ export function createHandlerEventLink(handler, pointer, platform = "web") {
|
|
|
47
97
|
}
|
|
48
98
|
/** Returns a link for an Address Pointer */
|
|
49
99
|
export function createHandlerAddressLink(handler, pointer, platform = "web") {
|
|
50
|
-
// First attempt to use a
|
|
100
|
+
// First attempt to use a naddr link, then fallback to the generic link
|
|
51
101
|
return (getHandlerLinkTemplate(handler, platform, "naddr")?.replace("<bech32>", naddrEncode(pointer)) ||
|
|
52
102
|
getHandlerLinkTemplate(handler, platform)?.replace("<bech32>", naddrEncode(pointer)));
|
|
53
103
|
}
|