@shopgate/pwa-common
Version:
Common library for the Shopgate Connect PWA.
11 lines • 1.13 kB
JavaScript
import queryString from'query-string';import{CHECKOUT_PATH,INDEX_PATH}from"../../constants/RoutePaths";/**
* Generates an url for registrations via the webcheckout. It injects additional parameters
* for redirections after a successful registration or checkout.
* @param {string} url The pure register url.
* @param {string} [redirect=''] An url which is supposed to be opened after registration.
* @return {string}
*/var getRegisterUrl=function getRegisterUrl(url){var redirect=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'';var parsed=queryString.parseUrl(url);// Generate the final redirect url. Checkout redirects are mapped to the start page.
var redirectTo=redirect&&!redirect.startsWith(CHECKOUT_PATH)?redirect:INDEX_PATH;// Build the callback data.
parsed.query.sgcloud_callback_data=JSON.stringify({redirectTo:redirectTo});// Explicitly check if we are about to be redirected to the checkout.
if(redirect.startsWith(CHECKOUT_PATH)){parsed.query.sgcloud_checkout=1;}// Recombine the url parts.
return"".concat(parsed.url,"?").concat(queryString.stringify(parsed.query));};export default getRegisterUrl;