@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
59 lines (55 loc) • 1.96 kB
JavaScript
;
var components_Navigation_utilities_resolver = require('../Navigation/utilities/resolver.js');
/**
* Build an app URL from an initial URL and a path
* @internal
* As a precautionary measure the `path` will be stripped off a host if one is
* given.
*/
function buildAppUrl(_a) {
var handle = _a.handle, initialUrl = _a.url, apiKey = _a.apiKey, pathname = _a.pathname, _b = _a.search, search = _b === void 0 ? undefined : _b;
var url = new URL(initialUrl);
var intermediatePath = new URL(pathname, url.origin).pathname;
var appPath = intermediatePath.replace(new RegExp("".concat(components_Navigation_utilities_resolver.APPS_URL, "/(").concat(handle, "|").concat(apiKey, ")")), '');
if (appPath !== '' && appPath !== '/') {
url.pathname = appPath;
}
if (search !== undefined) {
url.search = search;
}
return url;
}
/**
* Convert: 'some/path' to '/some/path'
*/
function normalizeRelativePath(path) {
return path[0] === '/' ? path : "/".concat(path);
}
// These parameters are added to the iframe url but we don't want to propagate
// them up to the address bar as they are not provided by the application
// Removing hmac is especially important as its presence may cause infinite
// oauth authentication loops
var RESTRICTED_PARAMS = [
'hmac',
'locale',
'protocol',
'session',
'shop',
'timestamp',
'host',
'embedded',
'id_token',
];
function removeRestrictedParams(path) {
try {
var uri_1 = new URL(path, location === null || location === void 0 ? void 0 : location.href);
RESTRICTED_PARAMS.forEach(function (param) { return uri_1.searchParams.delete(param); });
return "".concat(uri_1.pathname).concat(uri_1.search);
}
catch (_) {
return path;
}
}
exports.buildAppUrl = buildAppUrl;
exports.normalizeRelativePath = normalizeRelativePath;
exports.removeRestrictedParams = removeRestrictedParams;