bariweb-widget 0.1.10 → 0.1.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/dist/types/components/accordion/accordion-item.d.ts +8 -0
- package/dist/types/components/accordion/accordion.d.ts +1 -0
- package/dist/types/components/accordion/accordion.styles.d.ts +1 -0
- package/dist/types/components/button/button.d.ts +8 -0
- package/dist/types/components/button/button.styles.d.ts +1 -0
- package/dist/types/components/card/card.d.ts +6 -0
- package/dist/types/components/card/card.styles.d.ts +1 -0
- package/dist/types/controllers/a11y.controller.d.ts +50 -0
- package/dist/types/controllers/ai-a11y.controller.d.ts +17 -0
- package/dist/types/controllers/chat.controller.d.ts +100 -0
- package/dist/types/controllers/scanner.controller.d.ts +1 -0
- package/dist/types/controllers/tts.controller.d.ts +11 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/lib/AdminUI.d.ts +8 -0
- package/dist/types/lib/Fingerprint.d.ts +44 -0
- package/dist/types/lib/Watcher.d.ts +62 -0
- package/dist/types/lib/api/client/client.gen.d.ts +2 -0
- package/dist/types/lib/api/client/index.d.ts +8 -0
- package/dist/types/lib/api/client/types.gen.d.ts +117 -0
- package/dist/types/lib/api/client/utils.gen.d.ts +33 -0
- package/dist/types/lib/api/client.gen.d.ts +12 -0
- package/dist/types/lib/api/core/auth.gen.d.ts +18 -0
- package/dist/types/lib/api/core/bodySerializer.gen.d.ts +25 -0
- package/dist/types/lib/api/core/params.gen.d.ts +43 -0
- package/dist/types/lib/api/core/pathSerializer.gen.d.ts +33 -0
- package/dist/types/lib/api/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/types/lib/api/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/types/lib/api/core/types.gen.d.ts +78 -0
- package/dist/types/lib/api/core/utils.gen.d.ts +19 -0
- package/dist/types/lib/api/index.d.ts +2 -0
- package/dist/types/lib/api/sdk.gen.d.ts +118 -0
- package/dist/types/lib/api/types.gen.d.ts +694 -0
- package/dist/types/lib/icons.d.ts +28 -0
- package/dist/types/widget.d.ts +67 -0
- package/dist/types/widget.styles.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './accordion-item.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const accordionStyles: import("lit").CSSResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const buttonStyles: import("lit").CSSResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const cardStyles: import("lit").CSSResult;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
export interface A11ySettings {
|
|
3
|
+
monochrome: boolean;
|
|
4
|
+
darkHighContrast: boolean;
|
|
5
|
+
brightHighContrast: boolean;
|
|
6
|
+
lowSaturation: boolean;
|
|
7
|
+
highSaturation: boolean;
|
|
8
|
+
contrastMode: boolean;
|
|
9
|
+
customBgHue: number | null;
|
|
10
|
+
customHeaderHue: number | null;
|
|
11
|
+
customContentHue: number | null;
|
|
12
|
+
activeColorTab: 'background' | 'header' | 'content';
|
|
13
|
+
textScale: number;
|
|
14
|
+
highlightHeaders: boolean;
|
|
15
|
+
enlargeButtons: boolean;
|
|
16
|
+
textSpacing: boolean;
|
|
17
|
+
dyslexicFont: boolean;
|
|
18
|
+
focusVisualizer: boolean;
|
|
19
|
+
cursorMagnifier: boolean;
|
|
20
|
+
animationsDisabled: boolean;
|
|
21
|
+
linkHighlight: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare class A11yController implements ReactiveController {
|
|
24
|
+
host: ReactiveControllerHost;
|
|
25
|
+
settings: A11ySettings;
|
|
26
|
+
constructor(host: ReactiveControllerHost);
|
|
27
|
+
hostConnected(): void;
|
|
28
|
+
private _loadSettings;
|
|
29
|
+
private _saveSettings;
|
|
30
|
+
private _ensureGlobalStyles;
|
|
31
|
+
private _applySettings;
|
|
32
|
+
toggleMonochrome(): void;
|
|
33
|
+
toggleDarkHighContrast(): void;
|
|
34
|
+
toggleBrightHighContrast(): void;
|
|
35
|
+
toggleLowSaturation(): void;
|
|
36
|
+
toggleHighSaturation(): void;
|
|
37
|
+
toggleContrastMode(): void;
|
|
38
|
+
setCustomHue(hue: number): void;
|
|
39
|
+
resetCustomColors(): void;
|
|
40
|
+
toggleHighlightHeaders(): void;
|
|
41
|
+
toggleEnlargeButtons(): void;
|
|
42
|
+
incrementTextScale(): void;
|
|
43
|
+
toggleTextSpacing(): void;
|
|
44
|
+
toggleDyslexicFont(): void;
|
|
45
|
+
toggleFocusVisualizer(): void;
|
|
46
|
+
toggleCursorMagnifier(): void;
|
|
47
|
+
toggleAnimations(): void;
|
|
48
|
+
toggleLinkHighlight(): void;
|
|
49
|
+
reset(): void;
|
|
50
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
export declare class AiA11yController implements ReactiveController {
|
|
3
|
+
host: ReactiveControllerHost;
|
|
4
|
+
isFixing: boolean;
|
|
5
|
+
simplifyEnabled: boolean;
|
|
6
|
+
autoA11yEnabled: boolean;
|
|
7
|
+
constructor(host: ReactiveControllerHost);
|
|
8
|
+
toggleAutoA11y(): void;
|
|
9
|
+
hostConnected(): void;
|
|
10
|
+
hostDisconnected(): void;
|
|
11
|
+
private _announce;
|
|
12
|
+
fixMarkup(): Promise<void>;
|
|
13
|
+
toggleSimplify(): void;
|
|
14
|
+
private _onParagraphKeydown;
|
|
15
|
+
private _onParagraphClick;
|
|
16
|
+
private _triggerSimplify;
|
|
17
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
export interface ChatMessage {
|
|
3
|
+
role: 'user' | 'assistant';
|
|
4
|
+
text: string;
|
|
5
|
+
timestamp: number;
|
|
6
|
+
}
|
|
7
|
+
export interface InteractiveElement {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
tag: string;
|
|
11
|
+
type?: string;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
value?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ChatAction {
|
|
17
|
+
type: 'click_element' | 'navigate' | 'continue' | 'input_text';
|
|
18
|
+
element_id?: string;
|
|
19
|
+
url?: string;
|
|
20
|
+
value?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ChatResponse {
|
|
23
|
+
text: string;
|
|
24
|
+
action: ChatAction | null;
|
|
25
|
+
}
|
|
26
|
+
export type SttLanguageMode = 'kz' | 'ru' | 'en';
|
|
27
|
+
export interface SttResponse {
|
|
28
|
+
text: string;
|
|
29
|
+
provider: 'kz' | 'generic';
|
|
30
|
+
detected_language?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare class ChatController implements ReactiveController {
|
|
33
|
+
host: ReactiveControllerHost;
|
|
34
|
+
messages: ChatMessage[];
|
|
35
|
+
isLoading: boolean;
|
|
36
|
+
error: string | null;
|
|
37
|
+
private _tts;
|
|
38
|
+
private _voiceMode;
|
|
39
|
+
/** When non-null, the agent is paused waiting for user confirmation */
|
|
40
|
+
pendingConfirmation: {
|
|
41
|
+
text: string;
|
|
42
|
+
action: ChatAction;
|
|
43
|
+
currentQuery: string;
|
|
44
|
+
step: number;
|
|
45
|
+
} | null;
|
|
46
|
+
constructor(host: ReactiveControllerHost);
|
|
47
|
+
hostConnected(): void;
|
|
48
|
+
hostDisconnected(): void;
|
|
49
|
+
private _shouldSpeak;
|
|
50
|
+
private _loadMessages;
|
|
51
|
+
private _saveMessages;
|
|
52
|
+
/**
|
|
53
|
+
* Gather page context for the AI agent.
|
|
54
|
+
* Format: [tag|type|id|name|placeholder|value|label]
|
|
55
|
+
*/
|
|
56
|
+
gatherContext(): {
|
|
57
|
+
page_text: string;
|
|
58
|
+
elements: string;
|
|
59
|
+
page_url: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Execute a server-returned action on the DOM.
|
|
63
|
+
*/
|
|
64
|
+
executeAction(action: ChatAction): {
|
|
65
|
+
result: string;
|
|
66
|
+
causesNavigation: boolean;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Call the backend API with the current context.
|
|
70
|
+
*/
|
|
71
|
+
private _callAPI;
|
|
72
|
+
/**
|
|
73
|
+
* MINIMAL history sent to LLM:
|
|
74
|
+
* - The LAST user message (original task intent)
|
|
75
|
+
* - Last 2 assistant messages (action results only)
|
|
76
|
+
*
|
|
77
|
+
* We deliberately DROP early context. The LLM already gets the
|
|
78
|
+
* current DOM, elements, and page_url as context — that's the
|
|
79
|
+
* ground truth. Old history just confuses it.
|
|
80
|
+
*/
|
|
81
|
+
private _compressedHistory;
|
|
82
|
+
/**
|
|
83
|
+
* Main agentic loop with CONFIRMATION for critical actions.
|
|
84
|
+
*/
|
|
85
|
+
private _agentLoop;
|
|
86
|
+
/** User confirmed the critical action → execute it and resume the loop */
|
|
87
|
+
confirmAction(): Promise<void>;
|
|
88
|
+
/** User cancelled the critical action → inform the agent */
|
|
89
|
+
cancelAction(): void;
|
|
90
|
+
private _waitForDom;
|
|
91
|
+
/**
|
|
92
|
+
* Public API: send a user message and start the agentic loop.
|
|
93
|
+
*/
|
|
94
|
+
sendMessage(query: string, isVoice?: boolean): Promise<void>;
|
|
95
|
+
private _agentStep;
|
|
96
|
+
clearMessages(): void;
|
|
97
|
+
isTtsEnabled(): boolean;
|
|
98
|
+
setTtsEnabled(value: boolean): void;
|
|
99
|
+
transcribeAudio(audioBlob: Blob, languageMode: SttLanguageMode): Promise<SttResponse>;
|
|
100
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './widget.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AdminUI.ts — Passive Discovery Panel for BariWeb Widget
|
|
3
|
+
*
|
|
4
|
+
* No save button. Admin walks the site, system auto-discovers screens.
|
|
5
|
+
* This panel shows live status: what the system sees and whether it's trained.
|
|
6
|
+
*/
|
|
7
|
+
export declare function mountAdminPanel(): Promise<void>;
|
|
8
|
+
export declare function initAdminMode(): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fingerprint.ts — Stable Screen Fingerprinting
|
|
3
|
+
*
|
|
4
|
+
* Core insight: fingerprint = SCREEN TEMPLATE, not data instance.
|
|
5
|
+
*
|
|
6
|
+
* /users/123 → /users/:id } same screen
|
|
7
|
+
* /users/456 → /users/:id }
|
|
8
|
+
* /products/red-shoes → /products/:slug } same screen
|
|
9
|
+
* /orders/uuid-here → /orders/:id }
|
|
10
|
+
*
|
|
11
|
+
* Strategy (in priority order):
|
|
12
|
+
* 1. Normalized URL route (replaces IDs/UUIDs/slugs with :param)
|
|
13
|
+
* 2. H1 text (page identity, first 30 chars)
|
|
14
|
+
* 3. Form field names/placeholders (structural — stable across instances)
|
|
15
|
+
* 4. Nav link texts (global nav is constant)
|
|
16
|
+
* 5. Primary action button texts (max 4, inside main content)
|
|
17
|
+
*
|
|
18
|
+
* Excluded to avoid noise:
|
|
19
|
+
* - Transient UI: tooltips, popovers, dropdowns, dialogs
|
|
20
|
+
* - Pure numbers, prices, dates
|
|
21
|
+
* - Buttons inside transient containers
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Converts a specific URL into a route template.
|
|
25
|
+
*
|
|
26
|
+
* Examples:
|
|
27
|
+
* /dashboard/settings → /dashboard/settings (unchanged)
|
|
28
|
+
* /users/123/profile → /users/:id/profile
|
|
29
|
+
* /orders/abc-123/details → /orders/:id/details
|
|
30
|
+
* /blog/my-post-title-456 → /blog/:slug
|
|
31
|
+
* /products/550e8400-e29b-... → /products/:id
|
|
32
|
+
* /api/v2/items?id=99&page=1 → /api/v2/items?:id&page=1
|
|
33
|
+
*/
|
|
34
|
+
export declare function normalizeUrl(url: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Returns typed, stable structural tokens for the current screen.
|
|
37
|
+
* These represent the TEMPLATE, not the specific data on the page.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getFingerprintTokens(): string[];
|
|
40
|
+
/**
|
|
41
|
+
* Generates a stable semantic fingerprint for the current screen template.
|
|
42
|
+
* Identical for /users/123 and /users/456 (same template).
|
|
43
|
+
*/
|
|
44
|
+
export declare function getScreenFingerprint(): string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watcher.ts — MutationObserver-based SPA State Watcher
|
|
3
|
+
*
|
|
4
|
+
* Screen change detection strategy (stable):
|
|
5
|
+
* 1. URL change → ALWAYS a new screen (most reliable)
|
|
6
|
+
* 2. Token similarity < 0.55 → structural screen change
|
|
7
|
+
* (higher threshold = fewer false positives from tooltips/loaders)
|
|
8
|
+
*
|
|
9
|
+
* Passive Discovery: when admin is logged in, every real screen change
|
|
10
|
+
* is auto-reported to the backend. No manual save required.
|
|
11
|
+
*/
|
|
12
|
+
export interface LiveSnapshot {
|
|
13
|
+
url: string;
|
|
14
|
+
headings: string[];
|
|
15
|
+
fingerprint: string;
|
|
16
|
+
elements: Array<{
|
|
17
|
+
id: string;
|
|
18
|
+
text: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
export interface DiscoveryResult {
|
|
22
|
+
status: 'existing' | 'created';
|
|
23
|
+
is_trained: boolean;
|
|
24
|
+
label: string | null;
|
|
25
|
+
description: string | null;
|
|
26
|
+
}
|
|
27
|
+
type StateChangeCallback = (snapshot: LiveSnapshot) => void;
|
|
28
|
+
type DiscoveryCallback = (result: DiscoveryResult) => void;
|
|
29
|
+
export declare class BariwebWatcher {
|
|
30
|
+
private _observer;
|
|
31
|
+
private _debounceTimer;
|
|
32
|
+
private _lastTokens;
|
|
33
|
+
private _lastUrl;
|
|
34
|
+
private _callbacks;
|
|
35
|
+
private _discoveryCallbacks;
|
|
36
|
+
private readonly _debounceMs;
|
|
37
|
+
private _isDiscovering;
|
|
38
|
+
/** Enable passive discovery (set to true on admin login) */
|
|
39
|
+
isAutoDiscoveryEnabled: boolean;
|
|
40
|
+
constructor(debounceMs?: number);
|
|
41
|
+
start(): void;
|
|
42
|
+
stop(): void;
|
|
43
|
+
onStateChange(cb: StateChangeCallback): void;
|
|
44
|
+
onDiscovery(cb: DiscoveryCallback): void;
|
|
45
|
+
get isDiscovering(): boolean;
|
|
46
|
+
getLiveSnapshot(): LiveSnapshot;
|
|
47
|
+
private _onMutation;
|
|
48
|
+
/**
|
|
49
|
+
* Build typed token list: "btn:Магазин наград", "a:Подробнее", "input:Email"
|
|
50
|
+
* These let the backend store structured function labels that the agent reads.
|
|
51
|
+
*/
|
|
52
|
+
private _buildTypedTokens;
|
|
53
|
+
/**
|
|
54
|
+
* POST to /v1/training/discover — passive, no user interaction needed.
|
|
55
|
+
* Backend creates a draft if new, returns existing data if seen before.
|
|
56
|
+
*/
|
|
57
|
+
private _discover;
|
|
58
|
+
/** Immediately discover the current screen (called on admin login) */
|
|
59
|
+
forceDiscovery(): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
export declare const bariwebWatcher: BariwebWatcher;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { Auth } from '../core/auth.gen';
|
|
2
|
+
export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
3
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
|
|
4
|
+
export { buildClientParams } from '../core/params.gen';
|
|
5
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
6
|
+
export { createClient } from './client.gen';
|
|
7
|
+
export type { Client, ClientOptions, Config, CreateClientConfig, Options, RequestOptions, RequestResult, ResolvedRequestOptions, ResponseStyle, TDataShape, } from './types.gen';
|
|
8
|
+
export { createConfig, mergeHeaders } from './utils.gen';
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { Auth } from '../core/auth.gen';
|
|
2
|
+
import type { ServerSentEventsOptions, ServerSentEventsResult } from '../core/serverSentEvents.gen';
|
|
3
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen';
|
|
4
|
+
import type { Middleware } from './utils.gen';
|
|
5
|
+
export type ResponseStyle = 'data' | 'fields';
|
|
6
|
+
export interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Base URL for all requests made by this client.
|
|
9
|
+
*/
|
|
10
|
+
baseUrl?: T['baseUrl'];
|
|
11
|
+
/**
|
|
12
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
13
|
+
* fetch instance.
|
|
14
|
+
*
|
|
15
|
+
* @default globalThis.fetch
|
|
16
|
+
*/
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
/**
|
|
19
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
20
|
+
* options won't have any effect.
|
|
21
|
+
*
|
|
22
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
23
|
+
*/
|
|
24
|
+
next?: never;
|
|
25
|
+
/**
|
|
26
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
27
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
28
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
29
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
30
|
+
*
|
|
31
|
+
* @default 'auto'
|
|
32
|
+
*/
|
|
33
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
34
|
+
/**
|
|
35
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
36
|
+
*
|
|
37
|
+
* @default 'fields'
|
|
38
|
+
*/
|
|
39
|
+
responseStyle?: ResponseStyle;
|
|
40
|
+
/**
|
|
41
|
+
* Throw an error instead of returning it in the response?
|
|
42
|
+
*
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
throwOnError?: T['throwOnError'];
|
|
46
|
+
}
|
|
47
|
+
export interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
48
|
+
responseStyle: TResponseStyle;
|
|
49
|
+
throwOnError: ThrowOnError;
|
|
50
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onRequest' | 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
51
|
+
/**
|
|
52
|
+
* Any body that you want to add to your request.
|
|
53
|
+
*
|
|
54
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
55
|
+
*/
|
|
56
|
+
body?: unknown;
|
|
57
|
+
path?: Record<string, unknown>;
|
|
58
|
+
query?: Record<string, unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Security mechanism(s) to use for the request.
|
|
61
|
+
*/
|
|
62
|
+
security?: ReadonlyArray<Auth>;
|
|
63
|
+
url: Url;
|
|
64
|
+
}
|
|
65
|
+
export interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
66
|
+
serializedBody?: string;
|
|
67
|
+
}
|
|
68
|
+
export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = ThrowOnError extends true ? Promise<TResponseStyle extends 'data' ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
|
|
69
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
70
|
+
request: Request;
|
|
71
|
+
response: Response;
|
|
72
|
+
}> : Promise<TResponseStyle extends 'data' ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({
|
|
73
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
74
|
+
error: undefined;
|
|
75
|
+
} | {
|
|
76
|
+
data: undefined;
|
|
77
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
78
|
+
}) & {
|
|
79
|
+
request: Request;
|
|
80
|
+
response: Response;
|
|
81
|
+
}>;
|
|
82
|
+
export interface ClientOptions {
|
|
83
|
+
baseUrl?: string;
|
|
84
|
+
responseStyle?: ResponseStyle;
|
|
85
|
+
throwOnError?: boolean;
|
|
86
|
+
}
|
|
87
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
88
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
89
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
90
|
+
type BuildUrlFn = <TData extends {
|
|
91
|
+
body?: unknown;
|
|
92
|
+
path?: Record<string, unknown>;
|
|
93
|
+
query?: Record<string, unknown>;
|
|
94
|
+
url: string;
|
|
95
|
+
}>(options: TData & Options<TData>) => string;
|
|
96
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
97
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
101
|
+
* and the returned object will become the client's initial configuration.
|
|
102
|
+
*
|
|
103
|
+
* You may want to initialize your client this way instead of calling
|
|
104
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
105
|
+
* to ensure your client always has the correct values.
|
|
106
|
+
*/
|
|
107
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
108
|
+
export interface TDataShape {
|
|
109
|
+
body?: unknown;
|
|
110
|
+
headers?: unknown;
|
|
111
|
+
path?: unknown;
|
|
112
|
+
query?: unknown;
|
|
113
|
+
url: string;
|
|
114
|
+
}
|
|
115
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
116
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|
|
117
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
2
|
+
import type { Client, ClientOptions, Config, RequestOptions } from './types.gen';
|
|
3
|
+
export declare const createQuerySerializer: <T = unknown>({ parameters, ...args }?: QuerySerializerOptions) => (queryParams: T) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Infers parseAs value from provided Content-Type header.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getParseAs: (contentType: string | null) => Exclude<Config["parseAs"], "auto">;
|
|
8
|
+
export declare const setAuthParams: ({ security, ...options }: Pick<Required<RequestOptions>, "security"> & Pick<RequestOptions, "auth" | "query"> & {
|
|
9
|
+
headers: Headers;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
export declare const buildUrl: Client['buildUrl'];
|
|
12
|
+
export declare const mergeConfigs: (a: Config, b: Config) => Config;
|
|
13
|
+
export declare const mergeHeaders: (...headers: Array<Required<Config>["headers"] | undefined>) => Headers;
|
|
14
|
+
type ErrInterceptor<Err, Res, Req, Options> = (error: Err, response: Res, request: Req, options: Options) => Err | Promise<Err>;
|
|
15
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
16
|
+
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
17
|
+
declare class Interceptors<Interceptor> {
|
|
18
|
+
fns: Array<Interceptor | null>;
|
|
19
|
+
clear(): void;
|
|
20
|
+
eject(id: number | Interceptor): void;
|
|
21
|
+
exists(id: number | Interceptor): boolean;
|
|
22
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
23
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
24
|
+
use(fn: Interceptor): number;
|
|
25
|
+
}
|
|
26
|
+
export interface Middleware<Req, Res, Err, Options> {
|
|
27
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
28
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
29
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
30
|
+
}
|
|
31
|
+
export declare const createInterceptors: <Req, Res, Err, Options>() => Middleware<Req, Res, Err, Options>;
|
|
32
|
+
export declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ClientOptions, type Config } from './client';
|
|
2
|
+
import type { ClientOptions as ClientOptions2 } from './types.gen';
|
|
3
|
+
/**
|
|
4
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
5
|
+
* and the returned object will become the client's initial configuration.
|
|
6
|
+
*
|
|
7
|
+
* You may want to initialize your client this way instead of calling
|
|
8
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
9
|
+
* to ensure your client always has the correct values.
|
|
10
|
+
*/
|
|
11
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
12
|
+
export declare const client: import("./client").Client;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type AuthToken = string | undefined;
|
|
2
|
+
export interface Auth {
|
|
3
|
+
/**
|
|
4
|
+
* Which part of the request do we use to send the auth?
|
|
5
|
+
*
|
|
6
|
+
* @default 'header'
|
|
7
|
+
*/
|
|
8
|
+
in?: 'header' | 'query' | 'cookie';
|
|
9
|
+
/**
|
|
10
|
+
* Header or query parameter name.
|
|
11
|
+
*
|
|
12
|
+
* @default 'Authorization'
|
|
13
|
+
*/
|
|
14
|
+
name?: string;
|
|
15
|
+
scheme?: 'basic' | 'bearer';
|
|
16
|
+
type: 'apiKey' | 'http';
|
|
17
|
+
}
|
|
18
|
+
export declare const getAuthToken: (auth: Auth, callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken) => Promise<string | undefined>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen';
|
|
2
|
+
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
3
|
+
export type BodySerializer = (body: unknown) => unknown;
|
|
4
|
+
type QuerySerializerOptionsObject = {
|
|
5
|
+
allowReserved?: boolean;
|
|
6
|
+
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
7
|
+
object?: Partial<SerializerOptions<ObjectStyle>>;
|
|
8
|
+
};
|
|
9
|
+
export type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
10
|
+
/**
|
|
11
|
+
* Per-parameter serialization overrides. When provided, these settings
|
|
12
|
+
* override the global array/object settings for specific parameter names.
|
|
13
|
+
*/
|
|
14
|
+
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
15
|
+
};
|
|
16
|
+
export declare const formDataBodySerializer: {
|
|
17
|
+
bodySerializer: (body: unknown) => FormData;
|
|
18
|
+
};
|
|
19
|
+
export declare const jsonBodySerializer: {
|
|
20
|
+
bodySerializer: (body: unknown) => string;
|
|
21
|
+
};
|
|
22
|
+
export declare const urlSearchParamsBodySerializer: {
|
|
23
|
+
bodySerializer: (body: unknown) => string;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
type Slot = 'body' | 'headers' | 'path' | 'query';
|
|
2
|
+
export type Field = {
|
|
3
|
+
in: Exclude<Slot, 'body'>;
|
|
4
|
+
/**
|
|
5
|
+
* Field name. This is the name we want the user to see and use.
|
|
6
|
+
*/
|
|
7
|
+
key: string;
|
|
8
|
+
/**
|
|
9
|
+
* Field mapped name. This is the name we want to use in the request.
|
|
10
|
+
* If omitted, we use the same value as `key`.
|
|
11
|
+
*/
|
|
12
|
+
map?: string;
|
|
13
|
+
} | {
|
|
14
|
+
in: Extract<Slot, 'body'>;
|
|
15
|
+
/**
|
|
16
|
+
* Key isn't required for bodies.
|
|
17
|
+
*/
|
|
18
|
+
key?: string;
|
|
19
|
+
map?: string;
|
|
20
|
+
} | {
|
|
21
|
+
/**
|
|
22
|
+
* Field name. This is the name we want the user to see and use.
|
|
23
|
+
*/
|
|
24
|
+
key: string;
|
|
25
|
+
/**
|
|
26
|
+
* Field mapped name. This is the name we want to use in the request.
|
|
27
|
+
* If `in` is omitted, `map` aliases `key` to the transport layer.
|
|
28
|
+
*/
|
|
29
|
+
map: Slot;
|
|
30
|
+
};
|
|
31
|
+
export interface Fields {
|
|
32
|
+
allowExtra?: Partial<Record<Slot, boolean>>;
|
|
33
|
+
args?: ReadonlyArray<Field>;
|
|
34
|
+
}
|
|
35
|
+
export type FieldsConfig = ReadonlyArray<Field | Fields>;
|
|
36
|
+
interface Params {
|
|
37
|
+
body: unknown;
|
|
38
|
+
headers: Record<string, unknown>;
|
|
39
|
+
path: Record<string, unknown>;
|
|
40
|
+
query: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
export declare const buildClientParams: (args: ReadonlyArray<unknown>, fields: FieldsConfig) => Params;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
interface SerializeOptions<T> extends SerializePrimitiveOptions, SerializerOptions<T> {
|
|
2
|
+
}
|
|
3
|
+
interface SerializePrimitiveOptions {
|
|
4
|
+
allowReserved?: boolean;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SerializerOptions<T> {
|
|
8
|
+
/**
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
explode: boolean;
|
|
12
|
+
style: T;
|
|
13
|
+
}
|
|
14
|
+
export type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
|
|
15
|
+
export type ArraySeparatorStyle = ArrayStyle | MatrixStyle;
|
|
16
|
+
type MatrixStyle = 'label' | 'matrix' | 'simple';
|
|
17
|
+
export type ObjectStyle = 'form' | 'deepObject';
|
|
18
|
+
type ObjectSeparatorStyle = ObjectStyle | MatrixStyle;
|
|
19
|
+
interface SerializePrimitiveParam extends SerializePrimitiveOptions {
|
|
20
|
+
value: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const separatorArrayExplode: (style: ArraySeparatorStyle) => "." | ";" | "," | "&";
|
|
23
|
+
export declare const separatorArrayNoExplode: (style: ArraySeparatorStyle) => "," | "|" | "%20";
|
|
24
|
+
export declare const separatorObjectExplode: (style: ObjectSeparatorStyle) => "." | ";" | "," | "&";
|
|
25
|
+
export declare const serializeArrayParam: ({ allowReserved, explode, name, style, value, }: SerializeOptions<ArraySeparatorStyle> & {
|
|
26
|
+
value: unknown[];
|
|
27
|
+
}) => string;
|
|
28
|
+
export declare const serializePrimitiveParam: ({ allowReserved, name, value, }: SerializePrimitiveParam) => string;
|
|
29
|
+
export declare const serializeObjectParam: ({ allowReserved, explode, name, style, value, valueOnly, }: SerializeOptions<ObjectSeparatorStyle> & {
|
|
30
|
+
value: Record<string, unknown> | Date;
|
|
31
|
+
valueOnly?: boolean;
|
|
32
|
+
}) => string;
|
|
33
|
+
export {};
|