-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
403 lines (340 loc) · 14.5 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
declare type ObjectT<T> = {[key: string]: T};
declare type StackTraceCallData = {
sourceLine?: string;
beforeParse: string;
callee: string;
calleeShort?: string;
native: boolean;
file?: string;
fileRelative?: string;
fileShort?: string;
fileName?: string;
line?: number;
};
declare type StackTraceData = {
stack?: StackTraceCallData[];
};
declare type GetStackTraceFunctionOptions = {
calleeExclude?: string[];
fileNameExclude?: string[];
};
declare type GetStackTraceFunction = (errorOrStack: Error | string | undefined, options?: GetStackTraceFunctionOptions) => Promise<StackTraceData>;
declare type NetworkInterceptorOptions = {
// List of hosts to ignore, e.g. `services.test.com`
ignoredHosts?: string[];
// List of urls to ignore, e.g. `https://services.test.com/test`
ignoredUrls?: string[];
// List of url patterns to ignore, e.g. `/^GET https://test.com\/pages\/.*$/`; Url to match with is in the format: `${method} ${url}`, e.g. `GET https://test.com/pages/123`
ignoredPatterns?: RegExp[];
};
declare type SpecialInstructionId = "condition" | "delay" | "forwardData";
declare type RemoteEvent = {
id: string;
eventType: "default" | "special";
instructionId: string | SpecialInstructionId;
args?: any[];
};
declare type RemoteSettingsEnv = "dev" | "stg" | "prod";
declare type _RemoteSettings = {[env in RemoteSettingsEnv]: ObjectT<string>};
declare class Component<P, S> {
static contextType?: any | undefined;
context: unknown;
constructor(props: Readonly<P> | P);
setState<K extends keyof S>(
state: ((prevState: Readonly<S>, props: Readonly<P>) => (Pick<S, K> | S | null)) | (Pick<S, K> | S | null),
callback?: () => void
): void;
forceUpdate(callback?: () => void): void;
render(): any;
readonly props: Readonly<P>;
state: Readonly<S>;
refs: {[key: string]: any};
}
declare type ReactFunctionalComponent<T> = (props: T) => any | null;
declare module '@appklaar/codebud' {
export type ProjectInfo = {
projectId: string;
};
export type PackageMode = "dev" | "prod";
export type PackageConfig = {
mode?: PackageMode;
Interceptor?: any;
interceptorOptions?: NetworkInterceptorOptions;
EncryptionPlugin?: any;
ReactNativePlugin?: any;
projectInfo?: ProjectInfo;
remoteSettingsAutoUpdateInterval?: number;
getStackTraceFn?: GetStackTraceFunction;
stackTraceOptions?: GetStackTraceFunctionOptions;
};
export type NetworkInterceptorInstance = {
dispose: () => void;
};
export type InterceptedRequest = {
method: string;
body: ObjectT<any> | undefined;
url: string;
requestHeaders?: ObjectT<any> | undefined;
};
export type InterceptedResponse = {
status: number;
statusText: string;
data: ObjectT<any> | undefined;
responseHeaders?: ObjectT<any> | undefined;
};
export type NetworkInterceptorOnRequestPayload = {
request: InterceptedRequest;
requestId: string;
};
export type NetworkInterceptorOnResponsePayload = {
response: InterceptedResponse;
request?: InterceptedRequest;
requestId: string
};
export type NetworkInterceptorCallbacksTable = {
onRequest: (data: NetworkInterceptorOnRequestPayload) => void;
onResponse: (data: NetworkInterceptorOnResponsePayload) => void;
};
type InstructionPrototype = "login" | "logout";
type BaseParamType = "number" | "string" | "object" | "array" | "boolean";
type OptionalParamType = `?${BaseParamType}`;
type ParamType = BaseParamType | OptionalParamType;
type InstructionPublicFields = {
id: string;
prototype?: InstructionPrototype;
parametersDescription?: {[key: string]: ParamType};
description?: string;
_groupId?: string;
_groupDescription?: string;
_groupColor?: string;
}
export type Instruction = InstructionPublicFields & {
handler: (...args: any[]) => any;
};
export type InstructionGroup = {
groupId: string;
groupDescription?: string;
groupColor?: string;
groupInstructions: Instruction[];
};
export type InstructionsTable = {[key: string]: Instruction};
export type SpecialInstructionsTable = {[id in SpecialInstructionId]: Instruction};
export type OnEventUsersCustomCallback = (event: RemoteEvent) => void;
export type ClientType = "CLIENT" | "ADMIN_PANEL";
export type ConnectionInfoPacket = {
apiKey: string;
clientType: ClientType;
availableInstructions: InstructionPublicFields[];
specialInstructions: InstructionPublicFields[];
};
export type RemoteScenario = {
id: string;
events: RemoteEvent[];
};
export type ListenersTable<T> = {[key: string]: (data: T) => any};
export type EventListenersTable = ListenersTable<RemoteEvent>;
export type SelectFn = (state: any) => any;
export type RemoteSettings = _RemoteSettings;
export type RemoteSettingsListenersTable = ListenersTable<RemoteSettings>;
export type RefreshRemoteSettingsCallback = (r: RemoteSettings) => void;
export type ProjectSetting = {
remoteSettingsEnabled: boolean;
};
// Key - projectId
export type PersonalProjectsSetting = {[key: string]: ProjectSetting};
export type RefreshPersonalProjectsSettingCallback = (s: PersonalProjectsSetting) => void;
type MobxStoreMonitor = [
() => string,
(s: string) => void
];
export interface AppKlaarSdk {
/**
* Initialize the module.
* @param {String} apiKey The api key of yours.
* @param {(Instruction | InstructionGroup)[]} instructions Instructions that will be available from remote testing panel.
* @param {PackageConfig | undefined} config Package config (if needed)
*/
init: (apiKey: string, instructions: (Instruction | InstructionGroup)[], config?: PackageConfig) => void;
/**
* Set custom callback that will be called on every action.
* @param {OnEventUsersCustomCallback} usersCustomCallback Callback.
*/
onEvent: (usersCustomCallback: OnEventUsersCustomCallback) => void;
/**
* @returns {boolean} True if the module has been initiated. False otherwise.
*/
isInit: boolean;
/**
* @returns {string} Description of current module state.
*/
state: string;
/**
* @returns {RemoteSettings | null} Last fetched remote settings object (all environments).
*/
remoteSettings: RemoteSettings | null;
/**
* @param {string} env Remote settings environment.
* @returns {ObjectT<string> | null} Last fetched remote settings object (selected environment).
*/
getRemoteSettingsByEnv: (env: RemoteSettingsEnv) => ObjectT<string> | null;
/**
* @returns {boolean} Flag that determines that CodeBud remote settings are currently preferable for your project. Note: if package mode is "prod", false will be returned.
*/
getIsRemoteSettingsPreferableForSelectedProject: () => boolean;
/**
* Function that takes 2 args and returns one of them depending on package mode and your personal "preferable" toogle for chosen projectId on Control tab in GUI
* @param {any} valueA Option "A" that will be returned if CodeBud remote settings are currently preferable for your project
* @param {any} valueB Option "B" that will be returned if CodeBud remote settings are currently NOT preferable for your project
* @returns {boolean} valueA if CodeBud remote settings are currently preferable for your project, and valueB otherwise.
*/
getPersonalPreferableValueForSelectedProject: (valueA: any, valueB: any) => any;
/**
* Function for refreshing remote settings.
* @param {RefreshRemoteSettingsCallback} callbackFn Function that will be called if request succeeded.
*/
refreshRemoteSettings: (callbackFn?: RefreshRemoteSettingsCallback) => void;
/**
* Function for refreshing personal projects settings.
* @param {RefreshPersonalProjectsSettingCallback} callbackFn Function that will be called if request succeeded.
*/
refreshPersonalProjectsSettings: (callbackFn?: RefreshPersonalProjectsSettingCallback) => void;
/**
* Function that creates Redux Store Change Handler, that you can use to subscribe to Store Changes.
* @param {any} store Your store.
* @param {SelectFn} selectFn select function that returns part of the store.
* @param {number} [batchingTimeMs = 500] batching time of sending new redux state copy (in ms). Defaults to 500
* @returns {Function} Store change handler function.
*/
createReduxStoreChangeHandler: (store: any, selectFn: (state: any) => any, batchingTimeMs?: number) => (() => void);
/**
* Function that creates Redux middleware for actions monitoring.
* @param {number} [batchingTimeMs = 200] batching time of sending dispatched redux actions (in ms). Defaults to 200. This param only affects logging delay and does not slow down your redux flow.
* @param {RegExp[]} [ignoredPatterns = []] array of ignored action type patterns.
* @returns {Function} Middleware
*/
createReduxActionMonitorMiddleware: (batchingTimeMs?: number, ignoredPatterns?: RegExp[]) => any;
/**
* Function that creates Zustand Store Change Handler, that you can use to subscribe to Store Changes.
* @param {SelectFn} selectFn select function that returns part of the store.
* @param {number} [batchingTimeMs = 500] batching time of sending new zustand state copy (in ms). Defaults to 500
* @returns {Function} Store change handler function.
*/
createZustandStoreChangeHandler: (selectFn: (state: any) => any, batchingTimeMs?: number) => ((state: any, prevState: any) => void);
/**
* Function that enables AsyncStorage monitor.
* @param {any} asyncStorage your AsyncStorage
* @param {string[]} [ignoreKeys = []] storage keys that should be ignored. Defaults to empty array.
* @param {number} [batchingTimeMs = 500] batching time of sending intercepted storage actions (in ms). Defaults to 500.
*/
enableAsyncStorageMonitor: (asyncStorage: any, ignoreKeys?: string[], batchingTimeMs?: number) => void;
/**
* Function that enables localStorage monitor.
* @param {any} localStorage your localStorage
* @param {string[]} [ignoreKeys = []] storage keys that should be ignored. Defaults to empty array.
* @param {number} [batchingTimeMs = 500] batching time of sending intercepted storage actions (in ms). Defaults to 500.
*/
enableLocalStorageMonitor: (localStorage: any, ignoreKeys?: string[], batchingTimeMs?: number) => void;
/**
* Send custom event that will be shown in timeline on network tab.
* @param {string} title Title of the event
* @param {any} data Data that you want to share
*/
captureEvent: (title: string, data: any) => void;
/**
* Enable intercepting of crash signals and unhandled exceptions to send crash reports to GUI timeline.
*/
enableApplicationCrashInterception: () => void;
/**
* Function that enables TanStack queries data monitor.
* @param {any} queryClient Your queryClient
* @param {number} [updateIntervalMs = 1000] Interval of re-checking TanStack queries data (in ms). Defaults to 1000.
* @param {number} [batchingTimeMs = 500] Batching time of sending new TanStack queries data copy (in ms). Defaults to 500
* @returns {Function} Unsubscribe function.
*/
monitorTanStackQueriesData: (queryClient: any, updateIntervalMs?: number, batchingTimeMs?: number) => (() => void),
/**
* Function that enables TanStack Query events monitor.
* @param {any} queryClient Your queryClient
* @param {number} [batchingTimeMs = 500] Batching time of sending TanStack Query events (in ms). Defaults to 500
* @returns {Function} Unsubscribe function.
*/
monitorTanStackQueryEvents: (queryClient: any, batchingTimeMs?: number) => (() => void),
/**
* Function that creates Mobx Store Monitor, that you can use to subscribe to Store Changes.
* @param {any} store Your store.
* @param {number} [batchingTimeMs = 500] batching time of sending new mobx state copy (in ms). Defaults to 500
* @returns {MobxStoreMonitor} Expression and effect as a tuple for Mobx reaction.
*/
createMobxStoreMonitor: (store: any, batchingTimeMs?: number) => MobxStoreMonitor,
/**
* Function that creates MobX listener for events monitoring.
* @param {number} [batchingTimeMs = 300] batching time of sending MobX events (in ms). Defaults to 300.
* @returns {Function} Listener function.
*/
createMobxEventHandler: (batchingTimeMs?: number) => ((event: any) => void),
/**
* Close the connection.
*/
disconnect: () => void;
}
export const CodeBud: AppKlaarSdk;
}
declare module '@appklaar/codebud/react' {
export function useEvent(
handler: (event: RemoteEvent) => any,
instructionIds: ReadonlyArray<string>
): void;
export function useRemoteSettings(env: RemoteSettingsEnv): ObjectT<string> | null;
export function useContextMonitor(
SomeContext: any,
label?: string,
waitMs?: number
): void;
export type ErrorBoundaryProps = {
fallback?: any;
children: any;
};
export type ErrorBoundaryState = {
componentStack: null | string;
error: null | Error;
};
export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {}
}
declare module '@appklaar/codebud/Network/NetworkInterceptorClassic' {
export class NetworkInterceptorClassic {}
}
declare module '@appklaar/codebud/Network/NetworkInterceptorRN' {
export class NetworkInterceptorRN {}
}
declare module '@appklaar/codebud/Network/NetworkInterceptorXMLHttp' {
export class NetworkInterceptorXMLHttp {}
}
declare module '@appklaar/codebud/Network/NetworkInterceptorXHR' {
export class NetworkInterceptorXHR {}
}
declare module '@appklaar/codebud/rn' {
export type InitModalProps = {
animationType?: "fade" | "none" | "slide";
onInit: (apiKey: string) => void;
};
export type ReactNativeWrapperProps = {
ref?: any;
children: any;
initModalProps?: InitModalProps;
}
export type ReactNativeWrapperMethods = {
showInitModal: () => void;
hideInitModal: () => void;
};
export const ReactNativePlugin: any;
export const ReactNativeWrapper: ReactFunctionalComponent<ReactNativeWrapperProps>;
}
declare module '@appklaar/codebud/encryption' {
export class EncryptionPlugin {}
}
declare module '@appklaar/codebud/StackTracing/getStackTraceStackTracey' {
export const getStackTraceStackTracey: GetStackTraceFunction;
}
declare module '@appklaar/codebud/StackTracing/getStackTraceSimple' {
export const getStackTraceSimple: GetStackTraceFunction;
}