applesauce-core 0.0.0-next-20241115160057 → 0.0.0-next-20241119142128
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/helpers/bolt11.d.ts +1 -0
- package/dist/helpers/bolt11.js +1 -0
- package/dist/helpers/emoji.d.ts +7 -0
- package/dist/helpers/emoji.js +11 -0
- package/dist/helpers/json.d.ts +1 -0
- package/dist/helpers/json.js +1 -0
- package/dist/helpers/mailboxes.d.ts +0 -6
- package/dist/helpers/mailboxes.js +7 -8
- package/dist/helpers/profile.d.ts +2 -0
- package/dist/helpers/profile.js +15 -0
- package/dist/helpers/string.d.ts +6 -0
- package/dist/helpers/string.js +2 -0
- package/dist/helpers/zap.d.ts +1 -0
- package/dist/helpers/zap.js +15 -1
- package/dist/queries/profile.js +3 -3
- package/dist/queries/zaps.js +6 -2
- package/package.json +1 -1
package/dist/helpers/bolt11.d.ts
CHANGED
package/dist/helpers/bolt11.js
CHANGED
package/dist/helpers/emoji.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { EventTemplate, NostrEvent } from "nostr-tools";
|
|
2
2
|
export declare function getEmojiTag(event: NostrEvent | EventTemplate, code: string): ["emoji", string, string];
|
|
3
|
+
/** Returns the name of a NIP-30 emoji pack */
|
|
4
|
+
export declare function getPackName(pack: NostrEvent): string | undefined;
|
|
5
|
+
/** Returns an array of emojis from a NIP-30 emoji pack */
|
|
6
|
+
export declare function getEmojis(pack: NostrEvent): {
|
|
7
|
+
name: string;
|
|
8
|
+
url: string;
|
|
9
|
+
}[];
|
package/dist/helpers/emoji.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import { getTagValue } from "./event.js";
|
|
1
2
|
export function getEmojiTag(event, code) {
|
|
2
3
|
code = code.replace(/^:|:$/g, "").toLocaleLowerCase();
|
|
3
4
|
return event.tags.filter((t) => t[0] === "emoji" && t[1] && t[2]).find((t) => t[1].toLowerCase() === code);
|
|
4
5
|
}
|
|
6
|
+
/** Returns the name of a NIP-30 emoji pack */
|
|
7
|
+
export function getPackName(pack) {
|
|
8
|
+
return getTagValue(pack, "title") || getTagValue(pack, "d");
|
|
9
|
+
}
|
|
10
|
+
/** Returns an array of emojis from a NIP-30 emoji pack */
|
|
11
|
+
export function getEmojis(pack) {
|
|
12
|
+
return pack.tags
|
|
13
|
+
.filter((t) => t[0] === "emoji" && t[1] && t[2])
|
|
14
|
+
.map((t) => ({ name: t[1], url: t[2] }));
|
|
15
|
+
}
|
package/dist/helpers/json.d.ts
CHANGED
package/dist/helpers/json.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { NostrEvent } from "nostr-tools";
|
|
2
2
|
export declare const MailboxesInboxesSymbol: unique symbol;
|
|
3
3
|
export declare const MailboxesOutboxesSymbol: unique symbol;
|
|
4
|
-
declare module "nostr-tools" {
|
|
5
|
-
interface Event {
|
|
6
|
-
[MailboxesInboxesSymbol]?: string[];
|
|
7
|
-
[MailboxesOutboxesSymbol]?: string[];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
4
|
/**
|
|
11
5
|
* Parses a 10002 event and stores the inboxes in the event using the {@link MailboxesInboxesSymbol} symbol
|
|
12
6
|
*/
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { safeRelayUrl } from "./relays.js";
|
|
2
|
+
import { getOrComputeCachedValue } from "./cache.js";
|
|
2
3
|
export const MailboxesInboxesSymbol = Symbol.for("mailboxes-inboxes");
|
|
3
4
|
export const MailboxesOutboxesSymbol = Symbol.for("mailboxes-outboxes");
|
|
4
5
|
/**
|
|
5
6
|
* Parses a 10002 event and stores the inboxes in the event using the {@link MailboxesInboxesSymbol} symbol
|
|
6
7
|
*/
|
|
7
8
|
export function getInboxes(event) {
|
|
8
|
-
|
|
9
|
+
return getOrComputeCachedValue(event, MailboxesInboxesSymbol, () => {
|
|
9
10
|
const inboxes = [];
|
|
10
11
|
for (const tag of event.tags) {
|
|
11
12
|
if (tag[0] === "r" && tag[1] && (tag[2] === "read" || tag[2] === undefined)) {
|
|
@@ -14,15 +15,14 @@ export function getInboxes(event) {
|
|
|
14
15
|
inboxes.push(url);
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
return event[MailboxesInboxesSymbol];
|
|
18
|
+
return inboxes;
|
|
19
|
+
});
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Parses a 10002 event and stores the outboxes in the event using the {@link MailboxesOutboxesSymbol} symbol
|
|
23
23
|
*/
|
|
24
24
|
export function getOutboxes(event) {
|
|
25
|
-
|
|
25
|
+
return getOrComputeCachedValue(event, MailboxesOutboxesSymbol, () => {
|
|
26
26
|
const outboxes = [];
|
|
27
27
|
for (const tag of event.tags) {
|
|
28
28
|
if (tag[0] === "r" && tag[1] && (tag[2] === "write" || tag[2] === undefined)) {
|
|
@@ -31,7 +31,6 @@ export function getOutboxes(event) {
|
|
|
31
31
|
outboxes.push(url);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
return event[MailboxesOutboxesSymbol];
|
|
34
|
+
return outboxes;
|
|
35
|
+
});
|
|
37
36
|
}
|
|
@@ -16,3 +16,5 @@ export type ProfileContent = {
|
|
|
16
16
|
};
|
|
17
17
|
/** Returns the parsed profile content for a kind 0 event */
|
|
18
18
|
export declare function getProfileContent(event: NostrEvent): ProfileContent;
|
|
19
|
+
/** Checks if the content of the kind 0 event is valid JSON */
|
|
20
|
+
export declare function isValidProfile(profile?: NostrEvent): boolean;
|
package/dist/helpers/profile.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { kinds } from "nostr-tools";
|
|
1
2
|
import { getOrComputeCachedValue } from "./cache.js";
|
|
2
3
|
export const ProfileContentSymbol = Symbol.for("profile-content");
|
|
3
4
|
/** Returns the parsed profile content for a kind 0 event */
|
|
@@ -14,3 +15,17 @@ export function getProfileContent(event) {
|
|
|
14
15
|
return profile;
|
|
15
16
|
});
|
|
16
17
|
}
|
|
18
|
+
/** Checks if the content of the kind 0 event is valid JSON */
|
|
19
|
+
export function isValidProfile(profile) {
|
|
20
|
+
if (!profile)
|
|
21
|
+
return false;
|
|
22
|
+
if (profile.kind !== kinds.Metadata)
|
|
23
|
+
return false;
|
|
24
|
+
try {
|
|
25
|
+
getProfileContent(profile);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/dist/helpers/string.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
/** Tests if a string is hex */
|
|
1
2
|
export declare function isHex(str?: string): boolean;
|
|
3
|
+
/** Tests if a string is a 64 length hex string */
|
|
2
4
|
export declare function isHexKey(key?: string): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Remove invisible characters from a string
|
|
7
|
+
* @see read more https://www.regular-expressions.info/unicode.html#category
|
|
8
|
+
*/
|
|
3
9
|
export declare function stripInvisibleChar(str: string): string;
|
|
4
10
|
export declare function stripInvisibleChar(str?: string | undefined): string | undefined;
|
package/dist/helpers/string.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/** Tests if a string is hex */
|
|
1
2
|
export function isHex(str) {
|
|
2
3
|
if (str?.match(/^[0-9a-f]+$/i))
|
|
3
4
|
return true;
|
|
4
5
|
return false;
|
|
5
6
|
}
|
|
7
|
+
/** Tests if a string is a 64 length hex string */
|
|
6
8
|
export function isHexKey(key) {
|
|
7
9
|
if (key?.toLowerCase()?.match(/^[0-9a-f]{64}$/))
|
|
8
10
|
return true;
|
package/dist/helpers/zap.d.ts
CHANGED
|
@@ -11,3 +11,4 @@ export declare function getZapAddressPointer(zap: NostrEvent): import("nostr-too
|
|
|
11
11
|
export declare function getZapEventPointer(zap: NostrEvent): import("nostr-tools/nip19").EventPointer | null;
|
|
12
12
|
export declare function getZapPreimage(zap: NostrEvent): string | undefined;
|
|
13
13
|
export declare function getZapRequest(zap: NostrEvent): import("nostr-tools").Event;
|
|
14
|
+
export declare function isValidZap(zap?: NostrEvent): boolean;
|
package/dist/helpers/zap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { nip57 } from "nostr-tools";
|
|
1
|
+
import { kinds, nip57 } from "nostr-tools";
|
|
2
2
|
import { getOrComputeCachedValue } from "./cache.js";
|
|
3
3
|
import { getTagValue } from "./event.js";
|
|
4
4
|
import { isATag, isETag } from "./tags.js";
|
|
@@ -50,3 +50,17 @@ export function getZapRequest(zap) {
|
|
|
50
50
|
return JSON.parse(description);
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
+
export function isValidZap(zap) {
|
|
54
|
+
if (!zap)
|
|
55
|
+
return false;
|
|
56
|
+
if (zap.kind !== kinds.Zap)
|
|
57
|
+
return false;
|
|
58
|
+
try {
|
|
59
|
+
getZapRequest(zap);
|
|
60
|
+
getZapRecipient(zap);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
package/dist/queries/profile.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { kinds } from "nostr-tools";
|
|
2
|
-
import { map } from "rxjs/operators";
|
|
3
|
-
import { getProfileContent } from "../helpers/profile.js";
|
|
2
|
+
import { filter, map } from "rxjs/operators";
|
|
3
|
+
import { getProfileContent, isValidProfile } from "../helpers/profile.js";
|
|
4
4
|
export function ProfileQuery(pubkey) {
|
|
5
5
|
return {
|
|
6
6
|
key: pubkey,
|
|
7
7
|
run: (events) => {
|
|
8
|
-
return events.replaceable(kinds.Metadata, pubkey).pipe(map((event) => event && getProfileContent(event)));
|
|
8
|
+
return events.replaceable(kinds.Metadata, pubkey).pipe(filter(isValidProfile), map((event) => event && getProfileContent(event)));
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
11
|
}
|
package/dist/queries/zaps.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
import { map } from "rxjs";
|
|
1
2
|
import { kinds } from "nostr-tools";
|
|
2
3
|
import { getCoordinateFromAddressPointer, isAddressPointer } from "../helpers/pointers.js";
|
|
4
|
+
import { isValidZap } from "../helpers/zap.js";
|
|
3
5
|
export function EventZapsQuery(id) {
|
|
4
6
|
return {
|
|
5
7
|
key: JSON.stringify(id),
|
|
6
8
|
run: (events) => {
|
|
7
9
|
if (isAddressPointer(id)) {
|
|
8
|
-
return events
|
|
10
|
+
return events
|
|
11
|
+
.timeline([{ kinds: [kinds.Zap], "#a": [getCoordinateFromAddressPointer(id)] }])
|
|
12
|
+
.pipe(map((events) => events.filter(isValidZap)));
|
|
9
13
|
}
|
|
10
14
|
else {
|
|
11
15
|
id = typeof id === "string" ? id : id.id;
|
|
12
|
-
return events.timeline([{ kinds: [kinds.Zap], "#e": [id] }]);
|
|
16
|
+
return events.timeline([{ kinds: [kinds.Zap], "#e": [id] }]).pipe(map((events) => events.filter(isValidZap)));
|
|
13
17
|
}
|
|
14
18
|
},
|
|
15
19
|
};
|