@shopify/app-bridge-host
Version:
App Bridge Host contains middleware and components that are meant to be consumed by the app's host. The middleware and `Frame` component are responsible for facilitating messages posted between the client and host, and used to act on actions sent from the
102 lines (101 loc) • 3.01 kB
TypeScript
import { AnyAction, Dispatch, Unsubscribe } from '@shopify/app-bridge/actions/types';
import { Context, ContextualMessageTransport } from '@shopify/app-bridge/MessageTransport';
import { TransportSubscription } from '@shopify/app-bridge';
import { Store } from './store/async';
export declare const MessageTransportType = "application";
/**
* Configuration provided by an app.
*/
export interface AppConfig {
apiKey: string;
}
/**
* Configuration for an app.
*/
export interface PrivilegedAppConfig extends AppConfig {
apiClientId?: string;
appId: string;
name: string;
shopId: string;
url: string;
handle: string;
}
export declare type ApiClientConfig = PrivilegedAppConfig;
/**
* Interface for interacting with a loaded application. An application may have
* many transports for communication (e.g. multiple frames).
*/
export interface Application {
/**
* Attach a transport to an application.
* @returns a method that can be called to detach the transport
*/
attach(to: ContextualMessageTransport): (unload: boolean) => void;
/**
* Dispatch an action on all transports for an application.
*
* @todo Add option to dispatch directly to a given transport
*/
dispatch(action: AnyAction): void;
/**
* Get the current state of an application.
*
* @todo Filter once application state structure is finalised
*/
getState(): any;
/**
* Subscribe to all actions from an application on all transports.
*/
subscribe(listener: () => void): () => void;
/**
* Returns true if an action is subcribed for a specific transport context
*/
isTransportSubscribed(context: Context, type: string, id?: string): boolean;
}
export interface LoadData {
type: typeof MessageTransportType;
config: ApiClientConfig;
}
export interface MiddlewareAPI<S> {
dispatch: Dispatch<S>;
getState(): S;
}
/**
* Build middleware, binding it to a given Redux Store. The returned middleware
* will be responsible for loading application instances.
*/
export interface Middleware {
load(data: LoadData): Application;
<S>(api: MiddlewareAPI<S>): (next: Dispatch<S>) => Dispatch<S>;
}
export declare type Reducer<S> = (state: S, action: AnyAction) => S;
export interface Store<S> {
dispatch: Dispatch<S>;
getState(): S;
subscribe(listener: () => void): Unsubscribe;
replaceReducer(nextReducer: Reducer<S>): void;
}
export interface Subscription {
[key: string]: TransportSubscription[] | undefined;
}
export declare type Subscriptions = {
[key in Context]: Subscription;
};
export { AnyAction, Dispatch };
export interface TrackingEventPayload {
action: AnyAction;
appId: string;
shopId: string;
}
/**
* A union of all dynamic keys in the app store
* @public
*/
export declare type HostFeatures = keyof Store;
/**
* The interface for the host's components
* @public
* */
export interface ComponentProps {
globalStore: Store;
}