1 | import { KuzzleEventEmitter } from './core/KuzzleEventEmitter';
|
2 | import { KuzzleAbstractProtocol } from './protocols/abstract/Base';
|
3 | import { AuthController } from './controllers/Auth';
|
4 | import { CollectionController } from './controllers/Collection';
|
5 | import { DocumentController } from './controllers/Document';
|
6 | import { IndexController } from './controllers/Index';
|
7 | import { RealtimeController } from './controllers/Realtime';
|
8 | import { JSONObject } from './types';
|
9 | import { RequestPayload } from './types/RequestPayload';
|
10 | import { ResponsePayload } from './types/ResponsePayload';
|
11 | export declare class Kuzzle extends KuzzleEventEmitter {
|
12 | [key: string]: any;
|
13 | /**
|
14 | * Protocol used by the SDK to communicate with Kuzzle.
|
15 | */
|
16 | protocol: any;
|
17 | /**
|
18 | * If true, automatically renews all subscriptions on a reconnected event.
|
19 | */
|
20 | autoResubscribe: boolean;
|
21 | /**
|
22 | * Timeout before sending again a similar event.
|
23 | */
|
24 | eventTimeout: number;
|
25 | /**
|
26 | * SDK version.
|
27 | */
|
28 | sdkVersion: string;
|
29 | /**
|
30 | * SDK name (e.g: `js@7.4.2`).
|
31 | */
|
32 | sdkName: string;
|
33 | /**
|
34 | * Common volatile data that will be sent to all future requests.
|
35 | */
|
36 | volatile: JSONObject;
|
37 | auth: AuthController;
|
38 | bulk: any;
|
39 | collection: CollectionController;
|
40 | document: DocumentController;
|
41 | index: IndexController;
|
42 | ms: any;
|
43 | realtime: RealtimeController;
|
44 | security: any;
|
45 | server: any;
|
46 | private _protectedEvents;
|
47 | private _offlineQueue;
|
48 | private _autoQueue;
|
49 | private _autoReplay;
|
50 | private _offlineQueueLoader;
|
51 | private _queuing;
|
52 | private _queueFilter;
|
53 | private _queueMaxSize;
|
54 | private _queueTTL;
|
55 | private _replayInterval;
|
56 | private _tokenExpiredInterval;
|
57 | private _lastTokenExpired;
|
58 | private __proxy__;
|
59 | /**
|
60 | * Instantiate a new SDK
|
61 | *
|
62 | * @example
|
63 | *
|
64 | * import { Kuzzle, WebSocket } from 'kuzzle-sdk';
|
65 | *
|
66 | * const kuzzle = new Kuzzle(
|
67 | * new WebSocket('localhost')
|
68 | * );
|
69 | */
|
70 | constructor(
|
71 | /**
|
72 | * Network protocol to connect to Kuzzle. (e.g. `Http` or `WebSocket`)
|
73 | */
|
74 | protocol: KuzzleAbstractProtocol, options?: {
|
75 | /**
|
76 | * Automatically renew all subscriptions on a `reconnected` event
|
77 | * Default: `true`
|
78 | */
|
79 | autoResubscribe?: boolean;
|
80 | /**
|
81 | * Time (in ms) during which a similar event is ignored
|
82 | * Default: `200`
|
83 | */
|
84 | eventTimeout?: number;
|
85 | /**
|
86 | * Common volatile data, will be sent to all future requests
|
87 | * Default: `{}`
|
88 | */
|
89 | volatile?: JSONObject;
|
90 | /**
|
91 | * If `true`, automatically queues all requests during offline mode
|
92 | * Default: `false`
|
93 | */
|
94 | autoQueue?: boolean;
|
95 | /**
|
96 | * If `true`, automatically replays queued requests
|
97 | * on a `reconnected` event
|
98 | * Default: `false`
|
99 | */
|
100 | autoReplay?: boolean;
|
101 | /**
|
102 | * Custom function called during offline mode to filter
|
103 | * queued requests on-the-fly
|
104 | */
|
105 | queueFilter?: (request: RequestPayload) => boolean;
|
106 | /**
|
107 | * Called before dequeuing requests after exiting offline mode,
|
108 | * to add items at the beginning of the offline queue
|
109 | */
|
110 | offlineQueueLoader?: (...any: any[]) => any;
|
111 | /**
|
112 | * Number of maximum requests kept during offline mode
|
113 | * Default: `500`
|
114 | */
|
115 | queueMaxSize?: number;
|
116 | /**
|
117 | * Time a queued request is kept during offline mode, in milliseconds
|
118 | * Default: `120000`
|
119 | */
|
120 | queueTTL?: number;
|
121 | /**
|
122 | * Delay between each replayed requests, in milliseconds
|
123 | * Default: `10`
|
124 | */
|
125 | replayInterval?: number;
|
126 | /**
|
127 | * Time (in ms) during which a TokenExpired event is ignored
|
128 | * Default: `1000`
|
129 | */
|
130 | tokenExpiredInterval?: number;
|
131 | /**
|
132 | * If set to `auto`, the `autoQueue` and `autoReplay` are also set to `true`
|
133 | */
|
134 | offlineMode?: 'auto';
|
135 | });
|
136 | get authenticated(): boolean;
|
137 | get autoQueue(): any;
|
138 | set autoQueue(value: any);
|
139 | get autoReconnect(): any;
|
140 | set autoReconnect(value: any);
|
141 | get autoReplay(): any;
|
142 | set autoReplay(value: any);
|
143 | get connected(): any;
|
144 | get host(): any;
|
145 | get jwt(): any;
|
146 | set jwt(encodedJwt: any);
|
147 | get offlineQueue(): any;
|
148 | get offlineQueueLoader(): any;
|
149 | set offlineQueueLoader(value: any);
|
150 | get port(): any;
|
151 | get queueFilter(): any;
|
152 | set queueFilter(value: any);
|
153 | get queueMaxSize(): any;
|
154 | set queueMaxSize(value: any);
|
155 | get queueTTL(): any;
|
156 | set queueTTL(value: any);
|
157 | get reconnectionDelay(): any;
|
158 | get replayInterval(): any;
|
159 | set replayInterval(value: any);
|
160 | get sslConnection(): any;
|
161 | get tokenExpiredInterval(): any;
|
162 | set tokenExpiredInterval(value: any);
|
163 | /**
|
164 | * Emit an event to all registered listeners
|
165 | * An event cannot be emitted multiple times before a timeout has been reached.
|
166 | */
|
167 | emit(eventName: any, ...payload: any[]): boolean;
|
168 | private _superEmit;
|
169 | /**
|
170 | * Connects to a Kuzzle instance
|
171 | */
|
172 | connect(): Promise<void>;
|
173 | /**
|
174 | * Adds a listener to a Kuzzle global event. When an event is fired, listeners are called in the order of their
|
175 | * insertion.
|
176 | *
|
177 | * @param {string} event - name of the global event to subscribe to
|
178 | * function} listener - callback to invoke each time an event is fired
{ |
179 | */
|
180 | addListener(event: any, listener: any): this;
|
181 | private _superAddListener;
|
182 | /**
|
183 | * Empties the offline queue without replaying it.
|
184 | *
|
185 | * @returns {Kuzzle}
|
186 | */
|
187 | flushQueue(): this;
|
188 | /**
|
189 | * Disconnects from Kuzzle and invalidate this instance.
|
190 | */
|
191 | disconnect(): void;
|
192 | /**
|
193 | * This is a low-level method, exposed to allow advanced SDK users to bypass
|
194 | * high-level methods.
|
195 | * Base method used to send read queries to Kuzzle
|
196 | *
|
197 | * Takes an optional argument object with the following properties:
|
198 | * - volatile (object, default: null):
|
199 | * Additional information passed to notifications to other users
|
200 | *
|
201 | * @param request
|
202 | * @param options - Optional arguments
|
203 | */
|
204 | query(request?: RequestPayload, options?: JSONObject): Promise<ResponsePayload>;
|
205 | /**
|
206 | * Starts the requests queuing.
|
207 | */
|
208 | startQueuing(): this;
|
209 | /**
|
210 | * Stops the requests queuing.
|
211 | */
|
212 | stopQueuing(): this;
|
213 | /**
|
214 | * Plays the requests queued during offline mode.
|
215 | */
|
216 | playQueue(): this;
|
217 | /**
|
218 | * On token expiration, reset jwt and unsubscribe all rooms.
|
219 | * Throttles to avoid duplicate event triggers.
|
220 | */
|
221 | tokenExpired(): void;
|
222 | /**
|
223 | * Adds a new controller and make it available in the SDK.
|
224 | *
|
225 | * @param ControllerClass
|
226 | * @param accessor
|
227 | */
|
228 | useController(ControllerClass: any, accessor: string): this;
|
229 | private _checkPropertyType;
|
230 | /**
|
231 | * Clean up the queue, ensuring the queryTTL and queryMaxSize properties are respected
|
232 | */
|
233 | private _cleanQueue;
|
234 | /**
|
235 | * Play all queued requests, in order.
|
236 | */
|
237 | private _dequeue;
|
238 | }
|