docusaurus-theme-openapi-docs 0.0.0-349 → 0.0.0-352

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,181 +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
- 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;
@@ -1,211 +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
-
8
- import React, { useState } from "react";
9
-
10
- import clsx from "clsx";
11
-
12
- import FormItem from "../FormItem";
13
- import FormSelect from "../FormSelect";
14
- import FormTextInput from "../FormTextInput";
15
- import { useTypedDispatch, useTypedSelector } from "../hooks";
16
- import styles from "../styles.module.css";
17
- import { AuthState, Scheme, setAuthData, setSelectedAuth } from "./slice";
18
-
19
- type Props = {
20
- mode: "locked" | "unlocked";
21
- } & JSX.IntrinsicElements["button"];
22
-
23
- function LockButton({ mode, children, style, ...rest }: Props) {
24
- return (
25
- <button
26
- className={clsx("button", "button--primary", {
27
- "button--outline": mode !== "locked",
28
- })}
29
- style={{
30
- marginLeft: "auto",
31
- display: "flex",
32
- alignItems: "center",
33
- marginBottom: "var(--ifm-spacing-vertical)",
34
- ...style,
35
- }}
36
- {...rest}
37
- >
38
- <span>{children}</span>
39
-
40
- <svg
41
- style={{
42
- marginLeft: "12px",
43
- width: "18px",
44
- height: "18px",
45
- fill: "currentColor",
46
- }}
47
- viewBox="0 0 20 20"
48
- id={mode}
49
- >
50
- {mode === "locked" ? (
51
- <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>
52
- ) : (
53
- <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>
54
- )}
55
- </svg>
56
- </button>
57
- );
58
- }
59
-
60
- function validateData(selectedAuth: Scheme[], data: AuthState["data"]) {
61
- for (const scheme of selectedAuth) {
62
- if (data[scheme.key] === undefined) {
63
- return false;
64
- }
65
- const hasMissingKeys = Object.values(data[scheme.key]).includes(undefined);
66
- if (hasMissingKeys) {
67
- return false;
68
- }
69
- }
70
- return true;
71
- }
72
-
73
- function Authorization() {
74
- const [editing, setEditing] = useState(false);
75
-
76
- const data = useTypedSelector((state) => state.auth.data);
77
- const options = useTypedSelector((state) => state.auth.options);
78
- const selected = useTypedSelector((state) => state.auth.selected);
79
-
80
- const dispatch = useTypedDispatch();
81
-
82
- if (selected === undefined) {
83
- return null;
84
- }
85
-
86
- const selectedAuth = options[selected];
87
-
88
- const authenticated = validateData(selectedAuth, data);
89
-
90
- const optionKeys = Object.keys(options);
91
-
92
- if (editing) {
93
- return (
94
- <div className={styles.optionsPanel}>
95
- {optionKeys.length > 1 && (
96
- <FormItem label="Security Scheme">
97
- <FormSelect
98
- options={optionKeys}
99
- value={selected}
100
- onChange={(e) => {
101
- dispatch(setSelectedAuth(e.target.value));
102
- }}
103
- />
104
- </FormItem>
105
- )}
106
- {selectedAuth.map((a) => {
107
- if (a.type === "http" && a.scheme === "bearer") {
108
- return (
109
- <FormItem label="Bearer Token" key={selected + "-bearer"}>
110
- <FormTextInput
111
- placeholder="Bearer Token"
112
- value={data[a.key].token ?? ""}
113
- onChange={(e) => {
114
- const value = e.target.value.trim();
115
- dispatch(
116
- setAuthData({
117
- scheme: a.key,
118
- key: "token",
119
- value: value ? value : undefined,
120
- })
121
- );
122
- }}
123
- />
124
- </FormItem>
125
- );
126
- }
127
-
128
- if (a.type === "http" && a.scheme === "basic") {
129
- return (
130
- <React.Fragment key={selected + "-basic"}>
131
- <FormItem label="Username">
132
- <FormTextInput
133
- placeholder="Username"
134
- value={data[a.key].username ?? ""}
135
- onChange={(e) => {
136
- const value = e.target.value.trim();
137
- dispatch(
138
- setAuthData({
139
- scheme: a.key,
140
- key: "username",
141
- value: value ? value : undefined,
142
- })
143
- );
144
- }}
145
- />
146
- </FormItem>
147
- <FormItem label="Password">
148
- <FormTextInput
149
- placeholder="Password"
150
- password
151
- value={data[a.key].password ?? ""}
152
- onChange={(e) => {
153
- const value = e.target.value.trim();
154
- dispatch(
155
- setAuthData({
156
- scheme: a.key,
157
- key: "password",
158
- value: value ? value : undefined,
159
- })
160
- );
161
- }}
162
- />
163
- </FormItem>
164
- </React.Fragment>
165
- );
166
- }
167
-
168
- return null;
169
- })}
170
- <LockButton
171
- mode="unlocked"
172
- style={{
173
- marginTop: "var(--ifm-spacing-vertical)",
174
- marginBottom: 0,
175
- }}
176
- onClick={() => {
177
- setEditing(false);
178
- }}
179
- >
180
- Save
181
- </LockButton>
182
- </div>
183
- );
184
- }
185
-
186
- if (authenticated) {
187
- return (
188
- <LockButton
189
- mode="locked"
190
- onClick={() => {
191
- setEditing(true);
192
- }}
193
- >
194
- Authorized
195
- </LockButton>
196
- );
197
- }
198
-
199
- return (
200
- <LockButton
201
- mode="unlocked"
202
- onClick={() => {
203
- setEditing(true);
204
- }}
205
- >
206
- Authorize
207
- </LockButton>
208
- );
209
- }
210
-
211
- export default Authorization;
@@ -1,87 +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
-
8
- import React from "react";
9
-
10
- import sdk from "@paloaltonetworks/postman-collection";
11
-
12
- import { useTypedDispatch, useTypedSelector } from "../hooks";
13
- import { Param } from "../ParamOptions/slice";
14
- import { setResponse } from "../Response/slice";
15
- import buildPostmanRequest from "./../buildPostmanRequest";
16
- import makeRequest from "./makeRequest";
17
-
18
- function validateRequest(params: {
19
- path: Param[];
20
- query: Param[];
21
- header: Param[];
22
- cookie: Param[];
23
- }) {
24
- for (let paramList of Object.values(params)) {
25
- for (let param of paramList) {
26
- if (param.required && !param.value) {
27
- return false;
28
- }
29
- }
30
- }
31
- return true;
32
- }
33
-
34
- interface Props {
35
- postman: sdk.Request;
36
- proxy?: string;
37
- }
38
-
39
- function Execute({ postman, proxy }: Props) {
40
- const pathParams = useTypedSelector((state) => state.params.path);
41
- const queryParams = useTypedSelector((state) => state.params.query);
42
- const cookieParams = useTypedSelector((state) => state.params.cookie);
43
- const headerParams = useTypedSelector((state) => state.params.header);
44
- const contentType = useTypedSelector((state) => state.contentType.value);
45
- const body = useTypedSelector((state) => state.body);
46
- const accept = useTypedSelector((state) => state.accept.value);
47
- const server = useTypedSelector((state) => state.server.value);
48
- const params = useTypedSelector((state) => state.params);
49
- const auth = useTypedSelector((state) => state.auth);
50
-
51
- const isValidRequest = validateRequest(params);
52
-
53
- const dispatch = useTypedDispatch();
54
-
55
- const postmanRequest = buildPostmanRequest(postman, {
56
- queryParams,
57
- pathParams,
58
- cookieParams,
59
- contentType,
60
- accept,
61
- headerParams,
62
- body,
63
- server,
64
- auth,
65
- });
66
-
67
- return (
68
- <button
69
- className="button button--block button--primary"
70
- style={{ height: "48px", marginBottom: "var(--ifm-spacing-vertical)" }}
71
- disabled={!isValidRequest}
72
- onClick={async () => {
73
- dispatch(setResponse("loading..."));
74
- try {
75
- const res = await makeRequest(postmanRequest, proxy, body);
76
- dispatch(setResponse(res));
77
- } catch (e: any) {
78
- dispatch(setResponse(e.message ?? "Error fetching."));
79
- }
80
- }}
81
- >
82
- Execute
83
- </button>
84
- );
85
- }
86
-
87
- export default Execute;
@@ -1,182 +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
-
8
- import sdk from "@paloaltonetworks/postman-collection";
9
-
10
- import { Body } from "../Body/slice";
11
-
12
- async function loadImage(content: Blob): Promise<string | ArrayBuffer | null> {
13
- return new Promise((accept, reject) => {
14
- const reader = new FileReader();
15
-
16
- reader.onabort = () => {
17
- console.log("file reading was aborted");
18
- reject();
19
- };
20
-
21
- reader.onerror = () => {
22
- console.log("file reading has failed");
23
- reject();
24
- };
25
-
26
- reader.onload = () => {
27
- // Do whatever you want with the file contents
28
- const binaryStr = reader.result;
29
- accept(binaryStr);
30
- };
31
- reader.readAsArrayBuffer(content);
32
- });
33
- }
34
-
35
- async function makeRequest(
36
- request: sdk.Request,
37
- proxy: string | undefined,
38
- _body: Body
39
- ) {
40
- const headers = request.toJSON().header;
41
-
42
- let myHeaders = new Headers();
43
- if (headers) {
44
- headers.forEach((header: any) => {
45
- if (header.key && header.value) {
46
- myHeaders.append(header.key, header.value);
47
- }
48
- });
49
- }
50
-
51
- // The following code handles multiple files in the same formdata param.
52
- // It removes the form data params where the src property is an array of filepath strings
53
- // Splits that array into different form data params with src set as a single filepath string
54
- // TODO:
55
- // if (request.body && request.body.mode === 'formdata') {
56
- // let formdata = request.body.formdata,
57
- // formdataArray = [];
58
- // formdata.members.forEach((param) => {
59
- // let key = param.key,
60
- // type = param.type,
61
- // disabled = param.disabled,
62
- // contentType = param.contentType;
63
- // // check if type is file or text
64
- // if (type === 'file') {
65
- // // if src is not of type string we check for array(multiple files)
66
- // if (typeof param.src !== 'string') {
67
- // // if src is an array(not empty), iterate over it and add files as separate form fields
68
- // if (Array.isArray(param.src) && param.src.length) {
69
- // param.src.forEach((filePath) => {
70
- // addFormParam(
71
- // formdataArray,
72
- // key,
73
- // param.type,
74
- // filePath,
75
- // disabled,
76
- // contentType
77
- // );
78
- // });
79
- // }
80
- // // if src is not an array or string, or is an empty array, add a placeholder for file path(no files case)
81
- // else {
82
- // addFormParam(
83
- // formdataArray,
84
- // key,
85
- // param.type,
86
- // '/path/to/file',
87
- // disabled,
88
- // contentType
89
- // );
90
- // }
91
- // }
92
- // // if src is string, directly add the param with src as filepath
93
- // else {
94
- // addFormParam(
95
- // formdataArray,
96
- // key,
97
- // param.type,
98
- // param.src,
99
- // disabled,
100
- // contentType
101
- // );
102
- // }
103
- // }
104
- // // if type is text, directly add it to formdata array
105
- // else {
106
- // addFormParam(
107
- // formdataArray,
108
- // key,
109
- // param.type,
110
- // param.value,
111
- // disabled,
112
- // contentType
113
- // );
114
- // }
115
- // });
116
- // request.body.update({
117
- // mode: 'formdata',
118
- // formdata: formdataArray,
119
- // });
120
- // }
121
-
122
- const body = request.body?.toJSON();
123
-
124
- let myBody: RequestInit["body"] = undefined;
125
- if (body !== undefined && Object.keys(body).length > 0) {
126
- switch (body.mode) {
127
- case "urlencoded": {
128
- myBody = new URLSearchParams();
129
- if (Array.isArray(body.urlencoded)) {
130
- for (const data of body.urlencoded) {
131
- if (data.key && data.value) {
132
- myBody.append(data.key, data.value);
133
- }
134
- }
135
- }
136
- break;
137
- }
138
- case "raw": {
139
- myBody = (body.raw ?? "").toString();
140
- break;
141
- }
142
- case "formdata": {
143
- myBody = new FormData();
144
- if (Array.isArray(body.formdata)) {
145
- for (const data of body.formdata) {
146
- if (data.key && data.value) {
147
- myBody.append(data.key, data.value);
148
- }
149
- }
150
- }
151
- break;
152
- }
153
- case "file": {
154
- if (_body.type === "raw" && _body.content?.type === "file") {
155
- myBody = await loadImage(_body.content.value.content);
156
- }
157
- break;
158
- }
159
- default:
160
- break;
161
- }
162
- }
163
-
164
- const requestOptions: RequestInit = {
165
- method: request.method,
166
- headers: myHeaders,
167
- body: myBody,
168
- };
169
-
170
- let finalUrl = request.url.toString();
171
- if (proxy) {
172
- // Ensure the proxy ends with a slash.
173
- let normalizedProxy = proxy.replace(/\/$/, "") + "/";
174
- finalUrl = normalizedProxy + request.url.toString();
175
- }
176
-
177
- return await fetch(finalUrl, requestOptions).then((response) => {
178
- return response.text();
179
- });
180
- }
181
-
182
- export default makeRequest;