@nice2dev/ui-api 1.4.9 → 1.4.11
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/CHANGELOG.md +32 -0
- package/README.md +17 -0
- package/dist/NiceApiClient.d.ts +39 -0
- package/dist/apiClient/ApiClientParts.d.ts +73 -0
- package/dist/index.cjs +9 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +3040 -1458
- package/dist/ui-api.css +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @nice2dev/ui-api
|
|
2
2
|
|
|
3
|
+
## 1.4.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- bacce43: New `NiceApiClient`: an API client in the style of Scalar / Swagger UI, built on the
|
|
8
|
+
`@nice2dev/ui-api/core` model.
|
|
9
|
+
|
|
10
|
+
- **Try:**
|
|
11
|
+
- The collection's folders and requests on the left, searchable. Rename, duplicate and delete
|
|
12
|
+
items from the tree.
|
|
13
|
+
- The request builder: method and URL, with a preview of the URL as sent. Tabs: parameters (one
|
|
14
|
+
table with a location per row), headers, auth, body, scripts and settings.
|
|
15
|
+
- Auth: inherit, none, API key, Bearer, Basic, Digest, OAuth 2.0 (with "Get token"), AWS SigV4,
|
|
16
|
+
HMAC, mTLS or custom headers.
|
|
17
|
+
- Body: JSON, XML, text, form, multipart, file, GraphQL or SOAP.
|
|
18
|
+
- The response: status, time and size; views Pretty, Raw, Headers, Sent and code samples.
|
|
19
|
+
- **Docs:** each operation's parameters, body, responses with their schemas and examples, and code
|
|
20
|
+
samples; the collection's servers and models.
|
|
21
|
+
- **Import:** curl, OpenAPI / Swagger, Postman, HAR, GraphQL introspection or WSDL — paste or open
|
|
22
|
+
a file.
|
|
23
|
+
- **Export:** OpenAPI 3.1 (YAML or JSON), Postman, HAR or Markdown.
|
|
24
|
+
- **Environments:** switch between variable sets. Secrets are resolved through `resolveSecret`.
|
|
25
|
+
- **Sending:** requests go through `sendRequest`, the host's proxy. The default is the browser's
|
|
26
|
+
`fetch`, where CORS applies.
|
|
27
|
+
|
|
28
|
+
`value` / `defaultValue` / `onChange`, `mode` (`consume` / `document` / `both`), `readOnly`.
|
|
29
|
+
146 new `apiClient.*` keys in all 12 full dictionaries.
|
|
30
|
+
|
|
31
|
+
## 1.4.10
|
|
32
|
+
|
|
33
|
+
No changes in this release.
|
|
34
|
+
|
|
3
35
|
## 1.4.9
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -89,6 +89,23 @@ function App() {
|
|
|
89
89
|
}
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
+
### API Client (1.4.11)
|
|
93
|
+
|
|
94
|
+
`NiceApiClient`: Scalar / Swagger UI-style client and documentation on the core model below. It
|
|
95
|
+
imports curl, OpenAPI, Postman, HAR, GraphQL or WSDL and exports OpenAPI, Postman, HAR or Markdown.
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
import { NiceApiClient, importOpenApi } from '@nice2dev/ui-api';
|
|
99
|
+
|
|
100
|
+
<NiceApiClient
|
|
101
|
+
defaultValue={importOpenApi(openApiYaml)}
|
|
102
|
+
environments={[{ id: 'dev', name: 'Dev', values: [{ key: 'token', value: '{{secret:API_TOKEN}}' }] }]}
|
|
103
|
+
sendRequest={hostProxyTransport} // your proxy: the browser's fetch meets CORS
|
|
104
|
+
resolveSecret={(key) => vault.get(key)}
|
|
105
|
+
mode="both" // 'consume' | 'document' | 'both'
|
|
106
|
+
/>;
|
|
107
|
+
```
|
|
108
|
+
|
|
92
109
|
## Core without React — `@nice2dev/ui-api/core` (1.4.9)
|
|
93
110
|
|
|
94
111
|
The model and converters the API tools are built on, usable in Node (importers in CI, generators,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { NiceApiCallState } from './apiClient/ApiClientParts';
|
|
3
|
+
import { NiceApiCollection, NiceApiEnvironment, NiceApiImportOptions, NiceApiTransport } from './core';
|
|
4
|
+
export type { NiceApiCallState };
|
|
5
|
+
export interface NiceApiClientProps {
|
|
6
|
+
/** The collection (controlled). */
|
|
7
|
+
value?: NiceApiCollection;
|
|
8
|
+
/** The collection to start from (uncontrolled). */
|
|
9
|
+
defaultValue?: NiceApiCollection;
|
|
10
|
+
/** Every edit, import and rename — the whole collection. */
|
|
11
|
+
onChange?: (collection: NiceApiCollection) => void;
|
|
12
|
+
/** Variable sets (dev, test, prod…) the user switches between. */
|
|
13
|
+
environments?: NiceApiEnvironment[];
|
|
14
|
+
/** The active environment's id (controlled). */
|
|
15
|
+
activeEnvironment?: string;
|
|
16
|
+
defaultActiveEnvironment?: string;
|
|
17
|
+
onActiveEnvironmentChange?: (id: string) => void;
|
|
18
|
+
/** The selected request or folder id (controlled); empty = the collection itself. */
|
|
19
|
+
selectedItem?: string;
|
|
20
|
+
defaultSelectedItem?: string;
|
|
21
|
+
onSelectedItemChange?: (id: string) => void;
|
|
22
|
+
/** `consume` — send requests; `document` — read the API; `both` (default) — a switch between. */
|
|
23
|
+
mode?: 'consume' | 'document' | 'both';
|
|
24
|
+
/** Sends a resolved request — the host's proxy. Default: the browser's fetch (CORS applies). */
|
|
25
|
+
sendRequest?: NiceApiTransport;
|
|
26
|
+
/** After every send: the response (or the error) and the request as it went out — for logs, tests, history. */
|
|
27
|
+
onResponse?: (requestId: string, call: NiceApiCallState) => void;
|
|
28
|
+
/** The value of `{{secret:KEY}}` — the host's vault. */
|
|
29
|
+
resolveSecret?: (key: string) => string | undefined;
|
|
30
|
+
/** Options for importing OpenAPI with external `$ref`s, a full YAML parser, an XML parser. */
|
|
31
|
+
importOptions?: NiceApiImportOptions;
|
|
32
|
+
/** View and send only: no editing, import or new items. */
|
|
33
|
+
readOnly?: boolean;
|
|
34
|
+
/** Height of the client. Default 640. */
|
|
35
|
+
height?: number | string;
|
|
36
|
+
className?: string;
|
|
37
|
+
style?: React.CSSProperties;
|
|
38
|
+
}
|
|
39
|
+
export declare function NiceApiClient(props: NiceApiClientProps): React.ReactElement;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { NiceApiAuth, NiceApiBody, NiceApiCollection, NiceApiParam, NiceApiParamLocation, NiceApiRequest, NiceApiResolvedRequest, NiceApiResponse, NiceApiSchema } from '../core';
|
|
3
|
+
/** The method as a coloured badge (GET, POST, …). */
|
|
4
|
+
export declare function ApiMethodBadge({ method }: {
|
|
5
|
+
method: string;
|
|
6
|
+
}): React.ReactElement;
|
|
7
|
+
export interface ApiParamsTableProps {
|
|
8
|
+
rows: NiceApiParam[];
|
|
9
|
+
onChange: (rows: NiceApiParam[]) => void;
|
|
10
|
+
/** The location a new row gets — and, with `fixedLocation`, the only one shown. */
|
|
11
|
+
addLocation: NiceApiParamLocation;
|
|
12
|
+
fixedLocation?: boolean;
|
|
13
|
+
readOnly?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Parameters as a table: on/off, key, value, location, description. */
|
|
16
|
+
export declare function ApiParamsTable({ rows, onChange, addLocation, fixedLocation, readOnly, }: ApiParamsTableProps): React.ReactElement;
|
|
17
|
+
export interface ApiAuthEditorProps {
|
|
18
|
+
auth: NiceApiAuth | undefined;
|
|
19
|
+
onChange: (auth: NiceApiAuth) => void;
|
|
20
|
+
readOnly?: boolean;
|
|
21
|
+
/** For requests and folders: offer "inherit" (default). The collection has nothing above it. */
|
|
22
|
+
allowInherit?: boolean;
|
|
23
|
+
/** Obtain an OAuth 2 token (client credentials / password) — shown with the oauth2 kind. */
|
|
24
|
+
onGetToken?: () => void;
|
|
25
|
+
tokenBusy?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** The auth of a request, folder or collection: the kind, then the fields it needs. */
|
|
28
|
+
export declare function ApiAuthEditor({ auth, onChange, readOnly, allowInherit, onGetToken, tokenBusy, }: ApiAuthEditorProps): React.ReactElement;
|
|
29
|
+
export interface ApiBodyEditorProps {
|
|
30
|
+
body: NiceApiBody;
|
|
31
|
+
onChange: (body: NiceApiBody) => void;
|
|
32
|
+
readOnly?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** The request body: its kind, then an editor for it. */
|
|
35
|
+
export declare function ApiBodyEditor({ body, onChange, readOnly, }: ApiBodyEditorProps): React.ReactElement;
|
|
36
|
+
/** A schema as a property tree: name, type, required, description — nested objects and arrays open. */
|
|
37
|
+
export declare function ApiSchemaTree({ schema, resolve, depth, }: {
|
|
38
|
+
schema: NiceApiSchema | undefined;
|
|
39
|
+
resolve: (ref: string) => NiceApiSchema | undefined;
|
|
40
|
+
depth?: number;
|
|
41
|
+
}): React.ReactElement | null;
|
|
42
|
+
/** What the client keeps per request: the last response (or error) and what was sent. */
|
|
43
|
+
export interface NiceApiCallState {
|
|
44
|
+
loading?: boolean;
|
|
45
|
+
response?: NiceApiResponse;
|
|
46
|
+
sent?: NiceApiResolvedRequest;
|
|
47
|
+
error?: string;
|
|
48
|
+
}
|
|
49
|
+
/** Code samples: a language picker and the sample, read-only. */
|
|
50
|
+
export declare function ApiCodeSamples({ request, auth, transform, height, }: {
|
|
51
|
+
request: NiceApiRequest;
|
|
52
|
+
auth: NiceApiAuth;
|
|
53
|
+
transform?: (text: string) => string;
|
|
54
|
+
height?: number;
|
|
55
|
+
}): React.ReactElement;
|
|
56
|
+
/** The response of the selected request. */
|
|
57
|
+
export declare function ApiResponsePanel({ state, request, auth, transform, }: {
|
|
58
|
+
state: NiceApiCallState | undefined;
|
|
59
|
+
request: NiceApiRequest;
|
|
60
|
+
auth: NiceApiAuth;
|
|
61
|
+
transform: (text: string) => string;
|
|
62
|
+
}): React.ReactElement;
|
|
63
|
+
/** Documentation of one request: method and path, parameters, body, responses, code. */
|
|
64
|
+
export declare function ApiRequestDocs({ request, collection, auth, transform, }: {
|
|
65
|
+
request: NiceApiRequest;
|
|
66
|
+
collection: NiceApiCollection;
|
|
67
|
+
auth: NiceApiAuth;
|
|
68
|
+
transform: (text: string) => string;
|
|
69
|
+
}): React.ReactElement;
|
|
70
|
+
/** Documentation of the collection: name, version, description, servers, auth, models. */
|
|
71
|
+
export declare function ApiCollectionDocs({ collection, }: {
|
|
72
|
+
collection: NiceApiCollection;
|
|
73
|
+
}): React.ReactElement;
|