@mintlify/common 1.0.1250 → 1.0.1252

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,3 +1,5 @@
1
+ export declare function packageBuildBaseUrl(buildId: string): string;
2
+ export declare function packageBuildIdFromBaseUrl(baseUrl: string): string | undefined;
1
3
  export declare function packagePageBaseUrl(baseUrl: string, pagePath: string): string;
2
4
  export declare function packagePageStylesheets(baseUrl: string, pagePath: string, islandIds: readonly string[], manifest: {
3
5
  css: readonly {
@@ -15,7 +17,7 @@ export declare function compilePackageBuild<T extends {
15
17
  export declare function withPackageGlobalStylesheets<T extends {
16
18
  packageCssFiles?: string[];
17
19
  }>(mdxExtracts: T, packageBuild: {
18
- baseUrl: string;
20
+ buildId: string;
19
21
  css?: readonly {
20
22
  path: string;
21
23
  }[];
@@ -1,6 +1,21 @@
1
+ const PACKAGE_ROUTE_PREFIX = '/_mintlify/pkg';
2
+ const PACKAGE_BUILD_ID = /^[A-Za-z0-9_-]{1,64}$/;
1
3
  const PRODUCTION_PACKAGE_BASE_URL = /^\/_mintlify\/pkg\/[a-f0-9]{16,64}$/;
2
4
  const ROUTE_CANONICAL_BASE = 'https://pkg-access.invalid';
3
5
  const MAX_ACCESS_ROUTE_LENGTH = 1024;
6
+ export function packageBuildBaseUrl(buildId) {
7
+ if (!PACKAGE_BUILD_ID.test(buildId)) {
8
+ throw new Error(`Invalid package build ID: ${buildId}`);
9
+ }
10
+ return `${PACKAGE_ROUTE_PREFIX}/${buildId}`;
11
+ }
12
+ export function packageBuildIdFromBaseUrl(baseUrl) {
13
+ const prefix = `${PACKAGE_ROUTE_PREFIX}/`;
14
+ if (!baseUrl.startsWith(prefix))
15
+ return undefined;
16
+ const buildId = baseUrl.slice(prefix.length);
17
+ return PACKAGE_BUILD_ID.test(buildId) ? buildId : undefined;
18
+ }
4
19
  export function packagePageBaseUrl(baseUrl, pagePath) {
5
20
  if (!PRODUCTION_PACKAGE_BASE_URL.test(baseUrl))
6
21
  return baseUrl;
@@ -41,7 +56,7 @@ export function withPackageGlobalStylesheets(mdxExtracts, packageBuild, pagePath
41
56
  return mdxExtracts;
42
57
  let globalFiles;
43
58
  try {
44
- globalFiles = packagePageStylesheets(packageBuild.baseUrl, pagePath, [], {
59
+ globalFiles = packagePageStylesheets(packageBuildBaseUrl(packageBuild.buildId), pagePath, [], {
45
60
  css: packageBuild.css,
46
61
  islands: {},
47
62
  });
@@ -6,7 +6,7 @@ import { MdxExtracts } from '../../index.js';
6
6
  import { createSnippetTreeMap, type Snippet } from './getMdx/snippets.js';
7
7
  type RunWithTracingFn = <T>(spanName: string, fn: () => Promise<T>) => Promise<T>;
8
8
  export type PackageBuildInput = {
9
- baseUrl: string;
9
+ buildId: string;
10
10
  islands: Record<string, {
11
11
  html?: string;
12
12
  prefix: string;
@@ -11,7 +11,7 @@ import { serialize } from '@mintlify/mdx/server';
11
11
  import { getTailwindSelectors } from '../../css/tailwind.js';
12
12
  import { getMDXOptions, remarkMdxRemoveJs, remarkExpandContent, remarkSplitCodeGroup, remarkSplitTabs, remarkWrapCodeBlocks, remarkValidateAccordions, remarkValidateSteps, remarkValidateVisibility, remarkValidateTabs, remarkValidateApiExamples, } from '../../index.js';
13
13
  import { codeStylingToThemeOrThemes } from '../getCodeStyling.js';
14
- import { packagePageBaseUrl, packagePageStylesheets } from '../islands/package-page-url.js';
14
+ import { packageBuildBaseUrl, packagePageBaseUrl, packagePageStylesheets, } from '../islands/package-page-url.js';
15
15
  import { MINT_ISLAND_COMPONENT } from '../islands/packageImports.js';
16
16
  import { PackageIslandsError, parsePackageIslands, preprocessPageContent, } from '../islands/remarkPackageIslands.js';
17
17
  import { preprocessCustomHeadingIds } from '../preprocessCustomHeadingIds.js';
@@ -19,11 +19,8 @@ import { preprocessMdxFragmentCode } from '../preprocessMdxFragmentCode.js';
19
19
  import { replaceVariables } from '../replaceVariables.js';
20
20
  import { createSnippetTreeMap } from './getMdx/snippets.js';
21
21
  import { getSerializeExtras } from './getSerializeExtras.js';
22
- const PACKAGE_BASE_URL = /^\/_mintlify\/pkg\/[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*$/;
23
22
  const getPackageIslandOptions = (packageBuild, pagePath, processedContent, snippetTreeMap) => {
24
- if (!PACKAGE_BASE_URL.test(packageBuild.baseUrl)) {
25
- throw new Error(`packageBuild.baseUrl must be a /_mintlify/pkg/ path: ${packageBuild.baseUrl}`);
26
- }
23
+ const buildBaseUrl = packageBuildBaseUrl(packageBuild.buildId);
27
24
  const options = Object.assign({ packageNames: new Set(packageBuild.packageNames), pagePath }, (packageBuild.packageSnippets && {
28
25
  packageSnippets: new Set(packageBuild.packageSnippets),
29
26
  }));
@@ -34,7 +31,7 @@ const getPackageIslandOptions = (packageBuild, pagePath, processedContent, snipp
34
31
  catch (_a) {
35
32
  plan = undefined;
36
33
  }
37
- const baseUrl = packagePageBaseUrl(packageBuild.baseUrl, pagePath);
34
+ const baseUrl = packagePageBaseUrl(buildBaseUrl, pagePath);
38
35
  const islandHtml = Object.fromEntries(Object.entries(packageBuild.islands).map(([id, island]) => {
39
36
  if (typeof island.html !== 'string')
40
37
  return [id, island];
@@ -167,7 +164,7 @@ export function getMdx(_a) {
167
164
  mdxExtracts.multiViewItems = mdxExtracts.multiViewItems.map((item, index) => (Object.assign(Object.assign({}, item), { active: index === 0 })));
168
165
  }
169
166
  if (packageBuild) {
170
- const packageCssFiles = packagePageStylesheets(packageBuild.baseUrl, path, Object.keys((_d = mdxExtracts.islands) !== null && _d !== void 0 ? _d : {}), { css: (_e = packageBuild.css) !== null && _e !== void 0 ? _e : [], islands: packageBuild.islands });
167
+ const packageCssFiles = packagePageStylesheets(packageBuildBaseUrl(packageBuild.buildId), path, Object.keys((_d = mdxExtracts.islands) !== null && _d !== void 0 ? _d : {}), { css: (_e = packageBuild.css) !== null && _e !== void 0 ? _e : [], islands: packageBuild.islands });
171
168
  if (packageCssFiles.length > 0)
172
169
  mdxExtracts.packageCssFiles = packageCssFiles;
173
170
  }
@@ -2,4 +2,4 @@ export { createSnippetTreeMap, getMdx, type GetMdxType, type PackageBuildInput,
2
2
  export { getSerializeExtras } from './getSerializeExtras.js';
3
3
  export { createPackageSnippetTreeMap } from './package-snippet-tree-map.js';
4
4
  export { compileWithPackageBuildFallback } from '../islands/package-build-fallback.js';
5
- export { compilePackageBuild, packagePageBaseUrl, packagePageStylesheets, withPackageGlobalStylesheets, } from '../islands/package-page-url.js';
5
+ export { compilePackageBuild, packageBuildBaseUrl, packageBuildIdFromBaseUrl, packagePageBaseUrl, packagePageStylesheets, withPackageGlobalStylesheets, } from '../islands/package-page-url.js';
@@ -2,4 +2,4 @@ export { createSnippetTreeMap, getMdx, } from './getMdx.js';
2
2
  export { getSerializeExtras } from './getSerializeExtras.js';
3
3
  export { createPackageSnippetTreeMap } from './package-snippet-tree-map.js';
4
4
  export { compileWithPackageBuildFallback } from '../islands/package-build-fallback.js';
5
- export { compilePackageBuild, packagePageBaseUrl, packagePageStylesheets, withPackageGlobalStylesheets, } from '../islands/package-page-url.js';
5
+ export { compilePackageBuild, packageBuildBaseUrl, packageBuildIdFromBaseUrl, packagePageBaseUrl, packagePageStylesheets, withPackageGlobalStylesheets, } from '../islands/package-page-url.js';