docusaurus-theme-openapi-docs 0.0.0-345

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