@pyramid-embed/embed-js
Advanced tools
Comparing version 3.0.1 to 4.0.0
@@ -0,0 +0,0 @@ import { GlobalEmbedReportFilter } from '../types/types'; |
@@ -1,29 +0,27 @@ | ||
var Filter = /** @class */ (function () { | ||
function Filter() { | ||
export class Filter { | ||
constructor() { | ||
this.filters = []; | ||
} | ||
Filter.create = function () { | ||
static create() { | ||
return new Filter(); | ||
}; | ||
Filter.byUniqueName = function (uniqueName) { | ||
} | ||
static byUniqueName(uniqueName) { | ||
return new Filter().addUniqueName(uniqueName); | ||
}; | ||
Filter.by = function (dimension, hierarchy, member) { | ||
} | ||
static by(dimension, hierarchy, member) { | ||
return new Filter().add(dimension, hierarchy, member); | ||
}; | ||
Filter.prototype.addUniqueName = function (uniqueName) { | ||
} | ||
addUniqueName(uniqueName) { | ||
this.filters.push(uniqueName); | ||
return this; | ||
}; | ||
Filter.prototype.add = function (dimension, hierarchy, member) { | ||
this.filters.push("[".concat(dimension, "].[").concat(hierarchy, "].&[").concat(member, "]")); | ||
} | ||
add(dimension, hierarchy, member) { | ||
this.filters.push(`[${dimension}].[${hierarchy}].&[${member}]`); | ||
return this; | ||
}; | ||
Filter.prototype.toGlobalEmbedFilters = function () { | ||
return this.filters.map(function (x) { | ||
} | ||
toGlobalEmbedFilters() { | ||
return this.filters.map(x => { | ||
return { value: x }; | ||
}); | ||
}; | ||
return Filter; | ||
}()); | ||
export { Filter }; | ||
} | ||
} |
@@ -0,0 +0,0 @@ import { Filter } from './filter'; |
@@ -1,12 +0,12 @@ | ||
var Target = /** @class */ (function () { | ||
function Target() { | ||
export class Target { | ||
constructor() { | ||
this.targets = []; | ||
} | ||
Target.create = function () { | ||
static create() { | ||
return new Target(); | ||
}; | ||
Target.byFilter = function (filters, name, isOlap) { | ||
} | ||
static byFilter(filters, name, isOlap) { | ||
return new Target().add(filters, name, isOlap); | ||
}; | ||
Target.prototype.add = function (filters, name, isOlap) { | ||
} | ||
add(filters, name, isOlap) { | ||
this.targets.push({ | ||
@@ -18,5 +18,5 @@ filters: filters, | ||
return this; | ||
}; | ||
Target.prototype.toGlobalEmbedTarget = function () { | ||
return this.targets.map(function (x) { | ||
} | ||
toGlobalEmbedTarget() { | ||
return this.targets.map(x => { | ||
return { | ||
@@ -28,5 +28,3 @@ name: x.name, | ||
}); | ||
}; | ||
return Target; | ||
}()); | ||
export { Target }; | ||
} | ||
} |
export declare function wait(amount: number): Promise<void>; |
export function wait(amount) { | ||
return new Promise(function (resolve) { | ||
return new Promise(resolve => { | ||
setTimeout(resolve, amount); | ||
}); | ||
} |
@@ -0,1 +1,2 @@ | ||
import { EmbedHubAPI } from './types/types'; | ||
export declare class HubClient { | ||
@@ -2,0 +3,0 @@ private hubAPI; |
@@ -1,16 +0,14 @@ | ||
var HubClient = /** @class */ (function () { | ||
function HubClient(api) { | ||
export class HubClient { | ||
constructor(api) { | ||
this.hubAPI = api; | ||
} | ||
HubClient.prototype.changeSelectedTab = function (tabIdx) { | ||
changeSelectedTab(tabIdx) { | ||
this.hubAPI.changeSelectedTab(tabIdx); | ||
}; | ||
HubClient.prototype.getSelectedTab = function () { | ||
} | ||
getSelectedTab() { | ||
return this.hubAPI.getSelectedTab(); | ||
}; | ||
HubClient.prototype.getTabsList = function () { | ||
} | ||
getTabsList() { | ||
return this.hubAPI.getTabsList(); | ||
}; | ||
return HubClient; | ||
}()); | ||
export { HubClient }; | ||
} | ||
} |
@@ -5,3 +5,1 @@ export * from './pyramid-embed-client'; | ||
export * from './types/types'; | ||
export * from './global'; | ||
export * from './polyfill'; |
@@ -5,3 +5,1 @@ export * from './pyramid-embed-client'; | ||
export * from './types/types'; | ||
export * from './global'; | ||
export * from './polyfill'; |
@@ -0,0 +0,0 @@ import { HubClient } from './hub-client'; |
@@ -1,2 +0,1 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
import { wait } from './helper-utils'; | ||
@@ -10,6 +9,6 @@ import { HubClient } from './hub-client'; | ||
})(EmbedClientStatus || (EmbedClientStatus = {})); | ||
var fakeEmbedFnName = 'fakeEmbed'; | ||
var waitForLoadInterval = 200; | ||
var PyramidEmbedClient = /** @class */ (function () { | ||
function PyramidEmbedClient(host, userName, password, customData) { | ||
const fakeEmbedFnName = 'fakeEmbed'; | ||
const waitForLoadInterval = 200; | ||
export class PyramidEmbedClient { | ||
constructor(host, userName, password, customData) { | ||
this.status = EmbedClientStatus.NotInitialized; | ||
@@ -22,63 +21,34 @@ this.embedQueue = []; | ||
} | ||
Object.defineProperty(PyramidEmbedClient.prototype, "host", { | ||
get: function () { | ||
return this._host; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(PyramidEmbedClient.prototype, "isClientLoaded", { | ||
get: function () { | ||
return clientLoaded(); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(PyramidEmbedClient.prototype, "isLoggedIn", { | ||
get: function () { | ||
return this.hasCookie(); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
PyramidEmbedClient.quickEmbed = function (options) { | ||
var instance = new PyramidEmbedClient(options.host); | ||
instance.init(options.userName, options.password, options.customData).then(function () { | ||
get host() { | ||
return this._host; | ||
} | ||
get isClientLoaded() { | ||
return clientLoaded(); | ||
} | ||
get isLoggedIn() { | ||
return this.hasCookie(); | ||
} | ||
static quickEmbed(options) { | ||
const instance = new PyramidEmbedClient(options.host); | ||
instance.init(options.userName, options.password, options.customData).then(() => { | ||
instance.embed(options.container, options); | ||
}); | ||
return instance; | ||
}; | ||
PyramidEmbedClient.prototype.init = function (userName, password, customData) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var token, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (this.isClientLoaded && this.isLoggedIn) { | ||
return [2 /*return*/, null]; | ||
} | ||
if ((!userName || !password) && !this.isLoggedIn) { | ||
//throw error? | ||
return [2 /*return*/, null]; | ||
} | ||
if (!!this.isLoggedIn) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.login(userName, password, customData)]; | ||
case 1: | ||
_a = _b.sent(); | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
_a = null; | ||
_b.label = 3; | ||
case 3: | ||
token = _a; | ||
getLegacyEmbed(this.host.toString()); | ||
return [2 /*return*/, token]; | ||
} | ||
}); | ||
}); | ||
}; | ||
PyramidEmbedClient.prototype.setAuthToken = function (token) { | ||
} | ||
async init(userName, password, customData) { | ||
if (this.isClientLoaded && this.isLoggedIn) { | ||
return null; | ||
} | ||
if ((!userName || !password) && !this.isLoggedIn) { | ||
//throw error? | ||
return null; | ||
} | ||
const token = !this.isLoggedIn ? await this.login(userName, password, customData) : null; | ||
getLegacyEmbed(this.host.toString()); | ||
return token; | ||
} | ||
setAuthToken(token) { | ||
this.setTokenCookie(token); | ||
}; | ||
PyramidEmbedClient.prototype.getAuthToken = function () { | ||
} | ||
getAuthToken() { | ||
if (this.hasCookie()) { | ||
@@ -88,257 +58,162 @@ return this.getTokenCookie(); | ||
return null; | ||
}; | ||
PyramidEmbedClient.prototype.setAuthFailureCallback = function (callback) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.waitForClientToLoad()]; | ||
case 1: | ||
_a.sent(); | ||
pyramid.authFailure = callback; | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
PyramidEmbedClient.prototype.getCleanHostURL = function () { | ||
} | ||
async setAuthFailureCallback(callback) { | ||
await this.waitForClientToLoad(); | ||
pyramid.authFailure = callback; | ||
} | ||
getCleanHostURL() { | ||
//remove trailing slash | ||
return this.host.href.replace(/\/$/, ''); | ||
}; | ||
PyramidEmbedClient.prototype.hub = function (container, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var embedOptions, hubApi; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.waitForClientToLoad()]; | ||
case 1: | ||
_a.sent(); | ||
embedOptions = { | ||
host: this.getCleanHostURL(), | ||
theme: options.theme, | ||
style: options.style, | ||
editable: options.editable, | ||
showTabs: options.showTabs, | ||
responsiveness: options.responsiveness, | ||
locale: options.locale, | ||
smartReportDialogPopupMode: options.smartReportDialogPopupMode, | ||
template: options.template, | ||
}; | ||
hubApi = pyramid.hub; | ||
return [4 /*yield*/, hubApi.embed(container, embedOptions)]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/, new HubClient(hubApi)]; | ||
} | ||
}); | ||
}); | ||
}; | ||
PyramidEmbedClient.prototype.waitForClientToLoad = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (this.isClientLoaded) | ||
return [2 /*return*/]; | ||
return [4 /*yield*/, wait(waitForLoadInterval)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, this.waitForClientToLoad()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
} | ||
async hub(container, options = {}) { | ||
addSpinner(container); | ||
await this.waitForClientToLoad(); | ||
const embedOptions = { | ||
host: this.getCleanHostURL(), | ||
theme: options.theme, | ||
style: options.style, | ||
editable: options.editable, | ||
showTabs: options.showTabs, | ||
responsiveness: options.responsiveness, | ||
locale: options.locale, | ||
smartReportDialogPopupMode: options.smartReportDialogPopupMode, | ||
template: options.template, | ||
}; | ||
const hubApi = pyramid.hub; | ||
await hubApi.embed(container, embedOptions); | ||
return new HubClient(hubApi); | ||
} | ||
async waitForClientToLoad() { | ||
if (this.isClientLoaded) | ||
return; | ||
await wait(waitForLoadInterval); | ||
return this.waitForClientToLoad(); | ||
} | ||
//legacy embed. keep as is | ||
PyramidEmbedClient.prototype.embed = function (container, options) { | ||
async embed(container, options) { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var params, embedOptions, embedPromise; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: return [4 /*yield*/, this.waitForClientToLoad()]; | ||
case 1: | ||
_c.sent(); | ||
params = { | ||
reportFilters: (_a = options.filters) === null || _a === void 0 ? void 0 : _a.toGlobalEmbedFilters(), | ||
targets: (_b = options.targets) === null || _b === void 0 ? void 0 : _b.toGlobalEmbedTarget(), | ||
slideNumber: options.slideNumber, | ||
}; | ||
embedOptions = { | ||
id: options.contentId, | ||
contentType: options.visualOnly ? 'visual' : null, | ||
host: this.getCleanHostURL(), | ||
onLoad: options.onLoad, | ||
params: params, | ||
deviceType: options.deviceType, | ||
theme: options.theme, | ||
locale: options.locale, | ||
exporting: options.exporting, | ||
fullDiscovery: options.fullDiscovery, | ||
}; | ||
if (this.status === EmbedClientStatus.Initializing) { | ||
this.addEmbedRequestToQueue({ container: container, embedOptions: embedOptions }); | ||
return [2 /*return*/]; | ||
} | ||
embedPromise = pyramid.embed(container, embedOptions); | ||
if (!(this.status === EmbedClientStatus.NotInitialized)) return [3 /*break*/, 3]; | ||
this.setStatus(EmbedClientStatus.Initializing); | ||
return [4 /*yield*/, embedPromise]; | ||
case 2: | ||
_c.sent(); | ||
this.embedQueue.forEach(function (_a) { | ||
var container = _a.container, embedOptions = _a.embedOptions; | ||
pyramid.embed(container, embedOptions); | ||
}); | ||
this.setStatus(EmbedClientStatus.Initialized); | ||
_c.label = 3; | ||
case 3: return [2 /*return*/]; | ||
} | ||
addSpinner(container); | ||
await this.waitForClientToLoad(); | ||
const params = { | ||
reportFilters: (_a = options.filters) === null || _a === void 0 ? void 0 : _a.toGlobalEmbedFilters(), | ||
targets: (_b = options.targets) === null || _b === void 0 ? void 0 : _b.toGlobalEmbedTarget(), | ||
slideNumber: options.slideNumber, | ||
}; | ||
const embedOptions = { | ||
id: options.contentId, | ||
contentType: options.visualOnly ? 'visual' : null, | ||
host: this.getCleanHostURL(), | ||
onLoad: options.onLoad, | ||
params: params, | ||
deviceType: options.deviceType, | ||
theme: options.theme, | ||
locale: options.locale, | ||
exporting: options.exporting, | ||
fullDiscovery: options.fullDiscovery, | ||
}; | ||
if (this.status === EmbedClientStatus.Initializing) { | ||
this.addEmbedRequestToQueue({ container, embedOptions }); | ||
return; | ||
} | ||
const embedPromise = pyramid.embed(container, embedOptions); | ||
if (this.status === EmbedClientStatus.NotInitialized) { | ||
this.setStatus(EmbedClientStatus.Initializing); | ||
await embedPromise; | ||
this.embedQueue.forEach(({ container, embedOptions }) => { | ||
pyramid.embed(container, embedOptions); | ||
}); | ||
this.setStatus(EmbedClientStatus.Initialized); | ||
} | ||
} | ||
async login(userName, password, customData) { | ||
const credentials = { | ||
data: { | ||
userName: userName, | ||
password: password, | ||
domain: document.domain, | ||
customData, | ||
}, | ||
}; | ||
const token = await this.loginInternal(`${this.host.href}API2/auth/authenticateUserEmbed`, { | ||
method: 'POST', | ||
body: JSON.stringify(credentials), | ||
}); | ||
}; | ||
PyramidEmbedClient.prototype.login = function (userName, password, customData) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var credentials, token; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
credentials = { | ||
data: { | ||
userName: userName, | ||
password: password, | ||
domain: document.domain, | ||
customData: customData, | ||
}, | ||
}; | ||
return [4 /*yield*/, this.loginInternal("".concat(this.host.href, "API2/auth/authenticateUserEmbed"), { | ||
method: 'POST', | ||
body: JSON.stringify(credentials), | ||
})]; | ||
case 1: | ||
token = _a.sent(); | ||
this.setTokenCookie(token); | ||
return [2 /*return*/, token]; | ||
} | ||
}); | ||
this.setTokenCookie(token); | ||
return token; | ||
} | ||
async loginWindowsAuth() { | ||
const credentials = { data: { domain: document.domain } }; | ||
const token = await this.loginInternal(`${this.host.href}API2/auth/authenticateUserEmbedWindows`, { | ||
method: 'POST', | ||
credentials: 'include', | ||
body: JSON.stringify(credentials), | ||
}); | ||
}; | ||
PyramidEmbedClient.prototype.loginWindowsAuth = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var credentials, token; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
credentials = { data: { domain: document.domain } }; | ||
return [4 /*yield*/, this.loginInternal("".concat(this.host.href, "API2/auth/authenticateUserEmbedWindows"), { | ||
method: 'POST', | ||
credentials: 'include', | ||
body: JSON.stringify(credentials), | ||
})]; | ||
case 1: | ||
token = _a.sent(); | ||
this.setTokenCookie(token); | ||
return [2 /*return*/, token]; | ||
} | ||
}); | ||
this.setTokenCookie(token); | ||
return token; | ||
} | ||
async loginSamlAuth(samlToken, customData) { | ||
const credentials = { | ||
data: { domain: document.domain, token: samlToken, customData }, | ||
}; | ||
const token = await this.loginInternal(`${this.host.href}API2/auth/authenticateUserEmbedSAML`, { | ||
method: 'POST', | ||
body: JSON.stringify(credentials), | ||
}); | ||
}; | ||
PyramidEmbedClient.prototype.loginSamlAuth = function (samlToken, customData) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var credentials, token; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
credentials = { | ||
data: { domain: document.domain, token: samlToken, customData: customData }, | ||
}; | ||
return [4 /*yield*/, this.loginInternal("".concat(this.host.href, "API2/auth/authenticateUserEmbedSAML"), { | ||
method: 'POST', | ||
body: JSON.stringify(credentials), | ||
})]; | ||
case 1: | ||
token = _a.sent(); | ||
this.setTokenCookie(token); | ||
return [2 /*return*/, token]; | ||
} | ||
}); | ||
this.setTokenCookie(token); | ||
return token; | ||
} | ||
async loginOpenIdAuth(openIdToken, customData) { | ||
const credentials = { | ||
data: { domain: document.domain, parameterMap: { id_token: openIdToken }, customData }, | ||
}; | ||
const token = await this.loginInternal(`${this.host.href}API2/auth/authenticateUserEmbedOPENID`, { | ||
method: 'POST', | ||
body: JSON.stringify(credentials), | ||
}); | ||
}; | ||
PyramidEmbedClient.prototype.loginOpenIdAuth = function (openIdToken, customData) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var credentials, token; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
credentials = { | ||
data: { domain: document.domain, parameterMap: { id_token: openIdToken }, customData: customData }, | ||
}; | ||
return [4 /*yield*/, this.loginInternal("".concat(this.host.href, "API2/auth/authenticateUserEmbedOPENID"), { | ||
method: 'POST', | ||
body: JSON.stringify(credentials), | ||
})]; | ||
case 1: | ||
token = _a.sent(); | ||
this.setTokenCookie(token); | ||
return [2 /*return*/, token]; | ||
} | ||
}); | ||
}); | ||
}; | ||
PyramidEmbedClient.prototype.setStatus = function (status) { | ||
this.setTokenCookie(token); | ||
return token; | ||
} | ||
setStatus(status) { | ||
this.status = status; | ||
}; | ||
PyramidEmbedClient.prototype.addEmbedRequestToQueue = function (embedTask) { | ||
} | ||
addEmbedRequestToQueue(embedTask) { | ||
this.embedQueue.push(embedTask); | ||
}; | ||
PyramidEmbedClient.prototype.loginInternal = function (requestInfo, requestInit) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var errorMessage, response, token, error_1, errorMsg; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 7, , 8]); | ||
return [4 /*yield*/, fetch(requestInfo, requestInit)]; | ||
case 1: | ||
response = _a.sent(); | ||
if (!!response) return [3 /*break*/, 2]; | ||
errorMessage = 'Unknown Login Error'; | ||
return [3 /*break*/, 6]; | ||
case 2: | ||
if (!(response.status === 401)) return [3 /*break*/, 3]; | ||
errorMessage = 'Login failed'; | ||
return [3 /*break*/, 6]; | ||
case 3: | ||
if (!(response.status !== 200)) return [3 /*break*/, 4]; | ||
errorMessage = 'Unknown Login Error'; | ||
return [3 /*break*/, 6]; | ||
case 4: return [4 /*yield*/, response.text()]; | ||
case 5: | ||
token = _a.sent(); | ||
return [2 /*return*/, token]; | ||
case 6: return [3 /*break*/, 8]; | ||
case 7: | ||
error_1 = _a.sent(); | ||
errorMsg = typeof error_1 === 'string' ? error_1 : error_1 === null || error_1 === void 0 ? void 0 : error_1.message; | ||
errorMessage = "Login Error: ".concat(errorMsg); | ||
return [3 /*break*/, 8]; | ||
case 8: | ||
if (errorMessage) { | ||
throw new Error(errorMessage); | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
PyramidEmbedClient.prototype.hasCookie = function () { | ||
} | ||
async loginInternal(requestInfo, requestInit) { | ||
let errorMessage; | ||
try { | ||
const response = await fetch(requestInfo, requestInit); | ||
if (!response) { | ||
errorMessage = 'Unknown Login Error'; | ||
} | ||
else if (response.status === 401) { | ||
errorMessage = 'Login failed'; | ||
} | ||
else if (response.status !== 200) { | ||
errorMessage = 'Unknown Login Error'; | ||
} | ||
else { | ||
const token = await response.text(); | ||
return token; | ||
} | ||
} | ||
catch (error) { | ||
const errorMsg = typeof error === 'string' ? error : error === null || error === void 0 ? void 0 : error.message; | ||
errorMessage = `Login Error: ${errorMsg}`; | ||
} | ||
if (errorMessage) { | ||
throw new Error(errorMessage); | ||
} | ||
} | ||
hasCookie() { | ||
var _a; | ||
return ((_a = document.cookie.match(/^(.*;)?\s*PyramidEmbeddedAuth\s*=\s*[^;]+(.*)?$/)) === null || _a === void 0 ? void 0 : _a.length) > 0; | ||
}; | ||
PyramidEmbedClient.prototype.setTokenCookie = function (val) { | ||
document.cookie = "PyramidEmbeddedAuth=".concat(val); | ||
}; | ||
PyramidEmbedClient.prototype.getTokenCookie = function () { | ||
var name = 'PyramidEmbeddedAuth='; | ||
var decodedCookie = decodeURIComponent(document.cookie); | ||
var ca = decodedCookie.split(';'); | ||
} | ||
setTokenCookie(val) { | ||
document.cookie = `PyramidEmbeddedAuth=${val}`; | ||
} | ||
getTokenCookie() { | ||
const name = 'PyramidEmbeddedAuth='; | ||
const decodedCookie = decodeURIComponent(document.cookie); | ||
const ca = decodedCookie.split(';'); | ||
for (var i = 0; i < ca.length; i++) { | ||
@@ -354,8 +229,6 @@ var c = ca[i]; | ||
return ''; | ||
}; | ||
return PyramidEmbedClient; | ||
}()); | ||
export { PyramidEmbedClient }; | ||
} | ||
} | ||
function getActualHost(host) { | ||
var actualHost = !host.startsWith('http://') && !host.startsWith('https://') ? "http://".concat(host) : host; | ||
const actualHost = !host.startsWith('http://') && !host.startsWith('https://') ? `http://${host}` : host; | ||
return new URL(actualHost); | ||
@@ -366,4 +239,4 @@ } | ||
return; | ||
var headExists = false; | ||
Array.from(document.querySelectorAll('script')).forEach(function (x) { | ||
let headExists = false; | ||
Array.from(document.querySelectorAll('script')).forEach(x => { | ||
var _a; | ||
@@ -375,4 +248,4 @@ if ((_a = x.src) === null || _a === void 0 ? void 0 : _a.includes('no-shell/embed.js')) { | ||
if (!headExists) { | ||
var scriptElem = document.createElement('script'); | ||
scriptElem.src = "".concat(host, "no-shell/embed.js?v=").concat(new Date().getTime()); | ||
const scriptElem = document.createElement('script'); | ||
scriptElem.src = `${host}no-shell/embed.js?v=${new Date().getTime()}`; | ||
scriptElem.async = true; | ||
@@ -383,3 +256,3 @@ document.head.appendChild(scriptElem); | ||
function tryLoadStaticEmbed() { | ||
var staticEmbedElement = document.querySelector('.pyramid-embed.pyramid-auto[data-host]'); | ||
const staticEmbedElement = document.querySelector('.pyramid-embed.pyramid-auto[data-host]'); | ||
if (staticEmbedElement) { | ||
@@ -390,4 +263,4 @@ getLegacyEmbed(getActualHost(staticEmbedElement.getAttribute('data-host')).toString()); | ||
function clientLoaded() { | ||
var pyramid = window.pyramid; | ||
var embedFn = pyramid === null || pyramid === void 0 ? void 0 : pyramid.embed; | ||
const pyramid = window.pyramid; | ||
const embedFn = pyramid === null || pyramid === void 0 ? void 0 : pyramid.embed; | ||
// check that the embed function exists and that it's not the fake api | ||
@@ -397,4 +270,91 @@ // displayName will only appear in newer versions and will only be checked if exists | ||
} | ||
function addSpinner(container) { | ||
if (!container) { | ||
return; | ||
} | ||
if (container.childNodes.length > 0) { | ||
return; | ||
} | ||
if (clientLoaded()) { | ||
return; | ||
} | ||
createSpinnerStyleIfNeeded(); | ||
const spinnerHtml = ` | ||
<div style="display: flex; align-items: center; width: 100%; height: 100%; background-color: #fff; opacity: 0.8"> | ||
<div class="pre-loading-spinner-animation-container"> | ||
<div class="pre-loading-spinner-animation-bars"> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
</div> | ||
</div> | ||
</div>`.trim(); | ||
container.insertAdjacentHTML('beforeend', spinnerHtml); | ||
} | ||
function getSpinnerStyle() { | ||
return document.querySelector('style[data-pyramid-embed-client]'); | ||
} | ||
function createSpinnerStyleIfNeeded() { | ||
const spinnerStyle = getSpinnerStyle(); | ||
if (spinnerStyle) { | ||
return; | ||
} | ||
const color = '#555555'; | ||
const css = ` | ||
.pre-loading-spinner-animation-container { | ||
display: flex; | ||
justify-content: center; | ||
width: 100%; | ||
} | ||
@keyframes app-pre-loading-spinner-bars-random-animation { | ||
0% { | ||
transform: scale(1); | ||
} | ||
50% { | ||
transform: scale(0.5); | ||
} | ||
100% { | ||
transform: scale(1); | ||
} | ||
} | ||
.pre-loading-spinner-animation-bars { | ||
font-size: 0; | ||
} | ||
.pre-loading-spinner-animation-bars > div:nth-child(1) { | ||
animation-delay: 0.48s; | ||
animation-duration: 0.54s; | ||
} | ||
.pre-loading-spinner-animation-bars > div:nth-child(2) { | ||
animation-delay: -0.15s; | ||
animation-duration: 1.15s; | ||
} | ||
.pre-loading-spinner-animation-bars > div:nth-child(3) { | ||
animation-delay: 0.04s; | ||
animation-duration: 0.77s; | ||
} | ||
.pre-loading-spinner-animation-bars > div:nth-child(4) { | ||
animation-delay: -0.12s; | ||
animation-duration: 0.61s; | ||
} | ||
.pre-loading-spinner-animation-bars > div { | ||
background-color: ${color}; | ||
width: 2px; | ||
height: 22px; | ||
border-radius: 2px; | ||
margin: 2px; | ||
animation-fill-mode: both; | ||
display: inline-block; | ||
animation-name: app-pre-loading-spinner-bars-random-animation; | ||
animation-iteration-count: infinite; | ||
animation-delay: 0s; | ||
}` | ||
.trim() | ||
.replace(/\n/g, '') | ||
.replace(/\s\s+/g, ' '); | ||
const style = `<style data-pyramid-embed-client>${css}</style>`; | ||
document.head.insertAdjacentHTML('beforeend', style); | ||
} | ||
document.addEventListener('DOMContentLoaded', function () { | ||
tryLoadStaticEmbed(); | ||
}); |
@@ -32,6 +32,6 @@ import { Filter } from '../filters/filter'; | ||
} | ||
declare type ExportType = 'pdf' | 'png' | 'excel' | 'csv'; | ||
declare type HubTheme = 'light' | 'dark'; | ||
declare type HubResponsivenessType = 'none' | 'compact'; | ||
declare type HubSmartReportDialogPopupMode = 'none' | 'tab' | 'popup'; | ||
type ExportType = 'pdf' | 'png' | 'excel' | 'csv'; | ||
type HubTheme = 'light' | 'dark'; | ||
type HubResponsivenessType = 'none' | 'compact'; | ||
type HubSmartReportDialogPopupMode = 'none' | 'tab' | 'popup'; | ||
export interface EmbedHubOptions { | ||
@@ -84,2 +84,10 @@ theme?: HubTheme; | ||
} | ||
export interface EmbedHubAPI { | ||
embed(container: HTMLElement | string, options: Partial<EmbedHubOptions>): Promise<void>; | ||
changeSelectedTab(tabIdx: number): void; | ||
getSelectedTab(): number; | ||
getTabsList(): { | ||
tabName: string; | ||
}[]; | ||
} | ||
export {}; |
@@ -0,0 +0,0 @@ /* API types */ |
{ | ||
"name": "@pyramid-embed/embed-js", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "tsc", | ||
"build:publish": "tsc && npm version patch && npm publish", | ||
"build:publish:prod": "tsc && npm publish", | ||
"build:global": "webpack -p --config webpack.global.js", | ||
"clean": "rimraf dist/", | ||
"build": "npm run clean && tsc --project tsconfig.lib.json", | ||
"build:publish": "npm run build && npm version patch && npm publish", | ||
"build:publish:prod": "npm run build && npm publish", | ||
"build:global": "webpack --mode production --config webpack.global.js", | ||
"build:global:dev": "webpack --config webpack.global.dev.js", | ||
"postinstall": "npm prune" | ||
"postinstall": "npm prune", | ||
"build:package": "npm run build && npm pack" | ||
}, | ||
@@ -18,15 +19,11 @@ "author": "Pyramid Analytics", | ||
"dependencies": { | ||
"core-js": "3.20.1", | ||
"tslib": "2.3.1", | ||
"whatwg-fetch": "3.0.0" | ||
"tslib": "^2.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/jquery": "3.3.31", | ||
"remove-files-webpack-plugin": "1.4.3", | ||
"rimraf": "^5.0.5", | ||
"ts-loader": "8.3.0", | ||
"typescript": "4.6.3", | ||
"uglifyjs-webpack-plugin": "2.2.0", | ||
"webpack": "4.46.0", | ||
"webpack-cli": "3.3.12", | ||
"webpack-merge": "4.2.2" | ||
"typescript": "5.4.2", | ||
"webpack": "5.90.3", | ||
"webpack-cli": "5.1.4", | ||
"webpack-merge": "5.10.0" | ||
}, | ||
@@ -33,0 +30,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
1
6
1
28358
16
594
+ Addedtslib@2.8.1(transitive)
- Removedcore-js@3.20.1
- Removedwhatwg-fetch@3.0.0
- Removedcore-js@3.20.1(transitive)
- Removedtslib@2.3.1(transitive)
- Removedwhatwg-fetch@3.0.0(transitive)
Updatedtslib@^2.3.1