@shopify/app-bridge-host
Version:
App Bridge Host contains components and middleware to be consumed by the app's host, as well as the host itself. The middleware and `Frame` component are responsible for facilitating communication between the client and host, and used to act on actions se
108 lines (107 loc) • 3.42 kB
TypeScript
import type { AnyAction, Dispatch, Unsubscribe } from '@shopify/app-bridge-core/actions/types';
import type { Context, ContextualMessageTransport } from '@shopify/app-bridge-core/MessageTransport';
import type { TransportDispatch, TransportSubscription } from '@shopify/app-bridge-core/client/types';
import type { Store as GlobalStore } from './store';
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 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.
*/
getState(): GlobalStore;
/**
* Subscribe to a specific action dispatch event from the host
*/
hostSubscribe(eventNameSpace: string, callback: (payload: any) => void, id?: string): Unsubscribe;
/**
* Subscribe to all messages from an application on all transports.
*/
subscribe(callback: (message: TransportDispatch) => void): Unsubscribe;
/**
* Subscribe to a specific action dispatch event from an application on all transports.
*/
subscribe(eventNameSpace: string, callback: (payload: any) => void, id?: string): Unsubscribe;
/**
* 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 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 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 type HostFeatures = keyof GlobalStore;
/**
* The interface for the host's components
* @public
* */
export interface ComponentProps {
globalStore?: GlobalStore;
}