Skip to content

Commit

Permalink
chore: created a utility function for creating platform URLs
Browse files Browse the repository at this point in the history
Includes some additional constants needed for future work. Don't forget
to remove the `FIXME` stuff!
  • Loading branch information
zstix committed Jul 26, 2021
1 parent 02ad46c commit 3c25c6b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ export const SPLIT_TRACKING_EVENTS = {

export const SDK_BASE_URL =
'https://d1zobbh8kytrtv.cloudfront.net/platform/doc-app';

// FIXME: update this to production URL when deployed / launched
export const NR1_LOGIN_URL = 'https://staging-login.newrelic.com/login';

// FIXME: update this to production URL when deployed / launched
export const NR1_BASE_URL = 'https://dev-one.newrelic.com';

export const NR1_PACK_DETAILS_NERDLET =
'catalog-pack-details.catalog-pack-details';
30 changes: 30 additions & 0 deletions src/utils/get-pack-nr1-url.js
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;

0 comments on commit 3c25c6b

Please sign in to comment.