docusaurus-theme-openapi-docs 1.4.3 → 1.4.5

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 (130) hide show
  1. package/lib/index.js +5 -8
  2. package/lib/markdown/createDescription.js +1 -2
  3. package/lib/markdown/schema.js +7 -42
  4. package/lib/markdown/utils.js +1 -7
  5. package/lib/theme/ApiDemoPanel/Accept/index.js +1 -10
  6. package/lib/theme/ApiDemoPanel/Accept/slice.js +1 -2
  7. package/lib/theme/ApiDemoPanel/Authorization/auth-types.js +7 -8
  8. package/lib/theme/ApiDemoPanel/Authorization/index.js +1 -19
  9. package/lib/theme/ApiDemoPanel/Authorization/slice.js +7 -21
  10. package/lib/theme/ApiDemoPanel/Body/index.js +14 -47
  11. package/lib/theme/ApiDemoPanel/Body/slice.js +1 -4
  12. package/lib/theme/ApiDemoPanel/CodeTabs/index.js +14 -46
  13. package/lib/theme/ApiDemoPanel/ContentType/index.js +1 -10
  14. package/lib/theme/ApiDemoPanel/ContentType/slice.js +1 -2
  15. package/lib/theme/ApiDemoPanel/Curl/index.js +9 -29
  16. package/lib/theme/ApiDemoPanel/Execute/index.js +3 -22
  17. package/lib/theme/ApiDemoPanel/Execute/makeRequest.js +4 -27
  18. package/lib/theme/ApiDemoPanel/Export/index.js +1 -8
  19. package/lib/theme/ApiDemoPanel/FloatingButton/index.js +1 -5
  20. package/lib/theme/ApiDemoPanel/FormFileUpload/index.js +1 -14
  21. package/lib/theme/ApiDemoPanel/FormItem/index.js +1 -5
  22. package/lib/theme/ApiDemoPanel/FormMultiSelect/index.js +1 -8
  23. package/lib/theme/ApiDemoPanel/FormSelect/index.js +1 -6
  24. package/lib/theme/ApiDemoPanel/FormTextInput/index.js +1 -6
  25. package/lib/theme/ApiDemoPanel/LiveEditor/index.js +3 -17
  26. package/lib/theme/ApiDemoPanel/MethodEndpoint/index.js +1 -12
  27. package/lib/theme/ApiDemoPanel/ParamOptions/index.js +20 -52
  28. package/lib/theme/ApiDemoPanel/ParamOptions/slice.js +1 -2
  29. package/lib/theme/ApiDemoPanel/Request/index.js +1 -15
  30. package/lib/theme/ApiDemoPanel/Response/index.js +1 -14
  31. package/lib/theme/ApiDemoPanel/Response/slice.js +1 -2
  32. package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +1 -9
  33. package/lib/theme/ApiDemoPanel/Server/index.js +3 -27
  34. package/lib/theme/ApiDemoPanel/Server/slice.js +1 -3
  35. package/lib/theme/ApiDemoPanel/buildPostmanRequest.js +11 -62
  36. package/lib/theme/ApiDemoPanel/index.js +2 -14
  37. package/lib/theme/ApiDemoPanel/persistanceMiddleware.js +5 -11
  38. package/lib/theme/ApiDemoPanel/storage-utils.js +1 -7
  39. package/lib/theme/ApiItem/Layout/index.js +5 -22
  40. package/lib/theme/ApiItem/Layout/styles.module.css +0 -403
  41. package/lib/theme/ApiItem/hooks.js +1 -3
  42. package/lib/theme/ApiItem/index.js +14 -30
  43. package/lib/theme/ApiItem/store.js +1 -14
  44. package/lib/theme/ApiLogo/index.js +1 -4
  45. package/lib/theme/DiscriminatorTabs/styles.module.css +9 -5
  46. package/lib/theme/styles.css +429 -0
  47. package/lib/theme-classic.d.ts +5 -0
  48. package/lib-next/index.js +5 -3
  49. package/lib-next/markdown/createDescription.js +1 -1
  50. package/lib-next/markdown/schema.js +7 -35
  51. package/lib-next/markdown/utils.js +1 -4
  52. package/lib-next/theme/ApiDemoPanel/Accept/index.js +1 -4
  53. package/lib-next/theme/ApiDemoPanel/Accept/slice.js +1 -0
  54. package/lib-next/theme/ApiDemoPanel/Authorization/auth-types.js +7 -4
  55. package/lib-next/theme/ApiDemoPanel/Authorization/index.js +1 -8
  56. package/lib-next/theme/ApiDemoPanel/Authorization/slice.js +12 -14
  57. package/lib-next/theme/ApiDemoPanel/Body/index.js +16 -34
  58. package/lib-next/theme/ApiDemoPanel/Body/slice.js +1 -2
  59. package/lib-next/theme/ApiDemoPanel/CodeTabs/index.js +12 -26
  60. package/lib-next/theme/ApiDemoPanel/ContentType/index.js +1 -4
  61. package/lib-next/theme/ApiDemoPanel/ContentType/slice.js +1 -0
  62. package/lib-next/theme/ApiDemoPanel/Curl/index.js +11 -12
  63. package/lib-next/theme/ApiDemoPanel/Execute/index.js +3 -13
  64. package/lib-next/theme/ApiDemoPanel/Execute/makeRequest.js +4 -22
  65. package/lib-next/theme/ApiDemoPanel/Export/index.js +1 -5
  66. package/lib-next/theme/ApiDemoPanel/FloatingButton/index.js +1 -2
  67. package/lib-next/theme/ApiDemoPanel/FormFileUpload/index.js +1 -7
  68. package/lib-next/theme/ApiDemoPanel/FormItem/index.js +1 -2
  69. package/lib-next/theme/ApiDemoPanel/FormMultiSelect/index.js +1 -5
  70. package/lib-next/theme/ApiDemoPanel/FormSelect/index.js +1 -3
  71. package/lib-next/theme/ApiDemoPanel/FormTextInput/index.js +1 -2
  72. package/lib-next/theme/ApiDemoPanel/LiveEditor/index.js +3 -6
  73. package/lib-next/theme/ApiDemoPanel/MethodEndpoint/index.js +1 -9
  74. package/lib-next/theme/ApiDemoPanel/ParamOptions/index.js +34 -29
  75. package/lib-next/theme/ApiDemoPanel/ParamOptions/slice.js +1 -0
  76. package/lib-next/theme/ApiDemoPanel/Request/index.js +1 -2
  77. package/lib-next/theme/ApiDemoPanel/Response/index.js +3 -9
  78. package/lib-next/theme/ApiDemoPanel/Response/slice.js +1 -0
  79. package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +1 -5
  80. package/lib-next/theme/ApiDemoPanel/Server/index.js +3 -13
  81. package/lib-next/theme/ApiDemoPanel/Server/slice.js +1 -0
  82. package/lib-next/theme/ApiDemoPanel/buildPostmanRequest.js +12 -49
  83. package/lib-next/theme/ApiDemoPanel/index.js +2 -4
  84. package/lib-next/theme/ApiDemoPanel/persistanceMiddleware.js +5 -6
  85. package/lib-next/theme/ApiDemoPanel/storage-utils.js +1 -3
  86. package/lib-next/theme/ApiItem/Layout/index.js +8 -9
  87. package/lib-next/theme/ApiItem/Layout/styles.module.css +0 -403
  88. package/lib-next/theme/ApiItem/hooks.js +1 -0
  89. package/lib-next/theme/ApiItem/index.js +14 -13
  90. package/lib-next/theme/ApiItem/store.js +1 -0
  91. package/lib-next/theme/ApiLogo/index.js +1 -0
  92. package/lib-next/theme/DiscriminatorTabs/styles.module.css +9 -5
  93. package/lib-next/theme/styles.css +429 -0
  94. package/lib-next/theme-classic.d.ts +5 -0
  95. package/package.json +5 -5
  96. package/src/index.ts +5 -0
  97. package/src/theme/ApiDemoPanel/index.tsx +1 -2
  98. package/src/theme/ApiItem/Layout/index.tsx +5 -6
  99. package/src/theme/ApiItem/Layout/styles.module.css +0 -403
  100. package/src/theme/ApiItem/index.tsx +5 -4
  101. package/src/theme/DiscriminatorTabs/styles.module.css +9 -5
  102. package/src/theme/styles.css +429 -0
  103. package/src/theme-classic.d.ts +5 -0
  104. package/lib/theme/ApiDemoPanel/styles.module.css +0 -44
  105. package/lib/theme/ApiItem/Content/index.js +0 -65
  106. package/lib/theme/ApiItem/Footer/index.js +0 -78
  107. package/lib/theme/ApiItem/Footer/styles.module.css +0 -18
  108. package/lib/theme/ApiItem/Metadata/index.js +0 -32
  109. package/lib/theme/ApiItem/Paginator/index.js +0 -33
  110. package/lib/theme/ApiItem/TOC/Desktop/index.js +0 -31
  111. package/lib/theme/ApiItem/TOC/Mobile/index.js +0 -35
  112. package/lib/theme/ApiItem/TOC/Mobile/styles.module.css +0 -19
  113. package/lib-next/theme/ApiDemoPanel/styles.module.css +0 -44
  114. package/lib-next/theme/ApiItem/Content/index.js +0 -55
  115. package/lib-next/theme/ApiItem/Footer/index.js +0 -88
  116. package/lib-next/theme/ApiItem/Footer/styles.module.css +0 -18
  117. package/lib-next/theme/ApiItem/Metadata/index.js +0 -21
  118. package/lib-next/theme/ApiItem/Paginator/index.js +0 -19
  119. package/lib-next/theme/ApiItem/TOC/Desktop/index.js +0 -22
  120. package/lib-next/theme/ApiItem/TOC/Mobile/index.js +0 -24
  121. package/lib-next/theme/ApiItem/TOC/Mobile/styles.module.css +0 -19
  122. package/src/theme/ApiDemoPanel/styles.module.css +0 -44
  123. package/src/theme/ApiItem/Content/index.tsx +0 -57
  124. package/src/theme/ApiItem/Footer/index.tsx +0 -101
  125. package/src/theme/ApiItem/Footer/styles.module.css +0 -18
  126. package/src/theme/ApiItem/Metadata/index.tsx +0 -24
  127. package/src/theme/ApiItem/Paginator/index.tsx +0 -21
  128. package/src/theme/ApiItem/TOC/Desktop/index.tsx +0 -25
  129. package/src/theme/ApiItem/TOC/Mobile/index.tsx +0 -28
  130. package/src/theme/ApiItem/TOC/Mobile/styles.module.css +0 -19
package/lib/index.js CHANGED
@@ -4,31 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = docusaurusThemeOpenAPI;
7
-
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _webpack = require("webpack");
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  /* ============================================================================
15
11
  * Copyright (c) Palo Alto Networks
16
12
  *
17
13
  * This source code is licensed under the MIT license found in the
18
14
  * LICENSE file in the root directory of this source tree.
19
15
  * ========================================================================== */
16
+
20
17
  function docusaurusThemeOpenAPI() {
21
18
  return {
22
19
  name: "docusaurus-theme-openapi",
23
-
20
+ getClientModules() {
21
+ const modules = [require.resolve("./theme/styles.css")];
22
+ return modules;
23
+ },
24
24
  getThemePath() {
25
25
  return _path.default.join(__dirname, "..", "lib-next", "theme");
26
26
  },
27
-
28
27
  getTypeScriptThemePath() {
29
28
  return _path.default.resolve(__dirname, "..", "src", "theme");
30
29
  },
31
-
32
30
  configureWebpack() {
33
31
  return {
34
32
  plugins: [new _webpack.ProvidePlugin({
@@ -43,6 +41,5 @@ function docusaurusThemeOpenAPI() {
43
41
  }
44
42
  };
45
43
  }
46
-
47
44
  };
48
45
  }
@@ -4,17 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createDescription = createDescription;
7
-
8
7
  /* ============================================================================
9
8
  * Copyright (c) Palo Alto Networks
10
9
  *
11
10
  * This source code is licensed under the MIT license found in the
12
11
  * LICENSE file in the root directory of this source tree.
13
12
  * ========================================================================== */
13
+
14
14
  function createDescription(description) {
15
15
  if (!description) {
16
16
  return "";
17
17
  }
18
-
19
18
  return `\n\n${description}\n\n`;
20
19
  }
@@ -5,20 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getQualifierMessage = getQualifierMessage;
7
7
  exports.getSchemaName = getSchemaName;
8
-
9
8
  /* ============================================================================
10
9
  * Copyright (c) Palo Alto Networks
11
10
  *
12
11
  * This source code is licensed under the MIT license found in the
13
12
  * LICENSE file in the root directory of this source tree.
14
13
  * ========================================================================== */
14
+
15
15
  function prettyName(schema, circular) {
16
16
  var _schema$title;
17
-
18
17
  if (schema.format) {
19
18
  return schema.format;
20
19
  }
21
-
22
20
  if (schema.allOf) {
23
21
  if (typeof schema.allOf[0] === "string") {
24
22
  // @ts-ignore
@@ -26,43 +24,35 @@ function prettyName(schema, circular) {
26
24
  return schema.allOf[0];
27
25
  }
28
26
  }
29
-
30
27
  return "object";
31
28
  }
32
-
33
29
  if (schema.oneOf) {
34
30
  return "object";
35
31
  }
36
-
37
32
  if (schema.anyOf) {
38
33
  return "object";
39
34
  }
40
-
41
35
  if (schema.type === "object") {
42
36
  var _schema$xml$name, _schema$xml;
43
-
44
- return (_schema$xml$name = (_schema$xml = schema.xml) === null || _schema$xml === void 0 ? void 0 : _schema$xml.name) !== null && _schema$xml$name !== void 0 ? _schema$xml$name : schema.type; // return schema.type;
37
+ return (_schema$xml$name = (_schema$xml = schema.xml) === null || _schema$xml === void 0 ? void 0 : _schema$xml.name) !== null && _schema$xml$name !== void 0 ? _schema$xml$name : schema.type;
38
+ // return schema.type;
45
39
  }
46
40
 
47
41
  if (schema.type === "array") {
48
42
  var _schema$xml$name2, _schema$xml2;
49
-
50
- return (_schema$xml$name2 = (_schema$xml2 = schema.xml) === null || _schema$xml2 === void 0 ? void 0 : _schema$xml2.name) !== null && _schema$xml$name2 !== void 0 ? _schema$xml$name2 : schema.type; // return schema.type;
43
+ return (_schema$xml$name2 = (_schema$xml2 = schema.xml) === null || _schema$xml2 === void 0 ? void 0 : _schema$xml2.name) !== null && _schema$xml$name2 !== void 0 ? _schema$xml$name2 : schema.type;
44
+ // return schema.type;
51
45
  }
52
46
 
53
47
  return (_schema$title = schema.title) !== null && _schema$title !== void 0 ? _schema$title : schema.type;
54
48
  }
55
-
56
49
  function getSchemaName(schema, circular) {
57
50
  var _prettyName;
58
-
59
51
  if (schema.items) {
60
52
  return prettyName(schema.items, circular) + "[]";
61
53
  }
62
-
63
54
  return (_prettyName = prettyName(schema, circular)) !== null && _prettyName !== void 0 ? _prettyName : "";
64
55
  }
65
-
66
56
  function getQualifierMessage(schema) {
67
57
  // TODO:
68
58
  // - uniqueItems
@@ -72,57 +62,44 @@ function getQualifierMessage(schema) {
72
62
  if (!schema) {
73
63
  return undefined;
74
64
  }
75
-
76
65
  if (schema.items && schema.minItems === undefined && schema.maxItems === undefined) {
77
66
  return getQualifierMessage(schema.items);
78
67
  }
79
-
80
68
  let message = "**Possible values:** ";
81
69
  let qualifierGroups = [];
82
-
83
70
  if (schema.items && schema.items.enum) {
84
71
  if (schema.items.enum) {
85
72
  qualifierGroups.push(`[${schema.items.enum.map(e => `\`${e}\``).join(", ")}]`);
86
73
  }
87
74
  }
88
-
89
75
  if (schema.minLength || schema.maxLength) {
90
76
  let lengthQualifier = "";
91
77
  let minLength;
92
78
  let maxLength;
93
-
94
79
  if (schema.minLength && schema.minLength > 1) {
95
80
  minLength = `\`>= ${schema.minLength} characters\``;
96
81
  }
97
-
98
82
  if (schema.minLength && schema.minLength === 1) {
99
83
  minLength = `\`non-empty\``;
100
84
  }
101
-
102
85
  if (schema.maxLength) {
103
86
  maxLength = `\`<= ${schema.maxLength} characters\``;
104
87
  }
105
-
106
88
  if (minLength && !maxLength) {
107
89
  lengthQualifier += minLength;
108
90
  }
109
-
110
91
  if (maxLength && !minLength) {
111
92
  lengthQualifier += maxLength;
112
93
  }
113
-
114
94
  if (minLength && maxLength) {
115
95
  lengthQualifier += `${minLength} and ${maxLength}`;
116
96
  }
117
-
118
97
  qualifierGroups.push(lengthQualifier);
119
98
  }
120
-
121
99
  if (schema.minimum || schema.maximum || typeof schema.exclusiveMinimum === "number" || typeof schema.exclusiveMaximum === "number") {
122
100
  let minmaxQualifier = "";
123
101
  let minimum;
124
102
  let maximum;
125
-
126
103
  if (typeof schema.exclusiveMinimum === "number") {
127
104
  minimum = `\`> ${schema.exclusiveMinimum}\``;
128
105
  } else if (schema.minimum && !schema.exclusiveMinimum) {
@@ -130,7 +107,6 @@ function getQualifierMessage(schema) {
130
107
  } else if (schema.minimum && schema.exclusiveMinimum === true) {
131
108
  minimum = `\`> ${schema.minimum}\``;
132
109
  }
133
-
134
110
  if (typeof schema.exclusiveMaximum === "number") {
135
111
  maximum = `\`< ${schema.exclusiveMaximum}\``;
136
112
  } else if (schema.maximum && !schema.exclusiveMaximum) {
@@ -138,49 +114,38 @@ function getQualifierMessage(schema) {
138
114
  } else if (schema.maximum && schema.exclusiveMaximum === true) {
139
115
  maximum = `\`< ${schema.maximum}\``;
140
116
  }
141
-
142
117
  if (minimum && !maximum) {
143
118
  minmaxQualifier += minimum;
144
119
  }
145
-
146
120
  if (maximum && !minimum) {
147
121
  minmaxQualifier += maximum;
148
122
  }
149
-
150
123
  if (minimum && maximum) {
151
124
  minmaxQualifier += `${minimum} and ${maximum}`;
152
125
  }
153
-
154
126
  qualifierGroups.push(minmaxQualifier);
155
127
  }
156
-
157
128
  if (schema.pattern) {
158
129
  qualifierGroups.push(`Value must match regular expression \`${schema.pattern}\``);
159
- } // Check if discriminator mapping
160
-
130
+ }
161
131
 
132
+ // Check if discriminator mapping
162
133
  const discriminator = schema;
163
-
164
134
  if (discriminator.mapping) {
165
135
  const values = Object.keys(discriminator.mapping);
166
136
  qualifierGroups.push(`[${values.map(e => `\`${e}\``).join(", ")}]`);
167
137
  }
168
-
169
138
  if (schema.enum) {
170
139
  qualifierGroups.push(`[${schema.enum.map(e => `\`${e}\``).join(", ")}]`);
171
140
  }
172
-
173
141
  if (schema.minItems) {
174
142
  qualifierGroups.push(`\`>= ${schema.minItems}\``);
175
143
  }
176
-
177
144
  if (schema.maxItems) {
178
145
  qualifierGroups.push(`\`<= ${schema.maxItems}\``);
179
146
  }
180
-
181
147
  if (qualifierGroups.length === 0) {
182
148
  return undefined;
183
149
  }
184
-
185
150
  return message + qualifierGroups.join(", ");
186
151
  }
@@ -6,40 +6,34 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.create = create;
7
7
  exports.guard = guard;
8
8
  exports.render = render;
9
-
10
9
  /* ============================================================================
11
10
  * Copyright (c) Palo Alto Networks
12
11
  *
13
12
  * This source code is licensed under the MIT license found in the
14
13
  * LICENSE file in the root directory of this source tree.
15
14
  * ========================================================================== */
15
+
16
16
  function create(tag, props) {
17
17
  const {
18
18
  children,
19
19
  ...rest
20
20
  } = props;
21
21
  let propString = "";
22
-
23
22
  for (const [key, value] of Object.entries(rest)) {
24
23
  propString += ` ${key}={${JSON.stringify(value)}}`;
25
24
  }
26
-
27
25
  return `<${tag}${propString}>${render(children)}</${tag}>`;
28
26
  }
29
-
30
27
  function guard(value, cb) {
31
28
  if (value) {
32
29
  const children = cb(value);
33
30
  return render(children);
34
31
  }
35
-
36
32
  return "";
37
33
  }
38
-
39
34
  function render(children) {
40
35
  if (Array.isArray(children)) {
41
36
  return children.filter(c => c !== undefined).join("");
42
37
  }
43
-
44
38
  return children !== null && children !== void 0 ? children : "";
45
39
  }
@@ -4,38 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _react = _interopRequireDefault(require("react"));
9
-
10
8
  var _hooks = require("../../ApiItem/hooks");
11
-
12
9
  var _FormItem = _interopRequireDefault(require("./../FormItem"));
13
-
14
10
  var _FormSelect = _interopRequireDefault(require("./../FormSelect"));
15
-
16
11
  var _slice = require("./slice");
17
-
18
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
13
  /* ============================================================================
21
14
  * Copyright (c) Palo Alto Networks
22
15
  *
23
16
  * This source code is licensed under the MIT license found in the
24
17
  * LICENSE file in the root directory of this source tree.
25
18
  * ========================================================================== */
19
+
26
20
  function Accept() {
27
21
  const value = (0, _hooks.useTypedSelector)(state => state.accept.value);
28
22
  const options = (0, _hooks.useTypedSelector)(state => state.accept.options);
29
23
  const dispatch = (0, _hooks.useTypedDispatch)();
30
-
31
24
  if (options.length <= 1) {
32
25
  return null;
33
26
  }
34
-
35
27
  return <_FormItem.default label="Accept">
36
28
  <_FormSelect.default value={value} options={options} onChange={e => dispatch((0, _slice.setAccept)(e.target.value))} />
37
29
  </_FormItem.default>;
38
30
  }
39
-
40
31
  var _default = Accept;
41
32
  exports.default = _default;
@@ -4,15 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.slice = exports.setAccept = exports.default = void 0;
7
-
8
7
  var _toolkit = require("@reduxjs/toolkit");
9
-
10
8
  /* ============================================================================
11
9
  * Copyright (c) Palo Alto Networks
12
10
  *
13
11
  * This source code is licensed under the MIT license found in the
14
12
  * LICENSE file in the root directory of this source tree.
15
13
  * ========================================================================== */
14
+
16
15
  const initialState = {};
17
16
  const slice = (0, _toolkit.createSlice)({
18
17
  name: "accept",
@@ -4,33 +4,32 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getAuthDataKeys = getAuthDataKeys;
7
-
8
7
  /* ============================================================================
9
8
  * Copyright (c) Palo Alto Networks
10
9
  *
11
10
  * This source code is licensed under the MIT license found in the
12
11
  * LICENSE file in the root directory of this source tree.
13
12
  * ========================================================================== */
13
+
14
14
  function getAuthDataKeys(security) {
15
15
  // Bearer Auth
16
16
  if (security.type === "http" && security.scheme === "bearer") {
17
17
  return ["token"];
18
18
  }
19
-
20
19
  if (security.type === "oauth2") {
21
20
  return ["token"];
22
- } // Basic Auth
23
-
21
+ }
24
22
 
23
+ // Basic Auth
25
24
  if (security.type === "http" && security.scheme === "basic") {
26
25
  return ["username", "password"];
27
- } // API Auth
28
-
26
+ }
29
27
 
28
+ // API Auth
30
29
  if (security.type === "apiKey") {
31
30
  return ["apiKey"];
32
- } // none
33
-
31
+ }
34
32
 
33
+ // none
35
34
  return [];
36
35
  }
@@ -4,37 +4,28 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _react = _interopRequireDefault(require("react"));
9
-
10
8
  var _hooks = require("../../ApiItem/hooks");
11
-
12
9
  var _FormItem = _interopRequireDefault(require("../FormItem"));
13
-
14
10
  var _FormSelect = _interopRequireDefault(require("../FormSelect"));
15
-
16
11
  var _FormTextInput = _interopRequireDefault(require("../FormTextInput"));
17
-
18
12
  var _slice = require("./slice");
19
-
20
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
14
  /* ============================================================================
23
15
  * Copyright (c) Palo Alto Networks
24
16
  *
25
17
  * This source code is licensed under the MIT license found in the
26
18
  * LICENSE file in the root directory of this source tree.
27
19
  * ========================================================================== */
20
+
28
21
  function Authorization() {
29
22
  const data = (0, _hooks.useTypedSelector)(state => state.auth.data);
30
23
  const options = (0, _hooks.useTypedSelector)(state => state.auth.options);
31
24
  const selected = (0, _hooks.useTypedSelector)(state => state.auth.selected);
32
25
  const dispatch = (0, _hooks.useTypedDispatch)();
33
-
34
26
  if (selected === undefined) {
35
27
  return null;
36
28
  }
37
-
38
29
  const selectedAuth = options[selected];
39
30
  const optionKeys = Object.keys(options);
40
31
  return <div>
@@ -46,7 +37,6 @@ function Authorization() {
46
37
  {selectedAuth.map(a => {
47
38
  if (a.type === "http" && a.scheme === "bearer") {
48
39
  var _data$a$key$token;
49
-
50
40
  return <_FormItem.default label="Bearer Token" key={a.key + "-bearer"}>
51
41
  <_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 => {
52
42
  const value = e.target.value.trim();
@@ -58,10 +48,8 @@ function Authorization() {
58
48
  }} />
59
49
  </_FormItem.default>;
60
50
  }
61
-
62
51
  if (a.type === "oauth2") {
63
52
  var _data$a$key$token2;
64
-
65
53
  return <_FormItem.default label="Bearer Token" key={a.key + "-oauth2"}>
66
54
  <_FormTextInput.default placeholder="Bearer Token" value={(_data$a$key$token2 = data[a.key].token) !== null && _data$a$key$token2 !== void 0 ? _data$a$key$token2 : ""} onChange={e => {
67
55
  const value = e.target.value.trim();
@@ -73,10 +61,8 @@ function Authorization() {
73
61
  }} />
74
62
  </_FormItem.default>;
75
63
  }
76
-
77
64
  if (a.type === "http" && a.scheme === "basic") {
78
65
  var _data$a$key$username, _data$a$key$password;
79
-
80
66
  return <_react.default.Fragment key={a.key + "-basic"}>
81
67
  <_FormItem.default label="Username">
82
68
  <_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 => {
@@ -100,10 +86,8 @@ function Authorization() {
100
86
  </_FormItem.default>
101
87
  </_react.default.Fragment>;
102
88
  }
103
-
104
89
  if (a.type === "apiKey") {
105
90
  var _data$a$key$apiKey;
106
-
107
91
  return <_FormItem.default label={`${a.key}`} key={a.key + "-apikey"}>
108
92
  <_FormTextInput.default placeholder={`${a.key}`} value={(_data$a$key$apiKey = data[a.key].apiKey) !== null && _data$a$key$apiKey !== void 0 ? _data$a$key$apiKey : ""} onChange={e => {
109
93
  const value = e.target.value.trim();
@@ -115,11 +99,9 @@ function Authorization() {
115
99
  }} />
116
100
  </_FormItem.default>;
117
101
  }
118
-
119
102
  return null;
120
103
  })}
121
104
  </div>;
122
105
  }
123
-
124
106
  var _default = Authorization;
125
107
  exports.default = _default;
@@ -5,29 +5,28 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createAuth = createAuth;
7
7
  exports.slice = exports.setSelectedAuth = exports.setAuthData = exports.default = void 0;
8
-
9
8
  var _toolkit = require("@reduxjs/toolkit");
10
-
11
9
  var _storageUtils = require("../storage-utils");
12
-
13
10
  var _authTypes = require("./auth-types");
14
-
15
11
  /* ============================================================================
16
12
  * Copyright (c) Palo Alto Networks
17
13
  *
18
14
  * This source code is licensed under the MIT license found in the
19
15
  * LICENSE file in the root directory of this source tree.
20
16
  * ========================================================================== */
17
+
21
18
  // The global definitions
22
19
  // "securitySchemes": {
23
20
  // "BearerAuth": { "type": "http", "scheme": "BeAreR" },
24
21
  // "BasicAuth": { "type": "http", "scheme": "basic" }
25
22
  // },
23
+
26
24
  // The operation level requirements
27
25
  // "security": [
28
26
  // { "BearerAuth": [] },
29
27
  // { "BearerAuth": [], "BasicAuth": [] }
30
28
  // ],
29
+
31
30
  // SLICE_STATE
32
31
  // data:
33
32
  // BearerAuth:
@@ -41,73 +40,60 @@ var _authTypes = require("./auth-types");
41
40
  // "BearerAuth and BasicAuth": [{ key: "BearerAuth", scopes: [], ...rest }, { key: "BasicAuth", scopes: [], ...rest }]
42
41
  //
43
42
  // selected: "BearerAuth and BasicAuth"
43
+
44
44
  // LOCAL_STORAGE
45
45
  // hash(SLICE_STATE.options) -> "BearerAuth and BasicAuth"
46
46
  // BearerAuth -> { token: xxx }
47
47
  // BasicAuth -> { username: xxx, password: xxx }
48
+
48
49
  function createAuth({
49
50
  security,
50
51
  securitySchemes,
51
52
  options: opts
52
53
  }) {
53
54
  var _persisted;
54
-
55
55
  const storage = (0, _storageUtils.createStorage)("sessionStorage");
56
56
  let data = {};
57
57
  let options = {};
58
-
59
58
  for (const option of security !== null && security !== void 0 ? security : []) {
60
59
  const id = Object.keys(option).join(" and ");
61
-
62
60
  for (const [schemeID, scopes] of Object.entries(option)) {
63
61
  const scheme = securitySchemes === null || securitySchemes === void 0 ? void 0 : securitySchemes[schemeID];
64
-
65
62
  if (scheme) {
66
63
  if (options[id] === undefined) {
67
64
  options[id] = [];
68
65
  }
69
-
70
66
  const dataKeys = (0, _authTypes.getAuthDataKeys)(scheme);
71
-
72
67
  for (const key of dataKeys) {
73
68
  if (data[schemeID] === undefined) {
74
69
  data[schemeID] = {};
75
70
  }
76
-
77
71
  let persisted = undefined;
78
-
79
72
  try {
80
73
  var _storage$getItem;
81
-
82
74
  persisted = JSON.parse((_storage$getItem = storage.getItem(schemeID)) !== null && _storage$getItem !== void 0 ? _storage$getItem : "")[key];
83
75
  } catch {}
84
-
85
76
  data[schemeID][key] = persisted;
86
77
  }
87
-
88
- options[id].push({ ...scheme,
78
+ options[id].push({
79
+ ...scheme,
89
80
  key: schemeID,
90
81
  scopes
91
82
  });
92
83
  }
93
84
  }
94
85
  }
95
-
96
86
  let persisted = undefined;
97
-
98
87
  try {
99
88
  var _storage$getItem2;
100
-
101
89
  persisted = (_storage$getItem2 = storage.getItem((0, _storageUtils.hashArray)(Object.keys(options)))) !== null && _storage$getItem2 !== void 0 ? _storage$getItem2 : undefined;
102
90
  } catch {}
103
-
104
91
  return {
105
92
  data,
106
93
  options,
107
94
  selected: (_persisted = persisted) !== null && _persisted !== void 0 ? _persisted : Object.keys(options)[0]
108
95
  };
109
96
  }
110
-
111
97
  const initialState = {};
112
98
  const slice = (0, _toolkit.createSlice)({
113
99
  name: "auth",