@mintlify/common 1.0.474 → 1.0.476

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.
@@ -0,0 +1 @@
1
+ export declare const addBasePath: (path: string, basePath?: string) => string;
@@ -0,0 +1,6 @@
1
+ export const addBasePath = (path, basePath) => {
2
+ if (basePath) {
3
+ return `${basePath}${path}`;
4
+ }
5
+ return path;
6
+ };
@@ -2,3 +2,4 @@ export * from './createPathArr.js';
2
2
  export * from './optionallyLeadingSlash.js';
3
3
  export * from './removeLeadingSlash.js';
4
4
  export * from './normalizeRelativePath.js';
5
+ export * from './addBasePath.js';
package/dist/fs/index.js CHANGED
@@ -2,3 +2,4 @@ export * from './createPathArr.js';
2
2
  export * from './optionallyLeadingSlash.js';
3
3
  export * from './removeLeadingSlash.js';
4
4
  export * from './normalizeRelativePath.js';
5
+ export * from './addBasePath.js';
package/dist/index.d.ts CHANGED
@@ -18,4 +18,5 @@ export * from './camelToSentenceCase.js';
18
18
  export * from './asyncapi/index.js';
19
19
  export * from './isAbsoluteUrl.js';
20
20
  export * from './rss/index.js';
21
+ export * from './services/aws.js';
21
22
  export * from './slugify.js';
package/dist/index.js CHANGED
@@ -18,4 +18,5 @@ export * from './camelToSentenceCase.js';
18
18
  export * from './asyncapi/index.js';
19
19
  export * from './isAbsoluteUrl.js';
20
20
  export * from './rss/index.js';
21
+ export * from './services/aws.js';
21
22
  export * from './slugify.js';
@@ -6,7 +6,6 @@ import type { PluggableList } from 'unified';
6
6
  import { MdxExtracts } from '../types/mdx/MdxExtracts.js';
7
7
  type MDXOptionsData = {
8
8
  snippetTreeMap: Record<string, Root>;
9
- allowedComponents: string[];
10
9
  pageMetadata: PageMetaTags;
11
10
  config?: DocsConfig | MintConfig;
12
11
  subdomain?: string;
@@ -23,7 +23,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
23
23
  remarkMermaid,
24
24
  remarkComponentIds,
25
25
  ...remarkPlugins,
26
- [remarkMdxRemoveUnknownJsx, data.allowedComponents],
26
+ remarkMdxRemoveUnknownJsx,
27
27
  ],
28
28
  rehypePlugins: [
29
29
  rehypeCodeBlocks,
@@ -0,0 +1,4 @@
1
+ export declare const getS3ImageUri: (imagePath: string, subdomain: string, filePath: string, basePath: string | undefined, opts?: {
2
+ bucketName?: string;
3
+ region?: string;
4
+ }) => string;
@@ -0,0 +1,12 @@
1
+ import path from 'path';
2
+ import { removeBasePath } from '../fs/removeBasePath.js';
3
+ import { getS3URI } from '../services/aws.js';
4
+ export const getS3ImageUri = (imagePath, subdomain, filePath, basePath, opts = {}) => {
5
+ if (imagePath.startsWith('/')) {
6
+ const path = removeBasePath(imagePath, basePath);
7
+ return getS3URI(subdomain, path, opts);
8
+ }
9
+ const beforeFilePath = path.join(filePath, '../');
10
+ const relativePath = removeBasePath(path.join(beforeFilePath, imagePath), basePath);
11
+ return getS3URI(subdomain, relativePath, opts);
12
+ };
@@ -5,3 +5,4 @@ export * from './plugins/index.js';
5
5
  export * from './lib/index.js';
6
6
  export * from './getMDXOptions.js';
7
7
  export * from './astUtils.js';
8
+ export * from './getS3ImageUri.js';
package/dist/mdx/index.js CHANGED
@@ -5,3 +5,4 @@ export * from './plugins/index.js';
5
5
  export * from './lib/index.js';
6
6
  export * from './getMDXOptions.js';
7
7
  export * from './astUtils.js';
8
+ export * from './getS3ImageUri.js';
@@ -4,7 +4,6 @@ export * from './remarkRemoveImports.js';
4
4
  export * from './remarkExtractTableOfContents.js';
5
5
  export * from './remarkMdxRemoveUnusedVariables.js';
6
6
  export * from './remarkMdxRemoveUnknownJsx/index.js';
7
- export * from './remarkReplaceAllImages.js';
8
7
  export * from './remarkMermaid.js';
9
8
  export * from './remarkMdxRemoveJs.js';
10
9
  export * from './remarkExtractChangelogFilters.js';
@@ -4,7 +4,6 @@ export * from './remarkRemoveImports.js';
4
4
  export * from './remarkExtractTableOfContents.js';
5
5
  export * from './remarkMdxRemoveUnusedVariables.js';
6
6
  export * from './remarkMdxRemoveUnknownJsx/index.js';
7
- export * from './remarkReplaceAllImages.js';
8
7
  export * from './remarkMermaid.js';
9
8
  export * from './remarkMdxRemoveJs.js';
10
9
  export * from './remarkExtractChangelogFilters.js';
@@ -1,2 +1,2 @@
1
1
  import type { Root } from 'mdast';
2
- export declare const remarkMdxRemoveUnknownJsx: (allowedComponents?: string[]) => (tree: Root) => Root | import("mdast-util-mdxjs-esm").MdxjsEsm | import("mdast").Link | import("mdast").Delete | import("mdast").Blockquote | import("mdast").Break | import("mdast").Code | import("mdast").Definition | import("mdast").Emphasis | import("mdast").FootnoteDefinition | import("mdast").FootnoteReference | import("mdast").Heading | import("mdast").Html | import("mdast").Image | import("mdast").ImageReference | import("mdast").InlineCode | import("mdast").LinkReference | import("mdast").List | import("mdast").ListItem | import("mdast").Paragraph | import("mdast").Strong | import("mdast").Table | import("mdast").TableCell | import("mdast").TableRow | import("mdast").Text | import("mdast").ThematicBreak | import("mdast").Yaml | import("mdast-util-math").InlineMath | import("mdast-util-math").Math | import("mdast-util-mdx-expression").MdxTextExpression | import("mdast-util-mdx-expression").MdxFlowExpression | import("mdast-util-mdx").MdxJsxFlowElement | import("mdast-util-mdx").MdxJsxTextElement;
2
+ export declare const remarkMdxRemoveUnknownJsx: () => (tree: Root) => Root | import("mdast-util-mdxjs-esm").MdxjsEsm | import("mdast").Link | import("mdast").Delete | import("mdast").Blockquote | import("mdast").Break | import("mdast").Code | import("mdast").Definition | import("mdast").Emphasis | import("mdast").FootnoteDefinition | import("mdast").FootnoteReference | import("mdast").Heading | import("mdast").Html | import("mdast").Image | import("mdast").ImageReference | import("mdast").InlineCode | import("mdast").LinkReference | import("mdast").List | import("mdast").ListItem | import("mdast").Paragraph | import("mdast").Strong | import("mdast").Table | import("mdast").TableCell | import("mdast").TableRow | import("mdast").Text | import("mdast").ThematicBreak | import("mdast").Yaml | import("mdast-util-math").InlineMath | import("mdast-util-math").Math | import("mdast-util-mdx-expression").MdxTextExpression | import("mdast-util-mdx-expression").MdxFlowExpression | import("mdast-util-mdx").MdxJsxFlowElement | import("mdast-util-mdx").MdxJsxTextElement;
@@ -1,7 +1,8 @@
1
1
  import { map } from 'unist-util-map';
2
+ import { allowedComponents } from '../../../index.js';
2
3
  import { findExportedNodes, isMdxJsxFlowElementHast } from '../../../lib/index.js';
3
4
  import { createCommentNode } from './createCommentNode.js';
4
- export const remarkMdxRemoveUnknownJsx = (allowedComponents) => (tree) => {
5
+ export const remarkMdxRemoveUnknownJsx = () => (tree) => {
5
6
  const exportedComponentNames = findExportedNodes(tree, 'ArrowFunctionExpression');
6
7
  return map(tree, (node) => {
7
8
  if (isMdxJsxFlowElementHast(node)) {
@@ -0,0 +1,6 @@
1
+ import type { Root } from 'mdast';
2
+ export type Snippet = {
3
+ snippetFileLocation: string;
4
+ content: string;
5
+ };
6
+ export declare function createSnippetTreeMap(snippets: Snippet[]): Promise<Record<string, Root>>;
@@ -0,0 +1,110 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { fromMarkdown } from 'mdast-util-from-markdown';
11
+ import { gfmFromMarkdown } from 'mdast-util-gfm';
12
+ import { mdxFromMarkdown } from 'mdast-util-mdx';
13
+ import { gfm } from 'micromark-extension-gfm';
14
+ import { mdxjs } from 'micromark-extension-mdxjs';
15
+ import { coreRemark, remarkMdxInjectSnippets } from '../../../index.js';
16
+ export function createSnippetTreeMap(snippets) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ var _a;
19
+ if (snippets.length === 0) {
20
+ return {};
21
+ }
22
+ const orderedSnippets = orderSnippetsByNumberOfSnippetsInContent(snippets);
23
+ let treeMap = {};
24
+ // If the lowest number of references is greater than 0, then there will be cyclical references that will never resolve.
25
+ // In these cases we do not try to replace snippets in snippets
26
+ // TODO: Better error handling for cyclical references
27
+ if (((_a = orderedSnippets[0]) === null || _a === void 0 ? void 0 : _a.numSnippetsInContent) === 0) {
28
+ orderedSnippets.forEach((snippet) => {
29
+ treeMap = addSnippetTreeToMap(snippet, treeMap);
30
+ });
31
+ return treeMap;
32
+ }
33
+ let failedParseArr = [];
34
+ orderedSnippets.forEach((snippet) => __awaiter(this, void 0, void 0, function* () {
35
+ if (snippet.numSnippetsInContent === 0) {
36
+ // No need to remove references if none exist
37
+ treeMap = addSnippetTreeToMap(snippet, treeMap);
38
+ }
39
+ if (failedParseArr.length > 0) {
40
+ let prevArrLength = failedParseArr.length + 1;
41
+ // We try to resolve the failed snippets which likely failed because it was referencing
42
+ // another snippet that has not been resolved yet.
43
+ // We loop while snippets continue to be resolved.
44
+ while (prevArrLength > failedParseArr.length && prevArrLength !== 0) {
45
+ const newlyParsedSnippets = [];
46
+ for (const failedParse of failedParseArr) {
47
+ try {
48
+ treeMap = yield addParsedSnippetTreeToMap(failedParse, treeMap);
49
+ newlyParsedSnippets.push(failedParse);
50
+ }
51
+ catch (_a) { }
52
+ }
53
+ prevArrLength = failedParseArr.length;
54
+ failedParseArr = failedParseArr.filter((elem) => !newlyParsedSnippets.includes(elem));
55
+ }
56
+ }
57
+ try {
58
+ treeMap = yield addParsedSnippetTreeToMap(snippet, treeMap);
59
+ }
60
+ catch (_b) {
61
+ // TODO - find exact error message for when inner snippet doesn't exist
62
+ failedParseArr.push(snippet);
63
+ }
64
+ }));
65
+ return treeMap;
66
+ });
67
+ }
68
+ function addSnippetTreeToMap(snippet, map) {
69
+ try {
70
+ const tree = fromMarkdown(snippet.content, {
71
+ extensions: [gfm(), mdxjs()],
72
+ mdastExtensions: [gfmFromMarkdown(), mdxFromMarkdown()],
73
+ });
74
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- TODO: Please fix this violation when you can!
75
+ map = Object.assign(Object.assign({}, map), { [snippet.snippetFileLocation]: tree });
76
+ }
77
+ catch (_a) {
78
+ // TODO: Better error handling
79
+ }
80
+ return map;
81
+ }
82
+ function addParsedSnippetTreeToMap(snippet, treeMap) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ const parsedContent = yield preparseSnippet(snippet, treeMap);
85
+ return addSnippetTreeToMap(Object.assign(Object.assign({}, snippet), { content: parsedContent }), treeMap);
86
+ });
87
+ }
88
+ /*
89
+ * We order the snippets by increasing number of references to other snippets in an attempt to avoid
90
+ * trying to parse a snippet that references another snippet that has not been resolved yet.
91
+ */
92
+ function orderSnippetsByNumberOfSnippetsInContent(snippets) {
93
+ const snippetsWithNumSnippets = snippets.map((snippet) => {
94
+ return Object.assign(Object.assign({}, snippet), {
95
+ // Note: It's possible the regex might not be enough
96
+ numSnippetsInContent: (snippet.content.match(/<Snippet/g) || []).length });
97
+ });
98
+ snippetsWithNumSnippets.sort(function (first, second) {
99
+ return first.numSnippetsInContent - second.numSnippetsInContent;
100
+ });
101
+ return snippetsWithNumSnippets;
102
+ }
103
+ function preparseSnippet(snippet, snippetTreeMap) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ const file = yield coreRemark()
106
+ .use([remarkMdxInjectSnippets, snippetTreeMap])
107
+ .process(snippet.content);
108
+ return String(file);
109
+ });
110
+ }
@@ -0,0 +1,14 @@
1
+ import { type SerializeSuccess } from '@mintlify/mdx';
2
+ import type { PageMetaTags } from '@mintlify/models';
3
+ import type { DocsConfig } from '@mintlify/validation';
4
+ import { MdxExtracts } from '../../index.js';
5
+ import { createSnippetTreeMap, type Snippet } from './getMdx/snippets.js';
6
+ export type GetMdxType = {
7
+ mdxSource: SerializeSuccess;
8
+ mdxSourceWithNoJs: SerializeSuccess;
9
+ mdxExtracts: MdxExtracts;
10
+ panelMdxSource?: SerializeSuccess;
11
+ panelMdxSourceWithNoJs?: SerializeSuccess;
12
+ };
13
+ export declare function getMdx(path: string, content: string, metadata: PageMetaTags, snippets: Snippet[], subdomain: string, config: DocsConfig, tailwindSelectors: string[], pageType?: 'default' | 'pdf'): Promise<GetMdxType>;
14
+ export { createSnippetTreeMap, type Snippet };
@@ -0,0 +1,99 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { serialize } from '@mintlify/mdx';
11
+ import { getMDXOptions, remarkMdxRemoveJs, remarkExpandContent, remarkSplitCodeGroup, remarkSplitTabs, remarkValidateSteps, remarkValidateTabs, } from '../../index.js';
12
+ import { createSnippetTreeMap } from './getMdx/snippets.js';
13
+ export function getMdx(path_1, content_1, metadata_1, snippets_1, subdomain_1, config_1, tailwindSelectors_1) {
14
+ return __awaiter(this, arguments, void 0, function* (path, content, metadata, snippets, subdomain, config, tailwindSelectors, pageType = 'default') {
15
+ const snippetTreeMap = yield createSnippetTreeMap(snippets);
16
+ const mdxOptionsData = {
17
+ subdomain,
18
+ snippetTreeMap,
19
+ pageMetadata: metadata,
20
+ config,
21
+ tailwindSelectors,
22
+ };
23
+ let mdxExtracts = {};
24
+ let plugins = [remarkValidateSteps, remarkValidateTabs];
25
+ if (pageType === 'pdf') {
26
+ plugins = [...plugins, remarkExpandContent, remarkSplitCodeGroup, remarkSplitTabs];
27
+ }
28
+ const mdxOptions = getMDXOptions({ data: mdxOptionsData, remarkPlugins: plugins, mdxExtracts });
29
+ const mdxOptionsNoJs = getMDXOptions({
30
+ data: mdxOptionsData,
31
+ remarkPlugins: [remarkMdxRemoveJs, ...plugins],
32
+ });
33
+ const scope = {
34
+ config,
35
+ pageMetadata: metadata,
36
+ };
37
+ const { mdxSource, mdxSourceWithNoJs } = yield compileMdx(content, scope, mdxOptions, mdxOptionsNoJs, config, path);
38
+ const originalMdxExtracts = structuredClone(mdxExtracts);
39
+ let panelMdxSource;
40
+ let panelMdxSourceWithNoJs;
41
+ if (mdxExtracts.panel && mdxExtracts.panel.content) {
42
+ const panelContent = mdxExtracts.panel.content;
43
+ const compiledMdx = yield compileMdx(panelContent, scope, mdxOptions, mdxOptionsNoJs, config, path);
44
+ panelMdxSource = compiledMdx.mdxSource;
45
+ panelMdxSourceWithNoJs = compiledMdx.mdxSourceWithNoJs;
46
+ // serializing mdx content with the panel content will remove the original mdxExtracts
47
+ // so we need to restore the original mdxExtracts
48
+ mdxExtracts = Object.assign(Object.assign({}, originalMdxExtracts), { codeExamples: mdxExtracts.codeExamples });
49
+ }
50
+ return {
51
+ mdxExtracts,
52
+ mdxSource,
53
+ mdxSourceWithNoJs,
54
+ panelMdxSource,
55
+ panelMdxSourceWithNoJs,
56
+ };
57
+ });
58
+ }
59
+ function compileMdx(content, scope, mdxOptions, mdxOptionsNoJs, config, path) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const mdxSource = yield getCompiledMdxWithFallback(content, scope, mdxOptions, config, path);
62
+ const mdxSourceWithNoJs = yield getCompiledMdxWithFallback(content, scope, mdxOptionsNoJs, config, path);
63
+ return { mdxSource, mdxSourceWithNoJs };
64
+ });
65
+ }
66
+ function getCompiledMdxWithFallback(source, scope, mdxOptions, config, path) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ var _a;
69
+ try {
70
+ const result = yield serialize({
71
+ source,
72
+ scope,
73
+ mdxOptions,
74
+ syntaxHighlightingOptions: {
75
+ codeStyling: (_a = config.styling) === null || _a === void 0 ? void 0 : _a.codeblocks,
76
+ },
77
+ });
78
+ if ('error' in result) {
79
+ throw result.error;
80
+ }
81
+ return result;
82
+ }
83
+ catch (err) {
84
+ if (path)
85
+ console.log(`⚠️ Warning: MDX failed to parse page ${path}: `, err);
86
+ // placeholder content for when there is a syntax error.
87
+ const fallbackResult = yield serialize({
88
+ source: '🚧 A parsing error occured. Please contact the owner of this website. They can use the Mintlify CLI to test this website locally and see the errors that occur.',
89
+ scope,
90
+ mdxOptions,
91
+ });
92
+ if ('error' in fallbackResult) {
93
+ throw fallbackResult.error;
94
+ }
95
+ return fallbackResult;
96
+ }
97
+ });
98
+ }
99
+ export { createSnippetTreeMap };
@@ -0,0 +1 @@
1
+ export { createSnippetTreeMap, getMdx, type GetMdxType, type Snippet } from './getMdx.js';
@@ -0,0 +1 @@
1
+ export { createSnippetTreeMap, getMdx } from './getMdx.js';
@@ -16,3 +16,4 @@ export declare const isMdxJsxFlowElement: (node: Node) => node is MdxJsxFlowElem
16
16
  export declare const createUniqueVariableName: (variableName: string, id: number) => string;
17
17
  export declare const getObjectExpressionStringProperty: (key: string, attribute: MdxJsxAttribute | MdxJsxExpressionAttribute | undefined) => string | undefined;
18
18
  export declare const getArrayExpressionStringProperties: (attribute: MdxJsxAttribute | MdxJsxExpressionAttribute | undefined) => string[];
19
+ export declare const allowedComponents: string[];
package/dist/mdx/utils.js CHANGED
@@ -46,3 +46,88 @@ export const getArrayExpressionStringProperties = (attribute) => {
46
46
  }
47
47
  return collection;
48
48
  };
49
+ export const allowedComponents = [
50
+ 'ApiPlayground',
51
+ 'Accordion',
52
+ 'AccordionGroup',
53
+ 'CodeGroup',
54
+ 'Columns',
55
+ 'CodeBlock',
56
+ 'CustomCode',
57
+ 'CustomComponent',
58
+ 'DynamicCustomComponent',
59
+ 'Danger',
60
+ 'SnippetGroup',
61
+ 'Panel',
62
+ 'RequestExample',
63
+ 'ResponseExample',
64
+ 'Param',
65
+ 'ParamField',
66
+ 'Card',
67
+ 'CardGroup',
68
+ 'Expandable',
69
+ 'Frame',
70
+ 'Heading',
71
+ 'Info',
72
+ 'Icon',
73
+ 'Link',
74
+ 'MDXContentController',
75
+ 'ResponseField',
76
+ 'Warning',
77
+ 'Note',
78
+ 'Tip',
79
+ 'Check',
80
+ 'Tabs',
81
+ 'Tab',
82
+ 'Tooltip',
83
+ 'Latex',
84
+ 'Step',
85
+ 'Steps',
86
+ 'Update',
87
+ 'a',
88
+ 'b',
89
+ 'br',
90
+ 'button',
91
+ 'clipPath',
92
+ 'defs',
93
+ 'div',
94
+ 'form',
95
+ 'g',
96
+ 'h1',
97
+ 'h2',
98
+ 'h3',
99
+ 'h4',
100
+ 'head',
101
+ 'iframe',
102
+ 'img',
103
+ 'input',
104
+ 'label',
105
+ 'li',
106
+ 'link',
107
+ 'ol',
108
+ 'p',
109
+ 'path',
110
+ 'picture',
111
+ 'rect',
112
+ 'script',
113
+ 'section',
114
+ 'source',
115
+ 'span',
116
+ 'sub',
117
+ 'sup',
118
+ 'svg',
119
+ 'table',
120
+ 'tbody',
121
+ 'td',
122
+ 'th',
123
+ 'thead',
124
+ 'tr',
125
+ 'ul',
126
+ 'video',
127
+ 'code',
128
+ 'pre',
129
+ 'ZoomImage',
130
+ 'Mermaid',
131
+ // Custom tags
132
+ 'zapier-zap-templates',
133
+ ];