docusaurus-theme-openapi-docs 1.0.0 → 1.0.3

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 (47) hide show
  1. package/lib/postman-code-generators.d.ts +9 -0
  2. package/lib/react-magic-dropzone.d.ts +9 -0
  3. package/lib/theme/ApiDemoPanel/Curl/index.js +0 -1
  4. package/lib/theme/ApiDemoPanel/FormFileUpload/index.js +0 -1
  5. package/lib/theme/ApiDemoPanel/MethodEndpoint/index.js +9 -6
  6. package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +27 -4
  7. package/lib/theme/ApiDemoPanel/buildPostmanRequest.js +5 -2
  8. package/lib/theme/ApiDemoPanel/index.js +7 -13
  9. package/lib/theme/ApiItem/index.js +4 -3
  10. package/lib/theme/ApiItem/styles.module.css +6 -2
  11. package/lib/theme/{Tabs → ApiTabs}/index.js +3 -3
  12. package/lib/theme/{Tabs → ApiTabs}/styles.module.css +0 -0
  13. package/lib-next/postman-code-generators.d.ts +9 -0
  14. package/lib-next/react-magic-dropzone.d.ts +9 -0
  15. package/lib-next/theme/ApiDemoPanel/Curl/index.js +2 -4
  16. package/lib-next/theme/ApiDemoPanel/FormFileUpload/index.js +1 -2
  17. package/lib-next/theme/ApiDemoPanel/MethodEndpoint/index.js +9 -6
  18. package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +31 -4
  19. package/lib-next/theme/ApiDemoPanel/buildPostmanRequest.js +5 -2
  20. package/lib-next/theme/ApiDemoPanel/index.js +8 -15
  21. package/lib-next/theme/ApiItem/index.js +4 -13
  22. package/lib-next/theme/ApiItem/styles.module.css +6 -2
  23. package/{src/theme/Tabs → lib-next/theme/ApiTabs}/index.js +3 -3
  24. package/lib-next/theme/{Tabs → ApiTabs}/styles.module.css +0 -0
  25. package/package.json +15 -9
  26. package/src/postman-code-generators.d.ts +9 -0
  27. package/src/react-magic-dropzone.d.ts +9 -0
  28. package/src/theme/ApiDemoPanel/Curl/index.tsx +0 -2
  29. package/src/theme/ApiDemoPanel/FormFileUpload/index.tsx +0 -1
  30. package/src/theme/ApiDemoPanel/MethodEndpoint/index.tsx +6 -4
  31. package/src/theme/ApiDemoPanel/SecuritySchemes/index.tsx +32 -4
  32. package/src/theme/ApiDemoPanel/buildPostmanRequest.ts +5 -3
  33. package/src/theme/ApiDemoPanel/index.tsx +17 -17
  34. package/src/theme/ApiItem/index.tsx +11 -17
  35. package/src/theme/ApiItem/styles.module.css +6 -2
  36. package/{lib-next/theme/Tabs → src/theme/ApiTabs}/index.js +3 -3
  37. package/src/theme/{Tabs → ApiTabs}/styles.module.css +0 -0
  38. package/src/types.ts +112 -0
  39. package/lib/theme/ApiDemoPanel/Authorization/index.js +0 -174
  40. package/lib/theme/ApiDemoPanel/Execute/index.js +0 -85
  41. package/lib/theme/ApiDemoPanel/Execute/makeRequest.js +0 -202
  42. package/lib-next/theme/ApiDemoPanel/Authorization/index.js +0 -203
  43. package/lib-next/theme/ApiDemoPanel/Execute/index.js +0 -74
  44. package/lib-next/theme/ApiDemoPanel/Execute/makeRequest.js +0 -183
  45. package/src/theme/ApiDemoPanel/Authorization/index.tsx +0 -211
  46. package/src/theme/ApiDemoPanel/Execute/index.tsx +0 -88
  47. package/src/theme/ApiDemoPanel/Execute/makeRequest.ts +0 -184
@@ -1,174 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _clsx = _interopRequireDefault(require("clsx"));
11
-
12
- var _FormItem = _interopRequireDefault(require("../FormItem"));
13
-
14
- var _FormSelect = _interopRequireDefault(require("../FormSelect"));
15
-
16
- var _FormTextInput = _interopRequireDefault(require("../FormTextInput"));
17
-
18
- var _hooks = require("../hooks");
19
-
20
- var _stylesModule = _interopRequireDefault(require("../styles.module.css"));
21
-
22
- var _slice = require("./slice");
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
-
28
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
-
30
- /* ============================================================================
31
- * Copyright (c) Palo Alto Networks
32
- *
33
- * This source code is licensed under the MIT license found in the
34
- * LICENSE file in the root directory of this source tree.
35
- * ========================================================================== */
36
- function LockButton({
37
- mode,
38
- children,
39
- style,
40
- ...rest
41
- }) {
42
- return <button className={(0, _clsx.default)("button", "button--primary", {
43
- "button--outline": mode !== "locked"
44
- })} style={{
45
- marginLeft: "auto",
46
- display: "flex",
47
- alignItems: "center",
48
- marginBottom: "var(--ifm-spacing-vertical)",
49
- ...style
50
- }} {...rest}>
51
- <span>{children}</span>
52
-
53
- <svg style={{
54
- marginLeft: "12px",
55
- width: "18px",
56
- height: "18px",
57
- fill: "currentColor"
58
- }} viewBox="0 0 20 20" id={mode}>
59
- {mode === "locked" ? <path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"></path> : <path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>}
60
- </svg>
61
- </button>;
62
- }
63
-
64
- function validateData(selectedAuth, data) {
65
- for (const scheme of selectedAuth) {
66
- if (data[scheme.key] === undefined) {
67
- return false;
68
- }
69
-
70
- const hasMissingKeys = Object.values(data[scheme.key]).includes(undefined);
71
-
72
- if (hasMissingKeys) {
73
- return false;
74
- }
75
- }
76
-
77
- return true;
78
- }
79
-
80
- function Authorization() {
81
- const [editing, setEditing] = (0, _react.useState)(false);
82
- const data = (0, _hooks.useTypedSelector)(state => state.auth.data);
83
- const options = (0, _hooks.useTypedSelector)(state => state.auth.options);
84
- const selected = (0, _hooks.useTypedSelector)(state => state.auth.selected);
85
- const dispatch = (0, _hooks.useTypedDispatch)();
86
-
87
- if (selected === undefined) {
88
- return null;
89
- }
90
-
91
- const selectedAuth = options[selected];
92
- const authenticated = validateData(selectedAuth, data);
93
- const optionKeys = Object.keys(options);
94
-
95
- if (editing) {
96
- return <div className={_stylesModule.default.optionsPanel}>
97
- {optionKeys.length > 1 && <_FormItem.default label="Security Scheme">
98
- <_FormSelect.default options={optionKeys} value={selected} onChange={e => {
99
- dispatch((0, _slice.setSelectedAuth)(e.target.value));
100
- }} />
101
- </_FormItem.default>}
102
- {selectedAuth.map(a => {
103
- if (a.type === "http" && a.scheme === "bearer") {
104
- var _data$a$key$token;
105
-
106
- return <_FormItem.default label="Bearer Token" key={selected + "-bearer"}>
107
- <_FormTextInput.default placeholder="Bearer Token" value={(_data$a$key$token = data[a.key].token) !== null && _data$a$key$token !== void 0 ? _data$a$key$token : ""} onChange={e => {
108
- const value = e.target.value.trim();
109
- dispatch((0, _slice.setAuthData)({
110
- scheme: a.key,
111
- key: "token",
112
- value: value ? value : undefined
113
- }));
114
- }} />
115
- </_FormItem.default>;
116
- }
117
-
118
- if (a.type === "http" && a.scheme === "basic") {
119
- var _data$a$key$username, _data$a$key$password;
120
-
121
- return <_react.default.Fragment key={selected + "-basic"}>
122
- <_FormItem.default label="Username">
123
- <_FormTextInput.default placeholder="Username" value={(_data$a$key$username = data[a.key].username) !== null && _data$a$key$username !== void 0 ? _data$a$key$username : ""} onChange={e => {
124
- const value = e.target.value.trim();
125
- dispatch((0, _slice.setAuthData)({
126
- scheme: a.key,
127
- key: "username",
128
- value: value ? value : undefined
129
- }));
130
- }} />
131
- </_FormItem.default>
132
- <_FormItem.default label="Password">
133
- <_FormTextInput.default placeholder="Password" password value={(_data$a$key$password = data[a.key].password) !== null && _data$a$key$password !== void 0 ? _data$a$key$password : ""} onChange={e => {
134
- const value = e.target.value.trim();
135
- dispatch((0, _slice.setAuthData)({
136
- scheme: a.key,
137
- key: "password",
138
- value: value ? value : undefined
139
- }));
140
- }} />
141
- </_FormItem.default>
142
- </_react.default.Fragment>;
143
- }
144
-
145
- return null;
146
- })}
147
- <LockButton mode="unlocked" style={{
148
- marginTop: "var(--ifm-spacing-vertical)",
149
- marginBottom: 0
150
- }} onClick={() => {
151
- setEditing(false);
152
- }}>
153
- Save
154
- </LockButton>
155
- </div>;
156
- }
157
-
158
- if (authenticated) {
159
- return <LockButton mode="locked" onClick={() => {
160
- setEditing(true);
161
- }}>
162
- Authorized
163
- </LockButton>;
164
- }
165
-
166
- return <LockButton mode="unlocked" onClick={() => {
167
- setEditing(true);
168
- }}>
169
- Authorize
170
- </LockButton>;
171
- }
172
-
173
- var _default = Authorization;
174
- exports.default = _default;
@@ -1,85 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _hooks = require("../hooks");
11
-
12
- var _slice = require("../Response/slice");
13
-
14
- var _buildPostmanRequest = _interopRequireDefault(require("./../buildPostmanRequest"));
15
-
16
- var _makeRequest = _interopRequireDefault(require("./makeRequest"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- /* ============================================================================
21
- * Copyright (c) Palo Alto Networks
22
- *
23
- * This source code is licensed under the MIT license found in the
24
- * LICENSE file in the root directory of this source tree.
25
- * ========================================================================== */
26
- function validateRequest(params) {
27
- for (let paramList of Object.values(params)) {
28
- for (let param of paramList) {
29
- if (param.required && !param.value) {
30
- return false;
31
- }
32
- }
33
- }
34
-
35
- return true;
36
- }
37
-
38
- function Execute({
39
- postman,
40
- proxy
41
- }) {
42
- const pathParams = (0, _hooks.useTypedSelector)(state => state.params.path);
43
- const queryParams = (0, _hooks.useTypedSelector)(state => state.params.query);
44
- const cookieParams = (0, _hooks.useTypedSelector)(state => state.params.cookie);
45
- const headerParams = (0, _hooks.useTypedSelector)(state => state.params.header);
46
- const contentType = (0, _hooks.useTypedSelector)(state => state.contentType.value);
47
- const body = (0, _hooks.useTypedSelector)(state => state.body);
48
- const accept = (0, _hooks.useTypedSelector)(state => state.accept.value);
49
- const server = (0, _hooks.useTypedSelector)(state => state.server.value);
50
- const params = (0, _hooks.useTypedSelector)(state => state.params);
51
- const auth = (0, _hooks.useTypedSelector)(state => state.auth);
52
- const isValidRequest = validateRequest(params);
53
- const dispatch = (0, _hooks.useTypedDispatch)();
54
- const postmanRequest = (0, _buildPostmanRequest.default)(postman, {
55
- queryParams,
56
- pathParams,
57
- cookieParams,
58
- contentType,
59
- accept,
60
- headerParams,
61
- body,
62
- server,
63
- auth
64
- });
65
- return <button className="button button--block button--primary" style={{
66
- height: "48px",
67
- marginBottom: "var(--ifm-spacing-vertical)"
68
- }} disabled={!isValidRequest} onClick={async () => {
69
- dispatch((0, _slice.setResponse)("loading..."));
70
-
71
- try {
72
- const res = await (0, _makeRequest.default)(postmanRequest, proxy, body);
73
- dispatch((0, _slice.setResponse)(res));
74
- } catch (e) {
75
- var _e$message;
76
-
77
- dispatch((0, _slice.setResponse)((_e$message = e.message) !== null && _e$message !== void 0 ? _e$message : "Error fetching."));
78
- }
79
- }}>
80
- Execute
81
- </button>;
82
- }
83
-
84
- var _default = Execute;
85
- exports.default = _default;
@@ -1,202 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- /* ============================================================================
9
- * Copyright (c) Palo Alto Networks
10
- *
11
- * This source code is licensed under the MIT license found in the
12
- * LICENSE file in the root directory of this source tree.
13
- * ========================================================================== */
14
- // @ts-ignore
15
- async function loadImage(content) {
16
- return new Promise((accept, reject) => {
17
- const reader = new FileReader();
18
-
19
- reader.onabort = () => {
20
- console.log("file reading was aborted");
21
- reject();
22
- };
23
-
24
- reader.onerror = () => {
25
- console.log("file reading has failed");
26
- reject();
27
- };
28
-
29
- reader.onload = () => {
30
- // Do whatever you want with the file contents
31
- const binaryStr = reader.result;
32
- accept(binaryStr);
33
- };
34
-
35
- reader.readAsArrayBuffer(content);
36
- });
37
- }
38
-
39
- async function makeRequest(request, proxy, _body) {
40
- var _request$body;
41
-
42
- const headers = request.toJSON().header;
43
- let myHeaders = new Headers();
44
-
45
- if (headers) {
46
- // @ts-ignore
47
- headers.forEach(header => {
48
- if (header.key && header.value) {
49
- myHeaders.append(header.key, header.value);
50
- }
51
- });
52
- } // The following code handles multiple files in the same formdata param.
53
- // It removes the form data params where the src property is an array of filepath strings
54
- // Splits that array into different form data params with src set as a single filepath string
55
- // TODO:
56
- // if (request.body && request.body.mode === 'formdata') {
57
- // let formdata = request.body.formdata,
58
- // formdataArray = [];
59
- // formdata.members.forEach((param) => {
60
- // let key = param.key,
61
- // type = param.type,
62
- // disabled = param.disabled,
63
- // contentType = param.contentType;
64
- // // check if type is file or text
65
- // if (type === 'file') {
66
- // // if src is not of type string we check for array(multiple files)
67
- // if (typeof param.src !== 'string') {
68
- // // if src is an array(not empty), iterate over it and add files as separate form fields
69
- // if (Array.isArray(param.src) && param.src.length) {
70
- // param.src.forEach((filePath) => {
71
- // addFormParam(
72
- // formdataArray,
73
- // key,
74
- // param.type,
75
- // filePath,
76
- // disabled,
77
- // contentType
78
- // );
79
- // });
80
- // }
81
- // // if src is not an array or string, or is an empty array, add a placeholder for file path(no files case)
82
- // else {
83
- // addFormParam(
84
- // formdataArray,
85
- // key,
86
- // param.type,
87
- // '/path/to/file',
88
- // disabled,
89
- // contentType
90
- // );
91
- // }
92
- // }
93
- // // if src is string, directly add the param with src as filepath
94
- // else {
95
- // addFormParam(
96
- // formdataArray,
97
- // key,
98
- // param.type,
99
- // param.src,
100
- // disabled,
101
- // contentType
102
- // );
103
- // }
104
- // }
105
- // // if type is text, directly add it to formdata array
106
- // else {
107
- // addFormParam(
108
- // formdataArray,
109
- // key,
110
- // param.type,
111
- // param.value,
112
- // disabled,
113
- // contentType
114
- // );
115
- // }
116
- // });
117
- // request.body.update({
118
- // mode: 'formdata',
119
- // formdata: formdataArray,
120
- // });
121
- // }
122
-
123
-
124
- const body = (_request$body = request.body) === null || _request$body === void 0 ? void 0 : _request$body.toJSON();
125
- let myBody = undefined;
126
-
127
- if (body !== undefined && Object.keys(body).length > 0) {
128
- switch (body.mode) {
129
- case "urlencoded":
130
- {
131
- myBody = new URLSearchParams();
132
-
133
- if (Array.isArray(body.urlencoded)) {
134
- for (const data of body.urlencoded) {
135
- if (data.key && data.value) {
136
- myBody.append(data.key, data.value);
137
- }
138
- }
139
- }
140
-
141
- break;
142
- }
143
-
144
- case "raw":
145
- {
146
- var _body$raw;
147
-
148
- myBody = ((_body$raw = body.raw) !== null && _body$raw !== void 0 ? _body$raw : "").toString();
149
- break;
150
- }
151
-
152
- case "formdata":
153
- {
154
- myBody = new FormData();
155
-
156
- if (Array.isArray(body.formdata)) {
157
- for (const data of body.formdata) {
158
- if (data.key && data.value) {
159
- myBody.append(data.key, data.value);
160
- }
161
- }
162
- }
163
-
164
- break;
165
- }
166
-
167
- case "file":
168
- {
169
- var _body$content;
170
-
171
- if (_body.type === "raw" && ((_body$content = _body.content) === null || _body$content === void 0 ? void 0 : _body$content.type) === "file") {
172
- myBody = await loadImage(_body.content.value.content);
173
- }
174
-
175
- break;
176
- }
177
-
178
- default:
179
- break;
180
- }
181
- }
182
-
183
- const requestOptions = {
184
- method: request.method,
185
- headers: myHeaders,
186
- body: myBody
187
- };
188
- let finalUrl = request.url.toString();
189
-
190
- if (proxy) {
191
- // Ensure the proxy ends with a slash.
192
- let normalizedProxy = proxy.replace(/\/$/, "") + "/";
193
- finalUrl = normalizedProxy + request.url.toString();
194
- }
195
-
196
- return await fetch(finalUrl, requestOptions).then(response => {
197
- return response.text();
198
- });
199
- }
200
-
201
- var _default = makeRequest;
202
- exports.default = _default;
@@ -1,203 +0,0 @@
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, { useState } from "react";
8
- import clsx from "clsx";
9
- import FormItem from "../FormItem";
10
- import FormSelect from "../FormSelect";
11
- import FormTextInput from "../FormTextInput";
12
- import { useTypedDispatch, useTypedSelector } from "../hooks";
13
- import styles from "../styles.module.css";
14
- import { setAuthData, setSelectedAuth } from "./slice";
15
-
16
- function LockButton({ mode, children, style, ...rest }) {
17
- return (
18
- <button
19
- className={clsx("button", "button--primary", {
20
- "button--outline": mode !== "locked",
21
- })}
22
- style={{
23
- marginLeft: "auto",
24
- display: "flex",
25
- alignItems: "center",
26
- marginBottom: "var(--ifm-spacing-vertical)",
27
- ...style,
28
- }}
29
- {...rest}
30
- >
31
- <span>{children}</span>
32
-
33
- <svg
34
- style={{
35
- marginLeft: "12px",
36
- width: "18px",
37
- height: "18px",
38
- fill: "currentColor",
39
- }}
40
- viewBox="0 0 20 20"
41
- id={mode}
42
- >
43
- {mode === "locked" ? (
44
- <path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"></path>
45
- ) : (
46
- <path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
47
- )}
48
- </svg>
49
- </button>
50
- );
51
- }
52
-
53
- function validateData(selectedAuth, data) {
54
- for (const scheme of selectedAuth) {
55
- if (data[scheme.key] === undefined) {
56
- return false;
57
- }
58
-
59
- const hasMissingKeys = Object.values(data[scheme.key]).includes(undefined);
60
-
61
- if (hasMissingKeys) {
62
- return false;
63
- }
64
- }
65
-
66
- return true;
67
- }
68
-
69
- function Authorization() {
70
- const [editing, setEditing] = useState(false);
71
- const data = useTypedSelector((state) => state.auth.data);
72
- const options = useTypedSelector((state) => state.auth.options);
73
- const selected = useTypedSelector((state) => state.auth.selected);
74
- const dispatch = useTypedDispatch();
75
-
76
- if (selected === undefined) {
77
- return null;
78
- }
79
-
80
- const selectedAuth = options[selected];
81
- const authenticated = validateData(selectedAuth, data);
82
- const optionKeys = Object.keys(options);
83
-
84
- if (editing) {
85
- return (
86
- <div className={styles.optionsPanel}>
87
- {optionKeys.length > 1 && (
88
- <FormItem label="Security Scheme">
89
- <FormSelect
90
- options={optionKeys}
91
- value={selected}
92
- onChange={(e) => {
93
- dispatch(setSelectedAuth(e.target.value));
94
- }}
95
- />
96
- </FormItem>
97
- )}
98
- {selectedAuth.map((a) => {
99
- if (a.type === "http" && a.scheme === "bearer") {
100
- return (
101
- <FormItem label="Bearer Token" key={selected + "-bearer"}>
102
- <FormTextInput
103
- placeholder="Bearer Token"
104
- value={data[a.key].token ?? ""}
105
- onChange={(e) => {
106
- const value = e.target.value.trim();
107
- dispatch(
108
- setAuthData({
109
- scheme: a.key,
110
- key: "token",
111
- value: value ? value : undefined,
112
- })
113
- );
114
- }}
115
- />
116
- </FormItem>
117
- );
118
- }
119
-
120
- if (a.type === "http" && a.scheme === "basic") {
121
- return (
122
- <React.Fragment key={selected + "-basic"}>
123
- <FormItem label="Username">
124
- <FormTextInput
125
- placeholder="Username"
126
- value={data[a.key].username ?? ""}
127
- onChange={(e) => {
128
- const value = e.target.value.trim();
129
- dispatch(
130
- setAuthData({
131
- scheme: a.key,
132
- key: "username",
133
- value: value ? value : undefined,
134
- })
135
- );
136
- }}
137
- />
138
- </FormItem>
139
- <FormItem label="Password">
140
- <FormTextInput
141
- placeholder="Password"
142
- password
143
- value={data[a.key].password ?? ""}
144
- onChange={(e) => {
145
- const value = e.target.value.trim();
146
- dispatch(
147
- setAuthData({
148
- scheme: a.key,
149
- key: "password",
150
- value: value ? value : undefined,
151
- })
152
- );
153
- }}
154
- />
155
- </FormItem>
156
- </React.Fragment>
157
- );
158
- }
159
-
160
- return null;
161
- })}
162
- <LockButton
163
- mode="unlocked"
164
- style={{
165
- marginTop: "var(--ifm-spacing-vertical)",
166
- marginBottom: 0,
167
- }}
168
- onClick={() => {
169
- setEditing(false);
170
- }}
171
- >
172
- Save
173
- </LockButton>
174
- </div>
175
- );
176
- }
177
-
178
- if (authenticated) {
179
- return (
180
- <LockButton
181
- mode="locked"
182
- onClick={() => {
183
- setEditing(true);
184
- }}
185
- >
186
- Authorized
187
- </LockButton>
188
- );
189
- }
190
-
191
- return (
192
- <LockButton
193
- mode="unlocked"
194
- onClick={() => {
195
- setEditing(true);
196
- }}
197
- >
198
- Authorize
199
- </LockButton>
200
- );
201
- }
202
-
203
- export default Authorization;