@fluxtrace/embed 0.0.0-stage → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +13 -0
- package/dist/index.global.js +81 -0
- package/dist/index.js +62 -0
- package/package.json +15 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type DashboardElementOptions = {
|
|
2
|
+
projectId: string;
|
|
3
|
+
origin?: string;
|
|
4
|
+
host?: string;
|
|
5
|
+
height?: string;
|
|
6
|
+
userId?: string;
|
|
7
|
+
from?: string;
|
|
8
|
+
to?: string;
|
|
9
|
+
paths?: string[];
|
|
10
|
+
ttlSeconds?: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type { DashboardElementOptions };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var FluxtraceEmbed = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
|
|
17
|
+
// src/index.ts
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
var FluxtraceDashboard = class extends HTMLElement {
|
|
20
|
+
options = null;
|
|
21
|
+
connectedCallback() {
|
|
22
|
+
const projectId = this.getAttribute("project-id");
|
|
23
|
+
if (!projectId) {
|
|
24
|
+
this.textContent = "FluxTrace: project-id is required";
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const pathsRaw = this.getAttribute("paths");
|
|
28
|
+
const paths = pathsRaw ? pathsRaw.split(",").map((p) => p.trim()).filter(Boolean) : void 0;
|
|
29
|
+
const ttlRaw = this.getAttribute("ttl");
|
|
30
|
+
const ttlSeconds = ttlRaw ? Number(ttlRaw) : void 0;
|
|
31
|
+
this.options = {
|
|
32
|
+
projectId,
|
|
33
|
+
origin: this.getAttribute("origin") ?? window.location.origin,
|
|
34
|
+
host: this.getAttribute("host") ?? window.location.origin,
|
|
35
|
+
height: this.getAttribute("height") ?? "720px",
|
|
36
|
+
userId: this.getAttribute("user-id") ?? void 0,
|
|
37
|
+
from: this.getAttribute("from") ?? void 0,
|
|
38
|
+
to: this.getAttribute("to") ?? void 0,
|
|
39
|
+
paths: paths?.length ? paths : void 0,
|
|
40
|
+
ttlSeconds: ttlSeconds != null && Number.isFinite(ttlSeconds) ? ttlSeconds : void 0
|
|
41
|
+
};
|
|
42
|
+
void this.load();
|
|
43
|
+
}
|
|
44
|
+
async load() {
|
|
45
|
+
const options = this.options;
|
|
46
|
+
const response = await fetch(`${options.host}/api/embed/token`, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: { "Content-Type": "application/json" },
|
|
49
|
+
credentials: "include",
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
projectId: options.projectId,
|
|
52
|
+
origin: options.origin,
|
|
53
|
+
userId: options.userId,
|
|
54
|
+
from: options.from,
|
|
55
|
+
to: options.to,
|
|
56
|
+
paths: options.paths,
|
|
57
|
+
ttlSeconds: options.ttlSeconds
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
this.textContent = "FluxTrace: unable to create embed token";
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const { token } = await response.json();
|
|
65
|
+
const iframe = document.createElement("iframe");
|
|
66
|
+
iframe.src = `${options.host}/embed/${encodeURIComponent(options.projectId)}?token=${encodeURIComponent(token)}`;
|
|
67
|
+
iframe.title = "FluxTrace dashboard";
|
|
68
|
+
iframe.loading = "lazy";
|
|
69
|
+
iframe.style.border = "0";
|
|
70
|
+
iframe.style.height = options.height ?? "720px";
|
|
71
|
+
iframe.style.width = "100%";
|
|
72
|
+
this.replaceChildren(iframe);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
if (typeof window !== "undefined" && "customElements" in window) {
|
|
76
|
+
if (!customElements.get("fluxtrace-dashboard")) {
|
|
77
|
+
customElements.define("fluxtrace-dashboard", FluxtraceDashboard);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return __toCommonJS(index_exports);
|
|
81
|
+
})();
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var FluxtraceDashboard = class extends HTMLElement {
|
|
3
|
+
options = null;
|
|
4
|
+
connectedCallback() {
|
|
5
|
+
const projectId = this.getAttribute("project-id");
|
|
6
|
+
if (!projectId) {
|
|
7
|
+
this.textContent = "FluxTrace: project-id is required";
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const pathsRaw = this.getAttribute("paths");
|
|
11
|
+
const paths = pathsRaw ? pathsRaw.split(",").map((p) => p.trim()).filter(Boolean) : void 0;
|
|
12
|
+
const ttlRaw = this.getAttribute("ttl");
|
|
13
|
+
const ttlSeconds = ttlRaw ? Number(ttlRaw) : void 0;
|
|
14
|
+
this.options = {
|
|
15
|
+
projectId,
|
|
16
|
+
origin: this.getAttribute("origin") ?? window.location.origin,
|
|
17
|
+
host: this.getAttribute("host") ?? window.location.origin,
|
|
18
|
+
height: this.getAttribute("height") ?? "720px",
|
|
19
|
+
userId: this.getAttribute("user-id") ?? void 0,
|
|
20
|
+
from: this.getAttribute("from") ?? void 0,
|
|
21
|
+
to: this.getAttribute("to") ?? void 0,
|
|
22
|
+
paths: paths?.length ? paths : void 0,
|
|
23
|
+
ttlSeconds: ttlSeconds != null && Number.isFinite(ttlSeconds) ? ttlSeconds : void 0
|
|
24
|
+
};
|
|
25
|
+
void this.load();
|
|
26
|
+
}
|
|
27
|
+
async load() {
|
|
28
|
+
const options = this.options;
|
|
29
|
+
const response = await fetch(`${options.host}/api/embed/token`, {
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers: { "Content-Type": "application/json" },
|
|
32
|
+
credentials: "include",
|
|
33
|
+
body: JSON.stringify({
|
|
34
|
+
projectId: options.projectId,
|
|
35
|
+
origin: options.origin,
|
|
36
|
+
userId: options.userId,
|
|
37
|
+
from: options.from,
|
|
38
|
+
to: options.to,
|
|
39
|
+
paths: options.paths,
|
|
40
|
+
ttlSeconds: options.ttlSeconds
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
this.textContent = "FluxTrace: unable to create embed token";
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const { token } = await response.json();
|
|
48
|
+
const iframe = document.createElement("iframe");
|
|
49
|
+
iframe.src = `${options.host}/embed/${encodeURIComponent(options.projectId)}?token=${encodeURIComponent(token)}`;
|
|
50
|
+
iframe.title = "FluxTrace dashboard";
|
|
51
|
+
iframe.loading = "lazy";
|
|
52
|
+
iframe.style.border = "0";
|
|
53
|
+
iframe.style.height = options.height ?? "720px";
|
|
54
|
+
iframe.style.width = "100%";
|
|
55
|
+
this.replaceChildren(iframe);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
if (typeof window !== "undefined" && "customElements" in window) {
|
|
59
|
+
if (!customElements.get("fluxtrace-dashboard")) {
|
|
60
|
+
customElements.define("fluxtrace-dashboard", FluxtraceDashboard);
|
|
61
|
+
}
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluxtrace/embed",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.9.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsup src/index.ts --format esm,iife --global-name FluxtraceEmbed --dts --clean",
|
|
14
|
+
"typecheck": "tsc --noEmit"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {}
|
|
17
|
+
}
|
package/README.md
DELETED