@mintlify/common 1.0.819 → 1.0.821

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,9 +1,10 @@
1
1
  import { generateExampleFromSchema, } from '@mintlify/validation';
2
2
  import { visitParents } from 'unist-util-visit-parents';
3
+ import { parseApiString } from '../../../../openapi/index.js';
3
4
  import { isMdxJsxFlowElementHast } from '../../../lib/mdx-utils.js';
4
5
  import { findParentSchema } from './findParentSchema.js';
5
6
  import { insertSchema } from './insertSchema.js';
6
- import { parseApiString, parseAuthMethod, parseField } from './parsers.js';
7
+ import { parseAuthMethod, parseField } from './parsers.js';
7
8
  export const rehypeMdxExtractEndpoint = (metadata, config, mdxExtracts) => {
8
9
  return (tree) => {
9
10
  var _a;
@@ -1,12 +1,7 @@
1
1
  import { MintConfig } from '@mintlify/models';
2
- import { DataSchema, DocsConfig, HttpMethod, SecurityOption, Server } from '@mintlify/validation';
2
+ import { DataSchema, DocsConfig, SecurityOption } from '@mintlify/validation';
3
3
  import type { MdxJsxFlowElementHast } from 'mdast-util-mdx-jsx';
4
4
  import type { FieldLocation } from '../../../lib/mdx-utils.js';
5
- export declare const parseApiString: (apiString: string, config?: MintConfig | DocsConfig) => {
6
- servers?: Server[];
7
- path: string;
8
- method: HttpMethod;
9
- };
10
5
  export declare const parseAuthMethod: (authMethodString: string | undefined, config?: MintConfig | DocsConfig) => SecurityOption[];
11
6
  export type LocationAttr = {
12
7
  location: FieldLocation;
@@ -1,53 +1,6 @@
1
- import { OpenAPIV3 } from 'openapi-types';
2
1
  import { getSecurityOptionsForAuthMethod } from '../../../../index.js';
3
- import { isAbsoluteUrl } from '../../../../isAbsoluteUrl.js';
4
2
  import { isDocsConfig } from '../../../../isDocsConfig.js';
5
3
  import { isMdxJsxAttribute, isParamFieldLocation } from '../../../lib/mdx-utils.js';
6
- const VALID_METHODS = Object.values(OpenAPIV3.HttpMethods);
7
- export const parseApiString = (apiString, config) => {
8
- const components = apiString.trim().split(/\s+/);
9
- if (!components[0] || !components[1] || components.length > 2) {
10
- throw new Error('improperly formatted api string');
11
- }
12
- const upperMethod = components[0];
13
- const endpointStr = components[1];
14
- const method = upperMethod.toLowerCase();
15
- if (!VALID_METHODS.includes(method)) {
16
- throw new Error('invalid http method');
17
- }
18
- const { origin, path } = parseEndpoint(endpointStr);
19
- const servers = origin ? [{ url: origin }] : parseServers(config);
20
- return {
21
- path,
22
- method: method,
23
- servers,
24
- };
25
- };
26
- const parseEndpoint = (endpoint) => {
27
- if (!isAbsoluteUrl(endpoint)) {
28
- return {
29
- origin: undefined,
30
- path: endpoint,
31
- };
32
- }
33
- const url = new URL(endpoint);
34
- return {
35
- origin: decodeURI(url.origin),
36
- path: decodeURI(url.pathname),
37
- };
38
- };
39
- const parseServers = (config) => {
40
- var _a, _b, _c;
41
- const baseUrl = config && isDocsConfig(config) ? (_b = (_a = config.api) === null || _a === void 0 ? void 0 : _a.mdx) === null || _b === void 0 ? void 0 : _b.server : (_c = config === null || config === void 0 ? void 0 : config.api) === null || _c === void 0 ? void 0 : _c.baseUrl;
42
- if (!baseUrl) {
43
- return undefined;
44
- }
45
- if (typeof baseUrl === 'string') {
46
- return [{ url: baseUrl }];
47
- }
48
- const servers = baseUrl.filter(Boolean).map((url) => ({ url }));
49
- return servers.length > 0 ? servers : undefined;
50
- };
51
4
  export const parseAuthMethod = (authMethodString, config) => {
52
5
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
53
6
  const method = authMethodString !== null && authMethodString !== void 0 ? authMethodString : (config && isDocsConfig(config) ? (_c = (_b = (_a = config.api) === null || _a === void 0 ? void 0 : _a.mdx) === null || _b === void 0 ? void 0 : _b.auth) === null || _c === void 0 ? void 0 : _c.method : (_e = (_d = config === null || config === void 0 ? void 0 : config.api) === null || _d === void 0 ? void 0 : _d.auth) === null || _e === void 0 ? void 0 : _e.method);
@@ -7,3 +7,4 @@ export { getOpenApiDocumentFromUrl } from './getOpenApiDocumentFromUrl.js';
7
7
  export { buildOpenApiMetaTag } from './buildOpenApiMetaTag.js';
8
8
  export { registerXMintContent, getXMintContent, getAllXMintContent } from './contentRegistry.js';
9
9
  export { getMatchingOpenApiFile, type ApiReferenceMapping, type FileToUuidMap, type UuidToRefsMap, } from './getMatchingOpenApiFile.js';
10
+ export { parseApiString } from './parseApiString.js';
@@ -7,3 +7,4 @@ export { getOpenApiDocumentFromUrl } from './getOpenApiDocumentFromUrl.js';
7
7
  export { buildOpenApiMetaTag } from './buildOpenApiMetaTag.js';
8
8
  export { registerXMintContent, getXMintContent, getAllXMintContent } from './contentRegistry.js';
9
9
  export { getMatchingOpenApiFile, } from './getMatchingOpenApiFile.js';
10
+ export { parseApiString } from './parseApiString.js';
@@ -0,0 +1,7 @@
1
+ import { MintConfig } from '@mintlify/models';
2
+ import { DocsConfig, HttpMethod, Server } from '@mintlify/validation';
3
+ export declare const parseApiString: (apiString: string, config?: MintConfig | DocsConfig) => {
4
+ servers?: Server[];
5
+ path: string;
6
+ method: HttpMethod;
7
+ };
@@ -0,0 +1,48 @@
1
+ import { OpenAPIV3 } from 'openapi-types';
2
+ import { isAbsoluteUrl } from '../isAbsoluteUrl.js';
3
+ import { isDocsConfig } from '../isDocsConfig.js';
4
+ export const parseApiString = (apiString, config) => {
5
+ const components = apiString.trim().split(/\s+/);
6
+ if (!components[0] || !components[1] || components.length > 2) {
7
+ throw new Error('improperly formatted api string');
8
+ }
9
+ const upperMethod = components[0];
10
+ const endpointStr = components[1];
11
+ const method = upperMethod.toLowerCase();
12
+ if (!VALID_METHODS.includes(method)) {
13
+ throw new Error('invalid http method');
14
+ }
15
+ const { origin, path } = parseEndpoint(endpointStr);
16
+ const servers = origin ? [{ url: origin }] : parseServers(config);
17
+ return {
18
+ path,
19
+ method: method,
20
+ servers,
21
+ };
22
+ };
23
+ const VALID_METHODS = Object.values(OpenAPIV3.HttpMethods);
24
+ const parseEndpoint = (endpoint) => {
25
+ if (!isAbsoluteUrl(endpoint)) {
26
+ return {
27
+ origin: undefined,
28
+ path: endpoint,
29
+ };
30
+ }
31
+ const url = new URL(endpoint);
32
+ return {
33
+ origin: decodeURI(url.origin),
34
+ path: decodeURI(url.pathname),
35
+ };
36
+ };
37
+ const parseServers = (config) => {
38
+ var _a, _b, _c;
39
+ const baseUrl = config && isDocsConfig(config) ? (_b = (_a = config.api) === null || _a === void 0 ? void 0 : _a.mdx) === null || _b === void 0 ? void 0 : _b.server : (_c = config === null || config === void 0 ? void 0 : config.api) === null || _c === void 0 ? void 0 : _c.baseUrl;
40
+ if (!baseUrl) {
41
+ return undefined;
42
+ }
43
+ if (typeof baseUrl === 'string') {
44
+ return [{ url: baseUrl }];
45
+ }
46
+ const servers = baseUrl.filter(Boolean).map((url) => ({ url }));
47
+ return servers.length > 0 ? servers : undefined;
48
+ };