@redocly/openapi-docs 3.12.0 → 3.12.1

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 (384) hide show
  1. package/dist/redocly-openapi-docs.min.js +753 -750
  2. package/lib/components/ApiInfo/ApiInfo.js +29 -1
  3. package/lib/components/ApiInfo/Metadata.js +29 -1
  4. package/lib/components/ApiInfo/index.js +2 -1
  5. package/lib/components/ApiInfo/styled.js +16 -8
  6. package/lib/components/CallbackSamples/CallbackSamples.js +25 -4
  7. package/lib/components/CallbackSamples/index.js +2 -1
  8. package/lib/components/Callbacks/CallbackDetails.js +17 -3
  9. package/lib/components/Callbacks/CallbackOperation.js +24 -3
  10. package/lib/components/Callbacks/CallbackSummary.js +19 -3
  11. package/lib/components/Callbacks/CallbacksList.js +16 -1
  12. package/lib/components/Callbacks/index.js +4 -1
  13. package/lib/components/Callbacks/styled.js +6 -3
  14. package/lib/components/Content/Content.js +10 -1
  15. package/lib/components/Content/index.js +2 -1
  16. package/lib/components/Content/useAutoScroll.js +50 -1
  17. package/lib/components/ContentItem/ContentItem.js +31 -1
  18. package/lib/components/ContentItem/index.js +2 -1
  19. package/lib/components/ContentItem/useIsExpanded.js +33 -1
  20. package/lib/components/ContentItems/ContentItems.js +19 -1
  21. package/lib/components/ContentItems/Items.js +13 -1
  22. package/lib/components/ContentItems/VirtualList.js +35 -1
  23. package/lib/components/ContentItems/helpers.js +49 -1
  24. package/lib/components/ContentItems/index.js +2 -1
  25. package/lib/components/ContentItems/useScrollOnRender.js +26 -1
  26. package/lib/components/Discriminator/Discriminator.js +27 -2
  27. package/lib/components/Discriminator/index.js +2 -1
  28. package/lib/components/Download/DownloadSpecification.js +46 -4
  29. package/lib/components/Download/index.js +2 -1
  30. package/lib/components/Download/types.js +2 -0
  31. package/lib/components/Download/useDownloadInfo.js +42 -1
  32. package/lib/components/ErrorBoundary/ErrorBoundary.js +22 -2
  33. package/lib/components/ErrorBoundary/index.js +2 -1
  34. package/lib/components/ExpandAllButton/ExpandAllButton.js +31 -2
  35. package/lib/components/ExpandAllButton/index.js +2 -1
  36. package/lib/components/ExternalDocumentation/ExternalDocumentation.js +18 -4
  37. package/lib/components/ExternalDocumentation/index.js +2 -1
  38. package/lib/components/Language/LanguageDropdown.js +21 -1
  39. package/lib/components/Language/LanguageItem.js +33 -1
  40. package/lib/components/Language/LanguageList.js +93 -1
  41. package/lib/components/Language/_tests_/LanguageDropdown.test.js +23 -1
  42. package/lib/components/Language/constants.js +3 -1
  43. package/lib/components/Language/index.js +4 -1
  44. package/lib/components/Language/styled.js +29 -15
  45. package/lib/components/Markdown/Markdown.js +64 -1
  46. package/lib/components/Markdown/index.js +3 -1
  47. package/lib/components/Markdown/types.js +2 -0
  48. package/lib/components/MediaTypeSwitch/MediaTypesSwitch.js +51 -1
  49. package/lib/components/MediaTypeSwitch/index.js +2 -1
  50. package/lib/components/OperationItem/Description.js +9 -1
  51. package/lib/components/OperationItem/OperationItem.js +70 -5
  52. package/lib/components/OperationItem/_tests_/OperationItem.test.js +70 -1
  53. package/lib/components/OperationItem/_tests_/__mocks__/mock-intersection-observer.js +40 -1
  54. package/lib/components/OperationItem/index.js +2 -1
  55. package/lib/components/OperationItem/types.js +2 -0
  56. package/lib/components/Overlay.js +48 -3
  57. package/lib/components/Overview/Overview.js +20 -1
  58. package/lib/components/Overview/index.js +2 -1
  59. package/lib/components/PageFooter/PageFooter.js +19 -1
  60. package/lib/components/PageFooter/index.js +2 -1
  61. package/lib/components/Panel/ResponsePanel.js +12 -6
  62. package/lib/components/Panel/Trigger.js +4 -2
  63. package/lib/components/Panel/index.js +3 -1
  64. package/lib/components/PanelItem/PanelItem.js +6 -1
  65. package/lib/components/PanelItem/index.js +3 -1
  66. package/lib/components/PanelItem/styled.js +20 -10
  67. package/lib/components/PayloadSamples/Example.js +6 -1
  68. package/lib/components/PayloadSamples/ExampleValue.js +30 -1
  69. package/lib/components/PayloadSamples/MediaTypeSamples.js +36 -2
  70. package/lib/components/PayloadSamples/PayloadSamples.js +26 -1
  71. package/lib/components/PayloadSamples/index.js +7 -1
  72. package/lib/components/PayloadSamples/styled.js +9 -4
  73. package/lib/components/PayloadSamples/types.js +2 -0
  74. package/lib/components/PropertyDetails/DescriptionEnums.js +19 -3
  75. package/lib/components/PropertyDetails/EnumValues.js +37 -1
  76. package/lib/components/PropertyDetails/Examples.js +26 -1
  77. package/lib/components/PropertyDetails/Extensions.js +17 -2
  78. package/lib/components/PropertyDetails/FieldDetail.js +15 -2
  79. package/lib/components/PropertyDetails/FieldDetails.js +51 -6
  80. package/lib/components/PropertyDetails/Pattern.js +21 -1
  81. package/lib/components/PropertyDetails/PlusCircleIcon.js +10 -4
  82. package/lib/components/PropertyDetails/PropertyDetails.js +22 -5
  83. package/lib/components/PropertyDetails/SchemaTypeInfo.js +10 -2
  84. package/lib/components/PropertyDetails/SimpleEnums.js +13 -2
  85. package/lib/components/PropertyDetails/cycleColorsByLevel.js +18 -1
  86. package/lib/components/PropertyDetails/index.js +4 -1
  87. package/lib/components/PropertyDetails/styled.js +15 -7
  88. package/lib/components/PropertyDetails/types.js +2 -0
  89. package/lib/components/RedoclyOpenAPIDocs/Providers.js +114 -1
  90. package/lib/components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocs.js +57 -1
  91. package/lib/components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocsStandalone.js +86 -1
  92. package/lib/components/RedoclyOpenAPIDocs/index.js +5 -1
  93. package/lib/components/RedoclyOpenAPIDocs/styled.js +4 -2
  94. package/lib/components/RedoclyOpenAPIDocs/types.js +2 -0
  95. package/lib/components/RedoclyOpenAPIDocs/utils.js +33 -1
  96. package/lib/components/RenderHook/RenderHook.js +17 -1
  97. package/lib/components/RenderHook/index.js +2 -1
  98. package/lib/components/Replay/EmbeddedReplay.js +41 -3
  99. package/lib/components/Replay/Replay.js +99 -1
  100. package/lib/components/Replay/index.js +3 -1
  101. package/lib/components/Replay/utils.js +208 -1
  102. package/lib/components/Request/RequestDetails.js +33 -2
  103. package/lib/components/Request/types.js +2 -0
  104. package/lib/components/RequestParameters/Body.js +8 -1
  105. package/lib/components/RequestParameters/ParametersGroup.js +19 -4
  106. package/lib/components/RequestParameters/RequestParameters.js +40 -1
  107. package/lib/components/RequestParameters/index.js +4 -1
  108. package/lib/components/RequestSamples/CodeSample.js +55 -2
  109. package/lib/components/RequestSamples/Example.js +37 -1
  110. package/lib/components/RequestSamples/RequestSamples.js +89 -5
  111. package/lib/components/RequestSamples/index.js +3 -1
  112. package/lib/components/RequestSamples/useCodeSamples.js +92 -1
  113. package/lib/components/ResponseSamples/ResponseSamples.js +47 -1
  114. package/lib/components/ResponseSamples/Summary.js +9 -1
  115. package/lib/components/ResponseSamples/index.js +2 -1
  116. package/lib/components/Responses/OperationResponseList.js +42 -2
  117. package/lib/components/Responses/ResponseDetails.js +18 -1
  118. package/lib/components/Responses/ResponseHeaders.js +15 -1
  119. package/lib/components/Responses/index.js +6 -1
  120. package/lib/components/Responses/styled.js +14 -6
  121. package/lib/components/Responses/types.js +2 -0
  122. package/lib/components/RightPanel/RightPanel.js +21 -1
  123. package/lib/components/RightPanel/index.js +2 -1
  124. package/lib/components/Samples/ExampleSwitch.js +33 -1
  125. package/lib/components/Samples/index.js +3 -1
  126. package/lib/components/Samples/use-example-key.js +12 -1
  127. package/lib/components/Schema/ArraySchema.js +45 -1
  128. package/lib/components/Schema/ObjectSchema.js +29 -1
  129. package/lib/components/Schema/OneOfSchema.js +47 -3
  130. package/lib/components/Schema/RecursiveSchema.js +10 -1
  131. package/lib/components/Schema/Schema.js +63 -2
  132. package/lib/components/Schema/SubSchema.js +20 -1
  133. package/lib/components/Schema/helpers.js +16 -1
  134. package/lib/components/Schema/index.js +5 -1
  135. package/lib/components/Schema/types.js +2 -0
  136. package/lib/components/Schema/useOneOfLocationIdx.js +11 -1
  137. package/lib/components/SchemaDefinition/SchemaDefinition.js +65 -2
  138. package/lib/components/SchemaDefinition/index.js +2 -1
  139. package/lib/components/SectionContent/SectionContent.js +49 -6
  140. package/lib/components/SectionContent/index.js +2 -1
  141. package/lib/components/SectionItem/SectionItem.js +14 -1
  142. package/lib/components/SectionItem/index.js +2 -1
  143. package/lib/components/Security/Divider.js +9 -2
  144. package/lib/components/Security/OAuthFlow.js +11 -1
  145. package/lib/components/Security/OAuthScopes.js +59 -9
  146. package/lib/components/Security/Security.js +15 -1
  147. package/lib/components/Security/SecurityButton.js +31 -7
  148. package/lib/components/Security/SecurityFlow.js +28 -4
  149. package/lib/components/Security/SecurityModal.js +34 -5
  150. package/lib/components/Security/SecuritySchemeItem.js +15 -4
  151. package/lib/components/Security/helper.js +16 -1
  152. package/lib/components/Security/index.js +11 -1
  153. package/lib/components/Security/styled.js +6 -3
  154. package/lib/components/SelectOrLabel/SelectOrLabel.js +12 -2
  155. package/lib/components/SelectOrLabel/index.js +2 -1
  156. package/lib/components/ServerList/ServerList.js +36 -10
  157. package/lib/components/ServerList/index.js +2 -1
  158. package/lib/components/ServerList/types.js +2 -0
  159. package/lib/components/ServerListDropdown/ServerListDropdown.js +54 -1
  160. package/lib/components/ServerListDropdown/index.js +2 -1
  161. package/lib/components/ServerListDropdown/styled.js +15 -6
  162. package/lib/components/SideMenu/SideMenu.js +13 -2
  163. package/lib/components/SideMenu/hooks/useMenuItems.js +110 -1
  164. package/lib/components/SideMenu/index.js +2 -1
  165. package/lib/components/SideMenu/types.js +2 -0
  166. package/lib/components/StickySidebar/SidebarActions.js +14 -2
  167. package/lib/components/StickySidebar/StickyResponsiveSidebar.js +37 -7
  168. package/lib/components/StickySidebar/index.js +2 -1
  169. package/lib/components/Tabs/Tabs.js +16 -5
  170. package/lib/components/Tabs/index.js +3 -1
  171. package/lib/components/Tabs/useTabsState.js +22 -1
  172. package/lib/components/TagItem/OperationNavigationItems.js +18 -4
  173. package/lib/components/TagItem/OperationsNavigation.js +46 -2
  174. package/lib/components/TagItem/TagItem.js +40 -7
  175. package/lib/components/TagItem/index.js +2 -1
  176. package/lib/components/TagItem/styled.js +5 -2
  177. package/lib/components/TagItem/types.js +2 -0
  178. package/lib/components/ViewNested/ViewNested.js +42 -9
  179. package/lib/components/ViewNested/index.js +2 -1
  180. package/lib/components/common/Badges.js +21 -5
  181. package/lib/components/common/BodyContent/BodyContent.js +31 -4
  182. package/lib/components/common/BodyContent/index.js +2 -1
  183. package/lib/components/common/ClearButton/ClearButton.js +5 -1
  184. package/lib/components/common/ClearButton/index.js +3 -1
  185. package/lib/components/common/ClearButton/styled.js +5 -2
  186. package/lib/components/common/ClearButton/types.js +2 -0
  187. package/lib/components/common/CodeBlockPanel.js +7 -3
  188. package/lib/components/common/ConstraintsView.js +14 -2
  189. package/lib/components/common/Dropdown/Dropdown.js +22 -4
  190. package/lib/components/common/Dropdown/index.js +2 -1
  191. package/lib/components/common/ExpandableExample/ExpandableExample.js +24 -3
  192. package/lib/components/common/ExpandableExample/index.js +2 -1
  193. package/lib/components/common/Extensions.js +17 -2
  194. package/lib/components/common/Fields/fields-layout.js +76 -51
  195. package/lib/components/common/Fields/fields.js +39 -17
  196. package/lib/components/common/Fields/index.js +3 -1
  197. package/lib/components/common/LinkToField.js +33 -6
  198. package/lib/components/common/OperationItemTitle.js +12 -6
  199. package/lib/components/common/SchemaSelection/SchemaSelection.js +51 -1
  200. package/lib/components/common/SchemaSelection/index.js +2 -1
  201. package/lib/components/common/Select/Select.js +21 -1
  202. package/lib/components/common/Select/index.js +3 -1
  203. package/lib/components/common/Select/styled.js +17 -9
  204. package/lib/components/common/Select/types.js +2 -0
  205. package/lib/components/common/Skeleton/LanguageListSkeleton.js +16 -6
  206. package/lib/components/common/Skeleton/Skeleton.js +15 -5
  207. package/lib/components/common/Skeleton/index.js +3 -1
  208. package/lib/components/common/headers.js +4 -2
  209. package/lib/components/common/index.js +14 -1
  210. package/lib/components/common/linkify.js +28 -4
  211. package/lib/components/common/mixins.js +4 -2
  212. package/lib/components/common/panels.js +52 -29
  213. package/lib/components/common/schema.js +16 -8
  214. package/lib/components/common/styled.js +15 -7
  215. package/lib/components/index.js +25 -1
  216. package/lib/components/pluggable/RedocExample.js +20 -1
  217. package/lib/components/pluggable/RedocSchema.js +22 -1
  218. package/lib/components/pluggable/index.js +3 -1
  219. package/lib/components/pluggable/styled.components.js +9 -4
  220. package/lib/constants.js +30 -1
  221. package/lib/empty.js +7 -1
  222. package/lib/events/codeSampleCopy.js +19 -1
  223. package/lib/events/creator.js +5 -1
  224. package/lib/events/index.js +8 -1
  225. package/lib/events/languageSwitch.js +18 -1
  226. package/lib/events/panelToggle.js +16 -1
  227. package/lib/events/serverSwitch.js +13 -1
  228. package/lib/events/tryItOpen.js +12 -1
  229. package/lib/events/tryItSent.js +12 -1
  230. package/lib/events/types.js +11 -1
  231. package/lib/hoc/types.js +2 -0
  232. package/lib/hoc/utils.js +4 -1
  233. package/lib/hoc/withRouter.js +17 -1
  234. package/lib/hoc/withStore.js +28 -1
  235. package/lib/hooks/index.js +9 -1
  236. package/lib/hooks/useActivateExample.js +35 -1
  237. package/lib/hooks/useActiveWithFallback.js +12 -1
  238. package/lib/hooks/useContentItems.js +10 -1
  239. package/lib/hooks/useLicense.js +17 -1
  240. package/lib/hooks/usePerformanceMetrics.js +26 -1
  241. package/lib/hooks/useRouter.js +17 -1
  242. package/lib/hooks/useTelemetry.js +5 -1
  243. package/lib/hooks/useTranslate.js +6 -1
  244. package/lib/hooks/useUppercase2LowercaseRedirect.js +12 -1
  245. package/lib/icons/CSharpIcon/CSharpIcon.js +7 -1
  246. package/lib/icons/CSharpIcon/index.js +2 -1
  247. package/lib/icons/CurlIcon/CurlIcon.js +8 -2
  248. package/lib/icons/CurlIcon/index.js +2 -1
  249. package/lib/icons/GOIcon/GOIcon.js +7 -1
  250. package/lib/icons/GOIcon/index.js +2 -1
  251. package/lib/icons/JavaIcon/JavaIcon.js +7 -1
  252. package/lib/icons/JavaIcon/index.js +2 -1
  253. package/lib/icons/JavaScriptIcon/JavaScriptIcon.js +7 -1
  254. package/lib/icons/JavaScriptIcon/index.js +2 -1
  255. package/lib/icons/NodeJSIcon/NodeJSIcon.js +7 -1
  256. package/lib/icons/NodeJSIcon/index.js +2 -1
  257. package/lib/icons/PHPIcon/PHPIcon.js +7 -1
  258. package/lib/icons/PHPIcon/index.js +2 -1
  259. package/lib/icons/PayloadIcon/PayloadIcon.js +7 -1
  260. package/lib/icons/PayloadIcon/index.js +2 -1
  261. package/lib/icons/PythonIcon/PythonIcon.js +7 -1
  262. package/lib/icons/PythonIcon/index.js +2 -1
  263. package/lib/icons/RIcon/RIcon.js +7 -1
  264. package/lib/icons/RIcon/index.js +2 -1
  265. package/lib/icons/RubyIcon/RubyIcon.js +7 -1
  266. package/lib/icons/RubyIcon/index.js +2 -1
  267. package/lib/index.js +49 -1
  268. package/lib/jotai/app.js +113 -1
  269. package/lib/jotai/operation.js +28 -1
  270. package/lib/jotai/replay.js +5 -1
  271. package/lib/jotai/store.js +8 -1
  272. package/lib/jotai/use-write-atom.js +9 -1
  273. package/lib/models/callback.js +28 -1
  274. package/lib/models/code-sample-options.js +2 -0
  275. package/lib/models/example.js +17 -1
  276. package/lib/models/field.js +109 -1
  277. package/lib/models/group.js +38 -1
  278. package/lib/models/index.js +14 -1
  279. package/lib/models/mediaContent.js +26 -1
  280. package/lib/models/mediaType.js +153 -1
  281. package/lib/models/operation.js +166 -1
  282. package/lib/models/request.js +25 -1
  283. package/lib/models/response.js +46 -1
  284. package/lib/models/schema.js +474 -2
  285. package/lib/models/security.js +84 -1
  286. package/lib/models/tab.js +2 -0
  287. package/lib/models/types.js +2 -0
  288. package/lib/services/OpenAPIParser.js +321 -1
  289. package/lib/services/check.js +104 -1
  290. package/lib/services/code-samples/constants.js +16 -1
  291. package/lib/services/code-samples/generator.js +540 -1
  292. package/lib/services/code-samples/httpsnippet/helpers/code-builder.js +252 -3
  293. package/lib/services/code-samples/httpsnippet/helpers/code-helpers.js +90 -2
  294. package/lib/services/code-samples/httpsnippet/helpers/constants.js +28 -1
  295. package/lib/services/code-samples/httpsnippet/helpers/lodash-int.js +173 -1
  296. package/lib/services/code-samples/httpsnippet/helpers/mocks/code-helpers-mock.js +76 -37
  297. package/lib/services/code-samples/httpsnippet/helpers/reducer.js +16 -1
  298. package/lib/services/code-samples/httpsnippet/helpers/shell.js +20 -1
  299. package/lib/services/code-samples/httpsnippet/helpers/string-utility.js +19 -1
  300. package/lib/services/code-samples/httpsnippet/index.js +166 -1
  301. package/lib/services/code-samples/httpsnippet/targets/__mocks__/mock.js +2340 -146
  302. package/lib/services/code-samples/httpsnippet/targets/csharp/httpclient.js +227 -2
  303. package/lib/services/code-samples/httpsnippet/targets/csharp/index.js +11 -1
  304. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/httpclient.js +185 -2
  305. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/index.js +11 -1
  306. package/lib/services/code-samples/httpsnippet/targets/go/index.js +11 -1
  307. package/lib/services/code-samples/httpsnippet/targets/go/native.js +222 -3
  308. package/lib/services/code-samples/httpsnippet/targets/index.js +28 -1
  309. package/lib/services/code-samples/httpsnippet/targets/java/httpclient.js +184 -3
  310. package/lib/services/code-samples/httpsnippet/targets/java/index.js +11 -1
  311. package/lib/services/code-samples/httpsnippet/targets/java8/apachehttp.js +223 -2
  312. package/lib/services/code-samples/httpsnippet/targets/java8/index.js +11 -1
  313. package/lib/services/code-samples/httpsnippet/targets/javascript/fetch.js +147 -1
  314. package/lib/services/code-samples/httpsnippet/targets/javascript/index.js +11 -1
  315. package/lib/services/code-samples/httpsnippet/targets/node/fetch.js +199 -1
  316. package/lib/services/code-samples/httpsnippet/targets/node/index.js +11 -1
  317. package/lib/services/code-samples/httpsnippet/targets/php/curl.js +203 -5
  318. package/lib/services/code-samples/httpsnippet/targets/php/index.js +11 -1
  319. package/lib/services/code-samples/httpsnippet/targets/php/types.js +2 -0
  320. package/lib/services/code-samples/httpsnippet/targets/php/utils.js +106 -5
  321. package/lib/services/code-samples/httpsnippet/targets/python/index.js +11 -1
  322. package/lib/services/code-samples/httpsnippet/targets/python/requests.js +185 -6
  323. package/lib/services/code-samples/httpsnippet/targets/r/httr.js +111 -1
  324. package/lib/services/code-samples/httpsnippet/targets/r/index.js +11 -1
  325. package/lib/services/code-samples/httpsnippet/targets/r/utils.js +18 -6
  326. package/lib/services/code-samples/httpsnippet/targets/ruby/index.js +11 -1
  327. package/lib/services/code-samples/httpsnippet/targets/ruby/native.js +169 -1
  328. package/lib/services/code-samples/httpsnippet/targets/shell/curl.js +94 -6
  329. package/lib/services/code-samples/httpsnippet/targets/shell/index.js +11 -1
  330. package/lib/services/code-samples/index.js +3 -1
  331. package/lib/services/code-samples/types.js +2 -0
  332. package/lib/services/config-options/helpers.js +49 -1
  333. package/lib/services/config-options/index.js +3 -1
  334. package/lib/services/config-options/normalizeOptions.js +83 -1
  335. package/lib/services/config-options/types.js +2 -0
  336. package/lib/services/history/helpers.js +63 -1
  337. package/lib/services/history/index.js +2 -1
  338. package/lib/services/index.js +9 -1
  339. package/lib/services/menu/builder.js +47 -1
  340. package/lib/services/menu/index.js +2 -1
  341. package/lib/services/menu/markdown.js +93 -1
  342. package/lib/services/menu/operation.js +50 -1
  343. package/lib/services/menu/tags.js +166 -1
  344. package/lib/services/types.js +2 -0
  345. package/lib/services/utils.js +83 -1
  346. package/lib/standalone.js +68 -1
  347. package/lib/styled-components.js +6 -1
  348. package/lib/types/app.js +2 -0
  349. package/lib/types/index.js +4 -1
  350. package/lib/types/open-api.js +2 -0
  351. package/lib/types/security.js +2 -0
  352. package/lib/utils/JsonPointer.js +84 -1
  353. package/lib/utils/areArraysEqual.js +4 -1
  354. package/lib/utils/argValuesHelpers.js +35 -1
  355. package/lib/utils/compose.js +2 -1
  356. package/lib/utils/configure-helpers.js +223 -1
  357. package/lib/utils/convertSwagger2OpenAPI.js +14 -1
  358. package/lib/utils/cookies.js +73 -1
  359. package/lib/utils/debounce.js +22 -1
  360. package/lib/utils/debug.js +11 -1
  361. package/lib/utils/dom.js +65 -1
  362. package/lib/utils/environments.js +13 -1
  363. package/lib/utils/helpers.js +222 -12
  364. package/lib/utils/index.js +25 -1
  365. package/lib/utils/isMobile.js +13 -1
  366. package/lib/utils/loadAndBundleSpec.js +32 -1
  367. package/lib/utils/local-storage.js +12 -1
  368. package/lib/utils/object.js +31 -1
  369. package/lib/utils/openapi.js +592 -1
  370. package/lib/utils/parameters.js +13 -1
  371. package/lib/utils/path.js +22 -1
  372. package/lib/utils/queryString.js +60 -1
  373. package/lib/utils/replaceVariables.js +14 -1
  374. package/lib/utils/saveTextBeforeHeading.js +35 -1
  375. package/lib/utils/security-details.js +49 -1
  376. package/lib/utils/session-storage.js +12 -1
  377. package/lib/utils/simplifyAstStructure.js +22 -1
  378. package/lib/utils/sort.js +21 -1
  379. package/lib/utils/string.js +65 -1
  380. package/lib/utils/telemetry.js +7 -1
  381. package/lib/utils/test-utils.js +26 -1
  382. package/lib/utils/theme-helpers.js +24 -3
  383. package/lib/utils/url.js +38 -1
  384. package/package.json +3 -3
@@ -1 +1,321 @@
1
- import{IS_BROWSER as q,isObject as S,isString as E,isUndefined as o}from"@redocly/theme/core/openapi";import{tryDecodeURIComponent as B,getDefinitionName as v}from"../utils/index.js";import{JsonPointer as x}from"../utils/JsonPointer.js";import{normalizeOptions as W}from"./config-options/normalizeOptions.js";function A(m,e){return e&&m[m.length-1]!==e?[...m,e]:m}function R(m,e){return e?m.concat(e):m}class V{options;definitionUrl;definition;allowMergeRefs=!1;constructor(e,t,l=W({})){this.options=l,this.definition=Object.assign({},e),this.validate(e),this.definition=e,this.allowMergeRefs=e.openapi.startsWith("3.1");const n=q?window.location.href:"";E(t)&&(this.definitionUrl=new URL(t,n).href)}validate(e){if(o(e.openapi))throw new Error("Document must be valid OpenAPI 3.0.0 definition")}byRef=e=>{let t;if(this.definition){e.charAt(0)!=="#"&&(e="#"+e),e=B(e);try{t=x.get(this.definition,e)}catch{}return t||{}}};isRef(e){return e?(e=e,e.$ref!==void 0&&e.$ref!==null):!1}deref(e,t=[],l=!1,n=0){const i=e?.["x-refsStack"];if(t=R(t,i),n>5)return{resolved:Object.assign({},e,{"x-complex":!0}),refsStack:t};if(this.isRef(e)){const r=v(e.$ref);if(r&&this.options.ignoreNamedSchemas.has(r))return{resolved:{type:"object",title:r},refsStack:t};let s=this.byRef(e.$ref);if(!s)throw new Error(`Failed to resolve $ref "${e.$ref}"`);return t.includes(e.$ref)?s=Object.assign({},s,{"x-circular-ref":!0}):this.isRef(s)&&(s=this.deref(s,t,l,n).resolved),this.allowMergeRefs&&(s=this.mergeRefs(e,s,l)),{resolved:s,refsStack:A(t,e.$ref)}}return{resolved:e,refsStack:R(t,i)}}mergeRefs(e,t,l){const{$ref:n,...i}=e,r=Object.keys(i);if(r.length===0)return t;if(l&&r.some(s=>!["description","title","externalDocs","x-refsStack","x-parentRefs","readOnly","writeOnly","x-complex"].includes(s))){const{description:s,title:p,readOnly:u,writeOnly:d,...O}=i;return{allOf:[{description:s,title:p,readOnly:u,writeOnly:d},t,O]}}else return{...t,...i}}mergeAllOf(e,t,l,n="",i=0){if(e["x-circular-ref"])return e;if(e=this.hoistOneOfs(e),e.allOf===void 0)return{absolutePointer:n,...e};let r={...e,"x-parentRefs":[],absolutePointer:x.join(n,["allOf"]),allOf:void 0,title:i===0?e.title||v(t):e.title};!o(r.properties)&&S(r.properties)&&(r.properties={...r.properties}),!o(r.items)&&S(r.items)&&(r.items={...r.items});const s=e.allOf.map((p,u)=>{const{resolved:d,refsStack:O}=this.deref(p,l,!0,i),f=p.$ref,y=f||x.join(n,[String(u)]);if(d["x-complex"])return{$ref:f,refsStack:A(O,f),schema:{"x-complex":!0},absolutePointer:y};const a=this.mergeAllOf(d,f,O,y,i+1);if(!(a["x-circular-ref"]&&a.allOf))return f&&r["x-parentRefs"]?.push(...a["x-parentRefs"]||[],f),{$ref:f,refsStack:A(O,f),schema:a,absolutePointer:y}}).filter(Boolean);for(const[p,{schema:u,refsStack:d,absolutePointer:O}]of s.entries()){const{type:f,enum:y,properties:a,items:b,required:w,title:I,description:D,readOnly:C,writeOnly:M,oneOf:$,anyOf:k,"x-circular-ref":g,"x-complex":P,...N}=u||{};if(!(r.type!==f&&!o(r.type)&&!o(f)&&!i)){if(o(f)||(Array.isArray(f)&&Array.isArray(r.type)?r.type=[...f,...r.type]:r.type=f),o(y)||(Array.isArray(y)&&Array.isArray(r.enum)?r.enum=Array.from(new Set([...y,...r.enum])):r.enum=y),!o(a)&&S(a)){r.properties=r.properties||{};for(const c in a){const h=R(d,a[c]?.["x-refsStack"]);if(!r.properties[c])r.properties[c]={...a[c],absolutePointer:x.join(O,["properties",c]),"x-refsStack":h};else if(!g){const U=this.mergeAllOf({allOf:[r.properties[c],a[c]],"x-refsStack":h},t+"/properties/"+c,h,x.join(O,["allOf",String(p),"properties",c]),i+1);r.properties[c]=U}}}if(!o(b)&&!g&&!P){const c=typeof r.items=="boolean"?{}:Object.assign({},r.items),h=typeof u.items=="boolean"?{}:Object.assign({},u.items);r.items=this.mergeAllOf({allOf:[c,h]},t+"/items",d,"",i+1)}o($)||(r.oneOf=$),o(k)||(r.anyOf=k),Array.isArray(w)&&(r.required=[...r.required||[],...w]),r={...r,title:r.title||I,description:r.description||D,readOnly:o(r.readOnly)?C:r.readOnly,writeOnly:o(r.writeOnly)?M:r.writeOnly,"x-circular-ref":r["x-circular-ref"]||g,"x-complex":r["x-complex"]||P,...N}}}return r}findDerived(e){const t={},l=this.definition.components&&this.definition.components.schemas||{};for(const n in l){const{resolved:i}=this.deref(l[n]);!o(i.allOf)&&i.allOf.find(r=>!o(r.$ref)&&e.indexOf(r.$ref)>-1)&&(t["#/components/schemas/"+n]=[i["x-discriminator-value"]||n])}return t}hoistOneOfs(e){if(o(e.allOf))return e;const{allOf:t,...l}=e;for(let n=0;n<t.length;n++){const{oneOf:i,...r}=t[n];if(i&&Array.isArray(i)){const s=t.slice(0,n),p=t.slice(n+1),u=Object.keys(r).length>0?[r]:[];return{...l,oneOf:i.map(d=>({allOf:[...s,...u,d,...p]}))}}}return e}}export{V as OpenAPIParser,R as concatRefStacks,A as pushRef};
1
+ import { IS_BROWSER, isObject, isString, isUndefined } from '@redocly/theme/core/openapi';
2
+ import { tryDecodeURIComponent, getDefinitionName } from '../utils/index.js';
3
+ import { JsonPointer } from '../utils/JsonPointer.js';
4
+ import { normalizeOptions } from './config-options/normalizeOptions.js';
5
+ /**
6
+ * Loads and keeps spec. Provides raw spec operations
7
+ */
8
+ export function pushRef(stack, ref) {
9
+ return ref && stack[stack.length - 1] !== ref ? [...stack, ref] : stack;
10
+ }
11
+ export function concatRefStacks(base, stack) {
12
+ return stack ? base.concat(stack) : base;
13
+ }
14
+ export class OpenAPIParser {
15
+ options;
16
+ definitionUrl;
17
+ definition;
18
+ // private _refCounter: RefCounter = new RefCounter();
19
+ allowMergeRefs = false;
20
+ constructor(definition, definitionUrl, options = normalizeOptions({})) {
21
+ this.options = options;
22
+ this.definition = Object.assign({}, definition);
23
+ this.validate(definition);
24
+ this.definition = definition;
25
+ this.allowMergeRefs = definition.openapi.startsWith('3.1');
26
+ const href = IS_BROWSER ? window.location.href : '';
27
+ if (isString(definitionUrl)) {
28
+ this.definitionUrl = new URL(definitionUrl, href).href;
29
+ }
30
+ }
31
+ validate(spec) {
32
+ if (isUndefined(spec.openapi)) {
33
+ throw new Error('Document must be valid OpenAPI 3.0.0 definition');
34
+ }
35
+ }
36
+ /**
37
+ * get spec part by JsonPointer ($ref)
38
+ */
39
+ byRef = (ref) => {
40
+ let res;
41
+ if (!this.definition) {
42
+ return;
43
+ }
44
+ if (ref.charAt(0) !== '#') {
45
+ ref = '#' + ref;
46
+ }
47
+ ref = tryDecodeURIComponent(ref);
48
+ try {
49
+ res = JsonPointer.get(this.definition, ref);
50
+ }
51
+ catch {
52
+ // do nothing
53
+ }
54
+ return res || {};
55
+ };
56
+ /**
57
+ * checks if the object is OpenAPI reference (contains $ref property)
58
+ */
59
+ isRef(obj) {
60
+ if (!obj) {
61
+ return false;
62
+ }
63
+ obj = obj;
64
+ return obj.$ref !== undefined && obj.$ref !== null;
65
+ }
66
+ /**
67
+ * Resolve given reference object or return as is if it is not a reference
68
+ * @param obj object to dereference
69
+ * @param baseRefsStack
70
+ * @param mergeAsAllOf
71
+ */
72
+ deref(obj, baseRefsStack = [], mergeAsAllOf = false, level = 0) {
73
+ // this can be set by all of when it merges props from different sources
74
+ const objRefsStack = obj?.['x-refsStack'];
75
+ baseRefsStack = concatRefStacks(baseRefsStack, objRefsStack);
76
+ if (level > 5) {
77
+ return {
78
+ resolved: Object.assign({}, obj, { 'x-complex': true }),
79
+ refsStack: baseRefsStack,
80
+ };
81
+ }
82
+ if (this.isRef(obj)) {
83
+ const schemaName = getDefinitionName(obj.$ref);
84
+ if (schemaName && this.options.ignoreNamedSchemas.has(schemaName)) {
85
+ return { resolved: { type: 'object', title: schemaName }, refsStack: baseRefsStack };
86
+ }
87
+ let resolved = this.byRef(obj.$ref);
88
+ if (!resolved) {
89
+ throw new Error(`Failed to resolve $ref "${obj.$ref}"`);
90
+ }
91
+ if (baseRefsStack.includes(obj.$ref)) {
92
+ resolved = Object.assign({}, resolved, { 'x-circular-ref': true });
93
+ }
94
+ else if (this.isRef(resolved)) {
95
+ const res = this.deref(resolved, baseRefsStack, mergeAsAllOf, level);
96
+ resolved = res.resolved;
97
+ }
98
+ if (this.allowMergeRefs) {
99
+ resolved = this.mergeRefs(obj, resolved, mergeAsAllOf);
100
+ }
101
+ return { resolved, refsStack: pushRef(baseRefsStack, obj.$ref) };
102
+ }
103
+ return {
104
+ resolved: obj,
105
+ refsStack: concatRefStacks(baseRefsStack, objRefsStack),
106
+ };
107
+ }
108
+ mergeRefs(ref, resolved, mergeAsAllOf) {
109
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
110
+ const { $ref, ...rest } = ref;
111
+ const keys = Object.keys(rest);
112
+ if (keys.length === 0) {
113
+ return resolved;
114
+ }
115
+ if (mergeAsAllOf &&
116
+ keys.some((k) => ![
117
+ 'description',
118
+ 'title',
119
+ 'externalDocs',
120
+ 'x-refsStack',
121
+ 'x-parentRefs',
122
+ 'readOnly',
123
+ 'writeOnly',
124
+ 'x-complex',
125
+ ].includes(k))) {
126
+ const { description, title, readOnly, writeOnly, ...restSchema } = rest;
127
+ return {
128
+ allOf: [{ description, title, readOnly, writeOnly }, resolved, restSchema],
129
+ };
130
+ }
131
+ else {
132
+ // small optimization
133
+ return {
134
+ ...resolved,
135
+ ...rest,
136
+ };
137
+ }
138
+ }
139
+ /**
140
+ * Merge allOf constraints.
141
+ * @param schema schema with allOF
142
+ * @param $ref pointer of the schema
143
+ * @param refsStack
144
+ * @param absolutePointer
145
+ */
146
+ mergeAllOf(schema, $ref, refsStack, absolutePointer = '', level = 0) {
147
+ if (schema['x-circular-ref']) {
148
+ return schema;
149
+ }
150
+ schema = this.hoistOneOfs(schema);
151
+ if (schema.allOf === undefined) {
152
+ return { absolutePointer, ...schema };
153
+ }
154
+ let receiver = {
155
+ ...schema,
156
+ 'x-parentRefs': [],
157
+ absolutePointer: JsonPointer.join(absolutePointer, ['allOf']),
158
+ allOf: undefined,
159
+ title: level === 0 ? schema.title || getDefinitionName($ref) : schema.title,
160
+ };
161
+ // avoid mutating inner objects
162
+ if (!isUndefined(receiver.properties) && isObject(receiver.properties)) {
163
+ receiver.properties = { ...receiver.properties };
164
+ }
165
+ if (!isUndefined(receiver.items) && isObject(receiver.items)) {
166
+ receiver.items = { ...receiver.items };
167
+ }
168
+ const allOfSchemas = schema.allOf
169
+ .map((subSchema, index) => {
170
+ const { resolved, refsStack: subRefsStack } = this.deref(subSchema, refsStack, true, level);
171
+ const subRef = subSchema.$ref;
172
+ const subAbsolutePointer = subRef || JsonPointer.join(absolutePointer, [String(index)]);
173
+ if (resolved['x-complex']) {
174
+ return {
175
+ $ref: subRef,
176
+ refsStack: pushRef(subRefsStack, subRef),
177
+ schema: { 'x-complex': true },
178
+ absolutePointer: subAbsolutePointer,
179
+ };
180
+ }
181
+ const subMerged = this.mergeAllOf(resolved, subRef, subRefsStack, subAbsolutePointer, level + 1);
182
+ if (subMerged['x-circular-ref'] && subMerged.allOf) {
183
+ // if mergeAllOf is circular and still contains allOf, we should ignore it
184
+ return undefined;
185
+ }
186
+ if (subRef) {
187
+ // collect information for implicit descriminator lookup
188
+ receiver['x-parentRefs']?.push(...(subMerged['x-parentRefs'] || []), subRef);
189
+ }
190
+ return {
191
+ $ref: subRef,
192
+ refsStack: pushRef(subRefsStack, subRef),
193
+ schema: subMerged,
194
+ absolutePointer: subAbsolutePointer,
195
+ };
196
+ })
197
+ .filter(Boolean);
198
+ for (const [index, { schema: subSchema, refsStack: subRefsStack, absolutePointer },] of allOfSchemas.entries()) {
199
+ const { type, enum: enumProperty, properties, items, required, title, description, readOnly, writeOnly, oneOf, anyOf, 'x-circular-ref': isCircular, 'x-complex': isComplex, ...otherConstraints } = subSchema || {};
200
+ if (receiver.type !== type && !isUndefined(receiver.type) && !isUndefined(type) && !level) {
201
+ // console.warn(`Incompatible types in allOf at "${$ref}": "${receiver.type}" and "${type}"`);
202
+ continue;
203
+ }
204
+ if (!isUndefined(type)) {
205
+ if (Array.isArray(type) && Array.isArray(receiver.type)) {
206
+ receiver.type = [...type, ...receiver.type];
207
+ }
208
+ else {
209
+ receiver.type = type;
210
+ }
211
+ }
212
+ if (!isUndefined(enumProperty)) {
213
+ if (Array.isArray(enumProperty) && Array.isArray(receiver.enum)) {
214
+ receiver.enum = Array.from(new Set([...enumProperty, ...receiver.enum]));
215
+ }
216
+ else {
217
+ receiver.enum = enumProperty;
218
+ }
219
+ }
220
+ if (!isUndefined(properties) && isObject(properties)) {
221
+ receiver.properties = receiver.properties || {};
222
+ for (const prop in properties) {
223
+ const propRefsStack = concatRefStacks(subRefsStack, properties[prop]?.['x-refsStack']);
224
+ if (!receiver.properties[prop]) {
225
+ receiver.properties[prop] = {
226
+ ...properties[prop],
227
+ absolutePointer: JsonPointer.join(absolutePointer, ['properties', prop]),
228
+ 'x-refsStack': propRefsStack,
229
+ };
230
+ }
231
+ else if (!isCircular) {
232
+ // merge inner properties
233
+ const mergedProp = this.mergeAllOf({
234
+ allOf: [receiver.properties[prop], properties[prop]],
235
+ 'x-refsStack': propRefsStack,
236
+ }, $ref + '/properties/' + prop, propRefsStack, JsonPointer.join(absolutePointer, ['allOf', String(index), 'properties', prop]), level + 1);
237
+ receiver.properties[prop] = mergedProp;
238
+ }
239
+ }
240
+ }
241
+ if (!isUndefined(items) && !isCircular && !isComplex) {
242
+ const receiverItems = typeof receiver.items === 'boolean'
243
+ ? {}
244
+ : Object.assign({}, receiver.items);
245
+ const subSchemaItems = typeof subSchema.items === 'boolean'
246
+ ? {}
247
+ : Object.assign({}, subSchema.items);
248
+ // merge inner properties
249
+ receiver.items = this.mergeAllOf({
250
+ allOf: [receiverItems, subSchemaItems],
251
+ }, $ref + '/items', subRefsStack, '', level + 1);
252
+ }
253
+ if (!isUndefined(oneOf)) {
254
+ receiver.oneOf = oneOf;
255
+ }
256
+ if (!isUndefined(anyOf)) {
257
+ receiver.anyOf = anyOf;
258
+ }
259
+ if (Array.isArray(required)) {
260
+ receiver.required = [...(receiver.required || []), ...required];
261
+ }
262
+ // merge rest of constraints
263
+ // TODO: do more intelligent merge
264
+ receiver = {
265
+ ...receiver,
266
+ title: receiver.title || title,
267
+ description: receiver.description || description,
268
+ readOnly: !isUndefined(receiver.readOnly) ? receiver.readOnly : readOnly,
269
+ writeOnly: !isUndefined(receiver.writeOnly) ? receiver.writeOnly : writeOnly,
270
+ 'x-circular-ref': receiver['x-circular-ref'] || isCircular,
271
+ 'x-complex': receiver['x-complex'] || isComplex,
272
+ ...otherConstraints,
273
+ };
274
+ }
275
+ return receiver;
276
+ }
277
+ /**
278
+ * Find all derived definitions among #/components/schemas from any of $refs
279
+ * returns map of definition pointer to definition name
280
+ * @param $refs array of references to find derived from
281
+ */
282
+ findDerived($refs) {
283
+ const res = {};
284
+ const schemas = (this.definition.components && this.definition.components.schemas) || {};
285
+ for (const defName in schemas) {
286
+ const { resolved: def } = this.deref(schemas[defName]);
287
+ if (!isUndefined(def.allOf) &&
288
+ def.allOf.find((obj) => !isUndefined(obj.$ref) && $refs.indexOf(obj.$ref) > -1)) {
289
+ res['#/components/schemas/' + defName] = [def['x-discriminator-value'] || defName];
290
+ }
291
+ }
292
+ return res;
293
+ }
294
+ hoistOneOfs(schema) {
295
+ if (isUndefined(schema.allOf)) {
296
+ return schema;
297
+ }
298
+ const { allOf, ...restSchema } = schema;
299
+ for (let i = 0; i < allOf.length; i++) {
300
+ const { oneOf, ...sub } = allOf[i];
301
+ if (!oneOf) {
302
+ continue;
303
+ }
304
+ if (Array.isArray(oneOf)) {
305
+ const beforeAllOf = allOf.slice(0, i);
306
+ const afterAllOf = allOf.slice(i + 1);
307
+ const siblingValues = Object.keys(sub).length > 0 ? [sub] : [];
308
+ return {
309
+ ...restSchema,
310
+ oneOf: oneOf.map((part) => {
311
+ return {
312
+ allOf: [...beforeAllOf, ...siblingValues, part, ...afterAllOf],
313
+ };
314
+ }),
315
+ };
316
+ }
317
+ }
318
+ return schema;
319
+ }
320
+ }
321
+ //# sourceMappingURL=OpenAPIParser.js.map
@@ -1 +1,104 @@
1
- import{cryptoLib as o}from"./utils.js";function u(e){return"then"in e?e:new Promise(t=>{e.oncomplete=r=>{t(r.target.result)}})}function l(e){const t=new ArrayBuffer(e.length),r=new Uint8Array(t);for(let i=0,n=e.length;i<n;i++)r[i]=e.charCodeAt(i);return t}const a=()=>{const e=l(atob(typeof REDOCLY_PUBLIC_KEY<"u"?REDOCLY_PUBLIC_KEY:"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMHjNir5fXx/ZXoaEeXQ5XyxbNJ4YJYczoCRdSkL6NLzw1FHnng5Vfcgk5+bvox9QRYRbuk84mA4f2NhywDbXKECAwEAAQ=="));return u(o?.subtle.importKey("spki",e,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!0,["verify"]))};function f(e){if(window.TextEncoder)return new TextEncoder().encode(e);const t=unescape(encodeURIComponent(e)),r=new Uint8Array(t.length);for(let i=0;i<t.length;i++)r[i]=t.charCodeAt(i);return r}async function c(e,t){return u(o?.subtle.verify({name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},await a(),l(atob(t)),f(e)))}function s(e,t){return t===!0?!0:Array.isArray(t)&&typeof window<"u"?e==="localhost"||e==="127.0.0.1"||e.endsWith(".localhost")||t.find(r=>r===e||e.endsWith("."+r))?!0:!!t.find(r=>{if(r.indexOf("*")!==r.lastIndexOf("*"))return;const[i,n]=r.split("*");return n&&e.startsWith(i)&&e.endsWith(n)&&n.split(".").length>2}):!1}async function d(e){if(process.env.NODE_ENV==="development")return{valid:!0,allowed:!0};const t=window.location.hostname;if(!e)return t==="localhost"||t==="127.0.0.1"||t.endsWith(".localhost")?{local:!0}:{};const[r,i]=e.split(".");let n;try{if(!await c(atob(r),i))return{valid:!1};n=JSON.parse(atob(r))}catch{return{valid:!1,cryptoMissing:!0}}return n.valid=!0,(!n.e||Date.now()/1e3>n.e)&&(n.expired=!0),n.allowed=s(t,n.h),n}export{d as default,s as isHostAllowed};
1
+ import { cryptoLib } from './utils.js';
2
+ function promisifyIECryptoRes(res) {
3
+ if ('then' in res) {
4
+ return res;
5
+ }
6
+ else {
7
+ return new Promise((resolve) => {
8
+ res.oncomplete = (e) => {
9
+ resolve(e.target.result);
10
+ };
11
+ });
12
+ }
13
+ }
14
+ function str2ab(str) {
15
+ const buf = new ArrayBuffer(str.length);
16
+ const bufView = new Uint8Array(buf);
17
+ for (let i = 0, strLen = str.length; i < strLen; i++) {
18
+ bufView[i] = str.charCodeAt(i);
19
+ }
20
+ return buf;
21
+ }
22
+ const getKey = () => {
23
+ const publickeyDer = str2ab(atob(typeof REDOCLY_PUBLIC_KEY !== 'undefined'
24
+ ? REDOCLY_PUBLIC_KEY
25
+ : 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMHjNir5fXx/ZXoaEeXQ5XyxbNJ4YJYczoCRdSkL6NLzw1FHnng5Vfcgk5+bvox9QRYRbuk84mA4f2NhywDbXKECAwEAAQ=='));
26
+ return promisifyIECryptoRes(cryptoLib?.subtle.importKey('spki', publickeyDer, {
27
+ name: 'RSASSA-PKCS1-v1_5',
28
+ hash: 'SHA-256',
29
+ }, true, ['verify']));
30
+ };
31
+ function textEncode(str) {
32
+ if (window.TextEncoder) {
33
+ return new TextEncoder().encode(str);
34
+ }
35
+ const utf8 = unescape(encodeURIComponent(str));
36
+ const result = new Uint8Array(utf8.length);
37
+ for (let i = 0; i < utf8.length; i++) {
38
+ result[i] = utf8.charCodeAt(i);
39
+ }
40
+ return result;
41
+ }
42
+ async function verify(message, signature) {
43
+ return promisifyIECryptoRes(cryptoLib?.subtle.verify({ name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' }, await getKey(), str2ab(atob(signature)), textEncode(message)));
44
+ }
45
+ export function isHostAllowed(hostname, hosts) {
46
+ if (hosts === true)
47
+ return true;
48
+ if (Array.isArray(hosts) && typeof window !== 'undefined') {
49
+ if (hostname === 'localhost' ||
50
+ hostname === '127.0.0.1' ||
51
+ hostname.endsWith('.localhost') ||
52
+ !!hosts.find((h) => h === hostname || hostname.endsWith('.' + h))) {
53
+ return true;
54
+ }
55
+ return !!hosts.find((h) => {
56
+ if (h.indexOf('*') !== h.lastIndexOf('*'))
57
+ return;
58
+ const [leftPart, rightPart] = h.split('*');
59
+ return (rightPart &&
60
+ hostname.startsWith(leftPart) &&
61
+ hostname.endsWith(rightPart) &&
62
+ rightPart.split('.').length > 2);
63
+ });
64
+ }
65
+ return false;
66
+ }
67
+ // TODO: add tests
68
+ export default async function parse(key) {
69
+ if (process.env.NODE_ENV === 'development') {
70
+ return {
71
+ valid: true,
72
+ allowed: true,
73
+ };
74
+ }
75
+ const hostname = window.location.hostname;
76
+ if (!key) {
77
+ if (hostname === 'localhost' || hostname === '127.0.0.1' || hostname.endsWith('.localhost')) {
78
+ return {
79
+ local: true,
80
+ };
81
+ }
82
+ else {
83
+ return {};
84
+ }
85
+ }
86
+ const [token, signature] = key.split('.');
87
+ let info;
88
+ try {
89
+ if (!(await verify(atob(token), signature))) {
90
+ return { valid: false };
91
+ }
92
+ info = JSON.parse(atob(token));
93
+ }
94
+ catch {
95
+ return { valid: false, cryptoMissing: true };
96
+ }
97
+ info.valid = true;
98
+ if (!info.e || Date.now() / 1000 > info.e) {
99
+ info.expired = true;
100
+ }
101
+ info.allowed = isHostAllowed(hostname, info.h);
102
+ return info;
103
+ }
104
+ //# sourceMappingURL=check.js.map
@@ -1 +1,16 @@
1
- const a={curl:"curl",JavaScript:"JavaScript",NodeJs:"Node.js",Python:"Python",Java:"Java",CSharp:"C#",PHP:"PHP",Go:"Go",Ruby:"Ruby",R:"R",Payload:"Payload"};export{a as Languages};
1
+ export const Languages = {
2
+ curl: 'curl',
3
+ JavaScript: 'JavaScript',
4
+ NodeJs: 'Node.js',
5
+ Python: 'Python',
6
+ Java: 'Java',
7
+ // Java8: 'Java8+Apache',
8
+ CSharp: 'C#',
9
+ // CSharpNewtonsoft: 'C#+Newtonsoft',
10
+ PHP: 'PHP',
11
+ Go: 'Go',
12
+ Ruby: 'Ruby',
13
+ R: 'R',
14
+ Payload: 'Payload',
15
+ };
16
+ //# sourceMappingURL=constants.js.map