docusaurus-theme-openapi-docs 1.0.0

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 (187) hide show
  1. package/LICENSE +21 -0
  2. package/babel.config.js +35 -0
  3. package/lib/index.js +48 -0
  4. package/lib/markdown/createDescription.js +20 -0
  5. package/lib/markdown/schema.js +121 -0
  6. package/lib/markdown/utils.js +45 -0
  7. package/lib/theme/ApiDemoPanel/Accept/index.js +41 -0
  8. package/lib/theme/ApiDemoPanel/Accept/slice.js +32 -0
  9. package/lib/theme/ApiDemoPanel/Authorization/auth-types.js +32 -0
  10. package/lib/theme/ApiDemoPanel/Authorization/index.js +174 -0
  11. package/lib/theme/ApiDemoPanel/Authorization/slice.js +137 -0
  12. package/lib/theme/ApiDemoPanel/Body/index.js +185 -0
  13. package/lib/theme/ApiDemoPanel/Body/slice.js +105 -0
  14. package/lib/theme/ApiDemoPanel/ContentType/index.js +41 -0
  15. package/lib/theme/ApiDemoPanel/ContentType/slice.js +32 -0
  16. package/lib/theme/ApiDemoPanel/Curl/index.js +236 -0
  17. package/lib/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
  18. package/lib/theme/ApiDemoPanel/Execute/index.js +85 -0
  19. package/lib/theme/ApiDemoPanel/Execute/makeRequest.js +202 -0
  20. package/lib/theme/ApiDemoPanel/FloatingButton/index.js +32 -0
  21. package/lib/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
  22. package/lib/theme/ApiDemoPanel/FormFileUpload/index.js +97 -0
  23. package/lib/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
  24. package/lib/theme/ApiDemoPanel/FormItem/index.js +35 -0
  25. package/lib/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
  26. package/lib/theme/ApiDemoPanel/FormMultiSelect/index.js +52 -0
  27. package/lib/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
  28. package/lib/theme/ApiDemoPanel/FormSelect/index.js +39 -0
  29. package/lib/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
  30. package/lib/theme/ApiDemoPanel/FormTextInput/index.js +30 -0
  31. package/lib/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
  32. package/lib/theme/ApiDemoPanel/MethodEndpoint/index.js +60 -0
  33. package/lib/theme/ApiDemoPanel/ParamOptions/index.js +248 -0
  34. package/lib/theme/ApiDemoPanel/ParamOptions/slice.js +35 -0
  35. package/lib/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
  36. package/lib/theme/ApiDemoPanel/Response/index.js +75 -0
  37. package/lib/theme/ApiDemoPanel/Response/slice.js +37 -0
  38. package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +51 -0
  39. package/lib/theme/ApiDemoPanel/Server/index.js +109 -0
  40. package/lib/theme/ApiDemoPanel/Server/slice.js +41 -0
  41. package/lib/theme/ApiDemoPanel/Server/styles.module.css +61 -0
  42. package/lib/theme/ApiDemoPanel/VSCode/index.js +252 -0
  43. package/lib/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
  44. package/lib/theme/ApiDemoPanel/buildPostmanRequest.js +329 -0
  45. package/lib/theme/ApiDemoPanel/hooks.js +20 -0
  46. package/lib/theme/ApiDemoPanel/index.js +134 -0
  47. package/lib/theme/ApiDemoPanel/persistanceMiddleware.js +44 -0
  48. package/lib/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
  49. package/lib/theme/ApiDemoPanel/storage-utils.js +47 -0
  50. package/lib/theme/ApiDemoPanel/store.js +48 -0
  51. package/lib/theme/ApiDemoPanel/styles.module.css +44 -0
  52. package/lib/theme/ApiItem/index.js +160 -0
  53. package/lib/theme/ApiItem/styles.module.css +109 -0
  54. package/lib/theme/ParamsItem/index.js +68 -0
  55. package/lib/theme/ParamsItem/styles.module.css +24 -0
  56. package/lib/theme/SchemaItem/index.js +58 -0
  57. package/lib/theme/SchemaItem/styles.module.css +24 -0
  58. package/lib/theme/Tabs/index.js +258 -0
  59. package/lib/theme/Tabs/styles.module.css +118 -0
  60. package/lib/theme-classic.d.ts +8 -0
  61. package/lib/theme-openapi.d.ts +48 -0
  62. package/lib/theme-translations.d.ts +9 -0
  63. package/lib/types.js +1 -0
  64. package/lib-next/index.js +38 -0
  65. package/lib-next/markdown/createDescription.js +13 -0
  66. package/lib-next/markdown/schema.js +115 -0
  67. package/lib-next/markdown/utils.js +31 -0
  68. package/lib-next/theme/ApiDemoPanel/Accept/index.js +33 -0
  69. package/lib-next/theme/ApiDemoPanel/Accept/slice.js +19 -0
  70. package/lib-next/theme/ApiDemoPanel/Authorization/auth-types.js +22 -0
  71. package/lib-next/theme/ApiDemoPanel/Authorization/index.js +203 -0
  72. package/lib-next/theme/ApiDemoPanel/Authorization/slice.js +101 -0
  73. package/lib-next/theme/ApiDemoPanel/Body/index.js +210 -0
  74. package/lib-next/theme/ApiDemoPanel/Body/slice.js +89 -0
  75. package/lib-next/theme/ApiDemoPanel/ContentType/index.js +33 -0
  76. package/lib-next/theme/ApiDemoPanel/ContentType/slice.js +19 -0
  77. package/lib-next/theme/ApiDemoPanel/Curl/index.js +264 -0
  78. package/lib-next/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
  79. package/lib-next/theme/ApiDemoPanel/Execute/index.js +74 -0
  80. package/lib-next/theme/ApiDemoPanel/Execute/makeRequest.js +183 -0
  81. package/lib-next/theme/ApiDemoPanel/FloatingButton/index.js +19 -0
  82. package/lib-next/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
  83. package/lib-next/theme/ApiDemoPanel/FormFileUpload/index.js +113 -0
  84. package/lib-next/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
  85. package/lib-next/theme/ApiDemoPanel/FormItem/index.js +29 -0
  86. package/lib-next/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
  87. package/lib-next/theme/ApiDemoPanel/FormMultiSelect/index.js +49 -0
  88. package/lib-next/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
  89. package/lib-next/theme/ApiDemoPanel/FormSelect/index.js +28 -0
  90. package/lib-next/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
  91. package/lib-next/theme/ApiDemoPanel/FormTextInput/index.js +23 -0
  92. package/lib-next/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
  93. package/lib-next/theme/ApiDemoPanel/MethodEndpoint/index.js +53 -0
  94. package/lib-next/theme/ApiDemoPanel/ParamOptions/index.js +284 -0
  95. package/lib-next/theme/ApiDemoPanel/ParamOptions/slice.js +22 -0
  96. package/lib-next/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
  97. package/lib-next/theme/ApiDemoPanel/Response/index.js +65 -0
  98. package/lib-next/theme/ApiDemoPanel/Response/slice.js +22 -0
  99. package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +48 -0
  100. package/lib-next/theme/ApiDemoPanel/Server/index.js +114 -0
  101. package/lib-next/theme/ApiDemoPanel/Server/slice.js +25 -0
  102. package/lib-next/theme/ApiDemoPanel/Server/styles.module.css +61 -0
  103. package/lib-next/theme/ApiDemoPanel/VSCode/index.js +265 -0
  104. package/lib-next/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
  105. package/lib-next/theme/ApiDemoPanel/buildPostmanRequest.js +310 -0
  106. package/lib-next/theme/ApiDemoPanel/hooks.js +9 -0
  107. package/lib-next/theme/ApiDemoPanel/index.js +110 -0
  108. package/lib-next/theme/ApiDemoPanel/persistanceMiddleware.js +38 -0
  109. package/lib-next/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
  110. package/lib-next/theme/ApiDemoPanel/storage-utils.js +35 -0
  111. package/lib-next/theme/ApiDemoPanel/store.js +30 -0
  112. package/lib-next/theme/ApiDemoPanel/styles.module.css +44 -0
  113. package/lib-next/theme/ApiItem/index.js +171 -0
  114. package/lib-next/theme/ApiItem/styles.module.css +109 -0
  115. package/lib-next/theme/ParamsItem/index.js +68 -0
  116. package/lib-next/theme/ParamsItem/styles.module.css +24 -0
  117. package/lib-next/theme/SchemaItem/index.js +58 -0
  118. package/lib-next/theme/SchemaItem/styles.module.css +24 -0
  119. package/lib-next/theme/Tabs/index.js +258 -0
  120. package/lib-next/theme/Tabs/styles.module.css +118 -0
  121. package/lib-next/theme-classic.d.ts +8 -0
  122. package/lib-next/theme-openapi.d.ts +48 -0
  123. package/lib-next/theme-translations.d.ts +9 -0
  124. package/lib-next/types.js +1 -0
  125. package/package.json +68 -0
  126. package/src/index.ts +42 -0
  127. package/src/markdown/createDescription.ts +13 -0
  128. package/src/markdown/schema.ts +115 -0
  129. package/src/markdown/utils.ts +39 -0
  130. package/src/theme/ApiDemoPanel/Accept/index.tsx +35 -0
  131. package/src/theme/ApiDemoPanel/Accept/slice.ts +29 -0
  132. package/src/theme/ApiDemoPanel/Authorization/auth-types.ts +26 -0
  133. package/src/theme/ApiDemoPanel/Authorization/index.tsx +211 -0
  134. package/src/theme/ApiDemoPanel/Authorization/slice.ts +145 -0
  135. package/src/theme/ApiDemoPanel/Body/index.tsx +218 -0
  136. package/src/theme/ApiDemoPanel/Body/slice.ts +133 -0
  137. package/src/theme/ApiDemoPanel/ContentType/index.tsx +35 -0
  138. package/src/theme/ApiDemoPanel/ContentType/slice.ts +29 -0
  139. package/src/theme/ApiDemoPanel/Curl/index.tsx +280 -0
  140. package/src/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
  141. package/src/theme/ApiDemoPanel/Execute/index.tsx +88 -0
  142. package/src/theme/ApiDemoPanel/Execute/makeRequest.ts +184 -0
  143. package/src/theme/ApiDemoPanel/FloatingButton/index.tsx +27 -0
  144. package/src/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
  145. package/src/theme/ApiDemoPanel/FormFileUpload/index.tsx +116 -0
  146. package/src/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
  147. package/src/theme/ApiDemoPanel/FormItem/index.tsx +28 -0
  148. package/src/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
  149. package/src/theme/ApiDemoPanel/FormMultiSelect/index.tsx +54 -0
  150. package/src/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
  151. package/src/theme/ApiDemoPanel/FormSelect/index.tsx +36 -0
  152. package/src/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
  153. package/src/theme/ApiDemoPanel/FormTextInput/index.tsx +32 -0
  154. package/src/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
  155. package/src/theme/ApiDemoPanel/MethodEndpoint/index.tsx +55 -0
  156. package/src/theme/ApiDemoPanel/ParamOptions/index.tsx +316 -0
  157. package/src/theme/ApiDemoPanel/ParamOptions/slice.ts +37 -0
  158. package/src/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
  159. package/src/theme/ApiDemoPanel/Response/index.tsx +66 -0
  160. package/src/theme/ApiDemoPanel/Response/slice.ts +31 -0
  161. package/src/theme/ApiDemoPanel/SecuritySchemes/index.tsx +49 -0
  162. package/src/theme/ApiDemoPanel/Server/index.tsx +103 -0
  163. package/src/theme/ApiDemoPanel/Server/slice.ts +40 -0
  164. package/src/theme/ApiDemoPanel/Server/styles.module.css +61 -0
  165. package/src/theme/ApiDemoPanel/VSCode/index.tsx +205 -0
  166. package/src/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
  167. package/src/theme/ApiDemoPanel/buildPostmanRequest.ts +307 -0
  168. package/src/theme/ApiDemoPanel/hooks.ts +13 -0
  169. package/src/theme/ApiDemoPanel/index.tsx +118 -0
  170. package/src/theme/ApiDemoPanel/persistanceMiddleware.ts +46 -0
  171. package/src/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
  172. package/src/theme/ApiDemoPanel/storage-utils.ts +39 -0
  173. package/src/theme/ApiDemoPanel/store.ts +41 -0
  174. package/src/theme/ApiDemoPanel/styles.module.css +44 -0
  175. package/src/theme/ApiItem/index.tsx +171 -0
  176. package/src/theme/ApiItem/styles.module.css +109 -0
  177. package/src/theme/ParamsItem/index.js +68 -0
  178. package/src/theme/ParamsItem/styles.module.css +24 -0
  179. package/src/theme/SchemaItem/index.js +58 -0
  180. package/src/theme/SchemaItem/styles.module.css +24 -0
  181. package/src/theme/Tabs/index.js +258 -0
  182. package/src/theme/Tabs/styles.module.css +118 -0
  183. package/src/theme-classic.d.ts +8 -0
  184. package/src/theme-openapi.d.ts +48 -0
  185. package/src/theme-translations.d.ts +9 -0
  186. package/src/types.ts +70 -0
  187. package/tsconfig.json +10 -0
@@ -0,0 +1,264 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+ import React, { useRef, useState, useEffect } from "react";
8
+ import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; // @ts-ignore
9
+
10
+ import codegen from "@paloaltonetworks/postman-code-generators"; // @ts-ignore
11
+
12
+ import clsx from "clsx";
13
+ import Highlight, { defaultProps } from "prism-react-renderer";
14
+ import { useTypedSelector } from "../hooks";
15
+ import buildPostmanRequest from "./../buildPostmanRequest";
16
+ import FloatingButton from "./../FloatingButton";
17
+ import styles from "./styles.module.css";
18
+ const languageSet = [
19
+ {
20
+ tabName: "cURL",
21
+ highlight: "bash",
22
+ language: "curl",
23
+ variant: "curl",
24
+ options: {
25
+ longFormat: false,
26
+ followRedirect: true,
27
+ trimRequestBody: true,
28
+ },
29
+ },
30
+ {
31
+ tabName: "Node",
32
+ highlight: "javascript",
33
+ language: "nodejs",
34
+ variant: "axios",
35
+ options: {
36
+ ES6_enabled: true,
37
+ followRedirect: true,
38
+ trimRequestBody: true,
39
+ },
40
+ },
41
+ {
42
+ tabName: "Go",
43
+ highlight: "go",
44
+ language: "go",
45
+ variant: "native",
46
+ options: {
47
+ followRedirect: true,
48
+ trimRequestBody: true,
49
+ },
50
+ },
51
+ {
52
+ tabName: "Python",
53
+ highlight: "python",
54
+ language: "python",
55
+ variant: "requests",
56
+ options: {
57
+ followRedirect: true,
58
+ trimRequestBody: true,
59
+ },
60
+ },
61
+ ];
62
+ const languageTheme = {
63
+ plain: {
64
+ color: "var(--ifm-code-color)",
65
+ },
66
+ styles: [
67
+ {
68
+ types: ["inserted", "attr-name"],
69
+ style: {
70
+ color: "var(--openapi-code-green)",
71
+ },
72
+ },
73
+ {
74
+ types: ["string", "url"],
75
+ style: {
76
+ color: "var(--openapi-code-green)",
77
+ },
78
+ },
79
+ {
80
+ types: ["builtin", "char", "constant", "function"],
81
+ style: {
82
+ color: "var(--openapi-code-blue)",
83
+ },
84
+ },
85
+ {
86
+ types: ["punctuation", "operator"],
87
+ style: {
88
+ color: "var(--openapi-code-dim)",
89
+ },
90
+ },
91
+ {
92
+ types: ["class-name"],
93
+ style: {
94
+ color: "var(--openapi-code-orange)",
95
+ },
96
+ },
97
+ {
98
+ types: ["tag", "arrow", "keyword"],
99
+ style: {
100
+ color: "var(--openapi-code-purple)",
101
+ },
102
+ },
103
+ {
104
+ types: ["boolean"],
105
+ style: {
106
+ color: "var(--openapi-code-red)",
107
+ },
108
+ },
109
+ ],
110
+ };
111
+
112
+ function Curl({ postman, codeSamples }) {
113
+ // TODO: match theme for vscode.
114
+ const { siteConfig } = useDocusaurusContext();
115
+ const [copyText, setCopyText] = useState("Copy");
116
+ const contentType = useTypedSelector((state) => state.contentType.value);
117
+ const accept = useTypedSelector((state) => state.accept.value);
118
+ const server = useTypedSelector((state) => state.server.value);
119
+ const body = useTypedSelector((state) => state.body);
120
+ const pathParams = useTypedSelector((state) => state.params.path);
121
+ const queryParams = useTypedSelector((state) => state.params.query);
122
+ const cookieParams = useTypedSelector((state) => state.params.cookie);
123
+ const headerParams = useTypedSelector((state) => state.params.header);
124
+ const auth = useTypedSelector((state) => state.auth); // TODO
125
+
126
+ const langs = [
127
+ ...(siteConfig?.themeConfig?.languageTabs ?? languageSet),
128
+ ...codeSamples,
129
+ ];
130
+ const [language, setLanguage] = useState(langs[0]);
131
+ const [codeText, setCodeText] = useState("");
132
+ useEffect(() => {
133
+ if (language && !!language.options) {
134
+ const postmanRequest = buildPostmanRequest(postman, {
135
+ queryParams,
136
+ pathParams,
137
+ cookieParams,
138
+ contentType,
139
+ accept,
140
+ headerParams,
141
+ body,
142
+ server,
143
+ auth,
144
+ });
145
+ codegen.convert(
146
+ language.language,
147
+ language.variant,
148
+ postmanRequest,
149
+ language.options,
150
+ (error, snippet) => {
151
+ if (error) {
152
+ return;
153
+ }
154
+
155
+ setCodeText(snippet);
156
+ }
157
+ );
158
+ } else if (language && !!language.source) {
159
+ setCodeText(language.source);
160
+ } else {
161
+ setCodeText("");
162
+ }
163
+ }, [
164
+ accept,
165
+ body,
166
+ contentType,
167
+ cookieParams,
168
+ headerParams,
169
+ language,
170
+ pathParams,
171
+ postman,
172
+ queryParams,
173
+ server,
174
+ auth,
175
+ ]);
176
+ const ref = useRef(null);
177
+
178
+ const handleCurlCopy = () => {
179
+ setCopyText("Copied");
180
+ setTimeout(() => {
181
+ setCopyText("Copy");
182
+ }, 2000);
183
+
184
+ if (ref.current?.innerText) {
185
+ navigator.clipboard.writeText(ref.current.innerText);
186
+ }
187
+ };
188
+
189
+ if (language === undefined) {
190
+ return null;
191
+ }
192
+
193
+ return (
194
+ <>
195
+ <div className={clsx(styles.buttonGroup, "api-code-tab-group")}>
196
+ {langs.map((lang) => {
197
+ return (
198
+ <button
199
+ key={lang.tabName || lang.label}
200
+ className={clsx(
201
+ language === lang ? styles.selected : undefined,
202
+ language === lang ? "api-code-tab--active" : undefined,
203
+ "api-code-tab"
204
+ )}
205
+ onClick={() => setLanguage(lang)}
206
+ >
207
+ {lang.tabName || lang.label}
208
+ </button>
209
+ );
210
+ })}
211
+ </div>
212
+
213
+ <Highlight
214
+ {...defaultProps}
215
+ theme={languageTheme}
216
+ code={codeText}
217
+ language={language.highlight || language.lang}
218
+ >
219
+ {({ className, tokens, getLineProps, getTokenProps }) => (
220
+ <FloatingButton onClick={handleCurlCopy} label={copyText}>
221
+ <pre
222
+ className={className}
223
+ style={{
224
+ background: "var(--openapi-card-background-color)",
225
+ paddingRight: "60px",
226
+ borderRadius:
227
+ "2px 2px var(--openapi-card-border-radius) var(--openapi-card-border-radius)",
228
+ }}
229
+ >
230
+ <code ref={ref}>
231
+ {tokens.map((line, i) => (
232
+ <span
233
+ {...getLineProps({
234
+ line,
235
+ key: i,
236
+ })}
237
+ >
238
+ {line.map((token, key) => {
239
+ if (token.types.includes("arrow")) {
240
+ token.types = ["arrow"];
241
+ }
242
+
243
+ return (
244
+ <span
245
+ {...getTokenProps({
246
+ token,
247
+ key,
248
+ })}
249
+ />
250
+ );
251
+ })}
252
+ {"\n"}
253
+ </span>
254
+ ))}
255
+ </code>
256
+ </pre>
257
+ </FloatingButton>
258
+ )}
259
+ </Highlight>
260
+ </>
261
+ );
262
+ }
263
+
264
+ export default Curl;
@@ -0,0 +1,84 @@
1
+ .buttonGroup {
2
+ background: var(--openapi-card-background-color);
3
+ color: var(--ifm-pre-color);
4
+ font-family: var(--ifm-font-family-monospace);
5
+ /* font-size: var(--ifm-code-font-size); */
6
+ /* line-height: var(--ifm-pre-line-height); */
7
+ /* margin-bottom: calc(var(--ifm-spacing-vertical) / 4); */
8
+ margin-bottom: 1px;
9
+ margin-top: 0;
10
+ border-radius: var(--openapi-card-border-radius)
11
+ var(--openapi-card-border-radius) 2px 2px;
12
+ display: flex;
13
+ justify-content: flex-end;
14
+ }
15
+
16
+ .buttonGroup button {
17
+ -webkit-appearance: none;
18
+ -moz-appearance: none;
19
+ appearance: none;
20
+
21
+ cursor: pointer;
22
+ /* font-size: calc(0.875rem * var(--ifm-button-size-multiplier)); */
23
+ /* line-height: 1.5; */
24
+ /* font-weight: var(--ifm-button-font-weight); */
25
+
26
+ /* font-size: var(--ifm-code-font-size); */
27
+ font-size: 13.3333px;
28
+ line-height: var(--ifm-pre-line-height);
29
+ font-weight: var(--ifm-font-weight-semibold);
30
+
31
+ padding: calc(
32
+ var(--ifm-button-padding-vertical) * var(--ifm-button-size-multiplier)
33
+ )
34
+ calc(
35
+ var(--ifm-button-padding-horizontal) * var(--ifm-button-size-multiplier)
36
+ );
37
+
38
+ text-align: center;
39
+
40
+ transition: color var(--ifm-button-transition-duration)
41
+ cubic-bezier(0.08, 0.52, 0.52, 1),
42
+ background var(--ifm-button-transition-duration)
43
+ cubic-bezier(0.08, 0.52, 0.52, 1),
44
+ border-color var(--ifm-button-transition-duration)
45
+ cubic-bezier(0.08, 0.52, 0.52, 1);
46
+ -webkit-user-select: none;
47
+ user-select: none;
48
+ white-space: nowrap;
49
+
50
+ background: transparent;
51
+
52
+ color: var(--ifm-menu-color);
53
+ border: 0px solid transparent;
54
+ /* border-radius: var(--ifm-pre-border-radius); */
55
+
56
+ --margin: 0.25rem;
57
+
58
+ border-radius: calc(var(--margin));
59
+ /* border-radius: 0.25rem; */
60
+
61
+ display: block;
62
+ width: 100%;
63
+
64
+ /* margin: 2px; */
65
+ margin: var(--margin);
66
+ margin-right: 0;
67
+ }
68
+
69
+ .buttonGroup button:last-child {
70
+ margin-right: 0.25rem;
71
+ }
72
+
73
+ .buttonGroup button:hover {
74
+ background: var(--ifm-menu-color-background-active);
75
+ }
76
+
77
+ .buttonGroup button:focus {
78
+ outline: 0;
79
+ }
80
+
81
+ .buttonGroup button.selected {
82
+ background: var(--ifm-menu-color-background-active);
83
+ color: var(--ifm-menu-color-active);
84
+ }
@@ -0,0 +1,74 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+ import React from "react"; // @ts-ignore
8
+
9
+ import { useTypedDispatch, useTypedSelector } from "../hooks";
10
+ import { setResponse } from "../Response/slice";
11
+ import buildPostmanRequest from "./../buildPostmanRequest";
12
+ import makeRequest from "./makeRequest";
13
+
14
+ function validateRequest(params) {
15
+ for (let paramList of Object.values(params)) {
16
+ for (let param of paramList) {
17
+ if (param.required && !param.value) {
18
+ return false;
19
+ }
20
+ }
21
+ }
22
+
23
+ return true;
24
+ }
25
+
26
+ function Execute({ postman, proxy }) {
27
+ const pathParams = useTypedSelector((state) => state.params.path);
28
+ const queryParams = useTypedSelector((state) => state.params.query);
29
+ const cookieParams = useTypedSelector((state) => state.params.cookie);
30
+ const headerParams = useTypedSelector((state) => state.params.header);
31
+ const contentType = useTypedSelector((state) => state.contentType.value);
32
+ const body = useTypedSelector((state) => state.body);
33
+ const accept = useTypedSelector((state) => state.accept.value);
34
+ const server = useTypedSelector((state) => state.server.value);
35
+ const params = useTypedSelector((state) => state.params);
36
+ const auth = useTypedSelector((state) => state.auth);
37
+ const isValidRequest = validateRequest(params);
38
+ const dispatch = useTypedDispatch();
39
+ const postmanRequest = buildPostmanRequest(postman, {
40
+ queryParams,
41
+ pathParams,
42
+ cookieParams,
43
+ contentType,
44
+ accept,
45
+ headerParams,
46
+ body,
47
+ server,
48
+ auth,
49
+ });
50
+ return (
51
+ <button
52
+ className="button button--block button--primary"
53
+ style={{
54
+ height: "48px",
55
+ marginBottom: "var(--ifm-spacing-vertical)",
56
+ }}
57
+ disabled={!isValidRequest}
58
+ onClick={async () => {
59
+ dispatch(setResponse("loading..."));
60
+
61
+ try {
62
+ const res = await makeRequest(postmanRequest, proxy, body);
63
+ dispatch(setResponse(res));
64
+ } catch (e) {
65
+ dispatch(setResponse(e.message ?? "Error fetching."));
66
+ }
67
+ }}
68
+ >
69
+ Execute
70
+ </button>
71
+ );
72
+ }
73
+
74
+ export default Execute;
@@ -0,0 +1,183 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+ // @ts-ignore
8
+ async function loadImage(content) {
9
+ return new Promise((accept, reject) => {
10
+ const reader = new FileReader();
11
+
12
+ reader.onabort = () => {
13
+ console.log("file reading was aborted");
14
+ reject();
15
+ };
16
+
17
+ reader.onerror = () => {
18
+ console.log("file reading has failed");
19
+ reject();
20
+ };
21
+
22
+ reader.onload = () => {
23
+ // Do whatever you want with the file contents
24
+ const binaryStr = reader.result;
25
+ accept(binaryStr);
26
+ };
27
+
28
+ reader.readAsArrayBuffer(content);
29
+ });
30
+ }
31
+
32
+ async function makeRequest(request, proxy, _body) {
33
+ const headers = request.toJSON().header;
34
+ let myHeaders = new Headers();
35
+
36
+ if (headers) {
37
+ // @ts-ignore
38
+ headers.forEach((header) => {
39
+ if (header.key && header.value) {
40
+ myHeaders.append(header.key, header.value);
41
+ }
42
+ });
43
+ } // The following code handles multiple files in the same formdata param.
44
+ // It removes the form data params where the src property is an array of filepath strings
45
+ // Splits that array into different form data params with src set as a single filepath string
46
+ // TODO:
47
+ // if (request.body && request.body.mode === 'formdata') {
48
+ // let formdata = request.body.formdata,
49
+ // formdataArray = [];
50
+ // formdata.members.forEach((param) => {
51
+ // let key = param.key,
52
+ // type = param.type,
53
+ // disabled = param.disabled,
54
+ // contentType = param.contentType;
55
+ // // check if type is file or text
56
+ // if (type === 'file') {
57
+ // // if src is not of type string we check for array(multiple files)
58
+ // if (typeof param.src !== 'string') {
59
+ // // if src is an array(not empty), iterate over it and add files as separate form fields
60
+ // if (Array.isArray(param.src) && param.src.length) {
61
+ // param.src.forEach((filePath) => {
62
+ // addFormParam(
63
+ // formdataArray,
64
+ // key,
65
+ // param.type,
66
+ // filePath,
67
+ // disabled,
68
+ // contentType
69
+ // );
70
+ // });
71
+ // }
72
+ // // if src is not an array or string, or is an empty array, add a placeholder for file path(no files case)
73
+ // else {
74
+ // addFormParam(
75
+ // formdataArray,
76
+ // key,
77
+ // param.type,
78
+ // '/path/to/file',
79
+ // disabled,
80
+ // contentType
81
+ // );
82
+ // }
83
+ // }
84
+ // // if src is string, directly add the param with src as filepath
85
+ // else {
86
+ // addFormParam(
87
+ // formdataArray,
88
+ // key,
89
+ // param.type,
90
+ // param.src,
91
+ // disabled,
92
+ // contentType
93
+ // );
94
+ // }
95
+ // }
96
+ // // if type is text, directly add it to formdata array
97
+ // else {
98
+ // addFormParam(
99
+ // formdataArray,
100
+ // key,
101
+ // param.type,
102
+ // param.value,
103
+ // disabled,
104
+ // contentType
105
+ // );
106
+ // }
107
+ // });
108
+ // request.body.update({
109
+ // mode: 'formdata',
110
+ // formdata: formdataArray,
111
+ // });
112
+ // }
113
+
114
+ const body = request.body?.toJSON();
115
+ let myBody = undefined;
116
+
117
+ if (body !== undefined && Object.keys(body).length > 0) {
118
+ switch (body.mode) {
119
+ case "urlencoded": {
120
+ myBody = new URLSearchParams();
121
+
122
+ if (Array.isArray(body.urlencoded)) {
123
+ for (const data of body.urlencoded) {
124
+ if (data.key && data.value) {
125
+ myBody.append(data.key, data.value);
126
+ }
127
+ }
128
+ }
129
+
130
+ break;
131
+ }
132
+
133
+ case "raw": {
134
+ myBody = (body.raw ?? "").toString();
135
+ break;
136
+ }
137
+
138
+ case "formdata": {
139
+ myBody = new FormData();
140
+
141
+ if (Array.isArray(body.formdata)) {
142
+ for (const data of body.formdata) {
143
+ if (data.key && data.value) {
144
+ myBody.append(data.key, data.value);
145
+ }
146
+ }
147
+ }
148
+
149
+ break;
150
+ }
151
+
152
+ case "file": {
153
+ if (_body.type === "raw" && _body.content?.type === "file") {
154
+ myBody = await loadImage(_body.content.value.content);
155
+ }
156
+
157
+ break;
158
+ }
159
+
160
+ default:
161
+ break;
162
+ }
163
+ }
164
+
165
+ const requestOptions = {
166
+ method: request.method,
167
+ headers: myHeaders,
168
+ body: myBody,
169
+ };
170
+ let finalUrl = request.url.toString();
171
+
172
+ if (proxy) {
173
+ // Ensure the proxy ends with a slash.
174
+ let normalizedProxy = proxy.replace(/\/$/, "") + "/";
175
+ finalUrl = normalizedProxy + request.url.toString();
176
+ }
177
+
178
+ return await fetch(finalUrl, requestOptions).then((response) => {
179
+ return response.text();
180
+ });
181
+ }
182
+
183
+ export default makeRequest;
@@ -0,0 +1,19 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+ import React from "react";
8
+ import styles from "./styles.module.css";
9
+
10
+ function FloatingButton({ label, onClick, children }) {
11
+ return (
12
+ <div className={styles.floatingButton}>
13
+ {label && <button onClick={onClick}>{label}</button>}
14
+ {children}
15
+ </div>
16
+ );
17
+ }
18
+
19
+ export default FloatingButton;
@@ -0,0 +1,26 @@
1
+ .floatingButton {
2
+ position: relative;
3
+ }
4
+
5
+ .floatingButton button {
6
+ position: relative;
7
+ background: rgba(25, 26, 27, 0.9);
8
+ border: none;
9
+ border-radius: var(--ifm-global-radius);
10
+ color: var(--ifm-color-white);
11
+ cursor: pointer;
12
+ outline: none;
13
+ padding: 0.4rem 0.5rem;
14
+ opacity: 0;
15
+ visibility: hidden;
16
+ transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out,
17
+ bottom 0.2s ease-in-out;
18
+ position: absolute;
19
+ top: calc(var(--ifm-pre-padding) / 2);
20
+ right: calc(var(--ifm-pre-padding) / 2);
21
+ }
22
+
23
+ .floatingButton:hover button {
24
+ visibility: visible;
25
+ opacity: 1;
26
+ }