UNPKG

3.05 kBTypeScriptView Raw
1import { AnyAction, Dispatch, Unsubscribe } from '@shopify/app-bridge/actions/types';
2import { Context, ContextualMessageTransport } from '@shopify/app-bridge/MessageTransport';
3import { TransportSubscription, TransportDispatch } from '@shopify/app-bridge';
4import { Store } from './store/async';
5export declare const MessageTransportType = "application";
6/**
7 * Configuration provided by an app.
8 */
9export interface AppConfig {
10 apiKey: string;
11}
12/**
13 * Configuration for an app.
14 */
15export interface PrivilegedAppConfig extends AppConfig {
16 apiClientId?: string;
17 appId: string;
18 name: string;
19 shopId: string;
20 url: string;
21 handle: string;
22}
23export declare type ApiClientConfig = PrivilegedAppConfig;
24/**
25 * Interface for interacting with a loaded application. An application may have
26 * many transports for communication (e.g. multiple frames).
27 */
28export interface Application {
29 /**
30 * Attach a transport to an application.
31 * @returns a method that can be called to detach the transport
32 */
33 attach(to: ContextualMessageTransport): (unload?: boolean) => void;
34 /**
35 * Dispatch an action on all transports for an application.
36 *
37 * @todo Add option to dispatch directly to a given transport
38 */
39 dispatch(action: AnyAction): void;
40 /**
41 * Get the current state of an application.
42 *
43 * @todo Filter once application state structure is finalised
44 */
45 getState(): any;
46 /**
47 * Subscribe to all actions from an application on all transports.
48 */
49 subscribe(listener: (message: TransportDispatch) => void): () => void;
50 /**
51 * Returns true if an action is subcribed for a specific transport context
52 */
53 isTransportSubscribed(context: Context, type: string, id?: string): boolean;
54}
55export interface LoadData {
56 type: typeof MessageTransportType;
57 config: ApiClientConfig;
58}
59export interface MiddlewareAPI<S> {
60 dispatch: Dispatch<S>;
61 getState(): S;
62}
63/**
64 * Build middleware, binding it to a given Redux Store. The returned middleware
65 * will be responsible for loading application instances.
66 */
67export interface Middleware {
68 load(data: LoadData): Application;
69 <S>(api: MiddlewareAPI<S>): (next: Dispatch<S>) => Dispatch<S>;
70}
71export declare type Reducer<S> = (state: S, action: AnyAction) => S;
72export interface Store<S> {
73 dispatch: Dispatch<S>;
74 getState(): S;
75 subscribe(listener: () => void): Unsubscribe;
76 replaceReducer(nextReducer: Reducer<S>): void;
77}
78export interface Subscription {
79 [key: string]: TransportSubscription[] | undefined;
80}
81export declare type Subscriptions = {
82 [key in Context]: Subscription;
83};
84export { AnyAction, Dispatch };
85export interface TrackingEventPayload {
86 action: AnyAction;
87 appId: string;
88 shopId: string;
89}
90/**
91 * A union of all dynamic keys in the app store
92 * @public
93 */
94export declare type HostFeatures = keyof Store;
95/**
96 * The interface for the host's components
97 * @public
98 * */
99export interface ComponentProps {
100 globalStore: Store;
101}