@shopify/app-bridge
Version:
**Shopify is doubling our engineering staff in 2021! [Join our team and work on libraries like this one.](https://smrtr.io/5GGrc)**
32 lines (31 loc) • 1.04 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parsePayloadWithContext = void 0;
var merge_1 = __importDefault(require("../actions/merge"));
/**
* Adds context to the MessageTransport payload to distinguish whether an action
* is dispatched from Main or Modal.
*/
function parsePayloadWithContext(payload) {
var context = typeof window.MobileWebView.context === 'function'
? window.MobileWebView.context()
: window.__context__;
if (!context) {
return JSON.stringify(payload);
}
var dataWithContext = merge_1.default(payload, {
id: payload.id,
context: context,
data: {
payload: {
context: context,
},
context: context,
},
});
return JSON.stringify(dataWithContext);
}
exports.parsePayloadWithContext = parsePayloadWithContext;