@planeasyinc/fe-core 0.1.40 → 0.1.41
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/html-sanitizer.d.ts +14 -0
- package/dist/utils/html-sanitizer.d.ts.map +1 -0
- package/dist/utils/html-sanitizer.js +100 -0
- package/dist/utils/html-sanitizer.js.map +1 -0
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './guards';
|
|
|
8
8
|
export * from './utils/date-serializer';
|
|
9
9
|
export * from './utils/is-deeply-equal';
|
|
10
10
|
export * from './utils/is-object-with-property';
|
|
11
|
+
export * from './utils/html-sanitizer';
|
|
11
12
|
export * from './utils/value-at-path';
|
|
12
13
|
export * from './streaming';
|
|
13
14
|
export * from './document';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AAEtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from './guards';
|
|
|
8
8
|
export * from './utils/date-serializer';
|
|
9
9
|
export * from './utils/is-deeply-equal';
|
|
10
10
|
export * from './utils/is-object-with-property';
|
|
11
|
+
export * from './utils/html-sanitizer';
|
|
11
12
|
export * from './utils/value-at-path';
|
|
12
13
|
export * from './streaming';
|
|
13
14
|
export * from './document';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AAEtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML made from untrusted markdown, such as a chat answer: the model repeats what it read in
|
|
3
|
+
* documents and web pages, and `marked` passes raw HTML and any link target through. Keeps only
|
|
4
|
+
* what markdown makes; a link or image keeps its URL only for http, https, mailto or a relative
|
|
5
|
+
* one. Returns `''` where there is no DOM.
|
|
6
|
+
*/
|
|
7
|
+
export declare const sanitizeMarkdownHtml: (html: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* HTML written by hand in a form config, such as an info screen. Keeps its markup and inline
|
|
10
|
+
* styles, drops what runs, frames, forms and style sheets; a link or image keeps its URL only for
|
|
11
|
+
* http, https, mailto or a relative one. Returns `''` where there is no DOM.
|
|
12
|
+
*/
|
|
13
|
+
export declare const sanitizeAuthoredHtml: (html: string) => string;
|
|
14
|
+
//# sourceMappingURL=html-sanitizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-sanitizer.d.ts","sourceRoot":"","sources":["../../src/utils/html-sanitizer.ts"],"names":[],"mappings":"AA6FA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,SAAU,MAAM,KAAG,MAEnD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,SAAU,MAAM,KAAG,MAEnD,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import DOMPurify from 'dompurify';
|
|
2
|
+
/** http, https and mailto, or a URL without a scheme (relative to the page). */
|
|
3
|
+
const SAFE_URL = /^(?:(?:https?|mailto):|[^a-z]|[a-z+.-]+(?:[^a-z+.\-:]|$))/i;
|
|
4
|
+
/**
|
|
5
|
+
* What a chat answer may draw: the HTML markdown makes (headings, paragraphs, lists, emphasis,
|
|
6
|
+
* links, images, code, tables, quotes, rules) and a few inline tags models write by hand. Nothing
|
|
7
|
+
* that runs, frames a page, takes input or restyles the app: no scripts or event handlers, no SVG
|
|
8
|
+
* or MathML, no `style`, `class` or `id`. Text inside a dropped tag stays.
|
|
9
|
+
*/
|
|
10
|
+
const MARKDOWN = {
|
|
11
|
+
ALLOWED_TAGS: [
|
|
12
|
+
'h1',
|
|
13
|
+
'h2',
|
|
14
|
+
'h3',
|
|
15
|
+
'h4',
|
|
16
|
+
'h5',
|
|
17
|
+
'h6',
|
|
18
|
+
'p',
|
|
19
|
+
'br',
|
|
20
|
+
'hr',
|
|
21
|
+
'blockquote',
|
|
22
|
+
'ul',
|
|
23
|
+
'ol',
|
|
24
|
+
'li',
|
|
25
|
+
'strong',
|
|
26
|
+
'b',
|
|
27
|
+
'em',
|
|
28
|
+
'i',
|
|
29
|
+
'del',
|
|
30
|
+
's',
|
|
31
|
+
'code',
|
|
32
|
+
'pre',
|
|
33
|
+
'kbd',
|
|
34
|
+
'sub',
|
|
35
|
+
'sup',
|
|
36
|
+
'a',
|
|
37
|
+
'img',
|
|
38
|
+
'table',
|
|
39
|
+
'thead',
|
|
40
|
+
'tbody',
|
|
41
|
+
'tfoot',
|
|
42
|
+
'tr',
|
|
43
|
+
'th',
|
|
44
|
+
'td',
|
|
45
|
+
],
|
|
46
|
+
ALLOWED_ATTR: ['href', 'title', 'src', 'alt', 'align', 'start'],
|
|
47
|
+
ALLOWED_URI_REGEXP: SAFE_URL,
|
|
48
|
+
ALLOW_ARIA_ATTR: false,
|
|
49
|
+
ALLOW_DATA_ATTR: false,
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Authored HTML keeps its markup and inline styles. What goes: scripts and event handlers, SVG and
|
|
53
|
+
* MathML, frames, forms and their fields, style sheets and `data-*` attributes. Text inside a
|
|
54
|
+
* dropped tag stays.
|
|
55
|
+
*/
|
|
56
|
+
const AUTHORED = {
|
|
57
|
+
USE_PROFILES: { html: true },
|
|
58
|
+
FORBID_TAGS: ['style', 'form', 'input', 'button', 'select', 'textarea'],
|
|
59
|
+
ALLOWED_URI_REGEXP: SAFE_URL,
|
|
60
|
+
ALLOW_DATA_ATTR: false,
|
|
61
|
+
};
|
|
62
|
+
let purifier;
|
|
63
|
+
/**
|
|
64
|
+
* An instance of its own: a hook or `setConfig` the host app puts on the shared DOMPurify would
|
|
65
|
+
* change what this one lets through. `null` where there is no DOM to sanitize with.
|
|
66
|
+
*/
|
|
67
|
+
const getPurifier = () => {
|
|
68
|
+
if (purifier === undefined) {
|
|
69
|
+
const instance = typeof window === 'undefined' ? null : DOMPurify(window);
|
|
70
|
+
purifier = instance?.isSupported ? instance : null;
|
|
71
|
+
}
|
|
72
|
+
return purifier;
|
|
73
|
+
};
|
|
74
|
+
const sanitize = (html, config) => {
|
|
75
|
+
const purify = getPurifier();
|
|
76
|
+
// Without a DOM (a server render), DOMPurify hands back what it was given: show nothing rather
|
|
77
|
+
// than that.
|
|
78
|
+
if (!purify) {
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
return purify.sanitize(html, config);
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* HTML made from untrusted markdown, such as a chat answer: the model repeats what it read in
|
|
85
|
+
* documents and web pages, and `marked` passes raw HTML and any link target through. Keeps only
|
|
86
|
+
* what markdown makes; a link or image keeps its URL only for http, https, mailto or a relative
|
|
87
|
+
* one. Returns `''` where there is no DOM.
|
|
88
|
+
*/
|
|
89
|
+
export const sanitizeMarkdownHtml = (html) => {
|
|
90
|
+
return sanitize(html, MARKDOWN);
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* HTML written by hand in a form config, such as an info screen. Keeps its markup and inline
|
|
94
|
+
* styles, drops what runs, frames, forms and style sheets; a link or image keeps its URL only for
|
|
95
|
+
* http, https, mailto or a relative one. Returns `''` where there is no DOM.
|
|
96
|
+
*/
|
|
97
|
+
export const sanitizeAuthoredHtml = (html) => {
|
|
98
|
+
return sanitize(html, AUTHORED);
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=html-sanitizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-sanitizer.js","sourceRoot":"","sources":["../../src/utils/html-sanitizer.ts"],"names":[],"mappings":"AAAA,OAAO,SAAsD,MAAM,WAAW,CAAC;AAE/E,gFAAgF;AAChF,MAAM,QAAQ,GAAG,4DAA4D,CAAC;AAE9E;;;;;GAKG;AACH,MAAM,QAAQ,GAAW;IACvB,YAAY,EAAE;QACZ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,IAAI;QACJ,IAAI;QACJ,YAAY;QACZ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,QAAQ;QACR,GAAG;QACH,IAAI;QACJ,GAAG;QACH,KAAK;QACL,GAAG;QACH,MAAM;QACN,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,GAAG;QACH,KAAK;QACL,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,IAAI;QACJ,IAAI;QACJ,IAAI;KACL;IACD,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC;IAC/D,kBAAkB,EAAE,QAAQ;IAC5B,eAAe,EAAE,KAAK;IACtB,eAAe,EAAE,KAAK;CACvB,CAAC;AAEF;;;;GAIG;AACH,MAAM,QAAQ,GAAW;IACvB,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;IAC5B,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC;IACvE,kBAAkB,EAAE,QAAQ;IAC5B,eAAe,EAAE,KAAK;CACvB,CAAC;AAEF,IAAI,QAAqC,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,GAAG,GAAoB,EAAE;IACxC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAE1E,QAAQ,GAAG,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACrD,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,MAAc,EAAU,EAAE;IACxD,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAE7B,+FAA+F;IAC/F,aAAa;IACb,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAU,EAAE;IAC3D,OAAO,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAClC,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAU,EAAE;IAC3D,OAAO,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAClC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planeasyinc/fe-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"package.json"
|
|
12
12
|
],
|
|
13
13
|
"sideEffects": false,
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"dompurify": "^3.4.18"
|
|
16
|
+
},
|
|
14
17
|
"publishConfig": {
|
|
15
18
|
"access": "public",
|
|
16
19
|
"registry": "https://registry.npmjs.org/"
|