UNPKG

3.22 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 as GlobalStore } 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 getState(): GlobalStore;
44 /**
45 * Subscribe to all messages from an application on all transports.
46 */
47 subscribe(callback: (message: TransportDispatch) => void): Unsubscribe;
48 /**
49 * Subscribe to a specific action dispatch event from an application on all transports.
50 */
51 subscribe(eventNameSpace: string, callback: (payload: any) => void, id?: string): Unsubscribe;
52 /**
53 * Returns true if an action is subcribed for a specific transport context
54 */
55 isTransportSubscribed(context: Context, type: string, id?: string): boolean;
56}
57export interface LoadData {
58 type: typeof MessageTransportType;
59 config: ApiClientConfig;
60}
61export interface MiddlewareAPI<S> {
62 dispatch: Dispatch<S>;
63 getState(): S;
64}
65/**
66 * Build middleware, binding it to a given Redux Store. The returned middleware
67 * will be responsible for loading application instances.
68 */
69export interface Middleware {
70 load(data: LoadData): Application;
71 <S>(api: MiddlewareAPI<S>): (next: Dispatch<S>) => Dispatch<S>;
72}
73export declare type Reducer<S> = (state: S, action: AnyAction) => S;
74export interface Store<S> {
75 dispatch: Dispatch<S>;
76 getState(): S;
77 subscribe(listener: () => void): Unsubscribe;
78 replaceReducer(nextReducer: Reducer<S>): void;
79}
80export interface Subscription {
81 [key: string]: TransportSubscription[] | undefined;
82}
83export declare type Subscriptions = {
84 [key in Context]: Subscription;
85};
86export { AnyAction, Dispatch };
87export interface TrackingEventPayload {
88 action: AnyAction;
89 appId: string;
90 shopId: string;
91}
92/**
93 * A union of all dynamic keys in the app store
94 * @public
95 */
96export declare type HostFeatures = keyof GlobalStore;
97/**
98 * The interface for the host's components
99 * @public
100 * */
101export interface ComponentProps {
102 globalStore: GlobalStore;
103}