@habit.analytics/habit-smartlink-reactcomponent
Version:
A React component for Habit SmartLink integration.
22 lines (19 loc) • 656 B
text/typescript
import { SMARTLINK_BASE_URL } from "./constants";
import { Environment } from "./types";
export const urlStringToUrlObject = (url: string): string => {
const urlObj = new URL(url);
return urlObj.origin;
};
export const assembleURLWithOriginHashAndPin = (
baseURL: (typeof SMARTLINK_BASE_URL)[Environment],
hash: string,
pin?: string
): string => {
return `${baseURL}?hash=${hash}${pin ? `&pin=${pin}` : ""}`;
};
export const getEnviroment = (path: string): Environment => {
if (path.includes("localhost")) return "localhost";
if (path.includes("integrations")) return "int";
if (path.includes("qa")) return "qa";
return "default";
};