@mintlify/common 1.0.603 → 1.0.605

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.
@@ -1,2 +1,3 @@
1
1
  import type { Root } from 'mdast';
2
+ export declare function isStringSafe(value: string): boolean;
2
3
  export declare const remarkMdxRemoveJs: () => (tree: Root) => void;
@@ -2,6 +2,137 @@ import { walk } from 'estree-walker';
2
2
  import { remove } from 'unist-util-remove';
3
3
  import { CONTINUE, visit } from 'unist-util-visit';
4
4
  import { isMdxJsEsm } from '../../utils.js';
5
+ const objectEstree = {
6
+ type: 'Program',
7
+ body: [
8
+ {
9
+ type: 'ExpressionStatement',
10
+ expression: {
11
+ type: 'ObjectExpression',
12
+ properties: [],
13
+ },
14
+ },
15
+ ],
16
+ sourceType: 'module',
17
+ comments: [],
18
+ };
19
+ const arrayEstree = {
20
+ type: 'Program',
21
+ body: [
22
+ {
23
+ type: 'ExpressionStatement',
24
+ expression: {
25
+ type: 'ArrayExpression',
26
+ elements: [],
27
+ },
28
+ },
29
+ ],
30
+ sourceType: 'module',
31
+ comments: [],
32
+ };
33
+ const falseEstree = {
34
+ type: 'Program',
35
+ body: [
36
+ {
37
+ type: 'ExpressionStatement',
38
+ expression: {
39
+ type: 'Literal',
40
+ value: false,
41
+ raw: 'false',
42
+ },
43
+ },
44
+ ],
45
+ sourceType: 'module',
46
+ comments: [],
47
+ };
48
+ const trueEstree = {
49
+ type: 'Program',
50
+ body: [
51
+ {
52
+ type: 'ExpressionStatement',
53
+ expression: {
54
+ type: 'Literal',
55
+ value: true,
56
+ raw: 'true',
57
+ },
58
+ },
59
+ ],
60
+ sourceType: 'module',
61
+ comments: [],
62
+ };
63
+ function createStringEstree(str) {
64
+ return {
65
+ type: 'Program',
66
+ body: [
67
+ {
68
+ type: 'ExpressionStatement',
69
+ expression: {
70
+ type: 'Literal',
71
+ value: str,
72
+ raw: `'${str}'`,
73
+ },
74
+ },
75
+ ],
76
+ sourceType: 'module',
77
+ comments: [],
78
+ };
79
+ }
80
+ const numberEstree = {
81
+ type: 'Program',
82
+ body: [
83
+ {
84
+ type: 'ExpressionStatement',
85
+ expression: {
86
+ type: 'Literal',
87
+ value: 1,
88
+ raw: '1',
89
+ },
90
+ },
91
+ ],
92
+ sourceType: 'module',
93
+ comments: [],
94
+ };
95
+ const DEFAULT_PROP_EXPRESSIONS = {
96
+ placement: { value: '"bottom"', estree: createStringEstree('bottom') },
97
+ deflectionEmail: { value: '""', estree: createStringEstree('') },
98
+ searchSites: { value: '[]', estree: arrayEstree },
99
+ spendLimit: { value: '1', estree: numberEstree },
100
+ sampleQuestions: { value: '[]', estree: arrayEstree },
101
+ slack: { value: 'false', estree: falseEstree },
102
+ subdomain: { value: '""', estree: createStringEstree('') },
103
+ context: { value: '{}', estree: objectEstree },
104
+ title: { value: '""', estree: createStringEstree('') },
105
+ description: { value: '""', estree: createStringEstree('') },
106
+ icon: { value: '""', estree: createStringEstree('') },
107
+ href: { value: '""', estree: createStringEstree('') },
108
+ iconType: { value: '"regular"', estree: createStringEstree('regular') },
109
+ enabled: { value: '"false"', estree: createStringEstree('false') },
110
+ name: { value: '""', estree: createStringEstree('') },
111
+ mcp: { value: '{}', estree: objectEstree },
112
+ openapi: { value: '""', estree: createStringEstree('') },
113
+ servers: { value: '[]', estree: arrayEstree },
114
+ securitySchemes: { value: '{}', estree: objectEstree },
115
+ security: { value: '{}', estree: objectEstree },
116
+ authMethod: { value: '"bearer"', estree: createStringEstree('bearer') },
117
+ playground: { value: '"interactive"', estree: createStringEstree('interactive') },
118
+ server: { value: '""', estree: createStringEstree('') },
119
+ metadata: { value: '{}', estree: objectEstree },
120
+ content: { value: '""', estree: createStringEstree('') },
121
+ codeSamples: { value: '[]', estree: arrayEstree },
122
+ lang: { value: '""', estree: createStringEstree('') },
123
+ label: { value: '""', estree: createStringEstree('') },
124
+ source: { value: '""', estree: createStringEstree('') },
125
+ examples: { value: '{}', estree: objectEstree },
126
+ summary: { value: '""', estree: createStringEstree('') },
127
+ value: { value: '{}', estree: objectEstree },
128
+ contextual: { value: '{ "options": [] }', estree: falseEstree },
129
+ api: { value: '{}', estree: objectEstree },
130
+ navigation: { value: '{}', estree: objectEstree },
131
+ asyncapi: { value: '""', estree: createStringEstree('') },
132
+ directory: { value: '""', estree: createStringEstree('') },
133
+ 'x-hidden': { value: '"true"', estree: trueEstree },
134
+ 'x-excluded': { value: '"true"', estree: trueEstree },
135
+ };
5
136
  const REACT_HOOKS = [
6
137
  'useState',
7
138
  'useEffect',
@@ -21,6 +152,28 @@ const REACT_HOOKS = [
21
152
  'useOptimistic',
22
153
  'useActionState',
23
154
  ];
155
+ export function isStringSafe(value) {
156
+ switch (true) {
157
+ case value === 'true':
158
+ case value === 'false':
159
+ // purely alphanumeric string
160
+ case /^[_a-zA-Z0-9]+$/.test(value):
161
+ // string literal with quotes
162
+ case /^'[_a-zA-Z0-9\s`".\-\\{}\?\(\)&*^%#@!~=+\[\]|:;,\/]+'$/.test(value):
163
+ case /^"[_a-zA-Z0-9\s`'.\-\\{}\?\(\)&*^%#@!~=+\[\]|:;,\/]+"$/.test(value):
164
+ case /^`[_a-zA-Z0-9\s'".\-\\{}\?\(\)&*^%#@!~=+\[\]|:;,\/]+`$/.test(value):
165
+ // purely alphanumeric string prefixed with `!!`
166
+ case /^!![_a-zA-Z0-9]+$/.test(value):
167
+ // purely alphanumeric string wrapped in parens
168
+ case /^\([_a-zA-Z0-9]+\)$/.test(value):
169
+ // purely alphanumeric string prefixed with `!!` wrapped in parens
170
+ case /^\(!![_a-zA-Z0-9]+\)$/.test(value):
171
+ return true;
172
+ // could contain arbitrary javascript
173
+ default:
174
+ return false;
175
+ }
176
+ }
24
177
  export const remarkMdxRemoveJs = () => (tree) => {
25
178
  remove(tree, ['mdxTextExpression', 'mdxFlowExpression']);
26
179
  remove(tree, (node) => {
@@ -36,19 +189,24 @@ export const remarkMdxRemoveJs = () => (tree) => {
36
189
  visit(tree, (node) => {
37
190
  if (!('attributes' in node))
38
191
  return CONTINUE;
39
- node.attributes = node.attributes.map((attr) => {
40
- if (attr.type === 'mdxJsxExpressionAttribute') {
41
- attr.value = '""';
42
- if (attr.data)
43
- attr.data = undefined;
44
- }
192
+ const newAttributes = node.attributes.map((attr) => {
193
+ var _a, _b, _c, _d;
194
+ if (attr.type === 'mdxJsxAttribute' && !(attr.value instanceof Object))
195
+ return attr;
196
+ if (typeof attr.value === 'string' && isStringSafe(attr.value))
197
+ return attr;
45
198
  if (attr.type === 'mdxJsxAttribute' && attr.value instanceof Object) {
46
- attr.value.value = '""';
47
- if (attr.value.data)
48
- attr.value.data = undefined;
199
+ if (isStringSafe(attr.value.value))
200
+ return attr;
201
+ if (Object.keys(DEFAULT_PROP_EXPRESSIONS).includes(attr.name)) {
202
+ attr.value.value = (_b = (_a = DEFAULT_PROP_EXPRESSIONS[attr.name]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '{}';
203
+ attr.value.data = { estree: (_d = (_c = DEFAULT_PROP_EXPRESSIONS[attr.name]) === null || _c === void 0 ? void 0 : _c.estree) !== null && _d !== void 0 ? _d : objectEstree };
204
+ return attr;
205
+ }
49
206
  }
50
- return attr;
207
+ return undefined;
51
208
  });
209
+ node.attributes = newAttributes.filter((attr) => attr !== undefined);
52
210
  });
53
211
  };
54
212
  function isFunction(estree) {