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

31 lines (28 loc) 1.14 kB
import { SessionToken, Error } from '@shopify/app-bridge-core/actions'; import { fromAction } from '@shopify/app-bridge-core/actions/Error'; import withStatelessFeature from '../components/utilities/withStatelessFeature.js'; var getApi = function (_a) { var actions = _a.actions, subscribe = _a.subscribe; return { get: function () { return new Promise(function (resolve, reject) { var unsubscribe = subscribe(SessionToken.Action.RESPOND, function (_a) { var sessionToken = _a.sessionToken; if (sessionToken) { resolve(sessionToken); } else { reject(fromAction('Failed to retrieve a session token', Error.Action.FAILED_AUTHENTICATION)); } unsubscribe(); }); actions.request(); }); }, }; }; var sessionToken = withStatelessFeature('sessionToken', { respond: SessionToken.respond, request: SessionToken.request, }, getApi); export { sessionToken as default, getApi };