@redocly/portal-plugin-soap-api 0.21.0-next.9 → 0.21.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.
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@redocly/portal-plugin-soap-api",
3
- "version": "0.21.0-next.9",
3
+ "version": "0.21.1",
4
4
  "description": "SOAP API plugin for Redocly products",
5
5
  "author": "team@redocly.com",
6
6
  "license": "SEE LICENSE IN LICENSE",
7
+ "files": [
8
+ "lib",
9
+ "CHANGELOG.md"
10
+ ],
7
11
  "type": "module",
8
12
  "main": "lib/plugin.js",
9
13
  "exports": {
@@ -22,7 +26,7 @@
22
26
  "xml-formatter": "3.6.3",
23
27
  "file-saver": "2.0.5",
24
28
  "styled-components": "^6.4.2",
25
- "@redocly/config": "0.62.0"
29
+ "@redocly/config": "0.65.0"
26
30
  },
27
31
  "devDependencies": {
28
32
  "esbuild-minify-dir": "^0.0.1",
@@ -32,11 +36,11 @@
32
36
  "rimraf": "5.0.7"
33
37
  },
34
38
  "peerDependencies": {
35
- "@redocly/realm": "0.138.0-next.9",
36
- "@redocly/redoc": "0.138.0-next.9",
37
- "@redocly/redoc-reef": "0.138.0-next.9",
38
- "@redocly/redoc-revel": "0.138.0-next.9",
39
- "@redocly/theme": "0.70.0-next.6",
39
+ "@redocly/realm": "0.138.1",
40
+ "@redocly/redoc": "0.138.1",
41
+ "@redocly/redoc-reef": "0.138.1",
42
+ "@redocly/redoc-revel": "0.138.1",
43
+ "@redocly/theme": "0.70.1",
40
44
  "react": "^19.2.7",
41
45
  "react-dom": "^19.2.7"
42
46
  },
package/src/plugin.ts DELETED
@@ -1,274 +0,0 @@
1
- import { WSDL, Client } from 'soap';
2
- import formatXml from 'xml-formatter';
3
- import { fileURLToPath } from 'url';
4
- import path, { resolve, join } from 'node:path';
5
-
6
- import type { ExternalPlugin } from '@redocly/realm/dist/server/types';
7
- import type { Logger } from '@redocly/realm/dist/server/tools/notifiers/logger';
8
- import type { Feature } from '@redocly/realm/dist/types';
9
- import type { RedoclyConfig } from '@redocly/config';
10
-
11
- import { searchResolver } from './search-resolver.js';
12
-
13
- const SOAP_TEMPLATE_ID = 'soap-docs';
14
-
15
- const STUB_SOAP_RESPONSE = `HTTP/1.0 200 OK
16
- Content-Type: text/xml; charset = utf-8
17
- Content-Length: 42
18
-
19
- <?xml version = "1.0"?>
20
- <SOAP-ENV:Envelope
21
- xmlns:SOAP-ENV = "http://www.w3.org/2001/12/soap-envelope"
22
- SOAP-ENV:encodingStyle = "http://www.w3.org/2001/12/soap-encoding">
23
-
24
- <SOAP-ENV:Body xmlns:m = "http://www.xyz.org/quotation">
25
- </SOAP-ENV:Body>
26
- </SOAP-ENV:Envelope>`;
27
-
28
- export default function soapPlugin(): ExternalPlugin {
29
- return {
30
- id: 'soap',
31
- requiredEntitlements: ['soap' as Feature],
32
- loaders: {
33
- wsdl: async (relativePath, context) => {
34
- const config = await context.getConfig(relativePath);
35
- const { metadata } = getApiConfigByPath(config.apis, relativePath);
36
- const content = await context.fs.read(relativePath);
37
-
38
- const wsdl = (await new Promise((resolve) => {
39
- const wsdl = new WSDL(content, relativePath, {});
40
- wsdl.onReady(() => resolve(wsdl));
41
- })) as WSDL;
42
-
43
- const info = new Client(wsdl, undefined, {
44
- httpClient: {
45
- request: (
46
- _location: any,
47
- _data: any,
48
- cb: (err: any, res: any, body: string) => void,
49
- ): any => {
50
- cb(undefined, { status: 200 }, STUB_SOAP_RESPONSE);
51
- },
52
- },
53
- });
54
- const meta = info.describe();
55
- const serviceName = Object.keys(meta)[0];
56
- const bindingName = Object.keys(meta[serviceName])[0];
57
- const endpoints = meta[serviceName][bindingName];
58
-
59
- return {
60
- endpoints,
61
- metadata,
62
- serviceName,
63
- info,
64
- content,
65
- };
66
- },
67
- },
68
-
69
- processContent: async (actions: any, context: any) => {
70
- const soapTemplateId = actions.createTemplate(
71
- SOAP_TEMPLATE_ID,
72
- fromCurrentDir(import.meta.url, './template.js'),
73
- );
74
-
75
- for (const fileInfo of await context.fs.scan(/(\.wsdl)$/)) {
76
- if (await context.isPathIgnored(fileInfo.relativePath)) {
77
- continue;
78
- }
79
-
80
- const wsdlRecord = await context.cache.load(fileInfo.relativePath, 'wsdl');
81
- const { endpoints, metadata, serviceName, info, content } = wsdlRecord.data;
82
-
83
- for (const endpointName of Object.keys(endpoints ?? {})) {
84
- /**
85
- * Add a page for operation
86
- */
87
- actions.addRoute({
88
- fsPath: fileInfo.relativePath,
89
- slugSuffix: slugFromEndpoint(endpointName),
90
- templateId: soapTemplateId,
91
- getNavText: async () => endpointName,
92
- getSearchDocuments: searchResolver(actions),
93
- getStaticData: async () => {
94
- return {
95
- props: {
96
- title: endpointName,
97
- meta: {},
98
- endpointName,
99
- request: await generateRequestExample(
100
- endpointName,
101
- info,
102
- endpoints[endpointName].input,
103
- context.logger,
104
- ),
105
- },
106
- };
107
- },
108
- });
109
- }
110
-
111
- /**
112
- * Add a route with general information
113
- */
114
- actions.addRoute({
115
- fsPath: fileInfo.relativePath,
116
- templateId: soapTemplateId,
117
- metadata: {
118
- type: 'soap',
119
- title: serviceName,
120
- description: '',
121
- tags: ['SOAP'],
122
- ...metadata,
123
- },
124
- getSidebar: (route: any) => {
125
- const operationSidebarItems = [];
126
-
127
- for (const endpointName of Object.keys(endpoints)) {
128
- const routeSlug = join(route.slug, slugFromEndpoint(endpointName));
129
- operationSidebarItems.push({
130
- type: 'link',
131
- link: routeSlug,
132
- label: endpointName,
133
- routeSlug,
134
- });
135
- }
136
-
137
- return [
138
- {
139
- type: 'link',
140
- link: route.slug,
141
- routeSlug: route.slug,
142
- label: serviceName,
143
- },
144
- {
145
- type: 'group',
146
- label: 'Operations',
147
- items: operationSidebarItems,
148
- },
149
- ];
150
- },
151
- getNavText: async () => serviceName,
152
- getSearchDocuments: searchResolver(actions),
153
- getStaticData: async () => {
154
- return {
155
- props: {
156
- title: serviceName,
157
- wsdl: formatXml(content, { indentation: ' ' }),
158
- },
159
- };
160
- },
161
- });
162
- }
163
- },
164
- };
165
- }
166
-
167
- /**
168
- * function which generates an example request XML
169
- */
170
- const generateRequestExample = async (
171
- endpointName: string,
172
- info: any,
173
- inputParams: any,
174
- logger: Logger,
175
- ) => {
176
- const mockInput = mockProperties(endpointName, inputParams, 1, logger);
177
-
178
- const requestXml = (await new Promise((resolve) => {
179
- info[endpointName](mockInput, (...params: any[]) => {
180
- resolve(params[4]);
181
- });
182
- })) as string;
183
-
184
- return formatXml(requestXml, { indentation: ' ', throwOnFailure: false });
185
- };
186
-
187
- const mockProperties = (
188
- endpointName: string,
189
- inputParams: any,
190
- recursiveLevel: number,
191
- logger: Logger,
192
- ) => {
193
- const mockInput: Record<string, any> = {};
194
-
195
- if (recursiveLevel > 10) {
196
- return mockInput;
197
- }
198
-
199
- const paramNames = Object.keys(inputParams || {});
200
-
201
- for (let paramName of paramNames) {
202
- if (['targetNamespace', 'targetNSAlias'].includes(paramName)) {
203
- continue;
204
- }
205
-
206
- const paramValue = inputParams[paramName];
207
-
208
- if (paramName.endsWith('[]')) {
209
- paramName = paramName.slice(0, -2);
210
- }
211
-
212
- if (paramValue && typeof paramValue === 'object') {
213
- mockInput[paramName] = mockProperties(endpointName, paramValue, recursiveLevel + 1, logger);
214
- } else if (typeof paramValue === 'string') {
215
- const paramType = paramValue.split(':')[1];
216
- switch (paramType) {
217
- case 'string':
218
- mockInput[paramName] = 'Lorem ipsum';
219
- break;
220
-
221
- case 'date':
222
- mockInput[paramName] = '2023-07-06';
223
- break;
224
-
225
- case 'decimal':
226
- mockInput[paramName] = 42;
227
- break;
228
-
229
- default:
230
- mockInput[paramName] = paramName;
231
- }
232
- } else {
233
- const error = `Can't generate request example. Request param ${paramName} not supported in endpoint ${endpointName}`;
234
- mockInput[paramName] = { error };
235
- logger.warn(error);
236
- continue;
237
- }
238
- }
239
- return mockInput;
240
- };
241
-
242
- const slugFromEndpoint = (name: string): string => {
243
- return name
244
- .trim()
245
- .replace(/[^\w-]/g, '-')
246
- .replaceAll(/-+/g, '-')
247
- .toLowerCase()
248
- .replace(/^-|-$/g, '');
249
- };
250
-
251
- function __dirname(url: string): string {
252
- const __filename = fileURLToPath(url);
253
- return path.dirname(__filename);
254
- }
255
-
256
- function fromCurrentDir(moduleUrl: string, path: string): string {
257
- return resolve(__dirname(moduleUrl), path);
258
- }
259
-
260
- function getApiConfigByPath(
261
- apis: RedoclyConfig['apis'],
262
- relativePath: string,
263
- ): Record<string, any> {
264
- for (const versionValue of Object.values(apis || {})) {
265
- if (path.posix.normalize(versionValue.root) === relativePath) {
266
- return {
267
- ...versionValue.theme,
268
- ...versionValue,
269
- theme: undefined,
270
- };
271
- }
272
- }
273
- return {};
274
- }
@@ -1,44 +0,0 @@
1
- const SEARCH_GROUP_FIELD = 'redocly_category';
2
- const SEARCH_GROUP_NAME_API = 'API Reference';
3
-
4
- export function setDocumentSearchFacets(
5
- actions: any,
6
- documentSearchFacets: { [key: string]: string | Set<string> },
7
- ) {
8
- const searchFacets = actions.getSearchFacets();
9
-
10
- for (const [key, value] of Object.entries(documentSearchFacets)) {
11
- const facet = searchFacets.get(key);
12
- if (facet) {
13
- const facetValues = new Set((facet.values as string[]) ?? []);
14
- if (value instanceof Set) {
15
- [...value].forEach((v) => (facet.values = Array.from(facetValues.add(v))));
16
- } else {
17
- facet.values = Array.from(facetValues.add(value));
18
- }
19
- }
20
- }
21
-
22
- actions.setSearchFacets(searchFacets);
23
- }
24
-
25
- export function extractDocumentSearchFacets(
26
- actions: any,
27
- metadata?: Record<string, unknown>,
28
- ): { [key: string]: string } {
29
- const searchFacets: { [key: string]: string } = {
30
- [SEARCH_GROUP_FIELD]: SEARCH_GROUP_NAME_API,
31
- };
32
-
33
- if (!metadata) return searchFacets;
34
-
35
- const targetSearchFacets = actions.getSearchFacets();
36
-
37
- for (const [key, value] of Object.entries(metadata)) {
38
- if (!targetSearchFacets.has(key)) continue;
39
-
40
- searchFacets[key] = String(value);
41
- }
42
-
43
- return searchFacets;
44
- }
@@ -1,24 +0,0 @@
1
- import { REDOCLY_ROUTE_RBAC, REDOCLY_TEAMS_RBAC } from '@redocly/config';
2
-
3
- import { extractDocumentSearchFacets, setDocumentSearchFacets } from './search-facets.js';
4
-
5
- export function searchResolver(actions: any) {
6
- return async (route: any, staticData: any) => {
7
- const metadata = route.metadata || {};
8
- const facets = extractDocumentSearchFacets(actions, metadata);
9
- setDocumentSearchFacets(actions, facets);
10
- const searchDocument = [
11
- {
12
- id: route.slug,
13
- url: route.slug,
14
- title: staticData?.props?.title,
15
- text: staticData?.props?.description,
16
- facets,
17
- [REDOCLY_TEAMS_RBAC]: staticData[REDOCLY_TEAMS_RBAC] as Record<string, string>,
18
- [REDOCLY_ROUTE_RBAC]: staticData[REDOCLY_ROUTE_RBAC],
19
- },
20
- ];
21
-
22
- return searchDocument;
23
- };
24
- }
package/src/template.tsx DELETED
@@ -1,98 +0,0 @@
1
- import React from 'react';
2
- import styled from 'styled-components';
3
- import { saveAs } from 'file-saver';
4
- import { Button, CodeBlock, H1, useThemeHooks } from '@redocly/theme';
5
-
6
- import { DocumentationLayout } from '@redocly/theme/layouts/DocumentationLayout';
7
-
8
- type PageProps = {
9
- title: string;
10
- wsdl?: string;
11
- request?: string;
12
- description?: string;
13
- };
14
-
15
- type SoapDocsProps = {
16
- pageProps: PageProps;
17
- };
18
-
19
- const Template: React.FC<SoapDocsProps> = ({ pageProps }: SoapDocsProps) => {
20
- const { useSidebarSiblingsData, useCodeHighlight } = useThemeHooks();
21
- const { nextPage, prevPage } = useSidebarSiblingsData() || {};
22
- const { highlight } = useCodeHighlight() || {};
23
-
24
- const downloadWSDL = () => {
25
- const wsdlContent = pageProps.wsdl || '';
26
- const blob = new Blob([wsdlContent], { type: 'application/wsdl+xml' });
27
-
28
- saveAs(blob, `${pageProps.title || 'wsdl'}.wsdl`);
29
- };
30
-
31
- return (
32
- <DocumentationLayout
33
- tableOfContent={undefined}
34
- feedback={undefined}
35
- nextPage={nextPage}
36
- prevPage={prevPage}
37
- >
38
- <>
39
- {/* Render page with general information*/}
40
- {!pageProps.request ? (
41
- <>
42
- <H1>{pageProps.title}</H1>
43
- <MainPageContainer>
44
- <DownloadButton variant="primary" size="small" onClick={downloadWSDL}>
45
- Download WSDL
46
- </DownloadButton>
47
- <CodeBlock
48
- header={{
49
- controls: {
50
- copy: {},
51
- },
52
- title: pageProps.title,
53
- }}
54
- lang="xml"
55
- source={pageProps.wsdl}
56
- highlightedHtml={highlight(pageProps.wsdl || '', 'xml')}
57
- />
58
- </MainPageContainer>
59
- </>
60
- ) : (
61
- <>
62
- {/* Render a page with operation information */}
63
- <H1>{pageProps.title}</H1>
64
- {pageProps.description ? <Description>{pageProps.description}</Description> : null}
65
-
66
- <CodeBlock
67
- header={{
68
- controls: {
69
- copy: {},
70
- },
71
- title: 'Request example',
72
- }}
73
- lang="xml"
74
- source={pageProps.request}
75
- highlightedHtml={highlight(pageProps.request || '')}
76
- />
77
- </>
78
- )}
79
- </>
80
- </DocumentationLayout>
81
- );
82
- };
83
-
84
- export default Template;
85
-
86
- const MainPageContainer = styled.div`
87
- display: flex;
88
- flex-direction: column;
89
- gap: var(--spacing-base);
90
- `;
91
-
92
- const Description = styled.div`
93
- margin-bottom: var(--spacing-base);
94
- `;
95
-
96
- const DownloadButton = styled(Button)`
97
- align-self: flex-end;
98
- `;
@@ -1,12 +0,0 @@
1
- {
2
- "references": [{ "path": "../theme/tsconfig.build.json" }],
3
- "compilerOptions": {
4
- "declaration": true,
5
- "noEmit": false,
6
- "outDir": "lib",
7
- "rootDir": "src",
8
- "tsBuildInfoFile": "lib/.tsbuildinfo"
9
- },
10
- "extends": "./tsconfig.json",
11
- "include": ["src"]
12
- }
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "paths": {
7
- "@portal/*": ["./node_modules/@redocly/portal/dist/client/app"]
8
- }
9
- },
10
- "include": ["src"]
11
- }