1 | import type { ActionCallback, ActionSetInterface, ActionSetOptions, AnyAction, Dispatch, ErrorSubscriber, MetaAction, Unsubscribe } from '../actions/types';
|
2 | import { Group } from '../actions/types';
|
3 | import type { Handler, MessageTransport } from '../MessageTransport';
|
4 | import { Context } from '../MessageTransport';
|
5 |
|
6 |
|
7 |
|
8 | export interface AppConfig {
|
9 | apiKey: string;
|
10 | host: string;
|
11 | forceRedirect?: boolean;
|
12 | }
|
13 |
|
14 |
|
15 |
|
16 | export declare enum PermissionType {
|
17 | Dispatch = "Dispatch",
|
18 | Subscribe = "Subscribe"
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 | export declare type FeaturePermission = {
|
24 | [key in PermissionType]: boolean;
|
25 | };
|
26 |
|
27 |
|
28 |
|
29 | export interface FeaturesAction {
|
30 | [key: string]: FeaturePermission;
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 | export declare type FeaturesAvailable<T extends Group = Group> = Record<T, FeaturesAction>;
|
36 |
|
37 |
|
38 |
|
39 | export declare type FeaturesState<T = FeaturesAvailable> = {
|
40 | [key in Context]?: T;
|
41 | };
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | export interface ClientApplication<S> {
|
47 | dispatch: Dispatch<AnyAction>;
|
48 | localOrigin: string;
|
49 | error: ErrorSubscriber;
|
50 | hooks?: HooksInterface;
|
51 | getState(query?: string): Promise<S>;
|
52 | featuresAvailable(): Promise<FeaturesAvailable<Group>>;
|
53 | featuresAvailable<T extends Group[]>(...features: T): Promise<FeaturesAvailable<typeof features[number]>>;
|
54 | subscribe(callback: ActionCallback): Unsubscribe;
|
55 | subscribe(eventNameSpace: string, callback: ActionCallback, id?: string): Unsubscribe;
|
56 | }
|
57 |
|
58 |
|
59 |
|
60 | export interface ClientApplicationCreator {
|
61 | <S>(config: AppConfig): ClientApplication<S>;
|
62 | }
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | export interface ClientApplicationTransportInjector {
|
69 | (transport: MessageTransport, middleware?: AppMiddleware[]): ClientApplicationCreator;
|
70 | }
|
71 |
|
72 |
|
73 |
|
74 | export interface Dispatcher {
|
75 | (type: MessageType, payload?: AnyAction | undefined): void;
|
76 | }
|
77 |
|
78 |
|
79 |
|
80 | export declare enum MessageType {
|
81 | GetState = "getState",
|
82 | Dispatch = "dispatch",
|
83 | Subscribe = "subscribe",
|
84 | Unsubscribe = "unsubscribe"
|
85 | }
|
86 |
|
87 |
|
88 |
|
89 | export interface TransportDispatch {
|
90 | type: MessageType;
|
91 | source: AppConfig;
|
92 | payload?: AnyAction;
|
93 | }
|
94 |
|
95 |
|
96 |
|
97 | export interface TransportSubscription {
|
98 | id?: string;
|
99 | type: string;
|
100 | }
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | export interface Params {
|
106 | [key: string]: string;
|
107 | }
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | export declare enum LifecycleHook {
|
129 | UpdateAction = "UpdateAction",
|
130 | DispatchAction = "DispatchAction"
|
131 | }
|
132 |
|
133 |
|
134 |
|
135 | export interface Hook {
|
136 | handler: LifecycleHandler;
|
137 | remove: Unsubscribe;
|
138 | }
|
139 |
|
140 |
|
141 |
|
142 | export interface HookMap {
|
143 | [key: string]: Hook[];
|
144 | }
|
145 |
|
146 |
|
147 |
|
148 | export interface HooksInterface {
|
149 | set(hook: LifecycleHook.UpdateAction, handler: UpdateActionHook): any;
|
150 | set(hook: LifecycleHook.DispatchAction, handler: DispatchActionHook): any;
|
151 | set(hook: LifecycleHook, handler: LifecycleHandler): any;
|
152 | get(hook: LifecycleHook): LifecycleHandler[] | undefined;
|
153 | run<C>(hook: LifecycleHook, final: Function, context: C, ...arg: any[]): any;
|
154 | }
|
155 |
|
156 |
|
157 |
|
158 | export interface AppMiddleware {
|
159 | (hooks: HooksInterface, app: ClientApplication<any>): void;
|
160 | }
|
161 |
|
162 |
|
163 |
|
164 | export interface LifecycleHandler {
|
165 | (next: Function): (...args: any[]) => any;
|
166 | }
|
167 |
|
168 |
|
169 |
|
170 | export interface UpdateActionHandler {
|
171 | <O>(this: ActionSetInterface & ActionSetOptions<O>, options: O): any;
|
172 | }
|
173 |
|
174 |
|
175 |
|
176 | export interface UpdateActionHook {
|
177 | (next: Function): UpdateActionHandler;
|
178 | }
|
179 |
|
180 |
|
181 |
|
182 | export interface DispatchActionHandler {
|
183 | <A extends MetaAction>(this: ClientApplication<any>, action: A): any;
|
184 | }
|
185 |
|
186 |
|
187 |
|
188 | export interface DispatchActionHook {
|
189 | (next: Function): DispatchActionHandler;
|
190 | }
|
191 | export { Dispatch, Handler, Unsubscribe };
|