applesauce-content 6.0.0 → 6.2.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/markdown/cashu.d.ts +12 -0
- package/dist/markdown/cashu.js +24 -0
- package/dist/nast/types.d.ts +0 -14
- package/dist/text/cashu.d.ts +12 -1
- package/dist/text/cashu.js +8 -1
- package/dist/text/content.d.ts +1 -2
- package/dist/text/content.js +4 -5
- package/dist/text/imeta.d.ts +11 -0
- package/dist/text/imeta.js +40 -0
- package/dist/text/index.d.ts +5 -6
- package/dist/text/index.js +5 -6
- package/dist/text/lightning.d.ts +12 -1
- package/dist/text/lightning.js +7 -0
- package/package.json +23 -5
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Token } from "@cashu/cashu-ts";
|
|
2
|
+
import { Link, Nodes } from "mdast";
|
|
3
|
+
import { Transformer } from "unified";
|
|
4
|
+
export interface CashuMdastLink extends Link {
|
|
5
|
+
type: "link";
|
|
6
|
+
data: {
|
|
7
|
+
token: Token;
|
|
8
|
+
raw: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** Finds cashu tokens in a mdast tree and replaces them with link nodes carrying the decoded token */
|
|
12
|
+
export declare function remarkCashuTokens(): Transformer<Nodes>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getDecodedToken } from "@cashu/cashu-ts";
|
|
2
|
+
import { Tokens } from "applesauce-core/helpers/regexp";
|
|
3
|
+
import { findAndReplace } from "mdast-util-find-and-replace";
|
|
4
|
+
/** Finds cashu tokens in a mdast tree and replaces them with link nodes carrying the decoded token */
|
|
5
|
+
export function remarkCashuTokens() {
|
|
6
|
+
return (tree) => {
|
|
7
|
+
findAndReplace(tree, [
|
|
8
|
+
Tokens.cashu,
|
|
9
|
+
(_, $1) => {
|
|
10
|
+
try {
|
|
11
|
+
const token = getDecodedToken($1, []);
|
|
12
|
+
return {
|
|
13
|
+
type: "link",
|
|
14
|
+
data: { token, raw: $1 },
|
|
15
|
+
url: "cashu:" + $1,
|
|
16
|
+
children: [{ type: "text", value: $1 }],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
catch (error) { }
|
|
20
|
+
return false;
|
|
21
|
+
},
|
|
22
|
+
]);
|
|
23
|
+
};
|
|
24
|
+
}
|
package/dist/nast/types.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { type Token } from "@cashu/cashu-ts";
|
|
2
|
-
import { type ParsedInvoice } from "applesauce-common/helpers/bolt11";
|
|
3
1
|
import { type EventTemplate, type NostrEvent } from "applesauce-core/helpers/event";
|
|
4
2
|
import { type DecodeResult } from "applesauce-core/helpers/pointers";
|
|
5
3
|
import { type Parent, type Node as UnistNode } from "unist";
|
|
@@ -27,16 +25,6 @@ export interface Mention extends Node {
|
|
|
27
25
|
decoded: DecodeResult;
|
|
28
26
|
encoded: string;
|
|
29
27
|
}
|
|
30
|
-
export interface CashuToken extends Node {
|
|
31
|
-
type: "cashu";
|
|
32
|
-
token: Token;
|
|
33
|
-
raw: string;
|
|
34
|
-
}
|
|
35
|
-
export interface LightningInvoice extends Node {
|
|
36
|
-
type: "lightning";
|
|
37
|
-
invoice: string;
|
|
38
|
-
parsed: ParsedInvoice;
|
|
39
|
-
}
|
|
40
28
|
export interface Hashtag extends Node {
|
|
41
29
|
type: "hashtag";
|
|
42
30
|
/** The name as it was written in the event */
|
|
@@ -72,8 +60,6 @@ export interface ContentMap {
|
|
|
72
60
|
text: Text;
|
|
73
61
|
link: Link;
|
|
74
62
|
mention: Mention;
|
|
75
|
-
cashu: CashuToken;
|
|
76
|
-
lightning: LightningInvoice;
|
|
77
63
|
hashtag: Hashtag;
|
|
78
64
|
emoji: Emoji;
|
|
79
65
|
gallery: Gallery;
|
package/dist/text/cashu.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import { type Token } from "@cashu/cashu-ts";
|
|
1
2
|
import { Transformer } from "unified";
|
|
2
|
-
import { Root } from "../nast/types.js";
|
|
3
|
+
import { Node, Root } from "../nast/types.js";
|
|
4
|
+
export interface CashuToken extends Node {
|
|
5
|
+
type: "cashu";
|
|
6
|
+
token: Token;
|
|
7
|
+
raw: string;
|
|
8
|
+
}
|
|
9
|
+
declare module "../nast/types.js" {
|
|
10
|
+
interface ContentMap {
|
|
11
|
+
cashu: CashuToken;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
3
14
|
/** Parse cashu tokens from an ATS tree */
|
|
4
15
|
export declare function cashuTokens(): Transformer<Root>;
|
package/dist/text/cashu.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getDecodedToken } from "@cashu/cashu-ts";
|
|
2
2
|
import { Tokens } from "applesauce-core/helpers/regexp";
|
|
3
3
|
import { findAndReplace } from "../nast/find-and-replace.js";
|
|
4
|
+
import { textNoteTransformers } from "./content.js";
|
|
4
5
|
/** Parse cashu tokens from an ATS tree */
|
|
5
6
|
export function cashuTokens() {
|
|
6
7
|
return (tree) => {
|
|
@@ -9,7 +10,7 @@ export function cashuTokens() {
|
|
|
9
10
|
Tokens.cashu,
|
|
10
11
|
(_, $1) => {
|
|
11
12
|
try {
|
|
12
|
-
const token = getDecodedToken($1);
|
|
13
|
+
const token = getDecodedToken($1, []);
|
|
13
14
|
return {
|
|
14
15
|
type: "cashu",
|
|
15
16
|
token,
|
|
@@ -23,3 +24,9 @@ export function cashuTokens() {
|
|
|
23
24
|
]);
|
|
24
25
|
};
|
|
25
26
|
}
|
|
27
|
+
// Register the cashu transformer in the default text-note pipeline as a side
|
|
28
|
+
// effect of importing this module. Consumers opt-in to cashu support by
|
|
29
|
+
// importing `applesauce-content/text/cashu`.
|
|
30
|
+
if (!textNoteTransformers.includes(cashuTokens)) {
|
|
31
|
+
textNoteTransformers.push(cashuTokens);
|
|
32
|
+
}
|
package/dist/text/content.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Transformer } from "unified";
|
|
2
2
|
import { EventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
3
3
|
import { Root } from "../nast/types.js";
|
|
4
|
-
import { galleries } from "./gallery.js";
|
|
5
4
|
export declare const TextNoteContentSymbol: unique symbol;
|
|
6
|
-
export declare const textNoteTransformers: (
|
|
5
|
+
export declare const textNoteTransformers: (() => Transformer<Root>)[];
|
|
7
6
|
/** Parsed and process a note with custom transformers */
|
|
8
7
|
export declare function getParsedContent(event: NostrEvent | EventTemplate | string, content?: string, transformers?: (() => Transformer<Root>)[], cacheKey?: symbol | null | undefined): Root;
|
|
9
8
|
export declare function removeParsedTextContent(event: NostrEvent | EventTemplate): void;
|
package/dist/text/content.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { unified } from "unified";
|
|
2
2
|
import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
|
|
3
3
|
import { nostrMentions } from "./mentions.js";
|
|
4
|
-
import { cashuTokens } from "./cashu.js";
|
|
5
4
|
import { emojis } from "./emoji.js";
|
|
6
5
|
import { createEventContentTree } from "./parser.js";
|
|
7
6
|
import { hashtags } from "./hashtag.js";
|
|
8
7
|
import { galleries } from "./gallery.js";
|
|
9
|
-
import { lightningInvoices } from "./lightning.js";
|
|
10
8
|
import { eolMetadata } from "../nast/eol-metadata.js";
|
|
11
9
|
import { links } from "./links.js";
|
|
12
10
|
import { blossomURIs } from "./blossom.js";
|
|
13
11
|
export const TextNoteContentSymbol = Symbol.for("text-note-content");
|
|
14
|
-
// default kind 1 transformers
|
|
12
|
+
// default kind 1 transformers. Optional transformers (like `cashuTokens` and
|
|
13
|
+
// `lightningInvoices`) opt in by appending to this array when their module is
|
|
14
|
+
// imported — see `applesauce-content/text/cashu` and
|
|
15
|
+
// `applesauce-content/text/lightning`.
|
|
15
16
|
export const textNoteTransformers = [
|
|
16
17
|
blossomURIs,
|
|
17
18
|
links,
|
|
@@ -19,8 +20,6 @@ export const textNoteTransformers = [
|
|
|
19
20
|
galleries,
|
|
20
21
|
emojis,
|
|
21
22
|
hashtags,
|
|
22
|
-
lightningInvoices,
|
|
23
|
-
cashuTokens,
|
|
24
23
|
eolMetadata,
|
|
25
24
|
];
|
|
26
25
|
/** Parsed and process a note with custom transformers */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type FileMetadataFields } from "applesauce-common/helpers/file-metadata";
|
|
2
|
+
import { type Transformer } from "unified";
|
|
3
|
+
import { Root } from "../nast/types.js";
|
|
4
|
+
declare module "../nast/types.js" {
|
|
5
|
+
interface Link {
|
|
6
|
+
/** File metadata from a matching NIP-92 `imeta` tag on the event */
|
|
7
|
+
metadata?: FileMetadataFields;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/** Hydrates link nodes with NIP-92 file metadata from matching `imeta` tags on the event */
|
|
11
|
+
export declare function imetaLinks(): Transformer<Root>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getMediaAttachments } from "applesauce-common/helpers/file-metadata";
|
|
2
|
+
import { textNoteTransformers } from "./content.js";
|
|
3
|
+
/** Hydrates link nodes with NIP-92 file metadata from matching `imeta` tags on the event */
|
|
4
|
+
export function imetaLinks() {
|
|
5
|
+
return (tree) => {
|
|
6
|
+
const event = tree.event;
|
|
7
|
+
if (!event || !event.tags || event.tags.length === 0)
|
|
8
|
+
return;
|
|
9
|
+
const attachments = getMediaAttachments(event);
|
|
10
|
+
if (attachments.length === 0)
|
|
11
|
+
return;
|
|
12
|
+
// Build a normalized URL -> metadata map so lookups match `link.href` exactly
|
|
13
|
+
const byUrl = new Map();
|
|
14
|
+
for (const attachment of attachments) {
|
|
15
|
+
if (!attachment.url)
|
|
16
|
+
continue;
|
|
17
|
+
try {
|
|
18
|
+
byUrl.set(new URL(attachment.url).toString(), attachment);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// ignore invalid URLs
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (byUrl.size === 0)
|
|
25
|
+
return;
|
|
26
|
+
for (const node of tree.children) {
|
|
27
|
+
if (node.type !== "link")
|
|
28
|
+
continue;
|
|
29
|
+
const metadata = byUrl.get(node.href);
|
|
30
|
+
if (metadata)
|
|
31
|
+
node.metadata = metadata;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Register the imeta transformer in the default text-note pipeline as a side
|
|
36
|
+
// effect of importing this module. Consumers opt-in to imeta link hydration
|
|
37
|
+
// by importing `applesauce-content/text/imeta`.
|
|
38
|
+
if (!textNoteTransformers.includes(imetaLinks)) {
|
|
39
|
+
textNoteTransformers.push(imetaLinks);
|
|
40
|
+
}
|
package/dist/text/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
export * from "./blossom.js";
|
|
1
2
|
export * from "./content.js";
|
|
3
|
+
export * from "./emoji.js";
|
|
4
|
+
export * from "./gallery.js";
|
|
5
|
+
export * from "./hashtag.js";
|
|
6
|
+
export * from "./imeta.js";
|
|
2
7
|
export * from "./links.js";
|
|
3
8
|
export * from "./mentions.js";
|
|
4
|
-
export * from "./cashu.js";
|
|
5
|
-
export * from "./emoji.js";
|
|
6
9
|
export * from "./parser.js";
|
|
7
|
-
export * from "./hashtag.js";
|
|
8
|
-
export * from "./gallery.js";
|
|
9
|
-
export * from "./lightning.js";
|
|
10
|
-
export * from "./blossom.js";
|
package/dist/text/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
export * from "./blossom.js";
|
|
1
2
|
export * from "./content.js";
|
|
3
|
+
export * from "./emoji.js";
|
|
4
|
+
export * from "./gallery.js";
|
|
5
|
+
export * from "./hashtag.js";
|
|
6
|
+
export * from "./imeta.js";
|
|
2
7
|
export * from "./links.js";
|
|
3
8
|
export * from "./mentions.js";
|
|
4
|
-
export * from "./cashu.js";
|
|
5
|
-
export * from "./emoji.js";
|
|
6
9
|
export * from "./parser.js";
|
|
7
|
-
export * from "./hashtag.js";
|
|
8
|
-
export * from "./gallery.js";
|
|
9
|
-
export * from "./lightning.js";
|
|
10
|
-
export * from "./blossom.js";
|
package/dist/text/lightning.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import { type ParsedInvoice } from "applesauce-common/helpers/bolt11";
|
|
1
2
|
import { type Transformer } from "unified";
|
|
2
|
-
import { Root } from "../nast/types.js";
|
|
3
|
+
import { Node, Root } from "../nast/types.js";
|
|
4
|
+
export interface LightningInvoice extends Node {
|
|
5
|
+
type: "lightning";
|
|
6
|
+
invoice: string;
|
|
7
|
+
parsed: ParsedInvoice;
|
|
8
|
+
}
|
|
9
|
+
declare module "../nast/types.js" {
|
|
10
|
+
interface ContentMap {
|
|
11
|
+
lightning: LightningInvoice;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
3
14
|
/** Finds and creates lightning invoice nodes in the tree */
|
|
4
15
|
export declare function lightningInvoices(): Transformer<Root>;
|
package/dist/text/lightning.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { parseBolt11 } from "applesauce-common/helpers/bolt11";
|
|
2
2
|
import { Tokens } from "applesauce-core/helpers/regexp";
|
|
3
3
|
import { findAndReplace } from "../nast/find-and-replace.js";
|
|
4
|
+
import { textNoteTransformers } from "./content.js";
|
|
4
5
|
/** Finds and creates lightning invoice nodes in the tree */
|
|
5
6
|
export function lightningInvoices() {
|
|
6
7
|
return (tree) => {
|
|
@@ -24,3 +25,9 @@ export function lightningInvoices() {
|
|
|
24
25
|
]);
|
|
25
26
|
};
|
|
26
27
|
}
|
|
28
|
+
// Register the lightning transformer in the default text-note pipeline as a
|
|
29
|
+
// side effect of importing this module. Consumers opt-in to lightning invoice
|
|
30
|
+
// parsing by importing `applesauce-content/text/lightning`.
|
|
31
|
+
if (!textNoteTransformers.includes(lightningInvoices)) {
|
|
32
|
+
textNoteTransformers.push(lightningInvoices);
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-content",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"description": "Unified plugins for processing event content",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -39,19 +39,28 @@
|
|
|
39
39
|
"require": "./dist/markdown/index.js",
|
|
40
40
|
"types": "./dist/markdown/index.d.ts"
|
|
41
41
|
},
|
|
42
|
+
"./markdown/*": {
|
|
43
|
+
"import": "./dist/markdown/*.js",
|
|
44
|
+
"require": "./dist/markdown/*.js",
|
|
45
|
+
"types": "./dist/markdown/*.d.ts"
|
|
46
|
+
},
|
|
42
47
|
"./text": {
|
|
43
48
|
"import": "./dist/text/index.js",
|
|
44
49
|
"require": "./dist/text/index.js",
|
|
45
50
|
"types": "./dist/text/index.d.ts"
|
|
51
|
+
},
|
|
52
|
+
"./text/*": {
|
|
53
|
+
"import": "./dist/text/*.js",
|
|
54
|
+
"require": "./dist/text/*.js",
|
|
55
|
+
"types": "./dist/text/*.d.ts"
|
|
46
56
|
}
|
|
47
57
|
},
|
|
48
58
|
"dependencies": {
|
|
49
|
-
"@cashu/cashu-ts": "^3.1.1",
|
|
50
59
|
"@types/hast": "^3.0.4",
|
|
51
60
|
"@types/mdast": "^4.0.4",
|
|
52
61
|
"@types/unist": "^3.0.3",
|
|
53
|
-
"applesauce-common": "^6.
|
|
54
|
-
"applesauce-core": "^6.
|
|
62
|
+
"applesauce-common": "^6.2.0",
|
|
63
|
+
"applesauce-core": "^6.2.0",
|
|
55
64
|
"mdast-util-find-and-replace": "^3.0.2",
|
|
56
65
|
"remark": "^15.0.1",
|
|
57
66
|
"remark-parse": "^11.0.0",
|
|
@@ -59,11 +68,20 @@
|
|
|
59
68
|
"unist-util-visit-parents": "^6.0.1"
|
|
60
69
|
},
|
|
61
70
|
"devDependencies": {
|
|
62
|
-
"
|
|
71
|
+
"@cashu/cashu-ts": "^4.5.1",
|
|
72
|
+
"applesauce-signers": "^6.2.0",
|
|
63
73
|
"rimraf": "^6.0.1",
|
|
64
74
|
"typescript": "^5.8.3",
|
|
65
75
|
"vitest": "^4.0.15"
|
|
66
76
|
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"@cashu/cashu-ts": "^4.5.1"
|
|
79
|
+
},
|
|
80
|
+
"peerDependenciesMeta": {
|
|
81
|
+
"@cashu/cashu-ts": {
|
|
82
|
+
"optional": true
|
|
83
|
+
}
|
|
84
|
+
},
|
|
67
85
|
"funding": {
|
|
68
86
|
"type": "lightning",
|
|
69
87
|
"url": "lightning:nostrudel@geyser.fund"
|