UNPKG

@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

149 lines (148 loc) 5.64 kB
import { compose, Middleware as ReduxMiddleware, MiddlewareAPI, ReducersMapObject, Reducer, Store as ReduxStore, AnyAction } from 'redux'; import { MetaAction, Group } from '@shopify/app-bridge-core/actions'; import { Context } from '@shopify/app-bridge-core'; import type { buildMiddleware } from '../Middleware'; import type { HostFeatures } from '../types'; import { FeaturesState } from './reducers/embeddedApp/features'; import type { ToastStore } from './reducers/embeddedApp/toast'; import type { LoadingStore } from './reducers/embeddedApp/loading'; import type { ModalStore } from './reducers/embeddedApp/modal'; import type { TitleBarStore } from './reducers/embeddedApp/titleBar'; import type { ResourcePickerStore } from './reducers/embeddedApp/resourcePicker'; import type { NavigationStore } from './reducers/embeddedApp/navigation'; import type { POSStore } from './reducers/embeddedApp/pos'; import type { StaffMemberStore } from './reducers/embeddedApp/staffMember'; import type { ContextualSaveBarStore } from './reducers/embeddedApp/contextualSaveBar'; import type { MenuStore } from './reducers/embeddedApp/menu'; import type { Store as FeedbackModalStore } from './reducers/feedbackModal'; import type { Store as LeaveConfirmationStore } from './reducers/leaveConfirmation'; import type { PickerStore } from './reducers/embeddedApp/picker'; export * from './middlewares'; export * from './reducers'; export { setFeaturesAvailable } from './reducers/embeddedApp/features'; interface DevToolsOptions { name?: string; shouldHotReload?: boolean; } declare global { interface Window { __REDUX_DEVTOOLS_EXTENSION_COMPOSE__: (options: DevToolsOptions) => typeof compose; } } /** * The interface for the app state * @public */ export interface Store { features: FeaturesState; pos?: POSStore; staffMember?: StaffMemberStore; isLegacy?: boolean; contextualSaveBar?: ContextualSaveBarStore; fullscreen?: boolean; loading?: LoadingStore; modal?: ModalStore; navigation?: NavigationStore; resourcePicker?: ResourcePickerStore | null; titleBar?: TitleBarStore | null; toast?: ToastStore; menu?: MenuStore; scanner?: Record<string, never>; print?: Record<string, never>; share?: Record<string, never>; cart?: Record<string, never>; sessionToken?: Record<string, never>; authCode?: Record<string, never>; marketingExternalActivityTopBar?: Record<string, never>; feedbackModal?: FeedbackModalStore; leaveConfirmation?: LeaveConfirmationStore; performance?: Record<string, never>; client?: Record<string, never>; unstablePicker?: PickerStore | null; } /** * The app state keyed with `appBridge` * @internal */ export interface AppBridgeStore { appBridge: Store; } /** * The interface for an injected reducer's options * @public * */ export interface ReducerMap<State> { /** A key matching a property in the app state */ key: keyof Store; /** Reducer to add to a store */ reducer: Reducer<State>; /** Optional default state for the injected reducer*/ initialState?: Partial<State>; } /** * The constant key `appBridge` * @public */ export declare const APP_BRIDGE_KEY = "appBridge"; /** * Returns a combined reducer for the `appBridge` key * Always includes the `features` reducer * @public * @param stateReducers - a reducer map for the dynamic app state * @param initialState - an optional default value for the store */ export declare function createReducers(stateReducers?: ReducersMapObject, initialState?: Partial<Store>): (state: { appBridge: { features: {}; }; } | undefined, action: AnyAction) => import("redux").CombinedState<AppBridgeStore> | { appBridge: { features: {}; }; }; /** * Creates a store containing only the default `features` reducer * @public */ export declare function createStore(middleware?: (ReturnType<typeof buildMiddleware> | ReduxMiddleware)[], initialState?: Partial<Store> & Pick<Store, 'features'>, debug?: boolean): ReduxStore<import("redux").CombinedState<AppBridgeStore> | { appBridge: { features: {}; }; }, AnyAction> & { dispatch: unknown; }; /** * Creates a method that when called, dynamically adds a reducer to * the provided store * @internal * @param store - a Redux store * @param globalInitialState - custom overrides for resolving the app state when adding a new reducer * */ export declare function createAddReducer(store: ReduxStore, globalInitialState?: Partial<Store>): <State>({ key, reducer, initialState }: ReducerMap<State>) => void; type QueuedClientAction = MetaAction & { group: Group; }; /** * The inteface for a queue with methods to add to the queue, clear the queue and also resolve the queue * @internal * */ export interface ActionsQueue { /** Add the action to the queue for the provided `context` */ add(context: Context, action: QueuedClientAction): void; /** Add the host action to the queue */ addHostAction(action: QueuedClientAction): void; /** Removes all actions in the queue for the provided `context` */ clear(context: Context): void; /** Dispatch all actions related to the feature in the queue for all contexts */ resolve(key: HostFeatures): void; } /** * Creates an action queue for the provided store * @internal * */ export declare function createActionsQueue(store: MiddlewareAPI<any>): ActionsQueue; /** * Predicate to determine if a reducer for the associated action is already loaded * @internal */ export declare function isReducerLoaded(state: any, action: any): boolean;