-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: created a utility function for creating platform URLs
Includes some additional constants needed for future work. Don't forget to remove the `FIXME` stuff!
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { NR1_BASE_URL, NR1_PACK_DETAILS_NERDLET } from '../data/constants'; | ||
|
||
const NERDLET_PATH = `nerdlet/${NR1_PACK_DETAILS_NERDLET}`; | ||
|
||
/** | ||
* @param {string} packId The ID for an observability pack. | ||
* @param {boolean} [debug] If set to true, this will add `packages=local`. | ||
* @returns {string} The URL for the pack details within the platform. | ||
*/ | ||
const getPackNr1Url = (packId, debug = false) => { | ||
const pane = JSON.stringify({ | ||
nerdletId: NR1_PACK_DETAILS_NERDLET, | ||
packId, | ||
}); | ||
|
||
// Note: this works differently depending on whether or not we have access | ||
// to the window object (and the btoa function). | ||
const hash = | ||
window && window.btoa | ||
? btoa(pane) | ||
: Buffer.from(pane, 'utf-8').toString('base64'); | ||
|
||
const local = debug ? 'packages=local&' : ''; | ||
|
||
const url = new URL(`${NERDLET_PATH}?${local}pane=${hash}`, NR1_BASE_URL); | ||
|
||
return url.href; | ||
}; | ||
|
||
export default getPackNr1Url; |