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