@mintlify/common 1.0.1057 → 1.0.1059

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,4 @@
1
+ export declare const RESERVED_BASE_PATHS: string[];
2
+ export declare const normalizeCustomDomainBasePath: (basePath: string) => string;
3
+ export declare const isReservedBasePath: (basePath: string) => boolean;
4
+ export declare const validateCustomDomainBasePath: (basePath: string) => string | undefined;
@@ -0,0 +1,52 @@
1
+ export const RESERVED_BASE_PATHS = [
2
+ '/_next',
3
+ '/_mintlify',
4
+ '/_sites',
5
+ '/_live-preview',
6
+ '/api',
7
+ '/login',
8
+ '/logout',
9
+ '/mcp',
10
+ '/feedback',
11
+ '/openapi-specs.download',
12
+ '/llms.txt',
13
+ '/llms-full.txt',
14
+ '/sitemap.xml',
15
+ '/robots.txt',
16
+ '/skill.md',
17
+ '/.well-known',
18
+ ];
19
+ export const normalizeCustomDomainBasePath = (basePath) => {
20
+ const trimmedBasePath = basePath.trim();
21
+ if (trimmedBasePath === '/')
22
+ return trimmedBasePath;
23
+ return trimmedBasePath.replace(/\/+$/, '');
24
+ };
25
+ export const isReservedBasePath = (basePath) => RESERVED_BASE_PATHS.some((reservedBasePath) => basePath === reservedBasePath || basePath.startsWith(`${reservedBasePath}/`));
26
+ export const validateCustomDomainBasePath = (basePath) => {
27
+ const trimmedBasePath = basePath.trim();
28
+ const normalizedBasePath = normalizeCustomDomainBasePath(basePath);
29
+ if (trimmedBasePath.length === 0)
30
+ return 'Enter a base path.';
31
+ if (!trimmedBasePath.startsWith('/'))
32
+ return 'Base path must start with /.';
33
+ if (trimmedBasePath === '/')
34
+ return 'Base path must include a path segment.';
35
+ if (trimmedBasePath.length > 128)
36
+ return 'Base path must be at most 128 characters.';
37
+ if (trimmedBasePath.startsWith('//') || trimmedBasePath.includes('://')) {
38
+ return 'Base path cannot be an absolute URL.';
39
+ }
40
+ if (trimmedBasePath.includes('//'))
41
+ return 'Base path cannot contain consecutive slashes.';
42
+ if (/\s/.test(trimmedBasePath))
43
+ return 'Base path cannot contain spaces.';
44
+ if (/[?#]/.test(trimmedBasePath))
45
+ return 'Base path cannot include a query string or hash.';
46
+ if (trimmedBasePath.split('/').some((segment) => segment === '.' || segment === '..')) {
47
+ return 'Base path cannot contain "." or ".." segments.';
48
+ }
49
+ if (isReservedBasePath(normalizedBasePath))
50
+ return 'Base path is reserved.';
51
+ return undefined;
52
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { validateCustomDomainBasePath } from './validateCustomDomainBasePath.js';
3
+ describe('validateCustomDomainBasePath', () => {
4
+ it.each([
5
+ ['', 'Enter a base path.'],
6
+ ['docs', 'Base path must start with /.'],
7
+ ['/', 'Base path must include a path segment.'],
8
+ ['//docs', 'Base path cannot be an absolute URL.'],
9
+ ['https://example.com/docs', 'Base path must start with /.'],
10
+ ['/docs//api', 'Base path cannot contain consecutive slashes.'],
11
+ ['/docs api', 'Base path cannot contain spaces.'],
12
+ ['/docs?version=1', 'Base path cannot include a query string or hash.'],
13
+ ['/docs/../api', 'Base path cannot contain "." or ".." segments.'],
14
+ ['/docs/.', 'Base path cannot contain "." or ".." segments.'],
15
+ ['/api/reference', 'Base path is reserved.'],
16
+ ])('rejects invalid base path %s', (basePath, error) => {
17
+ expect(validateCustomDomainBasePath(basePath)).toBe(error);
18
+ });
19
+ it('accepts custom base paths', () => {
20
+ expect(validateCustomDomainBasePath('/resources')).toBeUndefined();
21
+ });
22
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintlify/common",
3
- "version": "1.0.1057",
3
+ "version": "1.0.1059",
4
4
  "description": "Commonly shared code within Mintlify",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -71,7 +71,7 @@
71
71
  "@mintlify/mdx": "4.0.1",
72
72
  "@mintlify/models": "0.0.344",
73
73
  "@mintlify/openapi-parser": "0.0.8",
74
- "@mintlify/validation": "0.1.808",
74
+ "@mintlify/validation": "0.1.809",
75
75
  "@sindresorhus/slugify": "2.2.0",
76
76
  "@types/mdast": "4.0.4",
77
77
  "acorn": "8.11.2",
@@ -129,5 +129,5 @@
129
129
  "typescript": "5.5.3",
130
130
  "vitest": "2.1.9"
131
131
  },
132
- "gitHead": "1b7774aa5f93b4b4bf0229a41cf2bb94512f704d"
132
+ "gitHead": "01132fcdea1229b4af02723b1cd62a2bae73ecf6"
133
133
  }