export const DARA_JWT_TOKEN = 'dara-jwt-token';
/**
 * Whether the Dara app is embedded within an IFrame
 */
export function isEmbedded() {
    var _a;
    const frame = window.frameElement;
    return frame && ((_a = frame === null || frame === void 0 ? void 0 : frame.dataset) === null || _a === void 0 ? void 0 : _a.daraPageId) !== '';
}
/**
 * Get the token key used to persist the embedded token
 */
export function getEmbedTokenKey() {
    var _a;
    const frame = window.frameElement;
    return (_a = frame === null || frame === void 0 ? void 0 : frame.dataset) === null || _a === void 0 ? void 0 : _a.daraPageId;
}
/**
 * Get token for the embedded Dara app
 */
export function getEmbedToken() {
    const key = getEmbedTokenKey();
    if (!key) {
        return null;
    }
    return localStorage.getItem(key);
}
/**
 * Get the jwt token. Uses the embedded token if the app is embedded.
 */
export function getToken() {
    if (isEmbedded()) {
        const embedToken = getEmbedToken();
        return embedToken;
    }
    return localStorage.getItem(DARA_JWT_TOKEN);
}
/**
 * Get the token key used to persist the jwt token. Uses the embedded token key if the app is embedded.
 */
export function getTokenKey() {
    if (isEmbedded()) {
        return getEmbedTokenKey();
    }
    return DARA_JWT_TOKEN;
}
//# sourceMappingURL=embed.js.map