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
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
1
|
+
import type { EventOperation } from "applesauce-core/factories";
|
|
2
2
|
import { EventTemplate, NostrEvent, UnsignedEvent } from "applesauce-core/helpers/event";
|
|
3
3
|
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
4
4
|
import { Rumor } from "../helpers/gift-wrap.js";
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Converts an event to a rumor. The first operation in the gift wrap pipeline
|
|
7
|
+
* @param signer - EventSigner for getting pubkey
|
|
8
|
+
*/
|
|
9
|
+
export declare function toRumor(signer?: import("applesauce-core/factories").EventSigner): EventOperation<EventTemplate | UnsignedEvent | NostrEvent, Rumor>;
|
|
10
|
+
/**
|
|
11
|
+
* Seals a rumor in a NIP-59 seal. The second operation in the gift wrap pipeline
|
|
12
|
+
* @param pubkey - Pubkey to encrypt seal for
|
|
13
|
+
* @param signer - EventSigner for signing the seal
|
|
14
|
+
*/
|
|
15
|
+
export declare function sealRumor(pubkey: string, signer?: import("applesauce-core/factories").EventSigner): EventOperation<Rumor, NostrEvent>;
|
|
9
16
|
export type GiftWrapOptions = MetaTagOptions;
|
|
10
17
|
/** Gift wraps a seal to a pubkey. The third operation in the gift wrap pipeline */
|
|
11
18
|
export declare function wrapSeal(pubkey: string, opts?: GiftWrapOptions): EventOperation<NostrEvent, NostrEvent>;
|
|
12
|
-
/**
|
|
13
|
-
|
|
19
|
+
/**
|
|
20
|
+
* An operation that gift wraps an event to a pubkey
|
|
21
|
+
* @param pubkey - Pubkey to gift wrap for
|
|
22
|
+
* @param signer - EventSigner for creating rumor and seal
|
|
23
|
+
* @param opts - Optional gift wrap options
|
|
24
|
+
*/
|
|
25
|
+
export declare function giftWrap(pubkey: string, signer?: import("applesauce-core/factories").EventSigner, opts?: GiftWrapOptions): EventOperation<EventTemplate | UnsignedEvent | NostrEvent, NostrEvent>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Read https://github.com/nostr-protocol/nips/blob/master/59.md#overview for details on rumors and seals
|
|
2
2
|
// Gift wrap (signed random key) -> seal (signed sender key) -> rumor (unsigned)
|
|
3
|
-
import {
|
|
3
|
+
import { blankEventTemplate } from "applesauce-core/factories";
|
|
4
4
|
import { EncryptedContentSymbol } from "applesauce-core/helpers/encrypted-content";
|
|
5
5
|
import { nip44 } from "applesauce-core/helpers/encryption";
|
|
6
6
|
import { finalizeEvent, getEventHash, kinds, } from "applesauce-core/helpers/event";
|
|
@@ -18,16 +18,19 @@ PRESERVE_EVENT_SYMBOLS.add(RumorSymbol);
|
|
|
18
18
|
function randomNow() {
|
|
19
19
|
return unixNow() - Math.floor(Math.random() * 60 * 60);
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Converts an event to a rumor. The first operation in the gift wrap pipeline
|
|
23
|
+
* @param signer - EventSigner for getting pubkey
|
|
24
|
+
*/
|
|
25
|
+
export function toRumor(signer) {
|
|
26
|
+
return async (draft) => {
|
|
24
27
|
// @ts-expect-error
|
|
25
28
|
const rumor = { ...draft };
|
|
26
29
|
// Ensure rumor has pubkey
|
|
27
30
|
if (!Reflect.has(rumor, "pubkey")) {
|
|
28
|
-
if (!
|
|
31
|
+
if (!signer)
|
|
29
32
|
throw new Error("A signer is required to create a rumor");
|
|
30
|
-
rumor.pubkey = await
|
|
33
|
+
rumor.pubkey = await signer.getPublicKey();
|
|
31
34
|
}
|
|
32
35
|
// Ensure rumor has id
|
|
33
36
|
if (!Reflect.has(rumor, "id"))
|
|
@@ -37,18 +40,22 @@ export function toRumor() {
|
|
|
37
40
|
return rumor;
|
|
38
41
|
};
|
|
39
42
|
}
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Seals a rumor in a NIP-59 seal. The second operation in the gift wrap pipeline
|
|
45
|
+
* @param pubkey - Pubkey to encrypt seal for
|
|
46
|
+
* @param signer - EventSigner for signing the seal
|
|
47
|
+
*/
|
|
48
|
+
export function sealRumor(pubkey, signer) {
|
|
49
|
+
return async (rumor) => {
|
|
50
|
+
if (!signer)
|
|
44
51
|
throw new Error("A signer is required to create a seal");
|
|
45
52
|
const plaintext = JSON.stringify(rumor);
|
|
46
|
-
const unsigned = await
|
|
53
|
+
const unsigned = await eventPipe(
|
|
47
54
|
// Set the encrypted content
|
|
48
|
-
setEncryptedContent(pubkey, plaintext),
|
|
49
|
-
// Stamp the seal with the
|
|
50
|
-
stamp());
|
|
51
|
-
const seal = await
|
|
55
|
+
setEncryptedContent(pubkey, plaintext, signer),
|
|
56
|
+
// Stamp the seal with the signer's pubkey
|
|
57
|
+
stamp(signer))({ ...blankEventTemplate(kinds.Seal), created_at: randomNow() });
|
|
58
|
+
const seal = await signer.signEvent(unsigned);
|
|
52
59
|
// Set the downstream reference on the seal
|
|
53
60
|
Reflect.set(seal, RumorSymbol, rumor);
|
|
54
61
|
// Add the upstream reference to the rumor
|
|
@@ -65,16 +72,14 @@ export function wrapSeal(pubkey, opts) {
|
|
|
65
72
|
return async (seal) => {
|
|
66
73
|
const key = generateSecretKey();
|
|
67
74
|
const plaintext = JSON.stringify(seal);
|
|
68
|
-
const draft = await
|
|
69
|
-
|
|
75
|
+
const draft = await eventPipe(
|
|
76
|
+
// Set meta tags on the gift wrap
|
|
77
|
+
setMetaTags(opts))({
|
|
78
|
+
...blankEventTemplate(kinds.GiftWrap),
|
|
70
79
|
created_at: randomNow(),
|
|
71
80
|
content: nip44.encrypt(plaintext, nip44.getConversationKey(key, pubkey)),
|
|
72
81
|
tags: [["p", pubkey]],
|
|
73
|
-
}
|
|
74
|
-
// Pass an empty context here so here there is no chance to use the users pubkey
|
|
75
|
-
{},
|
|
76
|
-
// Set meta tags on the gift wrap
|
|
77
|
-
setMetaTags(opts));
|
|
82
|
+
});
|
|
78
83
|
const gift = finalizeEvent(draft, key);
|
|
79
84
|
// Set the upstream references on the seal
|
|
80
85
|
Reflect.set(seal, GiftWrapSymbol, gift);
|
|
@@ -85,9 +90,14 @@ export function wrapSeal(pubkey, opts) {
|
|
|
85
90
|
return gift;
|
|
86
91
|
};
|
|
87
92
|
}
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
|
|
93
|
+
/**
|
|
94
|
+
* An operation that gift wraps an event to a pubkey
|
|
95
|
+
* @param pubkey - Pubkey to gift wrap for
|
|
96
|
+
* @param signer - EventSigner for creating rumor and seal
|
|
97
|
+
* @param opts - Optional gift wrap options
|
|
98
|
+
*/
|
|
99
|
+
export function giftWrap(pubkey, signer, opts) {
|
|
100
|
+
return eventPipe(toRumor(signer),
|
|
91
101
|
// @ts-expect-error
|
|
92
|
-
sealRumor(pubkey), wrapSeal(pubkey, opts));
|
|
102
|
+
sealRumor(pubkey, signer), wrapSeal(pubkey, opts));
|
|
93
103
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
2
|
import { EventPointer, ProfilePointer } from "applesauce-core/helpers";
|
|
3
3
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
4
4
|
import { GroupMetadata, GroupPointer } from "../helpers/groups.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
2
|
/** Adds a hashtag to the live event */
|
|
3
3
|
export declare function addHashtag(hashtag: string): EventOperation;
|
|
4
4
|
/** Removes a hashtag from the live event */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
2
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
3
|
import { AddressPointer, EventPointer } from "applesauce-core/helpers/pointers";
|
|
4
4
|
import { HighlightAttribution } from "../helpers/highlight.js";
|
|
@@ -14,25 +14,25 @@ export function setSource(source) {
|
|
|
14
14
|
const address = getAddressPointerForEvent(source);
|
|
15
15
|
if (address) {
|
|
16
16
|
// Include both the event pointer and address pointer
|
|
17
|
-
return modifyPublicTags(addEventPointerTag(source, true), addAddressPointerTag(address, true));
|
|
17
|
+
return modifyPublicTags(addEventPointerTag(source, undefined, true), addAddressPointerTag(address, undefined, true));
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
20
|
// Just include the event pointer
|
|
21
|
-
return modifyPublicTags(addEventPointerTag(source, true));
|
|
21
|
+
return modifyPublicTags(addEventPointerTag(source, undefined, true));
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
25
|
// Include the event pointer for normal events
|
|
26
|
-
return modifyPublicTags(addEventPointerTag(source, true));
|
|
26
|
+
return modifyPublicTags(addEventPointerTag(source, undefined, true));
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
else if (isAddressPointer(source)) {
|
|
30
30
|
// Include "a" tag for address pointers
|
|
31
|
-
return modifyPublicTags(addAddressPointerTag(source, true));
|
|
31
|
+
return modifyPublicTags(addAddressPointerTag(source, undefined, true));
|
|
32
32
|
}
|
|
33
33
|
else if (isEventPointer(source)) {
|
|
34
34
|
// Include "e" tag for event pointers
|
|
35
|
-
return modifyPublicTags(addEventPointerTag(source, true));
|
|
35
|
+
return modifyPublicTags(addEventPointerTag(source, undefined, true));
|
|
36
36
|
}
|
|
37
37
|
else if (typeof source === "string") {
|
|
38
38
|
// Include "r" tags for URLs
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export * as AppData from "./app-data.js";
|
|
2
|
+
export * as Badge from "./badge.js";
|
|
3
|
+
export * as BadgeAward from "./badge-award.js";
|
|
4
|
+
export * as CodeSnippet from "./code-snippet.js";
|
|
2
5
|
export * as Calendar from "./calendar.js";
|
|
3
6
|
export * as CalendarEvent from "./calendar-event.js";
|
|
4
7
|
export * as CalendarRsvp from "./calendar-rsvp.js";
|
|
@@ -20,10 +23,13 @@ export * as PicturePost from "./picture-post.js";
|
|
|
20
23
|
export * as Poll from "./poll.js";
|
|
21
24
|
export * as PollResponse from "./poll-response.js";
|
|
22
25
|
export * as Reaction from "./reaction.js";
|
|
26
|
+
export * as ProfileBadges from "./profile-badges.js";
|
|
23
27
|
export * as Stream from "./stream.js";
|
|
24
28
|
export * as StreamChat from "./stream-chat.js";
|
|
25
29
|
export * as Torrent from "./torrent.js";
|
|
26
30
|
export * as WrappedMessage from "./wrapped-message.js";
|
|
27
|
-
export * as Zap from "./zap
|
|
31
|
+
export * as Zap from "./zap.js";
|
|
28
32
|
export * as ZapGoal from "./zap-goal.js";
|
|
33
|
+
export * as ZapRequest from "./zap-request.js";
|
|
34
|
+
export * as ZapSplit from "./zap-split.js";
|
|
29
35
|
export * as TagOperations from "./tag/index.js";
|
package/dist/operations/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export * as AppData from "./app-data.js";
|
|
2
|
+
export * as Badge from "./badge.js";
|
|
3
|
+
export * as BadgeAward from "./badge-award.js";
|
|
4
|
+
export * as CodeSnippet from "./code-snippet.js";
|
|
2
5
|
export * as Calendar from "./calendar.js";
|
|
3
6
|
export * as CalendarEvent from "./calendar-event.js";
|
|
4
7
|
export * as CalendarRsvp from "./calendar-rsvp.js";
|
|
@@ -20,10 +23,13 @@ export * as PicturePost from "./picture-post.js";
|
|
|
20
23
|
export * as Poll from "./poll.js";
|
|
21
24
|
export * as PollResponse from "./poll-response.js";
|
|
22
25
|
export * as Reaction from "./reaction.js";
|
|
26
|
+
export * as ProfileBadges from "./profile-badges.js";
|
|
23
27
|
export * as Stream from "./stream.js";
|
|
24
28
|
export * as StreamChat from "./stream-chat.js";
|
|
25
29
|
export * as Torrent from "./torrent.js";
|
|
26
30
|
export * as WrappedMessage from "./wrapped-message.js";
|
|
27
|
-
export * as Zap from "./zap
|
|
31
|
+
export * as Zap from "./zap.js";
|
|
28
32
|
export * as ZapGoal from "./zap-goal.js";
|
|
33
|
+
export * as ZapRequest from "./zap-request.js";
|
|
34
|
+
export * as ZapSplit from "./zap-split.js";
|
|
29
35
|
export * as TagOperations from "./tag/index.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
2
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
3
|
/** Includes the nip-04 direct message "p" tag */
|
|
4
4
|
export declare function setMessageAddress(pubkey: string): EventOperation;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
2
|
/** Sets or removes the "title" tag on a NIP-51 list */
|
|
3
3
|
export declare function setTitle(title: string | null): EventOperation;
|
|
4
4
|
/** Sets or removes the "image" tag on a NIP-51 list */
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
2
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Includes the "a" tag for live streams
|
|
5
|
+
* @param stream - Live stream event
|
|
6
|
+
* @param getRelayHint - Optional function to get relay hint
|
|
7
|
+
*/
|
|
8
|
+
export declare function includeLiveStreamTag(stream: NostrEvent, getRelayHint?: (eventId: string) => Promise<string | undefined>): EventOperation;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { ensureMarkedAddressPointerTag } from "applesauce-core/helpers/factory";
|
|
2
2
|
import { getAddressPointerForEvent } from "applesauce-core/helpers/pointers";
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Includes the "a" tag for live streams
|
|
5
|
+
* @param stream - Live stream event
|
|
6
|
+
* @param getRelayHint - Optional function to get relay hint
|
|
7
|
+
*/
|
|
8
|
+
export function includeLiveStreamTag(stream, getRelayHint) {
|
|
9
|
+
return async (draft) => {
|
|
6
10
|
const pointer = getAddressPointerForEvent(stream);
|
|
7
11
|
if (!pointer)
|
|
8
12
|
throw new Error("Stream is not addressable");
|
|
9
13
|
// add relay hint if there isn't one
|
|
10
|
-
if (pointer.relays?.[0] === undefined &&
|
|
11
|
-
const hint = await
|
|
14
|
+
if (pointer.relays?.[0] === undefined && getRelayHint) {
|
|
15
|
+
const hint = await getRelayHint(stream.id);
|
|
12
16
|
if (hint)
|
|
13
17
|
pointer.relays = [hint];
|
|
14
18
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
2
|
-
import {
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
|
+
import { FileMetadataFields } from "../helpers/file-metadata.js";
|
|
3
3
|
/** Adds "imeta" tags on to any event */
|
|
4
|
-
export declare function addMediaAttachments(attachments:
|
|
4
|
+
export declare function addMediaAttachments(attachments: FileMetadataFields[]): EventOperation;
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
2
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
3
|
/**
|
|
4
4
|
* Includes NIP-10 reply tags
|
|
5
|
+
* @param parent - Parent event to reply to
|
|
6
|
+
* @param getRelayHint - Optional function to get relay hint for event ID
|
|
5
7
|
* @throws {Error} if the parent is not a short text note
|
|
6
8
|
*/
|
|
7
|
-
export declare function setThreadParent(parent: NostrEvent): EventOperation;
|
|
8
|
-
/**
|
|
9
|
-
|
|
9
|
+
export declare function setThreadParent(parent: NostrEvent, getRelayHint?: (eventId: string) => Promise<string | undefined>): EventOperation;
|
|
10
|
+
/**
|
|
11
|
+
* Copies "p" tags from parent event and adds new pubkeys
|
|
12
|
+
* @param parent - Parent event to copy p tags from
|
|
13
|
+
* @param getRelayHint - Optional function to get relay hint for pubkey
|
|
14
|
+
*/
|
|
15
|
+
export declare function includePubkeyNotificationTags(parent: NostrEvent, getRelayHint?: (pubkey: string) => Promise<string | undefined>): EventOperation;
|
package/dist/operations/note.js
CHANGED
|
@@ -4,16 +4,18 @@ import { isPTag } from "applesauce-core/helpers/tags";
|
|
|
4
4
|
import { getNip10References } from "../helpers/threading.js";
|
|
5
5
|
/**
|
|
6
6
|
* Includes NIP-10 reply tags
|
|
7
|
+
* @param parent - Parent event to reply to
|
|
8
|
+
* @param getRelayHint - Optional function to get relay hint for event ID
|
|
7
9
|
* @throws {Error} if the parent is not a short text note
|
|
8
10
|
*/
|
|
9
|
-
export function setThreadParent(parent) {
|
|
11
|
+
export function setThreadParent(parent, getRelayHint) {
|
|
10
12
|
if (parent.kind !== kinds.ShortTextNote)
|
|
11
13
|
throw new Error("Parent must be a short text note");
|
|
12
|
-
return async (draft
|
|
14
|
+
return async (draft) => {
|
|
13
15
|
let tags = Array.from(draft.tags);
|
|
14
16
|
const pointer = { id: parent.id, author: parent.pubkey, kind: parent.kind };
|
|
15
|
-
if (
|
|
16
|
-
const hint = await
|
|
17
|
+
if (getRelayHint) {
|
|
18
|
+
const hint = await getRelayHint(parent.id);
|
|
17
19
|
if (hint)
|
|
18
20
|
pointer.relays = [hint];
|
|
19
21
|
}
|
|
@@ -25,9 +27,13 @@ export function setThreadParent(parent) {
|
|
|
25
27
|
return { ...draft, tags };
|
|
26
28
|
};
|
|
27
29
|
}
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Copies "p" tags from parent event and adds new pubkeys
|
|
32
|
+
* @param parent - Parent event to copy p tags from
|
|
33
|
+
* @param getRelayHint - Optional function to get relay hint for pubkey
|
|
34
|
+
*/
|
|
35
|
+
export function includePubkeyNotificationTags(parent, getRelayHint) {
|
|
36
|
+
return async (draft) => {
|
|
31
37
|
let tags = Array.from(draft.tags);
|
|
32
38
|
// copy "p" tags from parent event that are not mentions
|
|
33
39
|
for (const tag of parent.tags) {
|
|
@@ -35,7 +41,7 @@ export function includePubkeyNotificationTags(parent) {
|
|
|
35
41
|
tags.push(tag);
|
|
36
42
|
}
|
|
37
43
|
// add new "p" tag
|
|
38
|
-
const hint = await
|
|
44
|
+
const hint = getRelayHint ? await getRelayHint(parent.pubkey) : undefined;
|
|
39
45
|
tags = ensureProfilePointerTag(tags, { pubkey: parent.pubkey, relays: hint ? [hint] : undefined });
|
|
40
46
|
return { ...draft, tags };
|
|
41
47
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
2
|
import { MediaAttachment } from "../helpers/file-metadata.js";
|
|
3
3
|
/** Includes the "x" and "m" tags for kind 20 picture posts */
|
|
4
4
|
export declare function setImageMetadata(pictures: MediaAttachment[]): EventOperation;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
2
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
3
|
import { EventPointer } from "applesauce-core/helpers/pointers";
|
|
4
4
|
/** Sets the poll event that this response is for using an 'e' tag */
|
|
@@ -2,7 +2,7 @@ import { addEventPointerTag } from "applesauce-core/operations/tag/common";
|
|
|
2
2
|
import { modifyPublicTags } from "applesauce-core/operations/tags";
|
|
3
3
|
/** Sets the poll event that this response is for using an 'e' tag */
|
|
4
4
|
export function setPollEvent(poll) {
|
|
5
|
-
return modifyPublicTags(addEventPointerTag(poll, true));
|
|
5
|
+
return modifyPublicTags(addEventPointerTag(poll, undefined, true));
|
|
6
6
|
}
|
|
7
7
|
/** Sets multiple response options at once, replacing any existing response tags */
|
|
8
8
|
export function setChoices(optionIds) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
2
|
import { PollType } from "../helpers/poll.js";
|
|
3
3
|
/** Sets the content (poll question/label) for a poll event */
|
|
4
4
|
export declare function setQuestion(question: string): EventOperation;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
|
+
import { type NostrEvent } from "applesauce-core/helpers/event";
|
|
3
|
+
import { AddressPointer, EventPointer } from "applesauce-core/helpers/pointers";
|
|
4
|
+
import type { ProfileBadgeSlot } from "../helpers/profile-badges.js";
|
|
5
|
+
export type ProfileBadgeSlotInput = {
|
|
6
|
+
badge: AddressPointer | NostrEvent | string;
|
|
7
|
+
award: EventPointer | NostrEvent | string;
|
|
8
|
+
};
|
|
9
|
+
/** Replaces every badge slot with the provided list */
|
|
10
|
+
export declare function setSlots(slots: Array<ProfileBadgeSlotInput | ProfileBadgeSlot>): EventOperation;
|
|
11
|
+
/** Adds a slot, replacing any existing slot for the same badge */
|
|
12
|
+
export declare function addSlot(slot: ProfileBadgeSlotInput | ProfileBadgeSlot): EventOperation;
|
|
13
|
+
/** Removes every slot */
|
|
14
|
+
export declare function clearSlots(): EventOperation;
|
|
15
|
+
/** Removes the slot associated with a specific badge definition */
|
|
16
|
+
export declare function removeSlotByBadge(badge: AddressPointer | NostrEvent | string): EventOperation;
|
|
17
|
+
/** Removes the slot referencing a specific award receipt */
|
|
18
|
+
export declare function removeSlotByAward(award: EventPointer | NostrEvent | string): EventOperation;
|
|
19
|
+
/** Inserts a slot at a specific position among existing slots */
|
|
20
|
+
export declare function insertSlot(index: number, slot: ProfileBadgeSlotInput | ProfileBadgeSlot): EventOperation;
|
|
21
|
+
/** Inserts a slot at the beginning */
|
|
22
|
+
export declare function prependSlot(slot: ProfileBadgeSlotInput | ProfileBadgeSlot): EventOperation;
|
|
23
|
+
/** Inserts a slot at the end */
|
|
24
|
+
export declare function appendSlot(slot: ProfileBadgeSlotInput | ProfileBadgeSlot): EventOperation;
|
|
25
|
+
/** Replaces the slot at a specific position with a new one */
|
|
26
|
+
export declare function setSlot(index: number, slot: ProfileBadgeSlotInput | ProfileBadgeSlot): EventOperation;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { isEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { createATagFromAddressPointer, createETagFromEventPointer } from "applesauce-core/helpers/factory";
|
|
3
|
+
import { getAddressPointerForEvent, getAddressPointerFromATag, getEventPointerForEvent, getEventPointerFromETag, getReplaceableAddressFromPointer, normalizeToAddressPointer, normalizeToEventPointer, } from "applesauce-core/helpers/pointers";
|
|
4
|
+
import { modifyPublicTags } from "applesauce-core/operations/tags";
|
|
5
|
+
import { isValidBadgeAward } from "../helpers/badge-award.js";
|
|
6
|
+
import { isValidBadge } from "../helpers/badge.js";
|
|
7
|
+
/** Normalizes a profile badge slot input to a profile badge slot */
|
|
8
|
+
function normalizeSlot(input) {
|
|
9
|
+
const badgePointer = typeof input.badge === "string"
|
|
10
|
+
? normalizeToAddressPointer(input.badge)
|
|
11
|
+
: isEvent(input.badge)
|
|
12
|
+
? isValidBadge(input.badge)
|
|
13
|
+
? getAddressPointerForEvent(input.badge)
|
|
14
|
+
: undefined
|
|
15
|
+
: input.badge;
|
|
16
|
+
if (!badgePointer)
|
|
17
|
+
throw new Error("Invalid badge pointer provided");
|
|
18
|
+
const awardPointer = typeof input.award === "string"
|
|
19
|
+
? normalizeToEventPointer(input.award)
|
|
20
|
+
: isEvent(input.award)
|
|
21
|
+
? isValidBadgeAward(input.award)
|
|
22
|
+
? getEventPointerForEvent(input.award)
|
|
23
|
+
: undefined
|
|
24
|
+
: input.award;
|
|
25
|
+
if (!awardPointer)
|
|
26
|
+
throw new Error("Invalid award pointer provided");
|
|
27
|
+
return { badge: badgePointer, award: awardPointer };
|
|
28
|
+
}
|
|
29
|
+
/** Encodes a profile badge slot to a list of tags */
|
|
30
|
+
function encodeSlot(slot) {
|
|
31
|
+
return [createATagFromAddressPointer(slot.badge), createETagFromEventPointer(slot.award)];
|
|
32
|
+
}
|
|
33
|
+
/** Removes slot pairs from a list of tags */
|
|
34
|
+
function removeSlotPairs(tags, predicate) {
|
|
35
|
+
const result = [];
|
|
36
|
+
for (let i = 0; i < tags.length; i++) {
|
|
37
|
+
const tag = tags[i];
|
|
38
|
+
if (tag[0] === "a" && i + 1 < tags.length && tags[i + 1][0] === "e") {
|
|
39
|
+
const next = tags[i + 1];
|
|
40
|
+
const badge = getAddressPointerFromATag(tag);
|
|
41
|
+
const award = getEventPointerFromETag(next);
|
|
42
|
+
const slot = badge && award ? { badge, award } : undefined;
|
|
43
|
+
const shouldRemove = predicate ? (slot ? predicate(slot) : false) : true;
|
|
44
|
+
if (shouldRemove) {
|
|
45
|
+
i += 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
result.push(tag, next);
|
|
49
|
+
i += 1;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
result.push(tag);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
function sameBadge(a, b) {
|
|
57
|
+
return getReplaceableAddressFromPointer(a) === getReplaceableAddressFromPointer(b);
|
|
58
|
+
}
|
|
59
|
+
function sameAward(a, b) {
|
|
60
|
+
return a.id === b.id;
|
|
61
|
+
}
|
|
62
|
+
/** Returns the tag-index ranges [start, start+2) for each slot pair */
|
|
63
|
+
function getSlotRanges(tags) {
|
|
64
|
+
const ranges = [];
|
|
65
|
+
for (let i = 0; i < tags.length; i++) {
|
|
66
|
+
if (tags[i][0] === "a" && i + 1 < tags.length && tags[i + 1][0] === "e") {
|
|
67
|
+
ranges.push([i, i + 2]);
|
|
68
|
+
i += 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return ranges;
|
|
72
|
+
}
|
|
73
|
+
/** Replaces every badge slot with the provided list */
|
|
74
|
+
export function setSlots(slots) {
|
|
75
|
+
const normalized = slots.map(normalizeSlot);
|
|
76
|
+
return modifyPublicTags((tags) => {
|
|
77
|
+
const remaining = removeSlotPairs(tags);
|
|
78
|
+
const newTags = normalized.flatMap((slot) => encodeSlot(slot));
|
|
79
|
+
return [...remaining, ...newTags];
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** Adds a slot, replacing any existing slot for the same badge */
|
|
83
|
+
export function addSlot(slot) {
|
|
84
|
+
const normalized = normalizeSlot(slot);
|
|
85
|
+
return modifyPublicTags((tags) => {
|
|
86
|
+
const filtered = removeSlotPairs(tags, (existing) => sameBadge(existing.badge, normalized.badge));
|
|
87
|
+
return [...filtered, ...encodeSlot(normalized)];
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/** Removes every slot */
|
|
91
|
+
export function clearSlots() {
|
|
92
|
+
return modifyPublicTags((tags) => removeSlotPairs(tags));
|
|
93
|
+
}
|
|
94
|
+
/** Removes the slot associated with a specific badge definition */
|
|
95
|
+
export function removeSlotByBadge(badge) {
|
|
96
|
+
let pointer = null;
|
|
97
|
+
if (typeof badge === "string")
|
|
98
|
+
pointer = normalizeToAddressPointer(badge);
|
|
99
|
+
else if (isEvent(badge))
|
|
100
|
+
pointer = isValidBadge(badge) ? getAddressPointerForEvent(badge) : null;
|
|
101
|
+
else
|
|
102
|
+
pointer = badge;
|
|
103
|
+
if (!pointer)
|
|
104
|
+
throw new Error("Invalid badge pointer provided");
|
|
105
|
+
return modifyPublicTags((tags) => removeSlotPairs(tags, (slot) => sameBadge(slot.badge, pointer)));
|
|
106
|
+
}
|
|
107
|
+
/** Removes the slot referencing a specific award receipt */
|
|
108
|
+
export function removeSlotByAward(award) {
|
|
109
|
+
let pointer = null;
|
|
110
|
+
if (typeof award === "string")
|
|
111
|
+
pointer = normalizeToEventPointer(award);
|
|
112
|
+
else if (isEvent(award))
|
|
113
|
+
pointer = isValidBadgeAward(award) ? getEventPointerForEvent(award) : null;
|
|
114
|
+
else
|
|
115
|
+
pointer = award;
|
|
116
|
+
if (!pointer)
|
|
117
|
+
throw new Error("Invalid award pointer provided");
|
|
118
|
+
return modifyPublicTags((tags) => removeSlotPairs(tags, (slot) => sameAward(slot.award, pointer)));
|
|
119
|
+
}
|
|
120
|
+
/** Inserts a slot at a specific position among existing slots */
|
|
121
|
+
export function insertSlot(index, slot) {
|
|
122
|
+
const normalized = normalizeSlot(slot);
|
|
123
|
+
return modifyPublicTags((tags) => {
|
|
124
|
+
const ranges = getSlotRanges(tags);
|
|
125
|
+
const encoded = encodeSlot(normalized);
|
|
126
|
+
if (ranges.length === 0 || index >= ranges.length)
|
|
127
|
+
return [...tags, ...encoded];
|
|
128
|
+
const insertAt = ranges[Math.max(0, index)][0];
|
|
129
|
+
return [...tags.slice(0, insertAt), ...encoded, ...tags.slice(insertAt)];
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/** Inserts a slot at the beginning */
|
|
133
|
+
export function prependSlot(slot) {
|
|
134
|
+
return insertSlot(0, slot);
|
|
135
|
+
}
|
|
136
|
+
/** Inserts a slot at the end */
|
|
137
|
+
export function appendSlot(slot) {
|
|
138
|
+
return insertSlot(Infinity, slot);
|
|
139
|
+
}
|
|
140
|
+
/** Replaces the slot at a specific position with a new one */
|
|
141
|
+
export function setSlot(index, slot) {
|
|
142
|
+
const normalized = normalizeSlot(slot);
|
|
143
|
+
return modifyPublicTags((tags) => {
|
|
144
|
+
const ranges = getSlotRanges(tags);
|
|
145
|
+
if (index < 0 || index >= ranges.length)
|
|
146
|
+
throw new Error(`Slot index ${index} out of range`);
|
|
147
|
+
const [start, end] = ranges[index];
|
|
148
|
+
return [...tags.slice(0, start), ...encodeSlot(normalized), ...tags.slice(end)];
|
|
149
|
+
});
|
|
150
|
+
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { EventOperation } from "applesauce-core/
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
2
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
3
|
import { Emoji } from "../helpers/emoji.js";
|
|
4
4
|
/** Sets the content for a reaction event */
|
|
5
5
|
export declare function setReaction(emoji?: string | Emoji): EventOperation;
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Includes NIP-25 "e", "p", "k", and "a" tags for a reaction event to point to a parent event
|
|
8
|
+
* @param event - Event being reacted to
|
|
9
|
+
* @param getEventRelayHint - Optional function to get relay hint for event ID
|
|
10
|
+
* @param getPubkeyRelayHint - Optional function to get relay hint for pubkey
|
|
11
|
+
*/
|
|
12
|
+
export declare function setReactionParent(event: NostrEvent, getEventRelayHint?: (eventId: string) => Promise<string | undefined>, getPubkeyRelayHint?: (pubkey: string) => Promise<string | undefined>): EventOperation;
|
|
@@ -5,12 +5,17 @@ import { ensureAddressPointerTag, ensureEventPointerTag, ensureKTag, ensureProfi
|
|
|
5
5
|
export function setReaction(emoji = "+") {
|
|
6
6
|
return (draft) => ({ ...draft, content: typeof emoji === "string" ? emoji : `:${emoji.shortcode}:` });
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Includes NIP-25 "e", "p", "k", and "a" tags for a reaction event to point to a parent event
|
|
10
|
+
* @param event - Event being reacted to
|
|
11
|
+
* @param getEventRelayHint - Optional function to get relay hint for event ID
|
|
12
|
+
* @param getPubkeyRelayHint - Optional function to get relay hint for pubkey
|
|
13
|
+
*/
|
|
14
|
+
export function setReactionParent(event, getEventRelayHint, getPubkeyRelayHint) {
|
|
15
|
+
return async (draft) => {
|
|
11
16
|
let tags = Array.from(draft.tags);
|
|
12
|
-
const eventHint = await
|
|
13
|
-
const pubkeyHint = await
|
|
17
|
+
const eventHint = getEventRelayHint ? await getEventRelayHint(event.id) : undefined;
|
|
18
|
+
const pubkeyHint = getPubkeyRelayHint ? await getPubkeyRelayHint(event.pubkey) : undefined;
|
|
14
19
|
// include "e" tag
|
|
15
20
|
tags = ensureEventPointerTag(tags, {
|
|
16
21
|
id: event.id,
|