@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
36 lines (31 loc) • 1.26 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var Actions = require('@shopify/app-bridge-core/actions');
var Error = require('@shopify/app-bridge-core/actions/Error');
var withStatelessFeature = require('../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(Actions.SessionToken.Action.RESPOND, function (_a) {
var sessionToken = _a.sessionToken;
if (sessionToken) {
resolve(sessionToken);
}
else {
reject(Error.fromAction('Failed to retrieve a session token', Actions.Error.Action.FAILED_AUTHENTICATION));
}
unsubscribe();
});
actions.request();
});
},
};
};
var sessionToken = withStatelessFeature('sessionToken', {
respond: Actions.SessionToken.respond,
request: Actions.SessionToken.request,
}, getApi);
exports.default = sessionToken;
exports.getApi = getApi;