@character-foundry/character-foundry 0.1.6 → 0.1.8-dev.1765911776
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -32
- package/dist/app-framework.cjs +1 -1
- package/dist/app-framework.cjs.map +1 -1
- package/dist/app-framework.js +1 -1
- package/dist/app-framework.js.map +1 -1
- package/dist/charx.cjs.map +1 -1
- package/dist/charx.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/exporter.cjs +3 -3
- package/dist/exporter.cjs.map +1 -1
- package/dist/exporter.js +3 -3
- package/dist/exporter.js.map +1 -1
- package/dist/federation.cjs +6 -6
- package/dist/federation.cjs.map +1 -1
- package/dist/federation.js +6 -6
- package/dist/federation.js.map +1 -1
- package/dist/image-utils.cjs +249 -0
- package/dist/image-utils.cjs.map +1 -0
- package/dist/image-utils.d.cts +136 -0
- package/dist/image-utils.d.ts +136 -0
- package/dist/image-utils.js +226 -0
- package/dist/image-utils.js.map +1 -0
- package/dist/index.cjs +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/loader.cjs +4 -4
- package/dist/loader.cjs.map +1 -1
- package/dist/loader.js +4 -4
- package/dist/loader.js.map +1 -1
- package/dist/lorebook.cjs +5 -5
- package/dist/lorebook.cjs.map +1 -1
- package/dist/lorebook.js +5 -5
- package/dist/lorebook.js.map +1 -1
- package/dist/media.cjs.map +1 -1
- package/dist/media.js.map +1 -1
- package/dist/normalizer.cjs.map +1 -1
- package/dist/normalizer.js.map +1 -1
- package/dist/png.cjs +1 -1
- package/dist/png.cjs.map +1 -1
- package/dist/png.js +1 -1
- package/dist/png.js.map +1 -1
- package/dist/schemas.cjs.map +1 -1
- package/dist/schemas.js.map +1 -1
- package/dist/tokenizers.cjs.map +1 -1
- package/dist/tokenizers.js.map +1 -1
- package/dist/voxta.cjs +1 -1
- package/dist/voxta.cjs.map +1 -1
- package/dist/voxta.js +1 -1
- package/dist/voxta.js.map +1 -1
- package/package.json +14 -3
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// ../image-utils/dist/index.js
|
|
2
|
+
function extractImageUrls(text, options = {}) {
|
|
3
|
+
const {
|
|
4
|
+
includeMarkdown = true,
|
|
5
|
+
includeHTML = true,
|
|
6
|
+
includeBase64 = true
|
|
7
|
+
} = options;
|
|
8
|
+
const results = [];
|
|
9
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10
|
+
if (includeMarkdown) {
|
|
11
|
+
const markdownPattern = /!\[([^\]]*)\]\(<?([^>\s)]+)>?(?:\s*=[^)]+)?\)/g;
|
|
12
|
+
let match;
|
|
13
|
+
while ((match = markdownPattern.exec(text)) !== null) {
|
|
14
|
+
const url = match[2]?.trim();
|
|
15
|
+
if (url && !seen.has(url)) {
|
|
16
|
+
seen.add(url);
|
|
17
|
+
results.push({
|
|
18
|
+
url,
|
|
19
|
+
source: "markdown",
|
|
20
|
+
context: match[0]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (includeHTML) {
|
|
26
|
+
const htmlQuotedPattern = /<img[^>]+src=["']([^"']+)["'][^>]*>/gi;
|
|
27
|
+
let match;
|
|
28
|
+
while ((match = htmlQuotedPattern.exec(text)) !== null) {
|
|
29
|
+
const url = match[1]?.trim();
|
|
30
|
+
if (url && !seen.has(url)) {
|
|
31
|
+
seen.add(url);
|
|
32
|
+
results.push({
|
|
33
|
+
url,
|
|
34
|
+
source: "html",
|
|
35
|
+
context: match[0]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const htmlUnquotedPattern = /<img[^>]+src=([^\s"'>]+)[^>]*>/gi;
|
|
40
|
+
while ((match = htmlUnquotedPattern.exec(text)) !== null) {
|
|
41
|
+
const url = match[1]?.trim();
|
|
42
|
+
if (url && !url.startsWith('"') && !url.startsWith("'") && !seen.has(url)) {
|
|
43
|
+
seen.add(url);
|
|
44
|
+
results.push({
|
|
45
|
+
url,
|
|
46
|
+
source: "html",
|
|
47
|
+
context: match[0]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const cssUrlPattern = /url\(["']?([^)"']+)["']?\)/gi;
|
|
52
|
+
while ((match = cssUrlPattern.exec(text)) !== null) {
|
|
53
|
+
const url = match[1]?.trim();
|
|
54
|
+
if (url && (url.startsWith("http://") || url.startsWith("https://")) && !seen.has(url)) {
|
|
55
|
+
seen.add(url);
|
|
56
|
+
results.push({
|
|
57
|
+
url,
|
|
58
|
+
source: "html",
|
|
59
|
+
context: match[0]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (includeHTML) {
|
|
65
|
+
const plainUrlPattern = /(?<![("'])(https?:\/\/[^\s<>"']+\.(?:jpg|jpeg|png|gif|webp|svg|avif|bmp))(?![)"'])/gi;
|
|
66
|
+
let match;
|
|
67
|
+
while ((match = plainUrlPattern.exec(text)) !== null) {
|
|
68
|
+
const url = match[0]?.trim();
|
|
69
|
+
if (url && !seen.has(url)) {
|
|
70
|
+
seen.add(url);
|
|
71
|
+
results.push({
|
|
72
|
+
url,
|
|
73
|
+
source: "html",
|
|
74
|
+
context: url
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (includeBase64) {
|
|
80
|
+
const dataUrlPattern = /data:image\/[^;]+;base64,[A-Za-z0-9+/=]+/g;
|
|
81
|
+
let match;
|
|
82
|
+
while ((match = dataUrlPattern.exec(text)) !== null) {
|
|
83
|
+
const url = match[0];
|
|
84
|
+
if (!seen.has(url)) {
|
|
85
|
+
seen.add(url);
|
|
86
|
+
results.push({
|
|
87
|
+
url,
|
|
88
|
+
source: "base64"
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return results;
|
|
94
|
+
}
|
|
95
|
+
function extractRemoteImageUrls(text) {
|
|
96
|
+
const all = extractImageUrls(text, { includeBase64: false });
|
|
97
|
+
return all.filter((img) => /^https?:\/\//i.test(img.url));
|
|
98
|
+
}
|
|
99
|
+
function extractDataUrls(text) {
|
|
100
|
+
return extractImageUrls(text, {
|
|
101
|
+
includeMarkdown: false,
|
|
102
|
+
includeHTML: false,
|
|
103
|
+
includeBase64: true
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function countImages(text) {
|
|
107
|
+
return extractImageUrls(text).length;
|
|
108
|
+
}
|
|
109
|
+
var DEFAULT_SSRF_POLICY = {
|
|
110
|
+
allowPrivateIPs: false,
|
|
111
|
+
allowLocalhost: false,
|
|
112
|
+
blockedDomains: [],
|
|
113
|
+
allowedDomains: [],
|
|
114
|
+
allowDataUrls: false
|
|
115
|
+
};
|
|
116
|
+
function isURLSafe(url, policy = {}) {
|
|
117
|
+
const config = { ...DEFAULT_SSRF_POLICY, ...policy };
|
|
118
|
+
let parsed;
|
|
119
|
+
try {
|
|
120
|
+
parsed = new URL(url);
|
|
121
|
+
} catch {
|
|
122
|
+
return { safe: false, reason: "Invalid URL format" };
|
|
123
|
+
}
|
|
124
|
+
if (parsed.protocol === "data:") {
|
|
125
|
+
if (!config.allowDataUrls) {
|
|
126
|
+
return { safe: false, reason: "Data URLs not allowed" };
|
|
127
|
+
}
|
|
128
|
+
return { safe: true };
|
|
129
|
+
}
|
|
130
|
+
if (!["http:", "https:"].includes(parsed.protocol)) {
|
|
131
|
+
return {
|
|
132
|
+
safe: false,
|
|
133
|
+
reason: `Protocol '${parsed.protocol}' not allowed (only http/https)`
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const hostname = parsed.hostname.toLowerCase();
|
|
137
|
+
if (config.allowedDomains.length > 0) {
|
|
138
|
+
const isAllowed = config.allowedDomains.some(
|
|
139
|
+
(pattern) => matchDomainPattern(hostname, pattern)
|
|
140
|
+
);
|
|
141
|
+
if (!isAllowed) {
|
|
142
|
+
return {
|
|
143
|
+
safe: false,
|
|
144
|
+
reason: `Domain '${hostname}' not in allowed list`
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (config.blockedDomains.length > 0) {
|
|
149
|
+
const isBlocked = config.blockedDomains.some(
|
|
150
|
+
(pattern) => matchDomainPattern(hostname, pattern)
|
|
151
|
+
);
|
|
152
|
+
if (isBlocked) {
|
|
153
|
+
return {
|
|
154
|
+
safe: false,
|
|
155
|
+
reason: `Domain '${hostname}' is blocked`
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (isLocalhost(hostname) && !config.allowLocalhost) {
|
|
160
|
+
return { safe: false, reason: "Localhost not allowed" };
|
|
161
|
+
}
|
|
162
|
+
if (isPrivateIP(hostname) && !config.allowPrivateIPs) {
|
|
163
|
+
return { safe: false, reason: "Private IP addresses not allowed" };
|
|
164
|
+
}
|
|
165
|
+
return { safe: true };
|
|
166
|
+
}
|
|
167
|
+
function isSafeForFetch(url) {
|
|
168
|
+
return isURLSafe(url).safe;
|
|
169
|
+
}
|
|
170
|
+
function matchDomainPattern(domain, pattern) {
|
|
171
|
+
if (domain === pattern) return true;
|
|
172
|
+
if (pattern.startsWith("*.")) {
|
|
173
|
+
const suffix = pattern.slice(2);
|
|
174
|
+
return domain.endsWith("." + suffix);
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
function isLocalhost(hostname) {
|
|
179
|
+
const lower = hostname.toLowerCase();
|
|
180
|
+
if (lower === "localhost" || lower === "0.0.0.0" || lower.startsWith("127.")) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
if (lower === "::1" || lower === "[::1]") {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
function isPrivateIP(hostname) {
|
|
189
|
+
const lower = hostname.toLowerCase();
|
|
190
|
+
const parts = hostname.split(".").map(Number);
|
|
191
|
+
if (parts.length === 4 && parts.every((p) => p >= 0 && p <= 255 && !isNaN(p))) {
|
|
192
|
+
const [octet1, octet2] = parts;
|
|
193
|
+
if (octet1 === 10) return true;
|
|
194
|
+
if (octet1 === 172 && octet2 !== void 0 && octet2 >= 16 && octet2 <= 31)
|
|
195
|
+
return true;
|
|
196
|
+
if (octet1 === 192 && octet2 === 168) return true;
|
|
197
|
+
if (octet1 === 169 && octet2 === 254) return true;
|
|
198
|
+
}
|
|
199
|
+
const cleanedHostname = lower.replace(/^\[|\]$/g, "");
|
|
200
|
+
const ipv6Patterns = [
|
|
201
|
+
/^f[cd][0-9a-f]{2}:/i,
|
|
202
|
+
// fc00::/7 (includes both fc and fd ranges)
|
|
203
|
+
/^fe80:/i
|
|
204
|
+
// fe80::/10 (link-local)
|
|
205
|
+
];
|
|
206
|
+
for (const pattern of ipv6Patterns) {
|
|
207
|
+
if (pattern.test(cleanedHostname)) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
function filterSafeUrls(urls, policy) {
|
|
214
|
+
return urls.filter((url) => isURLSafe(url, policy).safe);
|
|
215
|
+
}
|
|
216
|
+
export {
|
|
217
|
+
DEFAULT_SSRF_POLICY,
|
|
218
|
+
countImages,
|
|
219
|
+
extractDataUrls,
|
|
220
|
+
extractImageUrls,
|
|
221
|
+
extractRemoteImageUrls,
|
|
222
|
+
filterSafeUrls,
|
|
223
|
+
isSafeForFetch,
|
|
224
|
+
isURLSafe
|
|
225
|
+
};
|
|
226
|
+
//# sourceMappingURL=image-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../image-utils/src/extraction.ts","../../image-utils/src/ssrf.ts"],"sourcesContent":["/**\n * Image URL Extraction\n *\n * Extracts image URLs from markdown, HTML, and base64 data URLs in text.\n * Used across Federation, Archive, and Architect for image processing.\n */\n\nexport interface ImageExtractionOptions {\n /** Include markdown image syntax `` (default: true) */\n includeMarkdown?: boolean;\n /** Include HTML img tags `<img src=\"url\">` (default: true) */\n includeHTML?: boolean;\n /** Include base64 data URLs `data:image/...;base64,...` (default: true) */\n includeBase64?: boolean;\n}\n\nexport interface ExtractedImage {\n /** The extracted URL or data URL */\n url: string;\n /** Source format where the image was found */\n source: 'markdown' | 'html' | 'base64';\n /** Surrounding context for debugging (optional) */\n context?: string;\n}\n\n/**\n * Extract all image URLs from text.\n *\n * Supports markdown, HTML, and base64 data URLs.\n * Returns deduplicated results.\n *\n * @param text - Text to extract image URLs from\n * @param options - Extraction options\n * @returns Array of extracted images with source information\n *\n * @example\n * ```typescript\n * const text = 'Check out  and <img src=\"banner.jpg\">';\n * const images = extractImageUrls(text);\n * // [\n * // { url: 'avatar.png', source: 'markdown' },\n * // { url: 'banner.jpg', source: 'html' }\n * // ]\n * ```\n */\nexport function extractImageUrls(\n text: string,\n options: ImageExtractionOptions = {},\n): ExtractedImage[] {\n const {\n includeMarkdown = true,\n includeHTML = true,\n includeBase64 = true,\n } = options;\n\n const results: ExtractedImage[] = [];\n const seen = new Set<string>();\n\n // Extract markdown images:  or  or \n // Supports: standard, angle brackets, and SillyTavern dimension syntax\n if (includeMarkdown) {\n const markdownPattern = /!\\[([^\\]]*)\\]\\(<?([^>\\s)]+)>?(?:\\s*=[^)]+)?\\)/g;\n let match: RegExpExecArray | null;\n\n while ((match = markdownPattern.exec(text)) !== null) {\n const url = match[2]?.trim();\n if (url && !seen.has(url)) {\n seen.add(url);\n results.push({\n url,\n source: 'markdown',\n context: match[0],\n });\n }\n }\n }\n\n // Extract HTML img tags: <img src=\"url\"> (quoted and unquoted)\n if (includeHTML) {\n // Quoted src\n const htmlQuotedPattern = /<img[^>]+src=[\"']([^\"']+)[\"'][^>]*>/gi;\n let match: RegExpExecArray | null;\n\n while ((match = htmlQuotedPattern.exec(text)) !== null) {\n const url = match[1]?.trim();\n if (url && !seen.has(url)) {\n seen.add(url);\n results.push({\n url,\n source: 'html',\n context: match[0],\n });\n }\n }\n\n // Unquoted src (e.g., <img src=url>)\n const htmlUnquotedPattern = /<img[^>]+src=([^\\s\"'>]+)[^>]*>/gi;\n while ((match = htmlUnquotedPattern.exec(text)) !== null) {\n const url = match[1]?.trim();\n // Skip if it starts with a quote (already handled above)\n if (url && !url.startsWith('\"') && !url.startsWith(\"'\") && !seen.has(url)) {\n seen.add(url);\n results.push({\n url,\n source: 'html',\n context: match[0],\n });\n }\n }\n\n // CSS url() function: url(url), url(\"url\"), url('url')\n // Common in background-image, background, content properties\n const cssUrlPattern = /url\\([\"']?([^)\"']+)[\"']?\\)/gi;\n while ((match = cssUrlPattern.exec(text)) !== null) {\n const url = match[1]?.trim();\n // Only include http(s) URLs to avoid CSS variables and relative paths\n if (url && (url.startsWith('http://') || url.startsWith('https://')) && !seen.has(url)) {\n seen.add(url);\n results.push({\n url,\n source: 'html',\n context: match[0],\n });\n }\n }\n }\n\n // Extract plain image URLs (not wrapped in any syntax)\n if (includeHTML) {\n // Plain URLs with image extensions (common on image hosts)\n const plainUrlPattern = /(?<![(\"'])(https?:\\/\\/[^\\s<>\"']+\\.(?:jpg|jpeg|png|gif|webp|svg|avif|bmp))(?![)\"'])/gi;\n let match: RegExpExecArray | null;\n\n while ((match = plainUrlPattern.exec(text)) !== null) {\n const url = match[0]?.trim();\n if (url && !seen.has(url)) {\n seen.add(url);\n results.push({\n url,\n source: 'html',\n context: url,\n });\n }\n }\n }\n\n // Extract base64 data URLs: data:image/...;base64,...\n if (includeBase64) {\n const dataUrlPattern = /data:image\\/[^;]+;base64,[A-Za-z0-9+/=]+/g;\n let match: RegExpExecArray | null;\n\n while ((match = dataUrlPattern.exec(text)) !== null) {\n const url = match[0];\n if (!seen.has(url)) {\n seen.add(url);\n results.push({\n url,\n source: 'base64',\n });\n }\n }\n }\n\n return results;\n}\n\n/**\n * Extract only HTTP/HTTPS URLs (excludes data URLs and relative paths).\n *\n * Convenience wrapper around extractImageUrls that filters for remote URLs.\n *\n * @param text - Text to extract URLs from\n * @returns Array of extracted HTTP/HTTPS image URLs\n */\nexport function extractRemoteImageUrls(text: string): ExtractedImage[] {\n const all = extractImageUrls(text, { includeBase64: false });\n return all.filter((img) => /^https?:\\/\\//i.test(img.url));\n}\n\n/**\n * Extract only base64 data URLs.\n *\n * Convenience wrapper around extractImageUrls.\n *\n * @param text - Text to extract data URLs from\n * @returns Array of base64 image data URLs\n */\nexport function extractDataUrls(text: string): ExtractedImage[] {\n return extractImageUrls(text, {\n includeMarkdown: false,\n includeHTML: false,\n includeBase64: true,\n });\n}\n\n/**\n * Count images in text without extracting full details.\n *\n * More efficient than extractImageUrls when you only need the count.\n *\n * @param text - Text to count images in\n * @returns Total number of unique image references\n */\nexport function countImages(text: string): number {\n return extractImageUrls(text).length;\n}\n","/**\n * SSRF (Server-Side Request Forgery) Protection\n *\n * Validates URLs to prevent SSRF attacks.\n * Browser-safe implementation (no Node.js dependencies).\n */\n\nexport interface SSRFPolicy {\n /** Allow private IP addresses (10.x, 172.16-31.x, 192.168.x) (default: false) */\n allowPrivateIPs?: boolean;\n /** Allow localhost/loopback (127.x, ::1) (default: false) */\n allowLocalhost?: boolean;\n /** Blocked domain patterns (e.g., ['internal.company.com', '*.local']) */\n blockedDomains?: string[];\n /** Allowed domain patterns - if provided, ONLY these are allowed */\n allowedDomains?: string[];\n /** Allow data URLs (data:image/...) (default: false) */\n allowDataUrls?: boolean;\n}\n\nexport interface SafetyCheck {\n /** Whether the URL is safe according to policy */\n safe: boolean;\n /** Reason why URL is unsafe (if safe=false) */\n reason?: string;\n}\n\n/**\n * Default SSRF policy - blocks private IPs, localhost, and data URLs.\n */\nexport const DEFAULT_SSRF_POLICY: Required<SSRFPolicy> = {\n allowPrivateIPs: false,\n allowLocalhost: false,\n blockedDomains: [],\n allowedDomains: [],\n allowDataUrls: false,\n};\n\n/**\n * Check if URL is safe to fetch according to SSRF policy.\n *\n * This is the canonical SSRF protection - all apps should use this\n * before fetching external URLs.\n *\n * @param url - URL to validate\n * @param policy - SSRF policy (uses defaults if not provided)\n * @returns Safety check result with reason if unsafe\n *\n * @example\n * ```typescript\n * const check = isURLSafe('http://10.0.0.1/secret');\n * if (!check.safe) {\n * console.error('Unsafe URL:', check.reason);\n * }\n * ```\n */\nexport function isURLSafe(\n url: string,\n policy: SSRFPolicy = {},\n): SafetyCheck {\n const config = { ...DEFAULT_SSRF_POLICY, ...policy };\n\n // Parse URL\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n return { safe: false, reason: 'Invalid URL format' };\n }\n\n // Check protocol\n if (parsed.protocol === 'data:') {\n if (!config.allowDataUrls) {\n return { safe: false, reason: 'Data URLs not allowed' };\n }\n return { safe: true };\n }\n\n if (!['http:', 'https:'].includes(parsed.protocol)) {\n return {\n safe: false,\n reason: `Protocol '${parsed.protocol}' not allowed (only http/https)`,\n };\n }\n\n const hostname = parsed.hostname.toLowerCase();\n\n // Check allowed domains (whitelist)\n if (config.allowedDomains.length > 0) {\n const isAllowed = config.allowedDomains.some((pattern) =>\n matchDomainPattern(hostname, pattern),\n );\n if (!isAllowed) {\n return {\n safe: false,\n reason: `Domain '${hostname}' not in allowed list`,\n };\n }\n }\n\n // Check blocked domains (blacklist)\n if (config.blockedDomains.length > 0) {\n const isBlocked = config.blockedDomains.some((pattern) =>\n matchDomainPattern(hostname, pattern),\n );\n if (isBlocked) {\n return {\n safe: false,\n reason: `Domain '${hostname}' is blocked`,\n };\n }\n }\n\n // Check localhost\n if (isLocalhost(hostname) && !config.allowLocalhost) {\n return { safe: false, reason: 'Localhost not allowed' };\n }\n\n // Check private IPs\n if (isPrivateIP(hostname) && !config.allowPrivateIPs) {\n return { safe: false, reason: 'Private IP addresses not allowed' };\n }\n\n return { safe: true };\n}\n\n/**\n * Quick check if URL is safe with default policy.\n *\n * Convenience wrapper for common case.\n *\n * @param url - URL to validate\n * @returns true if safe, false otherwise\n */\nexport function isSafeForFetch(url: string): boolean {\n return isURLSafe(url).safe;\n}\n\n/**\n * Match domain against pattern (supports wildcards).\n *\n * @example\n * ```typescript\n * matchDomainPattern('api.github.com', '*.github.com') // true\n * matchDomainPattern('github.com', '*.github.com') // false\n * matchDomainPattern('github.com', 'github.com') // true\n * ```\n */\nfunction matchDomainPattern(domain: string, pattern: string): boolean {\n // Exact match\n if (domain === pattern) return true;\n\n // Wildcard match - only matches subdomains, not the base domain\n if (pattern.startsWith('*.')) {\n const suffix = pattern.slice(2);\n return domain.endsWith('.' + suffix);\n }\n\n return false;\n}\n\n/**\n * Check if hostname is localhost/loopback.\n */\nfunction isLocalhost(hostname: string): boolean {\n const lower = hostname.toLowerCase();\n\n // IPv4 loopback\n if (lower === 'localhost' || lower === '0.0.0.0' || lower.startsWith('127.')) {\n return true;\n }\n\n // IPv6 loopback\n if (lower === '::1' || lower === '[::1]') {\n return true;\n }\n\n return false;\n}\n\n/**\n * Check if hostname is a private IP address.\n *\n * Checks for:\n * - 10.0.0.0/8\n * - 172.16.0.0/12\n * - 192.168.0.0/16\n * - Link-local: 169.254.0.0/16 (includes AWS metadata endpoint)\n * - IPv6 private ranges\n */\nfunction isPrivateIP(hostname: string): boolean {\n const lower = hostname.toLowerCase();\n\n // IPv4 private ranges\n const parts = hostname.split('.').map(Number);\n\n if (\n parts.length === 4 &&\n parts.every((p) => p >= 0 && p <= 255 && !isNaN(p))\n ) {\n const [octet1, octet2] = parts;\n\n // 10.0.0.0/8\n if (octet1 === 10) return true;\n\n // 172.16.0.0/12\n if (octet1 === 172 && octet2 !== undefined && octet2 >= 16 && octet2 <= 31)\n return true;\n\n // 192.168.0.0/16\n if (octet1 === 192 && octet2 === 168) return true;\n\n // 169.254.0.0/16 (link-local) - includes AWS metadata endpoint\n if (octet1 === 169 && octet2 === 254) return true;\n }\n\n // IPv6 private ranges using regex patterns\n // Strip brackets if present (URL parser adds them: [fc00::1])\n const cleanedHostname = lower.replace(/^\\[|\\]$/g, '');\n\n const ipv6Patterns = [\n /^f[cd][0-9a-f]{2}:/i, // fc00::/7 (includes both fc and fd ranges)\n /^fe80:/i, // fe80::/10 (link-local)\n ];\n\n for (const pattern of ipv6Patterns) {\n if (pattern.test(cleanedHostname)) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Filter array of URLs, keeping only safe ones.\n *\n * @param urls - Array of URLs to filter\n * @param policy - SSRF policy\n * @returns Array of safe URLs\n */\nexport function filterSafeUrls(\n urls: string[],\n policy?: SSRFPolicy,\n): string[] {\n return urls.filter((url) => isURLSafe(url, policy).safe);\n}\n"],"mappings":";AA6CO,SAAS,iBACd,MACA,UAAkC,CAAC,GACjB;AAClB,QAAM;IACJ,kBAAkB;IAClB,cAAc;IACd,gBAAgB;EAClB,IAAI;AAEJ,QAAM,UAA4B,CAAC;AACnC,QAAM,OAAO,oBAAI,IAAY;AAI7B,MAAI,iBAAiB;AACnB,UAAM,kBAAkB;AACxB,QAAI;AAEJ,YAAQ,QAAQ,gBAAgB,KAAK,IAAI,OAAO,MAAM;AACpD,YAAM,MAAM,MAAM,CAAC,GAAG,KAAK;AAC3B,UAAI,OAAO,CAAC,KAAK,IAAI,GAAG,GAAG;AACzB,aAAK,IAAI,GAAG;AACZ,gBAAQ,KAAK;UACX;UACA,QAAQ;UACR,SAAS,MAAM,CAAC;QAClB,CAAC;MACH;IACF;EACF;AAGA,MAAI,aAAa;AAEf,UAAM,oBAAoB;AAC1B,QAAI;AAEJ,YAAQ,QAAQ,kBAAkB,KAAK,IAAI,OAAO,MAAM;AACtD,YAAM,MAAM,MAAM,CAAC,GAAG,KAAK;AAC3B,UAAI,OAAO,CAAC,KAAK,IAAI,GAAG,GAAG;AACzB,aAAK,IAAI,GAAG;AACZ,gBAAQ,KAAK;UACX;UACA,QAAQ;UACR,SAAS,MAAM,CAAC;QAClB,CAAC;MACH;IACF;AAGA,UAAM,sBAAsB;AAC5B,YAAQ,QAAQ,oBAAoB,K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EAC/C;AAIA,QAAM,kBAAkB,MAAM,QAAQ,YAAY,EAAE;AAEpD,QAAM,eAAe;IACnB;;IACA;;EACF;AAEA,aAAW,WAAW,cAAc;AAClC,QAAI,QAAQ,KAAK,eAAe,GAAG;AACjC,aAAO;IACT;EACF;AAEA,SAAO;AACT;AASO,SAAS,eACd,MACA,QACU;AACV,SAAO,KAAK,OAAO,CAAC,QAAQ,UAAU,KAAK,MAAM,EAAE,IAAI;AACzD;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -879,7 +879,7 @@ function inflateSyncWithLimit(compressed, maxSize = MAX_INFLATED_SIZE) {
|
|
|
879
879
|
const chunks = [];
|
|
880
880
|
let totalSize = 0;
|
|
881
881
|
let error = null;
|
|
882
|
-
const inflater = new import_fflate2.Inflate((data,
|
|
882
|
+
const inflater = new import_fflate2.Inflate((data, _final) => {
|
|
883
883
|
if (error) return;
|
|
884
884
|
if (data && data.length > 0) {
|
|
885
885
|
totalSize += data.length;
|
|
@@ -8172,7 +8172,7 @@ function sanitizeName2(name, ext) {
|
|
|
8172
8172
|
return safeName;
|
|
8173
8173
|
}
|
|
8174
8174
|
function writeVoxta(card, assets, options = {}) {
|
|
8175
|
-
|
|
8175
|
+
const { compressionLevel = 6, includePackageJson = false } = options;
|
|
8176
8176
|
const cardData = card.data;
|
|
8177
8177
|
const extensions = cardData.extensions;
|
|
8178
8178
|
const voxtaExt = extensions?.voxta;
|
|
@@ -8692,7 +8692,7 @@ function parsePng(data, options) {
|
|
|
8692
8692
|
throw new SizeLimitError(estimatedSize, options.maxAssetSize, `Orphan chunk ${chunk.keyword}`);
|
|
8693
8693
|
}
|
|
8694
8694
|
const buffer = decode(chunk.text);
|
|
8695
|
-
|
|
8695
|
+
const extMatch = assetId.match(/\.([^.]+)$/);
|
|
8696
8696
|
let ext = extMatch ? extMatch[1] : null;
|
|
8697
8697
|
if (!ext) {
|
|
8698
8698
|
const detected = detectExtension(buffer);
|
|
@@ -8741,7 +8741,7 @@ function parseCharx(data, options) {
|
|
|
8741
8741
|
isMain: asset.descriptor.type === "icon"
|
|
8742
8742
|
// Main icon is type='icon' in descriptor
|
|
8743
8743
|
}));
|
|
8744
|
-
|
|
8744
|
+
const sourceFormat = charxData.isRisuFormat ? "charx_risu" : "charx";
|
|
8745
8745
|
return {
|
|
8746
8746
|
card: charxData.card,
|
|
8747
8747
|
assets,
|
|
@@ -8860,7 +8860,7 @@ function parseJson(data, options) {
|
|
|
8860
8860
|
}
|
|
8861
8861
|
return parseJsonFromParsed(parsed, jsonStr, data, options);
|
|
8862
8862
|
}
|
|
8863
|
-
function parseJsonFromParsed(parsed, jsonStr, rawBuffer,
|
|
8863
|
+
function parseJsonFromParsed(parsed, jsonStr, rawBuffer, _options) {
|
|
8864
8864
|
const spec = detectSpec(parsed);
|
|
8865
8865
|
let card;
|
|
8866
8866
|
let sourceFormat;
|
|
@@ -8933,7 +8933,7 @@ function checkPngLoss(card, assets) {
|
|
|
8933
8933
|
if (soundAssets.length > 0) {
|
|
8934
8934
|
warnings.push(`${soundAssets.length} sound assets cannot be embedded in PNG`);
|
|
8935
8935
|
}
|
|
8936
|
-
const
|
|
8936
|
+
const _extensions = card.data.extensions;
|
|
8937
8937
|
if (card.data.assets && card.data.assets.length > 1) {
|
|
8938
8938
|
warnings.push("Card has multiple asset references - only main will be available");
|
|
8939
8939
|
}
|
|
@@ -8945,7 +8945,7 @@ function checkPngLoss(card, assets) {
|
|
|
8945
8945
|
isLossless: lostFields.length === 0 && lostAssets.length === 0
|
|
8946
8946
|
};
|
|
8947
8947
|
}
|
|
8948
|
-
function checkCharxLoss(card,
|
|
8948
|
+
function checkCharxLoss(card, _assets) {
|
|
8949
8949
|
const lostFields = [];
|
|
8950
8950
|
const lostAssets = [];
|
|
8951
8951
|
const warnings = [];
|