applesauce-common 5.1.0 → 6.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/dist/casts/_circular-import.d.ts +7 -0
- package/dist/casts/_circular-import.js +9 -0
- package/dist/casts/article.d.ts +1 -1
- package/dist/casts/badge-award.d.ts +24 -0
- package/dist/casts/badge-award.js +39 -0
- package/dist/casts/badge.d.ts +19 -0
- package/dist/casts/badge.js +48 -0
- package/dist/casts/bookmarks.d.ts +5 -5
- package/dist/casts/cast.d.ts +1 -30
- package/dist/casts/cast.js +2 -67
- package/dist/casts/comment.d.ts +5 -5
- package/dist/casts/emoji-pack.d.ts +11 -0
- package/dist/casts/emoji-pack.js +25 -0
- package/dist/casts/favorite-emojis.d.ts +25 -0
- package/dist/casts/favorite-emojis.js +62 -0
- package/dist/casts/file-metadata.d.ts +22 -0
- package/dist/casts/file-metadata.js +55 -0
- package/dist/casts/groups.d.ts +1 -1
- package/dist/casts/index.d.ts +7 -0
- package/dist/casts/index.js +7 -0
- package/dist/casts/mutes.d.ts +1 -1
- package/dist/casts/note.d.ts +7 -7
- package/dist/casts/profile-badges.d.ts +28 -0
- package/dist/casts/profile-badges.js +59 -0
- package/dist/casts/reaction.d.ts +1 -1
- package/dist/casts/relay-lists.d.ts +1 -1
- package/dist/casts/relay-monitor.d.ts +1 -1
- package/dist/casts/report.d.ts +2 -2
- package/dist/casts/share.d.ts +2 -2
- package/dist/casts/stream.d.ts +9 -9
- package/dist/casts/torrent.d.ts +3 -3
- package/dist/casts/trusted-assertions.d.ts +144 -0
- package/dist/casts/trusted-assertions.js +281 -0
- package/dist/casts/user.d.ts +22 -38
- package/dist/casts/user.js +106 -153
- package/dist/casts/zap-goal.d.ts +2 -2
- package/dist/casts/zap.d.ts +4 -4
- package/dist/factories/app-data.d.ts +13 -0
- package/dist/factories/app-data.js +20 -0
- package/dist/factories/badge-award.d.ts +25 -0
- package/dist/factories/badge-award.js +41 -0
- package/dist/factories/badge.d.ts +32 -0
- package/dist/factories/badge.js +50 -0
- package/dist/factories/blocked-relays.d.ts +10 -0
- package/dist/factories/blocked-relays.js +16 -0
- package/dist/factories/blossom-server-list.d.ts +19 -0
- package/dist/factories/blossom-server-list.js +36 -0
- package/dist/factories/bookmark-list.d.ts +23 -0
- package/dist/factories/bookmark-list.js +45 -0
- package/dist/factories/bookmark-set.d.ts +25 -0
- package/dist/factories/bookmark-set.js +51 -0
- package/dist/factories/calendar-event.d.ts +88 -0
- package/dist/factories/calendar-event.js +175 -0
- package/dist/factories/calendar-rsvp.d.ts +22 -0
- package/dist/factories/calendar-rsvp.js +35 -0
- package/dist/factories/calendar.d.ts +20 -0
- package/dist/factories/calendar.js +36 -0
- package/dist/factories/code-snippet.d.ts +65 -0
- package/dist/factories/code-snippet.js +100 -0
- package/dist/factories/comment.d.ts +26 -0
- package/dist/factories/comment.js +49 -0
- package/dist/factories/contacts.d.ts +19 -0
- package/dist/factories/contacts.js +36 -0
- package/dist/factories/dm-relays.d.ts +10 -0
- package/dist/factories/dm-relays.js +16 -0
- package/dist/factories/favorite-relays.d.ts +16 -0
- package/dist/factories/favorite-relays.js +31 -0
- package/dist/factories/file-metadata.d.ts +54 -0
- package/dist/factories/file-metadata.js +92 -0
- package/dist/factories/follow-set.d.ts +12 -0
- package/dist/factories/follow-set.js +22 -0
- package/dist/factories/gift-wrap.d.ts +17 -0
- package/dist/factories/gift-wrap.js +21 -0
- package/dist/factories/group-management.d.ts +63 -0
- package/dist/factories/group-management.js +147 -0
- package/dist/factories/group.d.ts +35 -0
- package/dist/factories/group.js +69 -0
- package/dist/factories/highlight.d.ts +33 -0
- package/dist/factories/highlight.js +49 -0
- package/dist/factories/index.d.ts +41 -0
- package/dist/factories/index.js +41 -0
- package/dist/factories/legacy-message.d.ts +10 -0
- package/dist/factories/legacy-message.js +19 -0
- package/dist/factories/list.d.ts +56 -0
- package/dist/factories/list.js +120 -0
- package/dist/factories/live-stream.d.ts +48 -0
- package/dist/factories/live-stream.js +90 -0
- package/dist/factories/mute-list.d.ts +27 -0
- package/dist/factories/mute-list.js +57 -0
- package/dist/factories/note.d.ts +38 -0
- package/dist/factories/note.js +66 -0
- package/dist/factories/picture-post.d.ts +28 -0
- package/dist/factories/picture-post.js +46 -0
- package/dist/factories/pin-list.d.ts +14 -0
- package/dist/factories/pin-list.js +24 -0
- package/dist/factories/poll-response.d.ts +36 -0
- package/dist/factories/poll-response.js +46 -0
- package/dist/factories/poll.d.ts +35 -0
- package/dist/factories/poll.js +48 -0
- package/dist/factories/profile-badges.d.ts +31 -0
- package/dist/factories/profile-badges.js +52 -0
- package/dist/factories/reaction.d.ts +22 -0
- package/dist/factories/reaction.js +37 -0
- package/dist/factories/relay-set.d.ts +12 -0
- package/dist/factories/relay-set.js +22 -0
- package/dist/factories/search-relays.d.ts +10 -0
- package/dist/factories/search-relays.js +16 -0
- package/dist/factories/share.d.ts +26 -0
- package/dist/factories/share.js +44 -0
- package/dist/factories/stream-chat-message.d.ts +22 -0
- package/dist/factories/stream-chat-message.js +31 -0
- package/dist/factories/torrent.d.ts +57 -0
- package/dist/factories/torrent.js +93 -0
- package/dist/factories/wrapped-message.d.ts +22 -0
- package/dist/factories/wrapped-message.js +39 -0
- package/dist/factories/zap-goal.d.ts +35 -0
- package/dist/factories/zap-goal.js +49 -0
- package/dist/factories/zap-request.d.ts +28 -0
- package/dist/factories/zap-request.js +55 -0
- package/dist/factories/zap.d.ts +13 -0
- package/dist/factories/zap.js +21 -0
- package/dist/helpers/badge-award.d.ts +15 -0
- package/dist/helpers/badge-award.js +32 -0
- package/dist/helpers/badge.d.ts +27 -0
- package/dist/helpers/badge.js +59 -0
- package/dist/helpers/blossom.d.ts +29 -1
- package/dist/helpers/blossom.js +64 -7
- package/dist/helpers/emoji-pack.d.ts +43 -0
- package/dist/helpers/emoji-pack.js +108 -0
- package/dist/helpers/emoji.d.ts +4 -5
- package/dist/helpers/emoji.js +3 -15
- package/dist/helpers/file-metadata.d.ts +18 -13
- package/dist/helpers/file-metadata.js +10 -4
- package/dist/helpers/groups.d.ts +1 -0
- package/dist/helpers/groups.js +3 -2
- package/dist/helpers/hashtag.d.ts +1 -0
- package/dist/helpers/hashtag.js +3 -3
- package/dist/helpers/index.d.ts +7 -2
- package/dist/helpers/index.js +7 -2
- package/dist/helpers/lists.d.ts +8 -0
- package/dist/helpers/lists.js +27 -5
- package/dist/helpers/picture-post.d.ts +2 -2
- package/dist/helpers/profile-badges.d.ts +23 -0
- package/dist/helpers/profile-badges.js +51 -0
- package/dist/helpers/trusted-assertions.d.ts +81 -0
- package/dist/helpers/trusted-assertions.js +161 -0
- package/dist/helpers/zap.d.ts +8 -2
- package/dist/helpers/zap.js +31 -26
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.js +1 -1
- package/dist/models/thread.d.ts +1 -1
- package/dist/models/thread.js +23 -7
- package/dist/observable/chainable.d.ts +1 -36
- package/dist/observable/chainable.js +2 -72
- package/dist/operations/app-data.d.ts +8 -3
- package/dist/operations/app-data.js +9 -4
- package/dist/operations/badge-award.d.ts +17 -0
- package/dist/operations/badge-award.js +30 -0
- package/dist/operations/badge.d.ts +22 -0
- package/dist/operations/badge.js +54 -0
- package/dist/operations/blossom.d.ts +1 -1
- package/dist/operations/calendar-event.d.ts +1 -1
- package/dist/operations/calendar-rsvp.d.ts +1 -1
- package/dist/operations/calendar.d.ts +1 -1
- package/dist/operations/channel.d.ts +1 -1
- package/dist/operations/client.d.ts +1 -1
- package/dist/operations/client.js +2 -2
- package/dist/operations/code-snippet.d.ts +27 -0
- package/dist/operations/code-snippet.js +63 -0
- package/dist/operations/comment.d.ts +7 -3
- package/dist/operations/comment.js +8 -4
- package/dist/operations/file-metadata.d.ts +38 -4
- package/dist/operations/file-metadata.js +105 -19
- package/dist/operations/geohash.d.ts +1 -1
- package/dist/operations/gift-wrap.d.ts +19 -7
- package/dist/operations/gift-wrap.js +36 -26
- package/dist/operations/group.d.ts +1 -1
- package/dist/operations/hashtags.d.ts +1 -1
- package/dist/operations/highlight.d.ts +1 -1
- package/dist/operations/highlight.js +5 -5
- package/dist/operations/index.d.ts +7 -1
- package/dist/operations/index.js +7 -1
- package/dist/operations/legacy-message.d.ts +1 -1
- package/dist/operations/list.d.ts +1 -1
- package/dist/operations/live-stream.d.ts +7 -3
- package/dist/operations/live-stream.js +9 -5
- package/dist/operations/media-attachment.d.ts +3 -3
- package/dist/operations/note.d.ts +10 -4
- package/dist/operations/note.js +14 -8
- package/dist/operations/picture-post.d.ts +1 -1
- package/dist/operations/poll-response.d.ts +1 -1
- package/dist/operations/poll-response.js +1 -1
- package/dist/operations/poll.d.ts +1 -1
- package/dist/operations/profile-badges.d.ts +26 -0
- package/dist/operations/profile-badges.js +150 -0
- package/dist/operations/reaction.d.ts +8 -3
- package/dist/operations/reaction.js +10 -5
- package/dist/operations/share.d.ts +8 -3
- package/dist/operations/share.js +10 -5
- package/dist/operations/stream.d.ts +1 -1
- package/dist/operations/tag/bookmarks.d.ts +1 -1
- package/dist/operations/torrent.d.ts +1 -1
- package/dist/operations/wrapped-message.d.ts +1 -1
- package/dist/operations/zap-goal.d.ts +1 -1
- package/dist/operations/zap-request.d.ts +22 -0
- package/dist/operations/zap-request.js +40 -0
- package/dist/operations/zap-split.d.ts +8 -4
- package/dist/operations/zap-split.js +10 -6
- package/dist/operations/zap.d.ts +12 -0
- package/dist/operations/zap.js +34 -0
- package/package.json +13 -12
- package/dist/blueprints/__register__.d.ts +0 -7
- package/dist/blueprints/__register__.js +0 -8
- package/dist/blueprints/app-data.d.ts +0 -5
- package/dist/blueprints/app-data.js +0 -10
- package/dist/blueprints/calendar.d.ts +0 -5
- package/dist/blueprints/calendar.js +0 -7
- package/dist/blueprints/channels.d.ts +0 -6
- package/dist/blueprints/channels.js +0 -13
- package/dist/blueprints/comment.d.ts +0 -13
- package/dist/blueprints/comment.js +0 -15
- package/dist/blueprints/delete.d.ts +0 -9
- package/dist/blueprints/delete.js +0 -14
- package/dist/blueprints/file-metadata.d.ts +0 -8
- package/dist/blueprints/file-metadata.js +0 -11
- package/dist/blueprints/follow-set.d.ts +0 -11
- package/dist/blueprints/follow-set.js +0 -21
- package/dist/blueprints/gift-wrap.d.ts +0 -5
- package/dist/blueprints/gift-wrap.js +0 -6
- package/dist/blueprints/group-mangement.d.ts +0 -25
- package/dist/blueprints/group-mangement.js +0 -40
- package/dist/blueprints/group.d.ts +0 -9
- package/dist/blueprints/group.js +0 -17
- package/dist/blueprints/highlight.d.ts +0 -20
- package/dist/blueprints/highlight.js +0 -12
- package/dist/blueprints/index.d.ts +0 -25
- package/dist/blueprints/index.js +0 -26
- package/dist/blueprints/legacy-message.d.ts +0 -7
- package/dist/blueprints/legacy-message.js +0 -29
- package/dist/blueprints/live-stream.d.ts +0 -6
- package/dist/blueprints/live-stream.js +0 -9
- package/dist/blueprints/note.d.ts +0 -16
- package/dist/blueprints/note.js +0 -30
- package/dist/blueprints/picture-post.d.ts +0 -12
- package/dist/blueprints/picture-post.js +0 -17
- package/dist/blueprints/poll.d.ts +0 -41
- package/dist/blueprints/poll.js +0 -33
- package/dist/blueprints/profile.d.ts +0 -3
- package/dist/blueprints/profile.js +0 -7
- package/dist/blueprints/reaction.d.ts +0 -10
- package/dist/blueprints/reaction.js +0 -14
- package/dist/blueprints/share.d.ts +0 -12
- package/dist/blueprints/share.js +0 -25
- package/dist/blueprints/stream.d.ts +0 -6
- package/dist/blueprints/stream.js +0 -7
- package/dist/blueprints/torrent.d.ts +0 -30
- package/dist/blueprints/torrent.js +0 -29
- package/dist/blueprints/wrapped-message.d.ts +0 -20
- package/dist/blueprints/wrapped-message.js +0 -64
- package/dist/blueprints/zap-goal.d.ts +0 -16
- package/dist/blueprints/zap-goal.js +0 -12
- package/dist/register.d.ts +0 -2
- package/dist/register.js +0 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isKind, kinds } from "applesauce-core/helpers";
|
|
3
|
+
import { NIP51RelayListFactory } from "./list.js";
|
|
4
|
+
/** A factory class for building kind 10007 search relays list events */
|
|
5
|
+
export class SearchRelaysFactory extends NIP51RelayListFactory {
|
|
6
|
+
/** Creates a new search relays factory */
|
|
7
|
+
static create() {
|
|
8
|
+
return new SearchRelaysFactory((res) => res(blankEventTemplate(kinds.SearchRelaysList)));
|
|
9
|
+
}
|
|
10
|
+
/** Creates a new search relays factory from an existing search relays event */
|
|
11
|
+
static modify(event) {
|
|
12
|
+
if (!isKind(event, kinds.SearchRelaysList))
|
|
13
|
+
throw new Error("Event is not a search relays event");
|
|
14
|
+
return new SearchRelaysFactory((res) => res(toEventTemplate(event)));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { EventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
4
|
+
import { ZapOptions } from "../operations/zap-split.js";
|
|
5
|
+
export type ShareBlueprintOptions = MetaTagOptions & ZapOptions;
|
|
6
|
+
/** A factory class for building NIP-18 repost/share events (kind 6/16) */
|
|
7
|
+
export declare class ShareFactory extends EventFactory<number, EventTemplate> {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new share factory
|
|
10
|
+
* @param event - The event being shared
|
|
11
|
+
* @returns A new share factory
|
|
12
|
+
*/
|
|
13
|
+
static create(event: NostrEvent): ShareFactory;
|
|
14
|
+
/** Creates a new share event for an existing event */
|
|
15
|
+
static share(event: NostrEvent): ShareFactory;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a quote-repost: sets the event reference tags and uses a custom comment as content
|
|
18
|
+
* @param event - The event being quoted
|
|
19
|
+
* @param comment - The quote comment text
|
|
20
|
+
*/
|
|
21
|
+
static quote(event: NostrEvent, comment: string): ShareFactory;
|
|
22
|
+
/** Sets the event being shared */
|
|
23
|
+
setEvent(event: NostrEvent): this;
|
|
24
|
+
/** Sets zap split configuration */
|
|
25
|
+
zapSplit(options: ZapOptions): this;
|
|
26
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds, pipeFromAsyncArray } from "applesauce-core/helpers";
|
|
3
|
+
import { embedSharedEvent, setShareKind, setShareTags } from "../operations/share.js";
|
|
4
|
+
import { setZapSplit } from "../operations/zap-split.js";
|
|
5
|
+
/** A factory class for building NIP-18 repost/share events (kind 6/16) */
|
|
6
|
+
export class ShareFactory extends EventFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new share factory
|
|
9
|
+
* @param event - The event being shared
|
|
10
|
+
* @returns A new share factory
|
|
11
|
+
*/
|
|
12
|
+
static create(event) {
|
|
13
|
+
return new ShareFactory((res) => res(blankEventTemplate(kinds.Repost))).setEvent(event);
|
|
14
|
+
}
|
|
15
|
+
/** Creates a new share event for an existing event */
|
|
16
|
+
static share(event) {
|
|
17
|
+
return ShareFactory.create(event);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a quote-repost: sets the event reference tags and uses a custom comment as content
|
|
21
|
+
* @param event - The event being quoted
|
|
22
|
+
* @param comment - The quote comment text
|
|
23
|
+
*/
|
|
24
|
+
static quote(event, comment) {
|
|
25
|
+
return new ShareFactory((res) => res(blankEventTemplate(kinds.Repost)))
|
|
26
|
+
.setEvent(event)
|
|
27
|
+
.chain((draft) => ({ ...draft, content: comment }));
|
|
28
|
+
}
|
|
29
|
+
/** Sets the event being shared */
|
|
30
|
+
setEvent(event) {
|
|
31
|
+
return this.chain(pipeFromAsyncArray([
|
|
32
|
+
// Set the kind
|
|
33
|
+
setShareKind(event),
|
|
34
|
+
// Then embed the event into the content
|
|
35
|
+
embedSharedEvent(event),
|
|
36
|
+
// Then set the reference tags
|
|
37
|
+
setShareTags(event),
|
|
38
|
+
]));
|
|
39
|
+
}
|
|
40
|
+
/** Sets zap split configuration */
|
|
41
|
+
zapSplit(options) {
|
|
42
|
+
return this.chain(setZapSplit(options, undefined));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { TextContentOptions } from "applesauce-core/operations/content";
|
|
4
|
+
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
5
|
+
import { AddressPointer } from "applesauce-core/helpers/pointers";
|
|
6
|
+
export type StreamChatMessageTemplate = KnownEventTemplate<kinds.LiveChatMessage>;
|
|
7
|
+
/** A factory class for building NIP-53 stream chat message events (kind 1311) */
|
|
8
|
+
export declare class StreamChatMessageFactory extends EventFactory<kinds.LiveChatMessage, StreamChatMessageTemplate> {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new stream chat message factory
|
|
11
|
+
* @param stream - The stream event or address pointer
|
|
12
|
+
* @param content - The message content
|
|
13
|
+
* @returns A new stream chat message factory
|
|
14
|
+
*/
|
|
15
|
+
static create(stream: NostrEvent | AddressPointer, content: string, options?: TextContentOptions): StreamChatMessageFactory;
|
|
16
|
+
/** Sets the stream for this chat message */
|
|
17
|
+
stream(stream: NostrEvent | AddressPointer): this;
|
|
18
|
+
/** Sets the message content */
|
|
19
|
+
message(content: string, options?: TextContentOptions): this;
|
|
20
|
+
/** Sets meta tags */
|
|
21
|
+
meta(options: MetaTagOptions): this;
|
|
22
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { kinds } from "applesauce-core/helpers";
|
|
3
|
+
import { setMetaTags } from "applesauce-core/operations/event";
|
|
4
|
+
import { setMessage, setStream } from "../operations/stream-chat.js";
|
|
5
|
+
/** A factory class for building NIP-53 stream chat message events (kind 1311) */
|
|
6
|
+
export class StreamChatMessageFactory extends EventFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new stream chat message factory
|
|
9
|
+
* @param stream - The stream event or address pointer
|
|
10
|
+
* @param content - The message content
|
|
11
|
+
* @returns A new stream chat message factory
|
|
12
|
+
*/
|
|
13
|
+
static create(stream, content, options) {
|
|
14
|
+
let factory = new StreamChatMessageFactory((res) => res(blankEventTemplate(kinds.LiveChatMessage)))
|
|
15
|
+
.stream(stream)
|
|
16
|
+
.message(content, options);
|
|
17
|
+
return factory;
|
|
18
|
+
}
|
|
19
|
+
/** Sets the stream for this chat message */
|
|
20
|
+
stream(stream) {
|
|
21
|
+
return this.chain(setStream(stream));
|
|
22
|
+
}
|
|
23
|
+
/** Sets the message content */
|
|
24
|
+
message(content, options) {
|
|
25
|
+
return this.chain(setMessage(content, options));
|
|
26
|
+
}
|
|
27
|
+
/** Sets meta tags */
|
|
28
|
+
meta(options) {
|
|
29
|
+
return this.chain(setMetaTags(options));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEventTemplate } from "applesauce-core/helpers";
|
|
3
|
+
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
4
|
+
import { TORRENT_KIND, TorrentExternalIdentifier, TorrentFile } from "../helpers/torrent.js";
|
|
5
|
+
export type TorrentTemplate = KnownEventTemplate<typeof TORRENT_KIND>;
|
|
6
|
+
export type TorrentBlueprintOptions = MetaTagOptions & {
|
|
7
|
+
/** Torrent title */
|
|
8
|
+
title?: string;
|
|
9
|
+
/** File entries in the torrent */
|
|
10
|
+
files?: TorrentFile[];
|
|
11
|
+
/** Tracker URLs */
|
|
12
|
+
trackers?: string[];
|
|
13
|
+
/** Newznab category ID */
|
|
14
|
+
category?: number;
|
|
15
|
+
/** Search tags for searchability (t tags) */
|
|
16
|
+
searchTags?: string[];
|
|
17
|
+
/** Category path (tcat) */
|
|
18
|
+
categoryPath?: string;
|
|
19
|
+
/** External identifiers */
|
|
20
|
+
externalIdentifiers?: TorrentExternalIdentifier[];
|
|
21
|
+
};
|
|
22
|
+
/** A factory class for building NIP-35 torrent events (kind 2003) */
|
|
23
|
+
export declare class TorrentFactory extends EventFactory<typeof TORRENT_KIND, TorrentTemplate> {
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new torrent factory
|
|
26
|
+
* @param infoHash - The torrent info hash
|
|
27
|
+
* @param content - Optional description
|
|
28
|
+
* @returns A new torrent factory
|
|
29
|
+
*/
|
|
30
|
+
static create(infoHash: string, content?: string): TorrentFactory;
|
|
31
|
+
/** Sets the torrent info hash */
|
|
32
|
+
infoHash(hash: string): this;
|
|
33
|
+
/** Sets the torrent title */
|
|
34
|
+
title(title: string): this;
|
|
35
|
+
/** Sets the category path */
|
|
36
|
+
categoryPath(path: string): this;
|
|
37
|
+
/** Sets the newznab category */
|
|
38
|
+
category(id: number): this;
|
|
39
|
+
/** Adds a file to the torrent */
|
|
40
|
+
addFile(file: TorrentFile): this;
|
|
41
|
+
/** Adds files to the torrent */
|
|
42
|
+
files(files: TorrentFile[]): this;
|
|
43
|
+
/** Adds a tracker URL */
|
|
44
|
+
addTracker(url: string): this;
|
|
45
|
+
/** Adds tracker URLs */
|
|
46
|
+
trackers(urls: string[]): this;
|
|
47
|
+
/** Adds a search tag */
|
|
48
|
+
addSearchTag(tag: string): this;
|
|
49
|
+
/** Adds search tags */
|
|
50
|
+
searchTags(tags: string[]): this;
|
|
51
|
+
/** Adds an external identifier */
|
|
52
|
+
addExternalId(id: TorrentExternalIdentifier): this;
|
|
53
|
+
/** Adds external identifiers */
|
|
54
|
+
externalIds(ids: TorrentExternalIdentifier[]): this;
|
|
55
|
+
/** Sets meta tags */
|
|
56
|
+
meta(options: MetaTagOptions): this;
|
|
57
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { setMetaTags } from "applesauce-core/operations/event";
|
|
3
|
+
import { TORRENT_KIND } from "../helpers/torrent.js";
|
|
4
|
+
import { addTorrentExternalIdentifier, addTorrentFile, addTorrentSearchTag, addTorrentTracker, setTorrentCategory, setTorrentCategoryPath, setTorrentInfoHash, setTorrentTitle, } from "../operations/torrent.js";
|
|
5
|
+
/** A factory class for building NIP-35 torrent events (kind 2003) */
|
|
6
|
+
export class TorrentFactory extends EventFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new torrent factory
|
|
9
|
+
* @param infoHash - The torrent info hash
|
|
10
|
+
* @param content - Optional description
|
|
11
|
+
* @returns A new torrent factory
|
|
12
|
+
*/
|
|
13
|
+
static create(infoHash, content) {
|
|
14
|
+
const factory = new TorrentFactory((res) => res(blankEventTemplate(TORRENT_KIND))).infoHash(infoHash);
|
|
15
|
+
return content ? factory.content(content) : factory;
|
|
16
|
+
}
|
|
17
|
+
/** Sets the torrent info hash */
|
|
18
|
+
infoHash(hash) {
|
|
19
|
+
return this.chain((draft) => setTorrentInfoHash(hash)(draft));
|
|
20
|
+
}
|
|
21
|
+
/** Sets the torrent title */
|
|
22
|
+
title(title) {
|
|
23
|
+
return this.chain((draft) => setTorrentTitle(title)(draft));
|
|
24
|
+
}
|
|
25
|
+
/** Sets the category path */
|
|
26
|
+
categoryPath(path) {
|
|
27
|
+
return this.chain((draft) => setTorrentCategoryPath(path)(draft));
|
|
28
|
+
}
|
|
29
|
+
/** Sets the newznab category */
|
|
30
|
+
category(id) {
|
|
31
|
+
return this.chain((draft) => setTorrentCategory(id)(draft));
|
|
32
|
+
}
|
|
33
|
+
/** Adds a file to the torrent */
|
|
34
|
+
addFile(file) {
|
|
35
|
+
return this.chain((draft) => addTorrentFile(file)(draft));
|
|
36
|
+
}
|
|
37
|
+
/** Adds files to the torrent */
|
|
38
|
+
files(files) {
|
|
39
|
+
return this.chain(async (draft) => {
|
|
40
|
+
let result = draft;
|
|
41
|
+
for (const file of files) {
|
|
42
|
+
result = await addTorrentFile(file)(result);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** Adds a tracker URL */
|
|
48
|
+
addTracker(url) {
|
|
49
|
+
return this.chain((draft) => addTorrentTracker(url)(draft));
|
|
50
|
+
}
|
|
51
|
+
/** Adds tracker URLs */
|
|
52
|
+
trackers(urls) {
|
|
53
|
+
return this.chain(async (draft) => {
|
|
54
|
+
let result = draft;
|
|
55
|
+
for (const url of urls) {
|
|
56
|
+
result = await addTorrentTracker(url)(result);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/** Adds a search tag */
|
|
62
|
+
addSearchTag(tag) {
|
|
63
|
+
return this.chain((draft) => addTorrentSearchTag(tag)(draft));
|
|
64
|
+
}
|
|
65
|
+
/** Adds search tags */
|
|
66
|
+
searchTags(tags) {
|
|
67
|
+
return this.chain(async (draft) => {
|
|
68
|
+
let result = draft;
|
|
69
|
+
for (const tag of tags) {
|
|
70
|
+
result = await addTorrentSearchTag(tag)(result);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** Adds an external identifier */
|
|
76
|
+
addExternalId(id) {
|
|
77
|
+
return this.chain((draft) => addTorrentExternalIdentifier(id)(draft));
|
|
78
|
+
}
|
|
79
|
+
/** Adds external identifiers */
|
|
80
|
+
externalIds(ids) {
|
|
81
|
+
return this.chain(async (draft) => {
|
|
82
|
+
let result = draft;
|
|
83
|
+
for (const id of ids) {
|
|
84
|
+
result = await addTorrentExternalIdentifier(id)(result);
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** Sets meta tags */
|
|
90
|
+
meta(options) {
|
|
91
|
+
return this.chain((draft) => setMetaTags(options)(draft));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds, KnownEventTemplate } from "applesauce-core/helpers";
|
|
3
|
+
import { TextContentOptions } from "applesauce-core/operations/content";
|
|
4
|
+
import { Rumor } from "../helpers/gift-wrap.js";
|
|
5
|
+
export type WrappedMessageTemplate = KnownEventTemplate<kinds.PrivateDirectMessage>;
|
|
6
|
+
export type WrappedMessageBlueprintOptions = TextContentOptions;
|
|
7
|
+
export declare class WrappedMessageFactory extends EventFactory<kinds.PrivateDirectMessage, WrappedMessageTemplate> {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new wrapped message.
|
|
10
|
+
* @param recipients - A single recipient pubkey or an array of recipient pubkeys
|
|
11
|
+
* @param message - The plaintext message content
|
|
12
|
+
*/
|
|
13
|
+
static create(recipients: string | string[], message: string): WrappedMessageFactory;
|
|
14
|
+
/** Creates a reply to a wrapped message */
|
|
15
|
+
static reply(parent: Rumor | string, recipient: string, message: string): WrappedMessageFactory;
|
|
16
|
+
/** Sets the text content of the message */
|
|
17
|
+
text(content: string, options?: TextContentOptions): this;
|
|
18
|
+
/** Sets the parent message "e" tag for NIP-17 reply threading */
|
|
19
|
+
replyTo(parent: Rumor | string): this;
|
|
20
|
+
/** Sets the subject tag for the message thread */
|
|
21
|
+
subject(subject: string): this;
|
|
22
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds } from "applesauce-core/helpers";
|
|
3
|
+
import { includeNameValueTag } from "applesauce-core/operations/tags";
|
|
4
|
+
import { setShortTextContent } from "applesauce-core/operations/content";
|
|
5
|
+
import { setParent, setSubject } from "../operations/wrapped-message.js";
|
|
6
|
+
export class WrappedMessageFactory extends EventFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new wrapped message.
|
|
9
|
+
* @param recipients - A single recipient pubkey or an array of recipient pubkeys
|
|
10
|
+
* @param message - The plaintext message content
|
|
11
|
+
*/
|
|
12
|
+
static create(recipients, message) {
|
|
13
|
+
const recipientList = typeof recipients === "string" ? [recipients] : recipients;
|
|
14
|
+
let factory = new WrappedMessageFactory((res) => res(blankEventTemplate(kinds.PrivateDirectMessage))).chain(setShortTextContent(message));
|
|
15
|
+
for (const recipient of recipientList) {
|
|
16
|
+
factory = factory.chain(includeNameValueTag(["p", recipient]));
|
|
17
|
+
}
|
|
18
|
+
return factory;
|
|
19
|
+
}
|
|
20
|
+
/** Creates a reply to a wrapped message */
|
|
21
|
+
static reply(parent, recipient, message) {
|
|
22
|
+
return new WrappedMessageFactory((res) => res(blankEventTemplate(kinds.PrivateDirectMessage)))
|
|
23
|
+
.chain(setShortTextContent(message))
|
|
24
|
+
.chain(includeNameValueTag(["p", recipient]))
|
|
25
|
+
.replyTo(parent);
|
|
26
|
+
}
|
|
27
|
+
/** Sets the text content of the message */
|
|
28
|
+
text(content, options) {
|
|
29
|
+
return this.chain(setShortTextContent(content, options));
|
|
30
|
+
}
|
|
31
|
+
/** Sets the parent message "e" tag for NIP-17 reply threading */
|
|
32
|
+
replyTo(parent) {
|
|
33
|
+
return this.chain(setParent(parent));
|
|
34
|
+
}
|
|
35
|
+
/** Sets the subject tag for the message thread */
|
|
36
|
+
subject(subject) {
|
|
37
|
+
return this.chain(setSubject(subject));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEventTemplate } from "applesauce-core/helpers";
|
|
3
|
+
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
4
|
+
import { ZAP_GOAL_KIND } from "../helpers/zap-goal.js";
|
|
5
|
+
import { ZapOptions } from "../operations/zap-split.js";
|
|
6
|
+
export type ZapGoalTemplate = KnownEventTemplate<typeof ZAP_GOAL_KIND>;
|
|
7
|
+
export type ZapGoalBlueprintOptions = MetaTagOptions & ZapOptions & {
|
|
8
|
+
closedAt?: number;
|
|
9
|
+
image?: string;
|
|
10
|
+
summary?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare class ZapGoalFactory extends EventFactory<typeof ZAP_GOAL_KIND, ZapGoalTemplate> {
|
|
13
|
+
static create(description: string, amount: number, relays: string[]): ZapGoalFactory;
|
|
14
|
+
/** Sets the amount of the zap goal */
|
|
15
|
+
amount(amount: number): this;
|
|
16
|
+
/** Sets the relays for the zap goal */
|
|
17
|
+
relays(urls: string[]): this;
|
|
18
|
+
/** Sets the closed at timestamp for the zap goal */
|
|
19
|
+
closedAt(timestamp: number): this;
|
|
20
|
+
/** Sets the image for the zap goal */
|
|
21
|
+
image(url: string): this;
|
|
22
|
+
/** Sets the summary for the zap goal */
|
|
23
|
+
summary(text: string): this;
|
|
24
|
+
/** Sets the beneficiaries for the zap goal using zap split tags */
|
|
25
|
+
beneficiaries(beneficiaries: Array<{
|
|
26
|
+
pubkey: string;
|
|
27
|
+
weight: number;
|
|
28
|
+
}>): this;
|
|
29
|
+
/** Sets a goal tag linking this goal to a specific event */
|
|
30
|
+
goal(goalId: string, relay?: string): this;
|
|
31
|
+
/** Sets the zap split for the zap goal */
|
|
32
|
+
zapSplit(options: ZapOptions): this;
|
|
33
|
+
/** Sets the meta tags for the zap goal */
|
|
34
|
+
meta(options: MetaTagOptions): this;
|
|
35
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { setMetaTags } from "applesauce-core/operations/event";
|
|
3
|
+
import { ZAP_GOAL_KIND } from "../helpers/zap-goal.js";
|
|
4
|
+
import * as ZapGoal from "../operations/zap-goal.js";
|
|
5
|
+
import { setZapSplit } from "../operations/zap-split.js";
|
|
6
|
+
export class ZapGoalFactory extends EventFactory {
|
|
7
|
+
static create(description, amount, relays) {
|
|
8
|
+
return new ZapGoalFactory((res) => res(blankEventTemplate(ZAP_GOAL_KIND)))
|
|
9
|
+
.content(description)
|
|
10
|
+
.amount(amount)
|
|
11
|
+
.relays(relays);
|
|
12
|
+
}
|
|
13
|
+
/** Sets the amount of the zap goal */
|
|
14
|
+
amount(amount) {
|
|
15
|
+
return this.chain(ZapGoal.setAmount(amount));
|
|
16
|
+
}
|
|
17
|
+
/** Sets the relays for the zap goal */
|
|
18
|
+
relays(urls) {
|
|
19
|
+
return this.chain(ZapGoal.setRelays(urls));
|
|
20
|
+
}
|
|
21
|
+
/** Sets the closed at timestamp for the zap goal */
|
|
22
|
+
closedAt(timestamp) {
|
|
23
|
+
return this.chain(ZapGoal.setClosedAt(timestamp));
|
|
24
|
+
}
|
|
25
|
+
/** Sets the image for the zap goal */
|
|
26
|
+
image(url) {
|
|
27
|
+
return this.chain(ZapGoal.setImage(url));
|
|
28
|
+
}
|
|
29
|
+
/** Sets the summary for the zap goal */
|
|
30
|
+
summary(text) {
|
|
31
|
+
return this.chain(ZapGoal.setSummary(text));
|
|
32
|
+
}
|
|
33
|
+
/** Sets the beneficiaries for the zap goal using zap split tags */
|
|
34
|
+
beneficiaries(beneficiaries) {
|
|
35
|
+
return this.chain(ZapGoal.setBeneficiaries(beneficiaries));
|
|
36
|
+
}
|
|
37
|
+
/** Sets a goal tag linking this goal to a specific event */
|
|
38
|
+
goal(goalId, relay) {
|
|
39
|
+
return this.chain(ZapGoal.setGoalTag(goalId, relay));
|
|
40
|
+
}
|
|
41
|
+
/** Sets the zap split for the zap goal */
|
|
42
|
+
zapSplit(options) {
|
|
43
|
+
return this.chain(setZapSplit(options, undefined));
|
|
44
|
+
}
|
|
45
|
+
/** Sets the meta tags for the zap goal */
|
|
46
|
+
meta(options) {
|
|
47
|
+
return this.chain(setMetaTags(options));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds, KnownEventTemplate, NostrEvent, ProfilePointer } from "applesauce-core/helpers";
|
|
3
|
+
export type ZapRequestTemplate = KnownEventTemplate<typeof kinds.ZapRequest>;
|
|
4
|
+
export declare class ZapRequestFactory extends EventFactory<typeof kinds.ZapRequest, ZapRequestTemplate> {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new zap request event
|
|
7
|
+
* @param event - The NostrEvent being zapped
|
|
8
|
+
* @param amount - The amount in millisatoshis
|
|
9
|
+
* @param relays - The relays to use for the zap request
|
|
10
|
+
*/
|
|
11
|
+
static create(event: NostrEvent, amount: number, relays: string[]): ZapRequestFactory;
|
|
12
|
+
/** Creates a zap request for a profile */
|
|
13
|
+
static profile(pubkey: string | ProfilePointer, amount: number, relays: string[], hint?: string): ZapRequestFactory;
|
|
14
|
+
/** Creates a zap request for an event */
|
|
15
|
+
static event(event: NostrEvent, amount: number, relays: string[], hint?: string): ZapRequestFactory;
|
|
16
|
+
/** Sets the relays for the zap request */
|
|
17
|
+
relays(urls: string[]): this;
|
|
18
|
+
/** Sets the event target. Sets the k (kind), e (event id), a (coordinate for replaceable events), and p (recipient) tags */
|
|
19
|
+
eventTarget(event: NostrEvent, hint?: string): this;
|
|
20
|
+
/** Sets the profile target. Sets the p tag (recipient) */
|
|
21
|
+
profileTarget(pubkey: string | ProfilePointer, hint?: string): this;
|
|
22
|
+
/** Sets the amount in millisatoshis */
|
|
23
|
+
amount(amount: number): this;
|
|
24
|
+
/** Sets the lnurl (bech32-encoded) */
|
|
25
|
+
lnurl(lnurl: string): this;
|
|
26
|
+
/** Sets the zap message */
|
|
27
|
+
message(text: string): this;
|
|
28
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds } from "applesauce-core/helpers";
|
|
3
|
+
import * as ZapRequest from "../operations/zap-request.js";
|
|
4
|
+
export class ZapRequestFactory extends EventFactory {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new zap request event
|
|
7
|
+
* @param event - The NostrEvent being zapped
|
|
8
|
+
* @param amount - The amount in millisatoshis
|
|
9
|
+
* @param relays - The relays to use for the zap request
|
|
10
|
+
*/
|
|
11
|
+
static create(event, amount, relays) {
|
|
12
|
+
return new ZapRequestFactory((res) => res(blankEventTemplate(kinds.ZapRequest)))
|
|
13
|
+
.eventTarget(event)
|
|
14
|
+
.amount(amount)
|
|
15
|
+
.relays(relays);
|
|
16
|
+
}
|
|
17
|
+
/** Creates a zap request for a profile */
|
|
18
|
+
static profile(pubkey, amount, relays, hint) {
|
|
19
|
+
return new ZapRequestFactory((res) => res(blankEventTemplate(kinds.ZapRequest)))
|
|
20
|
+
.amount(amount)
|
|
21
|
+
.relays(relays)
|
|
22
|
+
.profileTarget(pubkey, hint);
|
|
23
|
+
}
|
|
24
|
+
/** Creates a zap request for an event */
|
|
25
|
+
static event(event, amount, relays, hint) {
|
|
26
|
+
return new ZapRequestFactory((res) => res(blankEventTemplate(kinds.ZapRequest)))
|
|
27
|
+
.amount(amount)
|
|
28
|
+
.relays(relays)
|
|
29
|
+
.eventTarget(event, hint);
|
|
30
|
+
}
|
|
31
|
+
/** Sets the relays for the zap request */
|
|
32
|
+
relays(urls) {
|
|
33
|
+
return this.chain(ZapRequest.setRelays(urls));
|
|
34
|
+
}
|
|
35
|
+
/** Sets the event target. Sets the k (kind), e (event id), a (coordinate for replaceable events), and p (recipient) tags */
|
|
36
|
+
eventTarget(event, hint) {
|
|
37
|
+
return this.chain(ZapRequest.setEventTarget(event, hint));
|
|
38
|
+
}
|
|
39
|
+
/** Sets the profile target. Sets the p tag (recipient) */
|
|
40
|
+
profileTarget(pubkey, hint) {
|
|
41
|
+
return this.chain(ZapRequest.setProfileTarget(pubkey, hint));
|
|
42
|
+
}
|
|
43
|
+
/** Sets the amount in millisatoshis */
|
|
44
|
+
amount(amount) {
|
|
45
|
+
return this.chain(ZapRequest.setAmount(amount));
|
|
46
|
+
}
|
|
47
|
+
/** Sets the lnurl (bech32-encoded) */
|
|
48
|
+
lnurl(lnurl) {
|
|
49
|
+
return this.chain(ZapRequest.setLnurl(lnurl));
|
|
50
|
+
}
|
|
51
|
+
/** Sets the zap message */
|
|
52
|
+
message(text) {
|
|
53
|
+
return this.content(text);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
export type ZapTemplate = KnownEventTemplate<typeof kinds.Zap>;
|
|
4
|
+
export declare class ZapFactory extends EventFactory<typeof kinds.Zap, ZapTemplate> {
|
|
5
|
+
/** Creates a new zap event from a validated zap request */
|
|
6
|
+
static create(zapRequest: NostrEvent, bolt11: string): ZapFactory;
|
|
7
|
+
/** Sets the zap request. Validates, then sets description, P (sender), and copies p, e, a, k, amount tags */
|
|
8
|
+
request(zapRequest: NostrEvent): this;
|
|
9
|
+
/** Sets the bolt11 invoice */
|
|
10
|
+
bolt11(invoice: string): this;
|
|
11
|
+
/** Sets the preimage for the bolt11 invoice */
|
|
12
|
+
preimage(preimage: string): this;
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds } from "applesauce-core/helpers";
|
|
3
|
+
import * as Zap from "../operations/zap.js";
|
|
4
|
+
export class ZapFactory extends EventFactory {
|
|
5
|
+
/** Creates a new zap event from a validated zap request */
|
|
6
|
+
static create(zapRequest, bolt11) {
|
|
7
|
+
return new ZapFactory((res) => res(blankEventTemplate(kinds.Zap))).request(zapRequest).bolt11(bolt11);
|
|
8
|
+
}
|
|
9
|
+
/** Sets the zap request. Validates, then sets description, P (sender), and copies p, e, a, k, amount tags */
|
|
10
|
+
request(zapRequest) {
|
|
11
|
+
return this.chain(Zap.setRequest(zapRequest));
|
|
12
|
+
}
|
|
13
|
+
/** Sets the bolt11 invoice */
|
|
14
|
+
bolt11(invoice) {
|
|
15
|
+
return this.chain(Zap.setBolt11(invoice));
|
|
16
|
+
}
|
|
17
|
+
/** Sets the preimage for the bolt11 invoice */
|
|
18
|
+
preimage(preimage) {
|
|
19
|
+
return this.chain(Zap.setPreimage(preimage));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { kinds, KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { AddressPointer, ProfilePointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
/** Type guard for a valid badge award event */
|
|
4
|
+
export type BadgeAwardEvent = KnownEvent<typeof kinds.BadgeAward>;
|
|
5
|
+
/**
|
|
6
|
+
* Returns true if the event is a valid badge award (kind 8).
|
|
7
|
+
* Validates kind, required `a` tag (definition pointer), and at least one `p` tag (recipient).
|
|
8
|
+
*/
|
|
9
|
+
export declare function isValidBadgeAward(event?: NostrEvent): event is BadgeAwardEvent;
|
|
10
|
+
/** Returns the definition pointer referenced by a badge award's first `a` tag. */
|
|
11
|
+
export declare function getBadgeAwardPointer(event: BadgeAwardEvent): AddressPointer;
|
|
12
|
+
export declare function getBadgeAwardPointer(event?: NostrEvent): AddressPointer | undefined;
|
|
13
|
+
/** Returns every recipient pubkey listed in the badge award's `p` tags. */
|
|
14
|
+
export declare function getBadgeAwardRecipients(event: BadgeAwardEvent): ProfilePointer[];
|
|
15
|
+
export declare function getBadgeAwardRecipients(event?: NostrEvent): ProfilePointer[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
|
|
2
|
+
import { kinds } from "applesauce-core/helpers/event";
|
|
3
|
+
import { getAddressPointerFromATag, getProfilePointerFromPTag, } from "applesauce-core/helpers/pointers";
|
|
4
|
+
import { isATag, isPTag, processTags } from "applesauce-core/helpers/tags";
|
|
5
|
+
const BadgeAwardDefinitionSymbol = Symbol.for("badge-award-definition");
|
|
6
|
+
const BadgeAwardRecipientsSymbol = Symbol.for("badge-award-recipients");
|
|
7
|
+
/**
|
|
8
|
+
* Returns true if the event is a valid badge award (kind 8).
|
|
9
|
+
* Validates kind, required `a` tag (definition pointer), and at least one `p` tag (recipient).
|
|
10
|
+
*/
|
|
11
|
+
export function isValidBadgeAward(event) {
|
|
12
|
+
if (!event || event.kind !== kinds.BadgeAward)
|
|
13
|
+
return false;
|
|
14
|
+
if (!event.tags.find(isATag))
|
|
15
|
+
return false;
|
|
16
|
+
if (!event.tags.find(isPTag))
|
|
17
|
+
return false;
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
export function getBadgeAwardPointer(event) {
|
|
21
|
+
if (!isValidBadgeAward(event))
|
|
22
|
+
return undefined;
|
|
23
|
+
return getOrComputeCachedValue(event, BadgeAwardDefinitionSymbol, () => {
|
|
24
|
+
const aTag = event.tags.find(isATag);
|
|
25
|
+
return aTag ? (getAddressPointerFromATag(aTag) ?? undefined) : undefined;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export function getBadgeAwardRecipients(event) {
|
|
29
|
+
if (!isValidBadgeAward(event))
|
|
30
|
+
return [];
|
|
31
|
+
return getOrComputeCachedValue(event, BadgeAwardRecipientsSymbol, () => processTags(event.tags, (t) => (isPTag(t) ? (getProfilePointerFromPTag(t) ?? undefined) : undefined)));
|
|
32
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { kinds, KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
/** Thumbnail metadata defined by NIP-58 */
|
|
3
|
+
export type BadgeThumbnail = {
|
|
4
|
+
url: string;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
};
|
|
8
|
+
/** Type guard for a valid badge event */
|
|
9
|
+
export type BadgeEvent = KnownEvent<typeof kinds.BadgeDefinition>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if the event is a valid badge definition (kind 30009).
|
|
12
|
+
* Validates kind and the required `d` tag identifier.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isValidBadge(event?: NostrEvent): event is BadgeEvent;
|
|
15
|
+
/** Returns the `d` tag identifier for a badge definition. */
|
|
16
|
+
export declare function getBadgeIdentifier(event: BadgeEvent): string;
|
|
17
|
+
export declare function getBadgeIdentifier(event?: NostrEvent): string | undefined;
|
|
18
|
+
/** Returns the human-readable badge name (`name` tag). */
|
|
19
|
+
export declare function getBadgeName(event?: NostrEvent): string | undefined;
|
|
20
|
+
/** Returns the long-form badge description (`description` tag). */
|
|
21
|
+
export declare function getBadgeDescription(event?: NostrEvent): string | undefined;
|
|
22
|
+
/** Returns the hero image declared via the `image` tag. */
|
|
23
|
+
export declare function getBadgeHeroImage(event?: NostrEvent): BadgeThumbnail | undefined;
|
|
24
|
+
/** Returns every thumbnail declared via `thumb` tags. */
|
|
25
|
+
export declare function getBadgeThumbnails(event?: NostrEvent): BadgeThumbnail[];
|
|
26
|
+
/** Returns the preferred image for display (hero image or first thumbnail). */
|
|
27
|
+
export declare function getBadgeImage(event?: NostrEvent): BadgeThumbnail | undefined;
|