@nice2dev/ui-api 1.4.8 → 1.4.9

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.
@@ -0,0 +1,332 @@
1
+ /**
2
+ * @nice2dev/ui-api/core — the request model every converter reads and writes (1.4.9).
3
+ *
4
+ * One request carries everything a call needs: the method and URL, one parameter list with a
5
+ * location per row (query, path, header, cookie — the way Swagger and Scalar show them), a body
6
+ * of one of nine kinds, the auth, scripts and settings. A collection nests requests in folders
7
+ * and carries variables, auth for everything that inherits it, servers and schemas (models).
8
+ *
9
+ * React-free: usable in Node (importers in CI, generators, the host's proxy).
10
+ */
11
+ /** The HTTP method; any other verb (WebDAV `PROPFIND`, …) as a string. */
12
+ export type NiceApiMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | (string & {});
13
+ /** The methods offered in pickers, in the usual order. */
14
+ export declare const NICE_API_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "TRACE"];
15
+ /** A key / value row — a header, a query parameter, a form field, a variable. */
16
+ export interface NiceApiKeyValue {
17
+ key: string;
18
+ value: string;
19
+ /** Off rows stay in the request but are not sent. Default on. */
20
+ enabled?: boolean;
21
+ description?: string;
22
+ }
23
+ /** Where a parameter travels. */
24
+ export type NiceApiParamLocation = 'query' | 'path' | 'header' | 'cookie';
25
+ /** A parameter row: a key / value with its location (and, from OpenAPI, its schema). */
26
+ export interface NiceApiParam extends NiceApiKeyValue {
27
+ in: NiceApiParamLocation;
28
+ required?: boolean;
29
+ schema?: NiceApiSchema;
30
+ /** OpenAPI serialization: `form`, `simple`, `deepObject`, … */
31
+ style?: string;
32
+ explode?: boolean;
33
+ }
34
+ /** A JSON-schema subset — enough for documentation, examples and mock data. */
35
+ export interface NiceApiSchema {
36
+ type?: string | string[];
37
+ format?: string;
38
+ title?: string;
39
+ description?: string;
40
+ properties?: Record<string, NiceApiSchema>;
41
+ required?: string[];
42
+ items?: NiceApiSchema;
43
+ enum?: unknown[];
44
+ const?: unknown;
45
+ default?: unknown;
46
+ example?: unknown;
47
+ examples?: unknown[];
48
+ nullable?: boolean;
49
+ minimum?: number;
50
+ maximum?: number;
51
+ minLength?: number;
52
+ maxLength?: number;
53
+ pattern?: string;
54
+ additionalProperties?: boolean | NiceApiSchema;
55
+ oneOf?: NiceApiSchema[];
56
+ anyOf?: NiceApiSchema[];
57
+ allOf?: NiceApiSchema[];
58
+ /** A reference to a named schema, `#/components/schemas/Pet` as in OpenAPI. */
59
+ $ref?: string;
60
+ readOnly?: boolean;
61
+ writeOnly?: boolean;
62
+ deprecated?: boolean;
63
+ /** OpenAPI 3.1: the media type of a string's content (a file part). */
64
+ contentMediaType?: string;
65
+ contentEncoding?: string;
66
+ }
67
+ /** A multipart part: a text field or a file. */
68
+ export interface NiceApiFormPart extends NiceApiKeyValue {
69
+ type?: 'text' | 'file';
70
+ fileName?: string;
71
+ contentType?: string;
72
+ }
73
+ /** The body kinds the client sends. */
74
+ export type NiceApiBodyKind = 'none' | 'json' | 'xml' | 'text' | 'form' | 'multipart' | 'binary' | 'graphql' | 'soap';
75
+ /** The request body: one of nine kinds, each with the fields it needs. */
76
+ export type NiceApiBody = {
77
+ kind: 'none';
78
+ } | {
79
+ kind: 'json';
80
+ text: string;
81
+ } | {
82
+ kind: 'xml';
83
+ text: string;
84
+ } | {
85
+ kind: 'text';
86
+ text: string;
87
+ contentType?: string;
88
+ }
89
+ /** `application/x-www-form-urlencoded` */
90
+ | {
91
+ kind: 'form';
92
+ fields: NiceApiKeyValue[];
93
+ } | {
94
+ kind: 'multipart';
95
+ parts: NiceApiFormPart[];
96
+ }
97
+ /** A file: `data` base64 when the host keeps the bytes, else only the name. */
98
+ | {
99
+ kind: 'binary';
100
+ fileName?: string;
101
+ contentType?: string;
102
+ data?: string;
103
+ } | {
104
+ kind: 'graphql';
105
+ query: string;
106
+ variables?: string;
107
+ operationName?: string;
108
+ } | {
109
+ kind: 'soap';
110
+ envelope: string;
111
+ action?: string;
112
+ version: '1.1' | '1.2';
113
+ };
114
+ /** OAuth 2 grants the client can run (the host's proxy calls the token endpoint). */
115
+ export type NiceApiOAuth2Grant = 'clientCredentials' | 'authorizationCode' | 'password' | 'deviceCode' | 'implicit';
116
+ /** How a request authenticates. `inherit` takes the folder's or the collection's. */
117
+ export type NiceApiAuth = {
118
+ type: 'none';
119
+ } | {
120
+ type: 'inherit';
121
+ } | {
122
+ type: 'apiKey';
123
+ key: string;
124
+ value: string;
125
+ in: 'header' | 'query' | 'cookie';
126
+ } | {
127
+ type: 'bearer';
128
+ token: string;
129
+ prefix?: string;
130
+ } | {
131
+ type: 'basic';
132
+ username: string;
133
+ password: string;
134
+ } | {
135
+ type: 'digest';
136
+ username: string;
137
+ password: string;
138
+ /** From the server's `WWW-Authenticate` challenge (a first call without auth returns it). */
139
+ realm?: string;
140
+ nonce?: string;
141
+ qop?: string;
142
+ algorithm?: string;
143
+ opaque?: string;
144
+ } | {
145
+ type: 'oauth2';
146
+ grant: NiceApiOAuth2Grant;
147
+ tokenUrl?: string;
148
+ authUrl?: string;
149
+ deviceUrl?: string;
150
+ clientId: string;
151
+ clientSecret?: string;
152
+ scope?: string;
153
+ audience?: string;
154
+ username?: string;
155
+ password?: string;
156
+ redirectUri?: string;
157
+ /** Authorization code with PKCE (S256). */
158
+ usePkce?: boolean;
159
+ /** Client credentials in a Basic header (default) or in the token request body. */
160
+ clientAuth?: 'header' | 'body';
161
+ /** The token once obtained; sent as `Authorization: <tokenType> <accessToken>`. */
162
+ accessToken?: string;
163
+ tokenType?: string;
164
+ refreshToken?: string;
165
+ expiresAt?: number;
166
+ } | {
167
+ type: 'awsSigV4';
168
+ accessKeyId: string;
169
+ secretAccessKey: string;
170
+ sessionToken?: string;
171
+ region: string;
172
+ service: string;
173
+ } | {
174
+ type: 'hmac';
175
+ algorithm: 'SHA-1' | 'SHA-256' | 'SHA-512';
176
+ secret: string;
177
+ /** The header that carries the signature. */
178
+ header: string;
179
+ /**
180
+ * What is signed: placeholders `{method}`, `{path}`, `{query}`, `{body}`, `{timestamp}`.
181
+ * Default `{method}\n{path}\n{timestamp}\n{body}`.
182
+ */
183
+ template?: string;
184
+ encoding?: 'hex' | 'base64';
185
+ /** The header that carries the timestamp (seconds) when the template uses it. */
186
+ timestampHeader?: string;
187
+ /** Prefix in front of the signature, e.g. `HMAC ` or `sha256=`. */
188
+ prefix?: string;
189
+ }
190
+ /** A client certificate — applied by the host's transport, not in the browser. */
191
+ | {
192
+ type: 'mtls';
193
+ certificate?: string;
194
+ key?: string;
195
+ passphrase?: string;
196
+ } | {
197
+ type: 'custom';
198
+ headers: NiceApiKeyValue[];
199
+ };
200
+ /** The auth kinds offered in pickers. */
201
+ export declare const NICE_API_AUTH_TYPES: readonly ["inherit", "none", "apiKey", "bearer", "basic", "digest", "oauth2", "awsSigV4", "hmac", "mtls", "custom"];
202
+ /** A documented response of an operation (from OpenAPI) or a saved example response. */
203
+ export interface NiceApiResponseDoc {
204
+ description?: string;
205
+ contentType?: string;
206
+ schema?: NiceApiSchema;
207
+ example?: string;
208
+ headers?: NiceApiKeyValue[];
209
+ }
210
+ /** A saved example: the response a call returned, under a name. */
211
+ export interface NiceApiExample {
212
+ name: string;
213
+ status: number;
214
+ headers?: NiceApiKeyValue[];
215
+ body?: string;
216
+ }
217
+ /** Per-request settings. */
218
+ export interface NiceApiSettings {
219
+ timeoutMs?: number;
220
+ followRedirects?: boolean;
221
+ /** Skip TLS verification (`curl -k`) — the host's transport decides whether it honours it. */
222
+ insecure?: boolean;
223
+ }
224
+ /** One API call. */
225
+ export interface NiceApiRequest {
226
+ kind: 'request';
227
+ id: string;
228
+ name: string;
229
+ method: NiceApiMethod;
230
+ /** May hold `{{variables}}` and path parameters as `{id}` or `:id`. */
231
+ url: string;
232
+ params: NiceApiParam[];
233
+ body: NiceApiBody;
234
+ /** Unset = `inherit`. */
235
+ auth?: NiceApiAuth;
236
+ description?: string;
237
+ /** Script source run by the host before the call and on its response. */
238
+ scripts?: {
239
+ preRequest?: string;
240
+ test?: string;
241
+ };
242
+ settings?: NiceApiSettings;
243
+ /** OpenAPI: the operation id, tags, deprecation and the documented responses by status. */
244
+ operationId?: string;
245
+ tags?: string[];
246
+ deprecated?: boolean;
247
+ responses?: Record<string, NiceApiResponseDoc>;
248
+ examples?: NiceApiExample[];
249
+ }
250
+ /** A folder of requests and folders. */
251
+ export interface NiceApiFolder {
252
+ kind: 'folder';
253
+ id: string;
254
+ name: string;
255
+ description?: string;
256
+ items: NiceApiItem[];
257
+ auth?: NiceApiAuth;
258
+ }
259
+ /** A collection entry: a request or a folder. */
260
+ export type NiceApiItem = NiceApiRequest | NiceApiFolder;
261
+ /** A variable; secrets are never written into a seed — their value is `{{secret:KEY}}`. */
262
+ export interface NiceApiVariable {
263
+ key: string;
264
+ value: string;
265
+ secret?: boolean;
266
+ description?: string;
267
+ enabled?: boolean;
268
+ }
269
+ /** A server the collection can talk to. */
270
+ export interface NiceApiServer {
271
+ url: string;
272
+ description?: string;
273
+ }
274
+ /** An API: its requests in folders, its variables, auth, servers and models. */
275
+ export interface NiceApiCollection {
276
+ id: string;
277
+ name: string;
278
+ description?: string;
279
+ version?: string;
280
+ items: NiceApiItem[];
281
+ variables: NiceApiVariable[];
282
+ auth?: NiceApiAuth;
283
+ servers?: NiceApiServer[];
284
+ /** Named models, referenced from requests as `#/components/schemas/<name>`. */
285
+ schemas?: Record<string, NiceApiSchema>;
286
+ }
287
+ /** A named set of variable values (dev, test, prod…). */
288
+ export interface NiceApiEnvironment {
289
+ id: string;
290
+ name: string;
291
+ values: NiceApiVariable[];
292
+ }
293
+ /** A short id unique within the session (and practically across sessions). */
294
+ export declare function newApiId(prefix?: string): string;
295
+ /** A request with every required field filled — pass only what differs. */
296
+ export declare function newApiRequest(init?: Partial<Omit<NiceApiRequest, 'kind'>>): NiceApiRequest;
297
+ /** A folder with every required field filled. */
298
+ export declare function newApiFolder(init?: Partial<Omit<NiceApiFolder, 'kind'>>): NiceApiFolder;
299
+ /** An empty collection. */
300
+ export declare function newApiCollection(init?: Partial<NiceApiCollection>): NiceApiCollection;
301
+ /** Every request of `items`, depth first, with the folders above it (outermost first). */
302
+ export declare function flattenApiRequests(items: readonly NiceApiItem[], parents?: readonly NiceApiFolder[]): {
303
+ request: NiceApiRequest;
304
+ folders: NiceApiFolder[];
305
+ }[];
306
+ /** The item with `id` anywhere in `items`. */
307
+ export declare function findApiItem(items: readonly NiceApiItem[], id: string): NiceApiItem | undefined;
308
+ /** `items` with the item `id` replaced by `update(item)` (or removed when it returns null). */
309
+ export declare function updateApiItem(items: readonly NiceApiItem[], id: string, update: (item: NiceApiItem) => NiceApiItem | null): NiceApiItem[];
310
+ /** Whether a row is sent (rows are on unless switched off). */
311
+ export declare function isEnabled(row: {
312
+ enabled?: boolean;
313
+ }): boolean;
314
+ /** Rows → `{ key: value }` (enabled rows only; a later row wins). */
315
+ export declare function rowsToRecord(rows: readonly NiceApiKeyValue[]): Record<string, string>;
316
+ /** The enabled parameters of one location. */
317
+ export declare function paramsIn(request: NiceApiRequest, location: NiceApiParamLocation): NiceApiParam[];
318
+ /** The value of header `name` (case-insensitive) among the enabled header rows. */
319
+ export declare function headerValue(request: NiceApiRequest, name: string): string | undefined;
320
+ /**
321
+ * The auth that applies to `request`: its own, else the nearest folder's (innermost first), else
322
+ * the collection's; `inherit` all the way up is `none`.
323
+ */
324
+ export declare function effectiveAuth(request: NiceApiRequest, folders?: readonly NiceApiFolder[], collection?: Pick<NiceApiCollection, 'auth'>): NiceApiAuth;
325
+ /** The `Content-Type` a body is sent with when the request does not set one. */
326
+ export declare function bodyContentType(body: NiceApiBody): string | undefined;
327
+ /** The body as the text sent on the wire (multipart and binary have none — the transport builds them). */
328
+ export declare function bodyText(body: NiceApiBody): string | undefined;
329
+ /** The body kind a `Content-Type` suggests for text read from elsewhere (curl, HAR, …). */
330
+ export declare function bodyFromText(text: string, contentType?: string): NiceApiBody;
331
+ /** `a=1&b=2` as rows (`+` as a space, as browsers send it). */
332
+ export declare function parseFormEncoded(text: string): NiceApiKeyValue[];
@@ -0,0 +1,27 @@
1
+ import { NiceApiCollection } from './model';
2
+ type Json = Record<string, unknown>;
3
+ export interface NiceOpenApiImportOptions {
4
+ /** A full YAML parser for files beyond the built-in subset. */
5
+ parseYaml?: (text: string) => unknown;
6
+ /** The document an external `$ref` points to (its part before `#`: a file name or URL). */
7
+ resolveRef?: (ref: string) => unknown;
8
+ /** Folders per tag (default), per first path segment, or none. */
9
+ groupBy?: 'tag' | 'path' | 'none';
10
+ /** The variable that holds the server URL. Default `baseUrl`. */
11
+ baseUrlVariable?: string;
12
+ }
13
+ /** A JSON pointer (`#/components/schemas/Pet`) inside `doc`. */
14
+ export declare function jsonPointer(doc: unknown, ref: string): unknown;
15
+ /** Reads an OpenAPI 3.x / Swagger 2.0 document into a collection. */
16
+ export declare function importOpenApi(source: string | object, options?: NiceOpenApiImportOptions): NiceApiCollection;
17
+ /** A Swagger 2.0 document in the OpenAPI 3.0 shape (what `importOpenApi` reads). */
18
+ export declare function swagger2ToOpenApi3(doc: Json): Json;
19
+ export interface NiceOpenApiExportOptions {
20
+ /** The variable that holds the server URL. Default `baseUrl`. */
21
+ baseUrlVariable?: string;
22
+ }
23
+ /** A collection as an OpenAPI 3.1 document (an object — `stringifyYaml` or `JSON.stringify` it). */
24
+ export declare function exportOpenApi(collection: NiceApiCollection, options?: NiceOpenApiExportOptions): Record<string, unknown>;
25
+ /** The collection as an OpenAPI 3.1 YAML text. */
26
+ export declare function exportOpenApiYaml(collection: NiceApiCollection, options?: NiceOpenApiExportOptions): string;
27
+ export {};
@@ -0,0 +1,12 @@
1
+ import { NiceApiCollection, NiceApiEnvironment } from './model';
2
+ export declare const POSTMAN_SCHEMA_V21 = "https://schema.getpostman.com/json/collection/v2.1.0/collection.json";
3
+ /** Whether a parsed JSON value is a Postman collection. */
4
+ export declare function isPostmanCollection(value: unknown): boolean;
5
+ /** Reads a Postman collection (v2.1 or v2.0, parsed JSON or its text). */
6
+ export declare function importPostman(source: string | object): NiceApiCollection;
7
+ /** Reads a Postman environment. */
8
+ export declare function importPostmanEnvironment(source: string | object): NiceApiEnvironment;
9
+ /** A collection as a Postman Collection v2.1 object. */
10
+ export declare function exportPostman(collection: NiceApiCollection): Record<string, unknown>;
11
+ /** An environment as a Postman environment object. */
12
+ export declare function exportPostmanEnvironment(environment: NiceApiEnvironment): Record<string, unknown>;
@@ -0,0 +1,122 @@
1
+ import { NiceApiAuth, NiceApiFormPart, NiceApiRequest, NiceApiSettings } from './model';
2
+ import { NiceApiInterpolateOptions, NiceApiVariableLookup } from './variables';
3
+ /** The body on the wire: text, or parts / a file the transport builds the bytes of. */
4
+ export type NiceApiWireBody = string | {
5
+ kind: 'multipart';
6
+ parts: NiceApiFormPart[];
7
+ files?: Record<string, string>;
8
+ } | {
9
+ kind: 'binary';
10
+ fileName?: string;
11
+ contentType?: string;
12
+ data?: string;
13
+ };
14
+ /** A request ready to send. */
15
+ export interface NiceApiResolvedRequest {
16
+ method: string;
17
+ url: string;
18
+ headers: [string, string][];
19
+ body?: NiceApiWireBody;
20
+ settings: NiceApiSettings;
21
+ }
22
+ /** What came back. */
23
+ export interface NiceApiResponse {
24
+ status: number;
25
+ statusText: string;
26
+ headers: [string, string][];
27
+ /** The body as text (empty for a binary body — see `bodyBase64`). */
28
+ body: string;
29
+ /** The body as base64 when it is not text (an image, a file). */
30
+ bodyBase64?: string;
31
+ timeMs: number;
32
+ size: number;
33
+ /** The final URL after redirects. */
34
+ url?: string;
35
+ }
36
+ /** Sends a resolved request. The host's proxy, a mock, or {@link fetchTransport}. */
37
+ export type NiceApiTransport = (request: NiceApiResolvedRequest, signal?: AbortSignal) => Promise<NiceApiResponse>;
38
+ export interface NiceApiResolveContext extends NiceApiInterpolateOptions {
39
+ /** Variable values (see `variableScope`). */
40
+ variables?: Record<string, string> | NiceApiVariableLookup;
41
+ /** The auth to apply — pass the effective one for inherited auth. Default the request's own. */
42
+ auth?: NiceApiAuth;
43
+ }
44
+ /** SHA-1 / SHA-256 / SHA-512 of text or bytes. */
45
+ export declare function digest(algorithm: 'SHA-1' | 'SHA-256' | 'SHA-512', data: string | Uint8Array): Promise<ArrayBuffer>;
46
+ /** HMAC of `data` with `key`. */
47
+ export declare function hmac(algorithm: 'SHA-1' | 'SHA-256' | 'SHA-512', key: string | Uint8Array | ArrayBuffer, data: string | Uint8Array): Promise<ArrayBuffer>;
48
+ /** The parameters of a `WWW-Authenticate: Digest …` challenge. */
49
+ export declare function parseDigestChallenge(header: string): Record<string, string> | undefined;
50
+ /** The `Authorization: Digest …` value for a challenge already known. */
51
+ export declare function digestAuthorization(auth: Extract<NiceApiAuth, {
52
+ type: 'digest';
53
+ }>, method: string, url: string, options?: {
54
+ cnonce?: string;
55
+ nc?: number;
56
+ }): Promise<string | undefined>;
57
+ /** Signs a resolved request with AWS Signature V4 (headers added in place). */
58
+ export declare function signAwsV4(request: NiceApiResolvedRequest, auth: Extract<NiceApiAuth, {
59
+ type: 'awsSigV4';
60
+ }>, now?: Date): Promise<void>;
61
+ /** Signs a resolved request with an HMAC header (and a timestamp header when the template uses it). */
62
+ export declare function signHmac(request: NiceApiResolvedRequest, auth: Extract<NiceApiAuth, {
63
+ type: 'hmac';
64
+ }>, now?: Date): Promise<void>;
65
+ /** The request as it goes on the wire (async: signatures use Web Crypto). */
66
+ export declare function resolveRequest(request: NiceApiRequest, context?: NiceApiResolveContext): Promise<NiceApiResolvedRequest>;
67
+ /**
68
+ * Resolves and sends a request; for Digest auth without a challenge yet, answers the server's
69
+ * 401 challenge and sends again. Returns the response, the request as sent and the auth (with
70
+ * the challenge filled in — keep it for the next call).
71
+ */
72
+ export declare function sendApiRequest(request: NiceApiRequest, transport: NiceApiTransport, context?: NiceApiResolveContext, signal?: AbortSignal): Promise<{
73
+ response: NiceApiResponse;
74
+ sent: NiceApiResolvedRequest;
75
+ auth?: NiceApiAuth;
76
+ }>;
77
+ /**
78
+ * A transport over `fetch` (the browser's or Node's). Multipart file parts and binary bodies send
79
+ * the bytes the request holds (`data` / `files` base64). In a browser it meets CORS — pass a
80
+ * proxy transport from the host for other origins.
81
+ */
82
+ export declare function fetchTransport(fetchImpl?: typeof fetch): NiceApiTransport;
83
+ /** A token from a token endpoint. */
84
+ export interface NiceOAuth2Token {
85
+ accessToken: string;
86
+ tokenType: string;
87
+ refreshToken?: string;
88
+ /** Milliseconds since the epoch. */
89
+ expiresAt?: number;
90
+ scope?: string;
91
+ idToken?: string;
92
+ }
93
+ type OAuth2Auth = Extract<NiceApiAuth, {
94
+ type: 'oauth2';
95
+ }>;
96
+ /** A PKCE verifier and its S256 challenge. */
97
+ export declare function createPkcePair(): Promise<{
98
+ verifier: string;
99
+ challenge: string;
100
+ }>;
101
+ /** The authorization URL the user opens (authorization code — with PKCE when `challenge` is given — or implicit). */
102
+ export declare function buildAuthorizationUrl(auth: OAuth2Auth, options?: {
103
+ state?: string;
104
+ challenge?: string;
105
+ }): string;
106
+ /** Client credentials or password grant: the token, straight from the token endpoint. */
107
+ export declare function fetchOAuth2Token(auth: OAuth2Auth, transport: NiceApiTransport): Promise<NiceOAuth2Token>;
108
+ /** Authorization code grant: the code from the redirect exchanged for a token (with the PKCE verifier). */
109
+ export declare function exchangeAuthorizationCode(auth: OAuth2Auth, code: string, transport: NiceApiTransport, verifier?: string): Promise<NiceOAuth2Token>;
110
+ /** A new access token from a refresh token. */
111
+ export declare function refreshOAuth2Token(auth: OAuth2Auth, refreshToken: string, transport: NiceApiTransport): Promise<NiceOAuth2Token>;
112
+ /** Device flow, step 1: the code the user enters at `verificationUri`. */
113
+ export declare function startDeviceAuthorization(auth: OAuth2Auth, transport: NiceApiTransport): Promise<{
114
+ deviceCode: string;
115
+ userCode: string;
116
+ verificationUri: string;
117
+ interval: number;
118
+ expiresIn?: number;
119
+ }>;
120
+ /** Device flow, step 2: one poll — the token, or `pending` while the user has not finished. */
121
+ export declare function pollDeviceToken(auth: OAuth2Auth, deviceCode: string, transport: NiceApiTransport): Promise<NiceOAuth2Token | 'pending' | 'slow_down'>;
122
+ export {};
@@ -0,0 +1,23 @@
1
+ import { NiceApiKeyValue, NiceApiParam, NiceApiRequest } from './model';
2
+ /** A URL in parts: everything before `?`, the query rows and the `#fragment`. */
3
+ export interface NiceApiUrlParts {
4
+ base: string;
5
+ query: NiceApiKeyValue[];
6
+ hash: string;
7
+ }
8
+ /** Splits a URL — `{{variables}}` may sit anywhere, so this is text work, not `new URL()`. */
9
+ export declare function splitUrl(url: string): NiceApiUrlParts;
10
+ /** `{id}` (not `{{var}}`) and `:id` segments, in order of appearance. */
11
+ export declare function pathParamNames(url: string): string[];
12
+ /** The request's parameters with one path row per path parameter of its URL (values kept). */
13
+ export declare function syncPathParams(request: NiceApiRequest): NiceApiParam[];
14
+ /** The request with `url` set: its query moved into query rows (replacing them), path rows synced. */
15
+ export declare function setRequestUrl(request: NiceApiRequest, url: string): NiceApiRequest;
16
+ /**
17
+ * The URL a request is sent to: `transform` (interpolation) applied to every piece, path
18
+ * parameters substituted (encoded), the enabled query rows appended to whatever query the URL
19
+ * still carries.
20
+ */
21
+ export declare function buildRequestUrl(request: NiceApiRequest, transform?: (text: string) => string): string;
22
+ /** Joins a server URL and a path without doubling or dropping the slash. */
23
+ export declare function joinUrl(server: string, path: string): string;
@@ -0,0 +1,25 @@
1
+ import { NiceApiCollection, NiceApiEnvironment } from './model';
2
+ /** Looks a variable up; `undefined` leaves `{{name}}` as it is. */
3
+ export type NiceApiVariableLookup = (name: string) => string | undefined;
4
+ export interface NiceApiInterpolateOptions {
5
+ /** The value of `{{secret:KEY}}` — the host's vault. Unset leaves the placeholder. */
6
+ resolveSecret?: (key: string) => string | undefined;
7
+ /** Clock for `{{$timestamp}}` (tests). */
8
+ now?: () => Date;
9
+ /** Random source for `{{$guid}}` / `{{$randomInt}}` (tests). */
10
+ random?: () => number;
11
+ }
12
+ /** The variable names `text` refers to (secrets as `secret:KEY`, dynamic ones as `$guid`). */
13
+ export declare function findVariables(text: string): string[];
14
+ /**
15
+ * `text` with every `{{name}}` it can resolve replaced — up to five rounds, so a variable may hold
16
+ * another (`{{baseUrl}}` = `https://{{host}}`). Unknown names stay as they are.
17
+ */
18
+ export declare function interpolate(text: string, lookup: NiceApiVariableLookup | Record<string, string>, options?: NiceApiInterpolateOptions): string;
19
+ /** The names `text` still refers to after interpolation — what is missing. */
20
+ export declare function unresolvedVariables(text: string, lookup: NiceApiVariableLookup | Record<string, string>, options?: NiceApiInterpolateOptions): string[];
21
+ /**
22
+ * The values in force: the collection's variables, overridden by the environment's, overridden by
23
+ * `extra` (values set at run time — a token from a login call). Disabled rows are skipped.
24
+ */
25
+ export declare function variableScope(collection?: Pick<NiceApiCollection, 'variables'>, environment?: Pick<NiceApiEnvironment, 'values'>, extra?: Record<string, string>): Record<string, string>;
@@ -0,0 +1,62 @@
1
+ import { NiceApiCollection } from './model';
2
+ /** The part of `DOMParser` the reader needs. */
3
+ export interface NiceXmlParser {
4
+ parseFromString(text: string, type: string): Document;
5
+ }
6
+ export interface NiceWsdlOperation {
7
+ name: string;
8
+ soapAction?: string;
9
+ style: 'document' | 'rpc';
10
+ documentation?: string;
11
+ /** Document style: the input element `{namespace}name`; RPC: the operation's namespace. */
12
+ inputElement?: {
13
+ namespace?: string;
14
+ name: string;
15
+ };
16
+ /** RPC style: the input message's parts. */
17
+ inputParts?: {
18
+ name: string;
19
+ type?: {
20
+ namespace?: string;
21
+ name: string;
22
+ };
23
+ }[];
24
+ outputElement?: {
25
+ namespace?: string;
26
+ name: string;
27
+ };
28
+ }
29
+ export interface NiceWsdlPort {
30
+ name: string;
31
+ binding: string;
32
+ version: '1.1' | '1.2';
33
+ address: string;
34
+ operations: NiceWsdlOperation[];
35
+ }
36
+ export interface NiceWsdlService {
37
+ name: string;
38
+ documentation?: string;
39
+ ports: NiceWsdlPort[];
40
+ }
41
+ /** A WSDL read: its target namespace, services and the schema types the envelopes are built from. */
42
+ export interface NiceWsdl {
43
+ targetNamespace?: string;
44
+ services: NiceWsdlService[];
45
+ /** Global XSD elements and complex types by `{namespace}name`, for envelope bodies. */
46
+ schema: NiceXsdIndex;
47
+ }
48
+ export interface NiceXsdIndex {
49
+ elements: Map<string, Element>;
50
+ types: Map<string, Element>;
51
+ /** Whether local elements of a namespace's schema are qualified. */
52
+ qualified: Map<string, boolean>;
53
+ }
54
+ /** Reads a WSDL 1.1 document. */
55
+ export declare function parseWsdl(text: string, parser?: NiceXmlParser): NiceWsdl;
56
+ /** A request envelope for an operation, its body a sample from the schema. */
57
+ export declare function buildSoapEnvelope(wsdl: NiceWsdl, operation: NiceWsdlOperation, version?: '1.1' | '1.2'): string;
58
+ /** A collection: a folder per service port, a SOAP request per operation. */
59
+ export declare function importWsdl(text: string, options?: {
60
+ parser?: NiceXmlParser;
61
+ name?: string;
62
+ }): NiceApiCollection;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A YAML reader and writer for API documents — the subset OpenAPI files use: block mappings and
3
+ * sequences, plain / single- / double-quoted scalars (multi-line too), literal `|` and folded `>`
4
+ * block scalars with chomping, flow collections `[…]` / `{…}`, comments, anchors, aliases and
5
+ * `<<` merges, `---` / `...` markers. One document per text. No dependency: pass a full YAML
6
+ * library's `parse` to the importers when a file needs more.
7
+ */
8
+ /** A YAML text that cannot be read, with the line it stopped at (1-based). */
9
+ export declare class NiceYamlError extends Error {
10
+ readonly line: number;
11
+ constructor(message: string, line: number);
12
+ }
13
+ /** A plain scalar as YAML 1.2's core schema reads it. */
14
+ export declare function resolvePlainScalar(text: string): unknown;
15
+ /** Reads one YAML document. Throws {@link NiceYamlError} with the line it stopped at. */
16
+ export declare function parseYaml(text: string): unknown;
17
+ /** Writes a value as YAML (block style, two-space indentation, multi-line strings as `|`). */
18
+ export declare function stringifyYaml(value: unknown): string;
19
+ /** Reads JSON or YAML: JSON when the text starts with `{` or `[`, else YAML. */
20
+ export declare function parseJsonOrYaml(text: string, yaml?: (text: string) => unknown): unknown;