import { defaultGetUrlQuery } from '@broadleaf/commerce-quote-react';
const params = defaultGetUrlQuery();
console.log('params', params);
Utilities provided by @broadleaf/commerce-shared-react
.
Method to use to get query parameters from the URL. Defaults to using the Location API. This is the default implementation used in the Microfrontends, but generally can be overridden to use a router or framework specific implementation.
Returns the Authorized Client ID dynamically based on the currently resolved Application.
applicationToken: string
: The application token to use to resolve the client ID.
Required.
authBaseUrl: string
: The base URL of the authorization server to use to resolve the client ID.
Optional.
This is optional and defaults to /auth
, indicating the authorization server is hosted on the same domain as the application.
Promise<ClientDiscoveryResult>
, see ClientDiscoveryResult.
import { getClientIdDynamically } from '@broadleaf/commerce-quote-react';
const applicationToken = 'my-application-token';
(async function initialize() {
try {
const { clientId } = await getClientIdDynamically(applicationToken);
console.log('Client ID', clientId);
} catch (e) {
console.error(
"Unable to retrieve authorized client details dynamically. Alternatively, you can provide a client ID explicitly and use 'static' client discovery.",
e
);
}
})();
Gets the different parts of the client’s original URL. This takes into account whether its being called on the server-side or client and if there’s a reverse proxy in use (which is typical).
req: IncomingMessage
: The incoming web request from which to get the location state.
Optional.
options: LocationStateOptions
: Additional configuration options specifying whether a reverse-proxy is in use in front of the storefront app or if the port should be stripped from the hostname of the request.
Optional.
import { getLocationState } from '@broadleaf/commerce-quote-react';
const req = {
headers : {
host: 'localhost:3000',
'x-forwarded-host': 'localhost:3000',
'x-forwarded-proto': 'https',
'x-forwarded-port': '443'
}
};
const locationState = getLocationState(req);
console.log('locationState', locationState);
Tip
|
This is used during preview-on-site flows. |
Using the IncomingMesssage
, get the sandbox cookie and return the PreviewOptions
based on teh cached preview state.
req: IncomingMessage
: The incoming web request from which to get the location state. Required.
import { getPreviewOptionsFormCookie } from '@broadleaf/commerce-quote-react';
const request = {
headers: {
cookie: 'blSandboxPreview="{\"sandboxId\"=\"123\",\"token\"=\"abc123\", \"previewDate\"=\"2023-10-01T00:00:00Z\"}"'
}
};
const previewOptions = getPreviewOptionsFormCookie(request);
console.log('previewOptions', previewOptions);
Tip
|
This is used during preview-on-site flows. |
Returns the time in seconds until the date is reached from now.
Parses the given URL string and gateway host and returns a URL object. If the URL is relative, it will be resolved against the gateway host.
Adds the given image resize parameter to the image’s content URL.
url: string
: The image URL to check. Required.
imageSize: string
: The size param to add. Required.
gatewayHost: string
: The hostname of the Commerce Gateway. Used to determine if the url
is absolute or not. Required.
imageSizes: Record<string, string>
: Mapping of the defined image size parameters. Optional.