applesauce-common 6.2.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/casts/_circular-import.d.ts +3 -0
- package/dist/casts/_circular-import.js +3 -0
- package/dist/casts/app-handler.d.ts +56 -0
- package/dist/casts/app-handler.js +105 -0
- package/dist/casts/app-recommendation.d.ts +26 -0
- package/dist/casts/app-recommendation.js +41 -0
- package/dist/casts/external-identities.d.ts +9 -0
- package/dist/casts/external-identities.js +14 -0
- package/dist/casts/forum-thread.d.ts +17 -0
- package/dist/casts/forum-thread.js +31 -0
- package/dist/casts/git-issue.d.ts +18 -0
- package/dist/casts/git-issue.js +26 -0
- package/dist/casts/git-patch.d.ts +49 -0
- package/dist/casts/git-patch.js +88 -0
- package/dist/casts/git-pull-request.d.ts +67 -0
- package/dist/casts/git-pull-request.js +122 -0
- package/dist/casts/git-repository.d.ts +9 -0
- package/dist/casts/git-repository.js +16 -0
- package/dist/casts/git-thread.d.ts +33 -0
- package/dist/casts/git-thread.js +65 -0
- package/dist/casts/index.d.ts +12 -0
- package/dist/casts/index.js +12 -0
- package/dist/casts/napplet-handlers.d.ts +39 -0
- package/dist/casts/napplet-handlers.js +91 -0
- package/dist/casts/napplet.d.ts +98 -0
- package/dist/casts/napplet.js +196 -0
- package/dist/casts/note.d.ts +8 -0
- package/dist/casts/note.js +21 -1
- package/dist/casts/nsite.d.ts +134 -0
- package/dist/casts/nsite.js +249 -0
- package/dist/casts/profile.d.ts +20 -0
- package/dist/casts/profile.js +30 -0
- package/dist/casts/reaction.d.ts +1 -1
- package/dist/casts/relay-discovery.d.ts +4 -0
- package/dist/casts/relay-discovery.js +9 -1
- package/dist/casts/report.d.ts +28 -15
- package/dist/casts/report.js +42 -19
- package/dist/casts/share.d.ts +1 -1
- package/dist/casts/torrent.d.ts +5 -0
- package/dist/casts/torrent.js +8 -1
- package/dist/casts/trusted-assertions.d.ts +2 -0
- package/dist/casts/trusted-assertions.js +19 -18
- package/dist/casts/user-status.d.ts +33 -0
- package/dist/casts/user-status.js +69 -0
- package/dist/casts/user.d.ts +7 -0
- package/dist/casts/user.js +20 -1
- package/dist/factories/app-handler.d.ts +31 -0
- package/dist/factories/app-handler.js +50 -0
- package/dist/factories/app-recommendation.d.ts +21 -0
- package/dist/factories/app-recommendation.js +28 -0
- package/dist/factories/chat-message.d.ts +37 -0
- package/dist/factories/chat-message.js +56 -0
- package/dist/factories/comment.d.ts +8 -7
- package/dist/factories/comment.js +2 -2
- package/dist/factories/external-identities.d.ts +17 -0
- package/dist/factories/external-identities.js +28 -0
- package/dist/factories/file-message.d.ts +24 -0
- package/dist/factories/file-message.js +37 -0
- package/dist/factories/forum-thread.d.ts +34 -0
- package/dist/factories/forum-thread.js +50 -0
- package/dist/factories/git-applied-status.d.ts +39 -0
- package/dist/factories/git-applied-status.js +53 -0
- package/dist/factories/git-closed-status.d.ts +18 -0
- package/dist/factories/git-closed-status.js +24 -0
- package/dist/factories/git-draft-status.d.ts +18 -0
- package/dist/factories/git-draft-status.js +24 -0
- package/dist/factories/git-issue.d.ts +19 -0
- package/dist/factories/git-issue.js +25 -0
- package/dist/factories/git-open-status.d.ts +18 -0
- package/dist/factories/git-open-status.js +22 -0
- package/dist/factories/git-patch.d.ts +59 -0
- package/dist/factories/git-patch.js +102 -0
- package/dist/factories/git-pull-request-update.d.ts +23 -0
- package/dist/factories/git-pull-request-update.js +33 -0
- package/dist/factories/git-pull-request.d.ts +39 -0
- package/dist/factories/git-pull-request.js +64 -0
- package/dist/factories/index.d.ts +24 -0
- package/dist/factories/index.js +24 -0
- package/dist/factories/internal/git-pull-request.d.ts +19 -0
- package/dist/factories/internal/git-pull-request.js +26 -0
- package/dist/factories/internal/git-status.d.ts +11 -0
- package/dist/factories/internal/git-status.js +12 -0
- package/dist/factories/internal/git-thread.d.ts +19 -0
- package/dist/factories/internal/git-thread.js +29 -0
- package/dist/factories/internal/napplet-manifest.d.ts +52 -0
- package/dist/factories/internal/napplet-manifest.js +85 -0
- package/dist/factories/internal/nsite-manifest.d.ts +45 -0
- package/dist/factories/internal/nsite-manifest.js +68 -0
- package/dist/factories/legacy-message.d.ts +2 -0
- package/dist/factories/legacy-message.js +9 -2
- package/dist/factories/named-napplet.d.ts +20 -0
- package/dist/factories/named-napplet.js +30 -0
- package/dist/factories/named-nsite.d.ts +28 -0
- package/dist/factories/named-nsite.js +53 -0
- package/dist/factories/napplet-handlers.d.ts +34 -0
- package/dist/factories/napplet-handlers.js +77 -0
- package/dist/factories/napplet-snapshot.d.ts +18 -0
- package/dist/factories/napplet-snapshot.js +38 -0
- package/dist/factories/nsite-snapshot.d.ts +18 -0
- package/dist/factories/nsite-snapshot.js +29 -0
- package/dist/factories/reaction.d.ts +3 -2
- package/dist/factories/report.d.ts +48 -0
- package/dist/factories/report.js +66 -0
- package/dist/factories/root-napplet.d.ts +18 -0
- package/dist/factories/root-napplet.js +24 -0
- package/dist/factories/root-nsite.d.ts +23 -0
- package/dist/factories/root-nsite.js +44 -0
- package/dist/factories/torrent.d.ts +24 -10
- package/dist/factories/torrent.js +48 -44
- package/dist/factories/trusted-provider-list.d.ts +23 -0
- package/dist/factories/trusted-provider-list.js +39 -0
- package/dist/factories/user-status.d.ts +26 -0
- package/dist/factories/user-status.js +52 -0
- package/dist/factories/wrapped-message.js +10 -4
- package/dist/helpers/app-data.js +15 -7
- package/dist/helpers/app-handler.d.ts +43 -6
- package/dist/helpers/app-handler.js +53 -3
- package/dist/helpers/app-recommendation.d.ts +24 -0
- package/dist/helpers/app-recommendation.js +30 -0
- package/dist/helpers/bookmark.js +5 -2
- package/dist/helpers/comment.d.ts +11 -5
- package/dist/helpers/comment.js +7 -1
- package/dist/helpers/content.d.ts +3 -1
- package/dist/helpers/emoji-pack.js +11 -6
- package/dist/helpers/emoji.d.ts +2 -2
- package/dist/helpers/encrypted-content-cache.d.ts +2 -11
- package/dist/helpers/encrypted-content-cache.js +6 -14
- package/dist/helpers/encrypted-file.d.ts +41 -0
- package/dist/helpers/encrypted-file.js +64 -0
- package/dist/helpers/external-id.js +13 -19
- package/dist/helpers/external-identities.d.ts +29 -0
- package/dist/helpers/external-identities.js +52 -0
- package/dist/helpers/file-message.d.ts +18 -0
- package/dist/helpers/file-message.js +44 -0
- package/dist/helpers/file-metadata.d.ts +9 -4
- package/dist/helpers/file-metadata.js +21 -6
- package/dist/helpers/forum-thread.d.ts +10 -0
- package/dist/helpers/forum-thread.js +10 -0
- package/dist/helpers/gift-wrap.d.ts +40 -15
- package/dist/helpers/gift-wrap.js +110 -33
- package/dist/helpers/git-issue.d.ts +13 -0
- package/dist/helpers/git-issue.js +19 -0
- package/dist/helpers/git-patch.d.ts +41 -0
- package/dist/helpers/git-patch.js +73 -0
- package/dist/helpers/git-pull-request.d.ts +57 -0
- package/dist/helpers/git-pull-request.js +111 -0
- package/dist/helpers/git-repository.d.ts +4 -0
- package/dist/helpers/git-repository.js +16 -0
- package/dist/helpers/git-status.d.ts +44 -0
- package/dist/helpers/git-status.js +93 -0
- package/dist/helpers/git.d.ts +2 -0
- package/dist/helpers/git.js +4 -0
- package/dist/helpers/groups.d.ts +5 -2
- package/dist/helpers/groups.js +40 -18
- package/dist/helpers/hashtag.d.ts +4 -2
- package/dist/helpers/index.d.ts +13 -0
- package/dist/helpers/index.js +13 -0
- package/dist/helpers/lists.js +14 -2
- package/dist/helpers/lnurl.js +1 -1
- package/dist/helpers/messages.js +3 -2
- package/dist/helpers/mute.js +20 -9
- package/dist/helpers/napplet-handlers.d.ts +79 -0
- package/dist/helpers/napplet-handlers.js +187 -0
- package/dist/helpers/napplet.d.ts +107 -0
- package/dist/helpers/napplet.js +177 -0
- package/dist/helpers/nsite.d.ts +90 -0
- package/dist/helpers/nsite.js +217 -0
- package/dist/helpers/relay-discovery.d.ts +4 -0
- package/dist/helpers/relay-discovery.js +8 -0
- package/dist/helpers/reports.d.ts +35 -0
- package/dist/helpers/reports.js +36 -5
- package/dist/helpers/threading.d.ts +4 -2
- package/dist/helpers/torrent.d.ts +9 -6
- package/dist/helpers/torrent.js +23 -15
- package/dist/helpers/trusted-assertions.d.ts +7 -0
- package/dist/helpers/trusted-assertions.js +41 -2
- package/dist/helpers/user-status.d.ts +13 -1
- package/dist/helpers/user-status.js +15 -0
- package/dist/helpers/wrapped-messages.d.ts +2 -0
- package/dist/helpers/wrapped-messages.js +6 -1
- package/dist/models/app-handler.d.ts +21 -0
- package/dist/models/app-handler.js +47 -0
- package/dist/models/git.d.ts +34 -0
- package/dist/models/git.js +144 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +4 -0
- package/dist/models/legacy-messages.js +6 -1
- package/dist/models/napplet-handlers.d.ts +16 -0
- package/dist/models/napplet-handlers.js +45 -0
- package/dist/models/nsite.d.ts +22 -0
- package/dist/models/nsite.js +67 -0
- package/dist/models/thread.d.ts +4 -1
- package/dist/models/thread.js +34 -5
- package/dist/models/user-status.d.ts +8 -4
- package/dist/models/user-status.js +16 -22
- package/dist/models/wrapped-messages.js +9 -7
- package/dist/observable/filter-timeline-by-mutes.d.ts +1 -1
- package/dist/observable/filter-timeline-by-mutes.js +6 -2
- package/dist/operations/app-handler.d.ts +24 -0
- package/dist/operations/app-handler.js +58 -0
- package/dist/operations/app-recommendation.d.ts +13 -0
- package/dist/operations/app-recommendation.js +40 -0
- package/dist/operations/calendar-event.js +3 -2
- package/dist/operations/chat-message.d.ts +9 -0
- package/dist/operations/chat-message.js +12 -0
- package/dist/operations/client.d.ts +1 -4
- package/dist/operations/client.js +1 -23
- package/dist/operations/comment.d.ts +9 -3
- package/dist/operations/comment.js +12 -9
- package/dist/operations/external-identities.d.ts +8 -0
- package/dist/operations/external-identities.js +23 -0
- package/dist/operations/file-message.d.ts +7 -0
- package/dist/operations/file-message.js +34 -0
- package/dist/operations/forum-thread.d.ts +3 -0
- package/dist/operations/forum-thread.js +6 -0
- package/dist/operations/gift-wrap.js +38 -14
- package/dist/operations/git-issue.d.ts +18 -0
- package/dist/operations/git-issue.js +31 -0
- package/dist/operations/git-patch.d.ts +30 -0
- package/dist/operations/git-patch.js +75 -0
- package/dist/operations/git-pull-request.d.ts +29 -0
- package/dist/operations/git-pull-request.js +74 -0
- package/dist/operations/git-repository.js +4 -4
- package/dist/operations/git-status.d.ts +28 -0
- package/dist/operations/git-status.js +116 -0
- package/dist/operations/git-thread.d.ts +13 -0
- package/dist/operations/git-thread.js +39 -0
- package/dist/operations/index.d.ts +17 -0
- package/dist/operations/index.js +17 -0
- package/dist/operations/internal/git-commits.d.ts +2 -0
- package/dist/operations/internal/git-commits.js +16 -0
- package/dist/operations/napplet-handlers.d.ts +47 -0
- package/dist/operations/napplet-handlers.js +161 -0
- package/dist/operations/napplet.d.ts +51 -0
- package/dist/operations/napplet.js +121 -0
- package/dist/operations/nsite.d.ts +51 -0
- package/dist/operations/nsite.js +112 -0
- package/dist/operations/reaction.d.ts +12 -2
- package/dist/operations/reaction.js +1 -1
- package/dist/operations/report.d.ts +33 -0
- package/dist/operations/report.js +60 -0
- package/dist/operations/stream.js +5 -4
- package/dist/operations/torrent.d.ts +1 -4
- package/dist/operations/torrent.js +24 -11
- package/dist/operations/trusted-providers.d.ts +14 -0
- package/dist/operations/trusted-providers.js +33 -0
- package/dist/operations/user-status.d.ts +11 -0
- package/dist/operations/user-status.js +29 -0
- package/dist/operations/wrapped-message.js +2 -2
- package/package.json +13 -17
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isValidNappletSnapshot, NAPPLET_SNAPSHOT_KIND } from "../helpers/napplet.js";
|
|
3
|
+
import { NappletManifestFactory } from "./internal/napplet-manifest.js";
|
|
4
|
+
import { getReplaceableAddressForEvent } from "applesauce-core/helpers/pointers";
|
|
5
|
+
import { unixNow } from "applesauce-core/helpers/time";
|
|
6
|
+
import { isValidNapplet, isNappletSnapshot } from "../helpers/napplet.js";
|
|
7
|
+
/** A factory for snapshot napplet manifests (kind 5129) */
|
|
8
|
+
export class NappletSnapshotFactory extends NappletManifestFactory {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a snapshot of the current manifest and preserves its lineage
|
|
11
|
+
* @throws if the source is invalid
|
|
12
|
+
*/
|
|
13
|
+
static create(napplet) {
|
|
14
|
+
if (!isValidNapplet(napplet))
|
|
15
|
+
throw new Error("Expected a napplet manifest event");
|
|
16
|
+
// A snapshot of a snapshot keeps the source lineage since snapshots cannot be addressed
|
|
17
|
+
const coordinate = getReplaceableAddressForEvent(napplet);
|
|
18
|
+
const lineage = (name) => napplet.tags.find((t) => t[0] === name && t[1])?.[1];
|
|
19
|
+
const parent = isNappletSnapshot(napplet) ? lineage("a") : coordinate;
|
|
20
|
+
const root = isNappletSnapshot(napplet) ? lineage("A") : coordinate;
|
|
21
|
+
const tags = napplet.tags.filter((t) => t[0] !== "d" && t[0] !== "a" && t[0] !== "A");
|
|
22
|
+
let factory = new NappletSnapshotFactory((res) => res({ kind: NAPPLET_SNAPSHOT_KIND, created_at: unixNow(), content: napplet.content, tags }));
|
|
23
|
+
if (parent)
|
|
24
|
+
factory = factory.parent(parent);
|
|
25
|
+
if (root)
|
|
26
|
+
factory = factory.root(root);
|
|
27
|
+
return factory;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a factory for modifying a snapshot napplet manifest
|
|
31
|
+
* @throws if the event is not a valid snapshot napplet manifest
|
|
32
|
+
*/
|
|
33
|
+
static modify(event) {
|
|
34
|
+
if (!isValidNappletSnapshot(event))
|
|
35
|
+
throw new Error("Expected a snapshot napplet manifest");
|
|
36
|
+
return new NappletSnapshotFactory((res) => res(toEventTemplate(event)));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { NSITE_SNAPSHOT_KIND } from "../helpers/nsite.js";
|
|
3
|
+
import { NsiteManifestFactory } from "./internal/nsite-manifest.js";
|
|
4
|
+
/** An event template for a snapshot nsite manifest */
|
|
5
|
+
export type NsiteSnapshotTemplate = KnownEventTemplate<typeof NSITE_SNAPSHOT_KIND>;
|
|
6
|
+
/** A factory for snapshot nsite manifests (kind 5128) */
|
|
7
|
+
export declare class NsiteSnapshotFactory extends NsiteManifestFactory<typeof NSITE_SNAPSHOT_KIND> {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a snapshot of the current manifest and preserves its lineage
|
|
10
|
+
* @throws if the source is invalid, is a snapshot, or lacks an aggregate hash
|
|
11
|
+
*/
|
|
12
|
+
static create(site: NostrEvent): NsiteSnapshotFactory;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a factory for modifying a snapshot nsite manifest
|
|
15
|
+
* @throws if the event is not a valid snapshot nsite manifest
|
|
16
|
+
*/
|
|
17
|
+
static modify(event: NostrEvent): NsiteSnapshotFactory;
|
|
18
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isValidNsiteSnapshot, NSITE_SNAPSHOT_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 } from "../helpers/nsite.js";
|
|
7
|
+
/** A factory for snapshot nsite manifests (kind 5128) */
|
|
8
|
+
export class NsiteSnapshotFactory extends NsiteManifestFactory {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a snapshot of the current manifest and preserves its lineage
|
|
11
|
+
* @throws if the source is invalid, is a snapshot, or lacks an aggregate hash
|
|
12
|
+
*/
|
|
13
|
+
static create(site) {
|
|
14
|
+
if (!isValidNsite(site) || isNsiteSnapshot(site) || !site.tags.some((t) => t[0] === "x" && t[2] === "aggregate"))
|
|
15
|
+
throw new Error("Expected a root or named nsite with an aggregate hash");
|
|
16
|
+
// Preserve the source x and A tags unchanged; a identifies the site being snapshotted.
|
|
17
|
+
const tags = site.tags.filter((t) => t[0] !== "d" && t[0] !== "a").map((t) => [...t]);
|
|
18
|
+
return new NsiteSnapshotFactory((res) => res({ kind: NSITE_SNAPSHOT_KIND, created_at: unixNow(), content: site.content, tags })).parent(getReplaceableAddressForEvent(site));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a factory for modifying a snapshot nsite manifest
|
|
22
|
+
* @throws if the event is not a valid snapshot nsite manifest
|
|
23
|
+
*/
|
|
24
|
+
static modify(event) {
|
|
25
|
+
if (!isValidNsiteSnapshot(event))
|
|
26
|
+
throw new Error("Expected a snapshot nsite manifest");
|
|
27
|
+
return new NsiteSnapshotFactory((res) => res(toEventTemplate(event)));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EventFactory } from "applesauce-core/factories";
|
|
2
2
|
import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { ReactionParent } from "../operations/reaction.js";
|
|
3
4
|
import { Emoji } from "../helpers/emoji.js";
|
|
4
5
|
export type ReactionTemplate = KnownEventTemplate<kinds.Reaction>;
|
|
5
6
|
/** A factory class for building kind 7 reaction events */
|
|
@@ -10,13 +11,13 @@ export declare class ReactionFactory extends EventFactory<kinds.Reaction, Reacti
|
|
|
10
11
|
* @param emoji - The emoji to react with (default: "+")
|
|
11
12
|
* @returns A new reaction factory
|
|
12
13
|
*/
|
|
13
|
-
static create(event:
|
|
14
|
+
static create(event: ReactionParent, emoji?: string | Emoji): ReactionFactory;
|
|
14
15
|
/** Creates a "+" like reaction for an event */
|
|
15
16
|
static like(event: NostrEvent): ReactionFactory;
|
|
16
17
|
/** Creates a "-" dislike reaction for an event */
|
|
17
18
|
static dislike(event: NostrEvent): ReactionFactory;
|
|
18
19
|
/** Sets the parent event being reacted to */
|
|
19
|
-
reactTo(event:
|
|
20
|
+
reactTo(event: ReactionParent): this;
|
|
20
21
|
/** Sets the reaction emoji */
|
|
21
22
|
reaction(emoji: "+" | "-" | string | Emoji): this;
|
|
22
23
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { REPORT_KIND, ReportReason, ReportTarget } from "../helpers/reports.js";
|
|
4
|
+
import { ReportEventTarget } from "../operations/report.js";
|
|
5
|
+
/** A kind 1984 report draft */
|
|
6
|
+
export type ReportTemplate = KnownEventTemplate<typeof REPORT_KIND>;
|
|
7
|
+
/** A factory for NIP-56 reports */
|
|
8
|
+
export declare class ReportFactory extends EventFactory<typeof REPORT_KIND, ReportTemplate> {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a user or event report
|
|
11
|
+
* @throws if the target identity or reason is invalid
|
|
12
|
+
*/
|
|
13
|
+
static create(target: string | ReportEventTarget, reason: ReportReason): ReportFactory;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a blob report with its containing event and author
|
|
16
|
+
* @throws if the hash, event identity, or reason is invalid
|
|
17
|
+
*/
|
|
18
|
+
static blob(hash: string, event: ReportEventTarget, reason: ReportReason): ReportFactory;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a factory from an existing report
|
|
21
|
+
* @throws if the event is not kind 1984
|
|
22
|
+
*/
|
|
23
|
+
static modify(event: NostrEvent): ReportFactory;
|
|
24
|
+
/**
|
|
25
|
+
* Adds or updates a reported user
|
|
26
|
+
* @throws if the public key or reason is invalid
|
|
27
|
+
*/
|
|
28
|
+
reportUser(pubkey: string, reason: ReportReason): this;
|
|
29
|
+
/**
|
|
30
|
+
* Adds or updates a reported event
|
|
31
|
+
* @throws if the event identity or reason is invalid
|
|
32
|
+
*/
|
|
33
|
+
reportEvent(event: ReportEventTarget, reason: ReportReason): this;
|
|
34
|
+
/**
|
|
35
|
+
* Adds or updates a reported blob
|
|
36
|
+
* @throws if the hash, event identity, or reason is invalid
|
|
37
|
+
*/
|
|
38
|
+
reportBlob(hash: string, event: ReportEventTarget, reason: ReportReason): this;
|
|
39
|
+
/** Removes a target tag while preserving unrelated tags */
|
|
40
|
+
removeTarget(type: ReportTarget["type"], value: string): this;
|
|
41
|
+
/**
|
|
42
|
+
* Adds a media server or direct media URL
|
|
43
|
+
* @throws if the URL is invalid or does not use HTTP or HTTPS
|
|
44
|
+
*/
|
|
45
|
+
server(url: string): this;
|
|
46
|
+
/** Removes a media server or direct media URL */
|
|
47
|
+
removeServer(url: string): this;
|
|
48
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { REPORT_KIND } from "../helpers/reports.js";
|
|
3
|
+
import { addReportBlob, addReportEvent, addReportServer, addReportUser, removeReportServer, removeReportTarget, } from "../operations/report.js";
|
|
4
|
+
/** A factory for NIP-56 reports */
|
|
5
|
+
export class ReportFactory extends EventFactory {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a user or event report
|
|
8
|
+
* @throws if the target identity or reason is invalid
|
|
9
|
+
*/
|
|
10
|
+
static create(target, reason) {
|
|
11
|
+
const factory = new ReportFactory((resolve) => resolve(blankEventTemplate(REPORT_KIND)));
|
|
12
|
+
return typeof target === "string" ? factory.reportUser(target, reason) : factory.reportEvent(target, reason);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a blob report with its containing event and author
|
|
16
|
+
* @throws if the hash, event identity, or reason is invalid
|
|
17
|
+
*/
|
|
18
|
+
static blob(hash, event, reason) {
|
|
19
|
+
return new ReportFactory((resolve) => resolve(blankEventTemplate(REPORT_KIND))).reportBlob(hash, event, reason);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates a factory from an existing report
|
|
23
|
+
* @throws if the event is not kind 1984
|
|
24
|
+
*/
|
|
25
|
+
static modify(event) {
|
|
26
|
+
if (event.kind !== REPORT_KIND)
|
|
27
|
+
throw new Error("Expected a report event");
|
|
28
|
+
return new ReportFactory((resolve) => resolve(toEventTemplate(event)));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Adds or updates a reported user
|
|
32
|
+
* @throws if the public key or reason is invalid
|
|
33
|
+
*/
|
|
34
|
+
reportUser(pubkey, reason) {
|
|
35
|
+
return this.chain(addReportUser(pubkey, reason));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Adds or updates a reported event
|
|
39
|
+
* @throws if the event identity or reason is invalid
|
|
40
|
+
*/
|
|
41
|
+
reportEvent(event, reason) {
|
|
42
|
+
return this.chain(addReportEvent(event, reason));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Adds or updates a reported blob
|
|
46
|
+
* @throws if the hash, event identity, or reason is invalid
|
|
47
|
+
*/
|
|
48
|
+
reportBlob(hash, event, reason) {
|
|
49
|
+
return this.chain(addReportBlob(hash, event, reason));
|
|
50
|
+
}
|
|
51
|
+
/** Removes a target tag while preserving unrelated tags */
|
|
52
|
+
removeTarget(type, value) {
|
|
53
|
+
return this.chain(removeReportTarget(type, value));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Adds a media server or direct media URL
|
|
57
|
+
* @throws if the URL is invalid or does not use HTTP or HTTPS
|
|
58
|
+
*/
|
|
59
|
+
server(url) {
|
|
60
|
+
return this.chain(addReportServer(url));
|
|
61
|
+
}
|
|
62
|
+
/** Removes a media server or direct media URL */
|
|
63
|
+
removeServer(url) {
|
|
64
|
+
return this.chain(removeReportServer(url));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { NAPPLET_ROOT_KIND } from "../helpers/napplet.js";
|
|
3
|
+
import { NappletManifestFactory } from "./internal/napplet-manifest.js";
|
|
4
|
+
/** An event template for a root napplet manifest */
|
|
5
|
+
export type RootNappletTemplate = KnownEventTemplate<typeof NAPPLET_ROOT_KIND>;
|
|
6
|
+
/** A factory for root napplet manifests (kind 15129) */
|
|
7
|
+
export declare class RootNappletFactory extends NappletManifestFactory<typeof NAPPLET_ROOT_KIND> {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a root napplet manifest
|
|
10
|
+
* @throws if the artifact hash is invalid
|
|
11
|
+
*/
|
|
12
|
+
static create(artifactHash: string, description: string): RootNappletFactory;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a factory for modifying a root napplet manifest
|
|
15
|
+
* @throws if the event is not a valid root napplet manifest
|
|
16
|
+
*/
|
|
17
|
+
static modify(event: NostrEvent): RootNappletFactory;
|
|
18
|
+
}
|
|
@@ -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
|
+
}
|