mintlify 1.1.6 → 1.1.8

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.
Files changed (206) hide show
  1. package/CONTRIBUTING.md +5 -0
  2. package/bin/index.js +1 -8
  3. package/bin/index.js.map +1 -1
  4. package/bin/local-preview/injectNav.js +94 -0
  5. package/bin/local-preview/injectNav.js.map +1 -0
  6. package/bin/mint/client/.babel-plugin-macrosrc.json +5 -0
  7. package/bin/mint/client/.babelrc +4 -0
  8. package/bin/mint/client/.editorconfig +12 -0
  9. package/bin/mint/client/.eslintrc.json +7 -0
  10. package/bin/mint/client/.prettierignore +4 -0
  11. package/bin/mint/client/.prettierrc +14 -0
  12. package/bin/mint/client/.vscode/launch.json +28 -0
  13. package/bin/mint/client/README.md +44 -0
  14. package/bin/mint/client/jest.config.ts +195 -0
  15. package/bin/mint/client/next-env.d.ts +4 -0
  16. package/bin/mint/client/next.config.js +152 -0
  17. package/bin/mint/client/package.json +139 -0
  18. package/bin/mint/client/postcss.config.cjs +9 -0
  19. package/bin/mint/client/prebuild/faviconConfig.js +35 -0
  20. package/bin/mint/client/prebuild/getOpenApiContext.js +53 -0
  21. package/bin/mint/client/prebuild/index.js +117 -0
  22. package/bin/mint/client/prebuild/injectNav.js +115 -0
  23. package/bin/mint/client/prebuild/slugToTitle.js +7 -0
  24. package/bin/mint/client/rehype/withApiComponents.js +60 -0
  25. package/bin/mint/client/rehype/withCodeBlocks.js +54 -0
  26. package/bin/mint/client/rehype/withLayouts.js +113 -0
  27. package/bin/mint/client/rehype/withLinkRoles.js +13 -0
  28. package/bin/mint/client/rehype/withRawComponents.js +13 -0
  29. package/bin/mint/client/rehype/withStaticProps.js +25 -0
  30. package/bin/mint/client/rehype/withSyntaxHighlighting.js +60 -0
  31. package/bin/mint/client/remark/utils.js +369 -0
  32. package/bin/mint/client/remark/withFrames.js +55 -0
  33. package/bin/mint/client/remark/withImportsInjected.js +36 -0
  34. package/bin/mint/client/remark/withNextLinks.js +37 -0
  35. package/bin/mint/client/remark/withTableOfContents.js +71 -0
  36. package/bin/mint/client/scripts/local.js +177 -0
  37. package/bin/mint/client/sentry.client.config.js +15 -0
  38. package/bin/mint/client/sentry.properties +4 -0
  39. package/bin/mint/client/sentry.server.config.js +15 -0
  40. package/bin/mint/client/src/analytics/AbstractAnalyticsImplementation.ts +50 -0
  41. package/bin/mint/client/src/analytics/AnalyticsContext.ts +5 -0
  42. package/bin/mint/client/src/analytics/AnalyticsMediator.ts +101 -0
  43. package/bin/mint/client/src/analytics/FakeAnalyticsMediator.ts +9 -0
  44. package/bin/mint/client/src/analytics/GA4Script.tsx +33 -0
  45. package/bin/mint/client/src/analytics/implementations/amplitude.ts +26 -0
  46. package/bin/mint/client/src/analytics/implementations/fathom.ts +38 -0
  47. package/bin/mint/client/src/analytics/implementations/ga4.ts +33 -0
  48. package/bin/mint/client/src/analytics/implementations/hotjar.ts +53 -0
  49. package/bin/mint/client/src/analytics/implementations/mixpanel-browser.d.ts +1 -0
  50. package/bin/mint/client/src/analytics/implementations/mixpanel.ts +52 -0
  51. package/bin/mint/client/src/analytics/implementations/posthog.ts +37 -0
  52. package/bin/mint/client/src/components/Accordion/Accordion.tsx +43 -0
  53. package/bin/mint/client/src/components/Accordion/index.ts +4 -0
  54. package/bin/mint/client/src/components/ApiExample.tsx +9 -0
  55. package/bin/mint/client/src/components/Card.tsx +51 -0
  56. package/bin/mint/client/src/components/CodeGroup.tsx +132 -0
  57. package/bin/mint/client/src/components/Editor.tsx +12 -0
  58. package/bin/mint/client/src/components/Expandable.tsx +40 -0
  59. package/bin/mint/client/src/components/Heading.tsx +84 -0
  60. package/bin/mint/client/src/components/Param.tsx +56 -0
  61. package/bin/mint/client/src/components/Request.tsx +19 -0
  62. package/bin/mint/client/src/components/ResponseField.tsx +33 -0
  63. package/bin/mint/client/src/components/TabBar.tsx +61 -0
  64. package/bin/mint/client/src/config.ts +115 -0
  65. package/bin/mint/client/src/css/bar-of-progress.css +10 -0
  66. package/bin/mint/client/src/css/base.css +29 -0
  67. package/bin/mint/client/src/css/font-awesome.css +7 -0
  68. package/bin/mint/client/src/css/fonts.css +44 -0
  69. package/bin/mint/client/src/css/main.css +11 -0
  70. package/bin/mint/client/src/css/prism.css +270 -0
  71. package/bin/mint/client/src/css/utilities.css +43 -0
  72. package/bin/mint/client/src/enums/components.ts +8 -0
  73. package/bin/mint/client/src/fonts/FiraCode-VF.woff +0 -0
  74. package/bin/mint/client/src/fonts/FiraCode-VF.woff2 +0 -0
  75. package/bin/mint/client/src/fonts/IBMPlexMono-Regular.ttf +0 -0
  76. package/bin/mint/client/src/fonts/IBMPlexMono-SemiBold.ttf +0 -0
  77. package/bin/mint/client/src/fonts/Inter-italic-latin.var.woff2 +0 -0
  78. package/bin/mint/client/src/fonts/Inter-roman-latin.var.woff2 +0 -0
  79. package/bin/mint/client/src/fonts/Pally-Variable.ttf +0 -0
  80. package/bin/mint/client/src/fonts/SourceSansPro-Regular.otf +0 -0
  81. package/bin/mint/client/src/fonts/SourceSerifPro-Regular.ttf +0 -0
  82. package/bin/mint/client/src/fonts/Synonym-Variable.ttf +0 -0
  83. package/bin/mint/client/src/fonts/Ubuntu-Mono-bold.woff2 +0 -0
  84. package/bin/mint/client/src/fonts/generated/IBMPlexMono-Regular-subset.woff2 +0 -0
  85. package/bin/mint/client/src/fonts/generated/IBMPlexMono-Regular-subset.zopfli.woff +0 -0
  86. package/bin/mint/client/src/fonts/generated/IBMPlexMono-Regular.module.css +11 -0
  87. package/bin/mint/client/src/fonts/generated/IBMPlexMono-SemiBold-subset.woff2 +0 -0
  88. package/bin/mint/client/src/fonts/generated/IBMPlexMono-SemiBold-subset.zopfli.woff +0 -0
  89. package/bin/mint/client/src/fonts/generated/IBMPlexMono-SemiBold.module.css +11 -0
  90. package/bin/mint/client/src/fonts/generated/Pally-Variable-subset.woff2 +0 -0
  91. package/bin/mint/client/src/fonts/generated/Pally-Variable-subset.zopfli.woff +0 -0
  92. package/bin/mint/client/src/fonts/generated/Pally-Variable.module.css +11 -0
  93. package/bin/mint/client/src/fonts/generated/SourceSerifPro-Regular-subset.woff2 +0 -0
  94. package/bin/mint/client/src/fonts/generated/SourceSerifPro-Regular-subset.zopfli.woff +0 -0
  95. package/bin/mint/client/src/fonts/generated/SourceSerifPro-Regular.module.css +11 -0
  96. package/bin/mint/client/src/fonts/generated/Synonym-Variable-subset.woff2 +0 -0
  97. package/bin/mint/client/src/fonts/generated/Synonym-Variable-subset.zopfli.woff +0 -0
  98. package/bin/mint/client/src/fonts/generated/Synonym-Variable.module.css +11 -0
  99. package/bin/mint/client/src/fonts/generated/TenorSans-Regular-subset.woff2 +0 -0
  100. package/bin/mint/client/src/fonts/generated/TenorSans-Regular-subset.zopfli.woff +0 -0
  101. package/bin/mint/client/src/fonts/generated/TenorSans-Regular.module.css +11 -0
  102. package/bin/mint/client/src/hooks/useActionKey.ts +20 -0
  103. package/bin/mint/client/src/hooks/useIsomorphicLayoutEffect.ts +3 -0
  104. package/bin/mint/client/src/hooks/useMedia.ts +27 -0
  105. package/bin/mint/client/src/hooks/usePrevNext.ts +34 -0
  106. package/bin/mint/client/src/hooks/useTop.ts +15 -0
  107. package/bin/mint/client/src/icons/CopyToClipboard.tsx +33 -0
  108. package/bin/mint/client/src/index.d.ts +1 -0
  109. package/bin/mint/client/src/layouts/ApiSupplemental.tsx +173 -0
  110. package/bin/mint/client/src/layouts/ContentsLayout.tsx +256 -0
  111. package/bin/mint/client/src/layouts/DocumentationLayout.tsx +44 -0
  112. package/bin/mint/client/src/layouts/OpenApiContent.tsx +301 -0
  113. package/bin/mint/client/src/layouts/SidebarLayout.tsx +412 -0
  114. package/bin/mint/client/src/layouts/UserFeedback.tsx +73 -0
  115. package/bin/mint/client/src/layouts/getGroupsInDivision.ts +25 -0
  116. package/bin/mint/client/src/layouts/isPathInGroupPages.ts +10 -0
  117. package/bin/mint/client/src/metadata.ts +58 -0
  118. package/bin/mint/client/src/nav.json +219 -0
  119. package/bin/mint/client/src/openapi.ts +3 -0
  120. package/bin/mint/client/src/pages/404.tsx +73 -0
  121. package/bin/mint/client/src/pages/_app.tsx +138 -0
  122. package/bin/mint/client/src/pages/_document.tsx +57 -0
  123. package/bin/mint/client/src/pages/api/issue.ts +10 -0
  124. package/bin/mint/client/src/pages/api/name.ts +8 -0
  125. package/bin/mint/client/src/pages/api/request.ts +31 -0
  126. package/bin/mint/client/src/pages/api/suggest.ts +10 -0
  127. package/bin/mint/client/src/pages/api/syntax-highlighted-json.ts +13 -0
  128. package/bin/mint/client/src/pages/api/utils.ts +6 -0
  129. package/bin/mint/client/src/pages/index.tsx +31 -0
  130. package/bin/mint/client/src/ui/Api.tsx +359 -0
  131. package/bin/mint/client/src/ui/Footer.tsx +124 -0
  132. package/bin/mint/client/src/ui/Header.tsx +370 -0
  133. package/bin/mint/client/src/ui/Logo.tsx +55 -0
  134. package/bin/mint/client/src/ui/PageHeader.tsx +51 -0
  135. package/bin/mint/client/src/ui/Search.tsx +386 -0
  136. package/bin/mint/client/src/ui/ThemeToggle.tsx +285 -0
  137. package/bin/mint/client/src/ui/Title.tsx +22 -0
  138. package/bin/mint/client/src/ui/TopLevelLink.tsx +122 -0
  139. package/bin/mint/client/src/utils/api.ts +252 -0
  140. package/bin/mint/client/src/utils/brands.ts +217 -0
  141. package/bin/mint/client/src/utils/castArray.ts +3 -0
  142. package/bin/mint/client/src/utils/childrenArray.ts +3 -0
  143. package/bin/mint/client/src/utils/fit.ts +27 -0
  144. package/bin/mint/client/src/utils/fontAwesome.ts +577 -0
  145. package/bin/mint/client/src/utils/getAnalyticsConfig.ts +14 -0
  146. package/bin/mint/client/src/utils/getLogoHref.ts +9 -0
  147. package/bin/mint/client/src/utils/getOpenApiContext.ts +26 -0
  148. package/bin/mint/client/src/utils/importAll.ts +6 -0
  149. package/bin/mint/client/src/utils/isObject.ts +3 -0
  150. package/bin/mint/client/src/utils/kebabToTitleCase.ts +3 -0
  151. package/bin/mint/client/src/utils/loadImage.ts +8 -0
  152. package/bin/mint/client/src/utils/slugToTitle.ts +7 -0
  153. package/bin/mint/client/src/utils/wait.ts +5 -0
  154. package/bin/mint/client/tailwind.config.cjs +323 -0
  155. package/bin/mint/client/test/test.test.ts +5 -0
  156. package/bin/mint/client/tsconfig.json +36 -0
  157. package/bin/mint/client/yarn.lock +9702 -0
  158. package/bin/scraping/detectFramework.js +12 -3
  159. package/bin/scraping/detectFramework.js.map +1 -1
  160. package/bin/scraping/scrapeFileGettingFileNameFromUrl.js +2 -2
  161. package/bin/scraping/scrapeFileGettingFileNameFromUrl.js.map +1 -1
  162. package/bin/scraping/scrapeGettingFileNameFromUrl.js +3 -3
  163. package/bin/scraping/scrapeGettingFileNameFromUrl.js.map +1 -1
  164. package/bin/scraping/scrapePage.js +2 -2
  165. package/bin/scraping/scrapePage.js.map +1 -1
  166. package/bin/scraping/scrapePageCommands.js +6 -6
  167. package/bin/scraping/scrapePageCommands.js.map +1 -1
  168. package/bin/scraping/scrapeSection.js +2 -2
  169. package/bin/scraping/scrapeSection.js.map +1 -1
  170. package/bin/scraping/scrapeSectionCommands.js +8 -7
  171. package/bin/scraping/scrapeSectionCommands.js.map +1 -1
  172. package/bin/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.js +36 -0
  173. package/bin/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.js.map +1 -0
  174. package/bin/scraping/site-scrapers/links-per-group/getLinksRecursively.js +38 -0
  175. package/bin/scraping/site-scrapers/links-per-group/getLinksRecursively.js.map +1 -0
  176. package/bin/scraping/site-scrapers/scrapeDocusaurusPage.js +14 -8
  177. package/bin/scraping/site-scrapers/scrapeDocusaurusPage.js.map +1 -1
  178. package/bin/scraping/site-scrapers/scrapeDocusaurusSection.js +4 -29
  179. package/bin/scraping/site-scrapers/scrapeDocusaurusSection.js.map +1 -1
  180. package/bin/scraping/site-scrapers/scrapeGitBookPage.js +2 -1
  181. package/bin/scraping/site-scrapers/scrapeGitBookPage.js.map +1 -1
  182. package/bin/scraping/site-scrapers/scrapeGitBookSection.js +7 -5
  183. package/bin/scraping/site-scrapers/scrapeGitBookSection.js.map +1 -1
  184. package/bin/scraping/site-scrapers/scrapeReadMePage.js +2 -1
  185. package/bin/scraping/site-scrapers/scrapeReadMePage.js.map +1 -1
  186. package/bin/scraping/site-scrapers/scrapeReadMeSection.js +3 -3
  187. package/bin/scraping/site-scrapers/scrapeReadMeSection.js.map +1 -1
  188. package/package.json +1 -1
  189. package/src/index.ts +0 -16
  190. package/src/scraping/detectFramework.ts +13 -3
  191. package/src/scraping/scrapeFileGettingFileNameFromUrl.ts +5 -2
  192. package/src/scraping/scrapeGettingFileNameFromUrl.ts +5 -1
  193. package/src/scraping/scrapePage.ts +6 -3
  194. package/src/scraping/scrapePageCommands.ts +10 -6
  195. package/src/scraping/scrapeSection.ts +9 -2
  196. package/src/scraping/scrapeSectionCommands.ts +24 -7
  197. package/src/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.ts +46 -0
  198. package/src/scraping/site-scrapers/{getLinksRecursively.ts → links-per-group/getLinksRecursively.ts} +0 -0
  199. package/src/scraping/site-scrapers/scrapeDocusaurusPage.ts +20 -8
  200. package/src/scraping/site-scrapers/scrapeDocusaurusSection.ts +9 -33
  201. package/src/scraping/site-scrapers/scrapeGitBookPage.ts +2 -1
  202. package/src/scraping/site-scrapers/scrapeGitBookSection.ts +9 -5
  203. package/src/scraping/site-scrapers/scrapeReadMePage.ts +2 -1
  204. package/src/scraping/site-scrapers/scrapeReadMeSection.ts +4 -2
  205. package/bin/local-preview/helper-commands/cleanCommand.js +0 -8
  206. package/bin/local-preview/helper-commands/cleanCommand.js.map +0 -1
@@ -0,0 +1,122 @@
1
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
2
+ import clsx from 'clsx';
3
+ import Link from 'next/link';
4
+ import { forwardRef } from 'react';
5
+
6
+ import { config } from '@/config';
7
+ import {
8
+ getAnchorBackgroundColor,
9
+ getAnchorHoverBackgroundColor,
10
+ getAnchorShadowColor,
11
+ getAnchorTextColor,
12
+ } from '@/utils/brands';
13
+ import { isBrandFontAwesomeIcon } from '@/utils/fontAwesome';
14
+
15
+ type TopLevelProps = {
16
+ href: string;
17
+ i: number;
18
+ isActive: boolean;
19
+ children?: any;
20
+ className?: string;
21
+ color?: string;
22
+ onClick?: (el: any) => void;
23
+ icon?: any;
24
+ shadow?: string;
25
+ mobile?: boolean;
26
+ name?: string;
27
+ as?: string;
28
+ };
29
+
30
+ const TopLevelAnchor = forwardRef(
31
+ ({ children, href, className, icon, isActive, onClick, color, i }: TopLevelProps, ref: any) => {
32
+ const activeBackgroundColor =
33
+ config.classes?.activeAnchors ?? getAnchorBackgroundColor(i, color);
34
+ const hoverBackgroundColor = config.classes?.anchors ?? getAnchorHoverBackgroundColor(i, color);
35
+ const shadowColor = getAnchorShadowColor(i, color);
36
+ return (
37
+ <li>
38
+ <a
39
+ ref={ref}
40
+ href={href}
41
+ onClick={onClick}
42
+ className={clsx(
43
+ 'group flex items-center lg:text-sm lg:leading-6',
44
+ className,
45
+ isActive
46
+ ? ['font-semibold', getAnchorTextColor(i, color)]
47
+ : 'font-medium text-slate-600 hover:text-slate-900 dark:text-slate-400 dark:hover:text-slate-300'
48
+ )}
49
+ >
50
+ <div
51
+ className={clsx(
52
+ `mr-4 rounded-md ring-slate-900/5 group-hover:ring-slate-900/10 dark:group-hover:highlight-white/10`,
53
+ shadowColor || 'shadow-primary/40',
54
+ hoverBackgroundColor,
55
+ isActive
56
+ ? [activeBackgroundColor, 'highlight-slate-700/10 dark:highlight-white/10']
57
+ : 'bg-slate-300 highlight-slate-700/5 dark:bg-slate-800 dark:highlight-white/5'
58
+ )}
59
+ >
60
+ {icon}
61
+ </div>
62
+ {children}
63
+ </a>
64
+ </li>
65
+ );
66
+ }
67
+ );
68
+
69
+ export function TopLevelLink({ ...props }: TopLevelProps) {
70
+ const { href, as } = props;
71
+ if (/^https?:\/\//.test(href)) {
72
+ return <TopLevelAnchor {...props} />;
73
+ }
74
+
75
+ return (
76
+ <Link href={href} as={as} passHref>
77
+ <TopLevelAnchor {...props} />
78
+ </Link>
79
+ );
80
+ }
81
+
82
+ export function StyledTopLevelLink({
83
+ href,
84
+ as,
85
+ name,
86
+ icon,
87
+ color,
88
+ isActive,
89
+ i,
90
+ ...props
91
+ }: TopLevelProps) {
92
+ const isBrandIcon = isBrandFontAwesomeIcon(icon);
93
+ const iconPrefix = isBrandIcon ? 'fab' : 'fad';
94
+ const Icon =
95
+ icon == null ? (
96
+ <div className="h-6 w-px"></div>
97
+ ) : (
98
+ <FontAwesomeIcon
99
+ className={clsx(
100
+ `h-6 w-6 p-1 text-white secondary-opacity group-hover:fill-primary-dark dark:group-hover:text-white`,
101
+ isBrandIcon && 'fa-secondary',
102
+ isActive ? 'dark:text-white' : 'dark:text-slate-500',
103
+ color == null && 'dark:group-hover:text-white'
104
+ )}
105
+ icon={[iconPrefix, icon.toLowerCase()]}
106
+ />
107
+ );
108
+ return (
109
+ <TopLevelLink
110
+ {...props}
111
+ as={as}
112
+ href={href}
113
+ className="mb-4"
114
+ icon={Icon}
115
+ isActive={isActive}
116
+ color={color}
117
+ i={i}
118
+ >
119
+ {name ?? href}
120
+ </TopLevelLink>
121
+ );
122
+ }
@@ -0,0 +1,252 @@
1
+ import { AxiosRequestHeaders } from 'axios';
2
+ import isAbsoluteUrl from 'is-absolute-url';
3
+
4
+ import { ParamProps } from '@/components/Param';
5
+ import { config } from '@/config';
6
+ import { Component } from '@/enums/components';
7
+ import { openApi } from '@/openapi';
8
+ import { ApiComponent } from '@/ui/Api';
9
+
10
+ export type MediaType = 'json' | 'form';
11
+
12
+ export type Child = {
13
+ props: ParamProps & { mdxType: string };
14
+ };
15
+
16
+ export type Children = Child[];
17
+
18
+ export type Param = {
19
+ name: string;
20
+ placeholder?: string;
21
+ required?: boolean;
22
+ type?: string;
23
+ enum?: string[];
24
+ format?: string;
25
+ };
26
+
27
+ export type ParamGroup = {
28
+ name: string;
29
+ params: Param[];
30
+ };
31
+
32
+ const paramTypeToNameMap: Record<string, string> = {
33
+ auth: 'Authorization',
34
+ query: 'Query',
35
+ path: 'Path',
36
+ body: 'Body',
37
+ };
38
+
39
+ const getPlaceholderFromObjectOrString = (value: any): undefined => {
40
+ return (typeof value === 'string' && value) || value?.value?.toString();
41
+ };
42
+
43
+ const removeEmpty = (obj?: Object) => {
44
+ if (!obj) return obj;
45
+
46
+ return Object.fromEntries(Object.entries(obj).filter(([_, v]) => v || v === false));
47
+ };
48
+
49
+ const potentiallAddPathParams = (inputUrl: string, inputData: Record<string, any>) => {
50
+ let url = inputUrl;
51
+ if (inputData.Path) {
52
+ Object.entries(inputData.Path).forEach(([pathName, pathValue]: [string, any]) => {
53
+ if (!pathValue) {
54
+ return;
55
+ }
56
+ url = url.replace(`{${pathName}}`, pathValue);
57
+ });
58
+ }
59
+
60
+ return url;
61
+ };
62
+
63
+ const getApiBody = (obj: Object, media: MediaType) => {
64
+ if (media === 'form') {
65
+ let cleanedObj = removeEmpty(obj);
66
+ const bodyFormData = new FormData();
67
+ for (var key in cleanedObj) {
68
+ bodyFormData.append(key, cleanedObj[key]);
69
+ }
70
+
71
+ return bodyFormData;
72
+ }
73
+ return removeEmpty(obj);
74
+ };
75
+
76
+ export const getApiContext = (
77
+ apiBase: string,
78
+ path: string,
79
+ inputData: Record<string, any>,
80
+ media: MediaType
81
+ ): { url: string; body?: Object; params?: Object; headers?: AxiosRequestHeaders } => {
82
+ const endpoint = `${apiBase}${path}`;
83
+ const url = potentiallAddPathParams(endpoint, inputData);
84
+ const body = getApiBody(inputData.Body, media);
85
+ const params = removeEmpty(inputData.Query);
86
+ const headers: AxiosRequestHeaders = {};
87
+
88
+ if (inputData.Authorization) {
89
+ const authEntires = Object.entries(inputData.Authorization);
90
+ if (config.api?.auth?.method === 'basic' && authEntires.length === 2) {
91
+ let [[usernameField, username], [, password]]: any = authEntires;
92
+ // Get order based on username:password
93
+ if (
94
+ (config.api.auth.name && config.api.auth.name.split(':')[0] !== usernameField) ||
95
+ (!config.api.auth.name && usernameField.toLowerCase() !== 'username')
96
+ ) {
97
+ // switch orders
98
+ const temp = username;
99
+ username = password;
100
+ password = temp;
101
+ }
102
+ headers.Authorization =
103
+ 'Basic ' + Buffer.from(`${username}:${password}`, 'utf8').toString('base64');
104
+ } else {
105
+ authEntires.forEach(([authName, authValue]: [string, any]) => {
106
+ if (authName === 'Bearer') {
107
+ headers.Authorization = `Bearer ${authValue}`;
108
+ return;
109
+ }
110
+
111
+ headers[authName] = authValue;
112
+ });
113
+ }
114
+ }
115
+
116
+ return { url, body, params, headers };
117
+ };
118
+
119
+ export const extractMethodAndEndpoint = (api: string) => {
120
+ const methodRegex = /^get|post|put|delete|patch/i;
121
+ const foundMethod = api.trim().match(methodRegex);
122
+
123
+ const endIndexOfMethod = foundMethod ? api.indexOf(foundMethod[0]) + foundMethod[0].length : 0;
124
+
125
+ return {
126
+ method: foundMethod ? foundMethod[0].toUpperCase() : undefined,
127
+ endpoint: api.substring(endIndexOfMethod).trim(),
128
+ };
129
+ };
130
+
131
+ export const extractBaseAndPath = (endpoint: string, apiBaseIndex = 0) => {
132
+ let fullEndpoint;
133
+ const baseUrl =
134
+ config.api?.baseUrl ?? openApi?.servers?.map((server: { url: string }) => server.url);
135
+ if (isAbsoluteUrl(endpoint)) {
136
+ fullEndpoint = endpoint;
137
+ } else if (baseUrl) {
138
+ const selectedBase = Array.isArray(baseUrl) ? baseUrl[apiBaseIndex] : baseUrl;
139
+ fullEndpoint = `${selectedBase}${endpoint}`;
140
+ } else {
141
+ throw new Error('Invalid endpoint');
142
+ }
143
+
144
+ const url = new URL(fullEndpoint);
145
+ const base = url.origin;
146
+ const path = fullEndpoint.substring(fullEndpoint.indexOf(base) + base.length);
147
+
148
+ return {
149
+ path,
150
+ base,
151
+ };
152
+ };
153
+
154
+ export const getParamGroupsFromAPIComponents = (
155
+ apiComponents?: ApiComponent[],
156
+ auth?: string
157
+ ): ParamGroup[] => {
158
+ const groups: Record<string, Param[]> = {};
159
+
160
+ // Add auth if configured
161
+ if (auth?.toLowerCase() !== 'none') {
162
+ if (config.api?.auth?.name) {
163
+ groups.Authorization = [
164
+ {
165
+ name: config.api.auth.name,
166
+ required: true,
167
+ },
168
+ ];
169
+ }
170
+
171
+ if (config.api?.auth?.method === 'basic') {
172
+ const name = config.api.auth.name || 'username:password';
173
+ groups.Authorization = name.split(':').map((section) => {
174
+ return {
175
+ name: section,
176
+ required: true,
177
+ };
178
+ });
179
+ }
180
+
181
+ if (config.api?.auth?.method?.toLowerCase() === 'bearer' || auth?.toLowerCase() === 'bearer') {
182
+ groups.Authorization = [
183
+ {
184
+ name: 'Bearer',
185
+ required: true,
186
+ },
187
+ ];
188
+ }
189
+ }
190
+
191
+ const paramFields = apiComponents
192
+ ?.filter((apiComponent) => apiComponent.type === Component.ParamField)
193
+ .map((apiComponent) => {
194
+ const attributesMap: Record<any, any> = {};
195
+ apiComponent?.attributes?.forEach((attribute: any) => {
196
+ attributesMap[attribute.name] = attribute.value;
197
+ });
198
+
199
+ return attributesMap;
200
+ });
201
+
202
+ paramFields?.forEach((paramField) => {
203
+ let paramType;
204
+ if (paramField?.query) {
205
+ paramType = 'query';
206
+ } else if (paramField?.path) {
207
+ paramType = 'path';
208
+ } else if (paramField?.body) {
209
+ paramType = 'body';
210
+ }
211
+
212
+ if (!paramType) {
213
+ return;
214
+ }
215
+
216
+ const groupName = paramTypeToNameMap[paramType];
217
+ const existingGroup = groups[groupName];
218
+
219
+ const { query, body, path } = paramField;
220
+
221
+ let name = query || body || path;
222
+
223
+ if (!name) {
224
+ return;
225
+ }
226
+
227
+ const { placeholder, default: defaultValue, required, type, enum: enumValues } = paramField;
228
+
229
+ const param = {
230
+ name,
231
+ placeholder:
232
+ getPlaceholderFromObjectOrString(placeholder) ||
233
+ getPlaceholderFromObjectOrString(defaultValue),
234
+ required: required === null || required === true, // intentionally check for just null or true
235
+ type,
236
+ enum: enumValues,
237
+ };
238
+
239
+ if (existingGroup) {
240
+ groups[groupName] = [...existingGroup, param];
241
+ } else {
242
+ groups[groupName] = [param];
243
+ }
244
+ });
245
+
246
+ return Object.entries(groups).map(([groupName, params]) => {
247
+ return {
248
+ name: groupName,
249
+ params,
250
+ };
251
+ });
252
+ };
@@ -0,0 +1,217 @@
1
+ // For PostCSS parsers
2
+ export const getAnchorBackgroundColor = (i: number, color?: string) => {
3
+ if (!color) {
4
+ return 'bg-primary';
5
+ }
6
+
7
+ switch (i) {
8
+ case 0:
9
+ return 'bg-anchor-0';
10
+ case 1:
11
+ return 'bg-anchor-1';
12
+ case 2:
13
+ return 'bg-anchor-2';
14
+ case 3:
15
+ return 'bg-anchor-3';
16
+ case 4:
17
+ return 'bg-anchor-4';
18
+ case 5:
19
+ return 'bg-anchor-5';
20
+ case 6:
21
+ return 'bg-anchor-6';
22
+ case 7:
23
+ return 'bg-anchor-7';
24
+ case 8:
25
+ return 'bg-anchor-8';
26
+ case 9:
27
+ return 'bg-anchor-9';
28
+ case 10:
29
+ return 'bg-anchor-10';
30
+ default:
31
+ return 'bg-primary';
32
+ }
33
+ };
34
+
35
+ export const getAnchorHoverBackgroundColor = (i: number, color?: string) => {
36
+ if (!color) {
37
+ return 'group-hover:bg-primary';
38
+ }
39
+
40
+ switch (i) {
41
+ case 0:
42
+ return 'group-hover:bg-anchor-0';
43
+ case 1:
44
+ return 'group-hover:bg-anchor-1';
45
+ case 2:
46
+ return 'group-hover:bg-anchor-2';
47
+ case 3:
48
+ return 'group-hover:bg-anchor-3';
49
+ case 4:
50
+ return 'group-hover:bg-anchor-4';
51
+ case 5:
52
+ return 'group-hover:bg-anchor-5';
53
+ case 6:
54
+ return 'group-hover:bg-anchor-6';
55
+ case 7:
56
+ return 'group-hover:bg-anchor-7';
57
+ case 8:
58
+ return 'group-hover:bg-anchor-8';
59
+ case 9:
60
+ return 'group-hover:bg-anchor-9';
61
+ case 10:
62
+ return 'group-hover:bg-anchor-10';
63
+ default:
64
+ return 'group-hover:bg-primary';
65
+ }
66
+ };
67
+
68
+ export const getAnchorTextColor = (i: number, color?: string) => {
69
+ if (!color) {
70
+ return 'text-primary dark:text-primary-light';
71
+ }
72
+
73
+ switch (i) {
74
+ case 0:
75
+ return 'text-anchor-0';
76
+ case 1:
77
+ return 'text-anchor-1';
78
+ case 2:
79
+ return 'text-anchor-2';
80
+ case 3:
81
+ return 'text-anchor-3';
82
+ case 4:
83
+ return 'text-anchor-4';
84
+ case 5:
85
+ return 'text-anchor-5';
86
+ case 6:
87
+ return 'text-anchor-6';
88
+ case 7:
89
+ return 'text-anchor-7';
90
+ case 8:
91
+ return 'text-anchor-8';
92
+ case 9:
93
+ return 'text-anchor-9';
94
+ case 10:
95
+ return 'text-anchor-10';
96
+ default:
97
+ return 'text-primary dark:text-primary-light';
98
+ }
99
+ };
100
+
101
+ export const getAnchorShadowColor = (i: number, color?: string) => {
102
+ if (!color) {
103
+ return 'shadow-primary/40';
104
+ }
105
+
106
+ switch (i) {
107
+ case 0:
108
+ return 'shadow-anchor-0/40';
109
+ case 1:
110
+ return 'shadow-anchor-1/40';
111
+ case 2:
112
+ return 'shadow-anchor-2/40';
113
+ case 3:
114
+ return 'shadow-anchor-3/40';
115
+ case 4:
116
+ return 'shadow-anchor-4/40';
117
+ case 5:
118
+ return 'shadow-anchor-5/40';
119
+ case 6:
120
+ return 'shadow-anchor-6/40';
121
+ case 7:
122
+ return 'shadow-anchor-7/40';
123
+ case 8:
124
+ return 'shadow-anchor-8/40';
125
+ case 9:
126
+ return 'shadow-anchor-9/40';
127
+ case 10:
128
+ return 'shadow-anchor-10/40';
129
+ default:
130
+ return 'shadow-primary/40';
131
+ }
132
+ };
133
+
134
+ export const getMethodDotsColor = (method?: string) => {
135
+ switch (method?.toUpperCase()) {
136
+ case 'GET':
137
+ return 'bg-green-600/80 dark:bg-green-400/80';
138
+ case 'POST':
139
+ return 'bg-blue-600/80 dark:bg-blue-400/80';
140
+ case 'PUT':
141
+ return 'bg-yellow-600/80 dark:bg-yellow-400/80';
142
+ case 'DELETE':
143
+ return 'bg-red-600/80 dark:bg-red-400/80';
144
+ case 'PATCH':
145
+ return 'bg-orange-600/80 dark:bg-orange-400/80';
146
+ default:
147
+ return 'bg-slate-600 dark:bg-slate-400/80';
148
+ }
149
+ };
150
+
151
+ export const getMethodBgColor = (method?: string) => {
152
+ switch (method?.toUpperCase()) {
153
+ case 'GET':
154
+ return 'bg-green-600';
155
+ case 'POST':
156
+ return 'bg-blue-600';
157
+ case 'PUT':
158
+ return 'bg-yellow-600';
159
+ case 'DELETE':
160
+ return 'bg-red-600';
161
+ case 'PATCH':
162
+ return 'bg-orange-600';
163
+ default:
164
+ return 'bg-slate-600';
165
+ }
166
+ };
167
+
168
+ export const getMethodBgColorWithHover = (method?: string) => {
169
+ switch (method?.toUpperCase()) {
170
+ case 'GET':
171
+ return 'bg-green-600 hover:bg-green-800 disabled:bg-green-700';
172
+ case 'POST':
173
+ return 'bg-blue-600 hover:bg-blue-800 disabled:bg-blue-700';
174
+ case 'PUT':
175
+ return 'bg-yellow-600 hover:bg-yellow-800 disabled:bg-yellow-700';
176
+ case 'DELETE':
177
+ return 'bg-red-600 hover:bg-red-800 disabled:bg-red-700';
178
+ case 'PATCH':
179
+ return 'bg-orange-600 hover:bg-orange-800 disabled:bg-orange-700';
180
+ default:
181
+ return 'bg-slate-600 hover:bg-slate-800 disabled:bg-slate-700';
182
+ }
183
+ };
184
+
185
+ export const getMethodTextColor = (method?: string) => {
186
+ switch (method?.toUpperCase()) {
187
+ case 'GET':
188
+ return 'text-green-600 dark:text-green-500';
189
+ case 'POST':
190
+ return 'text-blue-600 dark:text-blue-500';
191
+ case 'PUT':
192
+ return 'text-yellow-600 dark:text-yellow-500';
193
+ case 'DELETE':
194
+ return 'text-red-600 dark:text-red-500';
195
+ case 'PATCH':
196
+ return 'text-orange-600 dark:text-orange-500';
197
+ default:
198
+ return 'text-slate-600 dark:text-slate-500';
199
+ }
200
+ };
201
+
202
+ export const getMethodBorderColor = (method?: string) => {
203
+ switch (method?.toUpperCase()) {
204
+ case 'GET':
205
+ return 'border-green-600 dark:border-green-500';
206
+ case 'POST':
207
+ return 'border-blue-600 dark:border-blue-500';
208
+ case 'PUT':
209
+ return 'border-yellow-600 dark:border-yellow-500';
210
+ case 'DELETE':
211
+ return 'border-red-600 dark:border-red-500';
212
+ case 'PATCH':
213
+ return 'border-orange-600 dark:border-orange-500';
214
+ default:
215
+ return 'border-slate-600 dark:border-slate-500';
216
+ }
217
+ };
@@ -0,0 +1,3 @@
1
+ export function castArray(value: any) {
2
+ return Array.isArray(value) ? value : [value]
3
+ }
@@ -0,0 +1,3 @@
1
+ export const childrenArray = (children: any) => {
2
+ return Array.isArray(children) ? children.flat() : [children];
3
+ };
@@ -0,0 +1,27 @@
1
+ export function fit(
2
+ parentWidth: number,
3
+ parentHeight: number,
4
+ childWidth: number,
5
+ childHeight: number,
6
+ scale = 1,
7
+ offsetX = 0.5,
8
+ offsetY = 0.5
9
+ ) {
10
+ const childRatio = childWidth / childHeight
11
+ const parentRatio = parentWidth / parentHeight
12
+ let width = parentWidth * scale
13
+ let height = parentHeight * scale
14
+
15
+ if (childRatio < parentRatio) {
16
+ height = width / childRatio
17
+ } else {
18
+ width = height * childRatio
19
+ }
20
+
21
+ return {
22
+ width: Math.round(width),
23
+ height: Math.round(height),
24
+ left: Math.round((parentWidth - width) * offsetX),
25
+ top: Math.round((parentHeight - height) * offsetY),
26
+ }
27
+ }