rivia 0.0.88 → 0.0.90
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.js +181 -55
- package/index.d.ts +18 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4309,40 +4309,139 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4309
4309
|
name: "abc",
|
|
4310
4310
|
user_avatar: null,
|
|
4311
4311
|
url: "https://img.freepik.com/free-photo/closeup-scarlet-macaw-from-side-view-scarlet-macaw-closeup-head_488145-3540.jpg?semt=ais_hybrid&w=740&q=80",
|
|
4312
|
-
email: "priyanshu@yopmail.com"
|
|
4312
|
+
email: "priyanshu@yopmail.com",
|
|
4313
|
+
// hardcoded preview id while debugging
|
|
4314
|
+
changelogPreviewId: "outplay"
|
|
4313
4315
|
};
|
|
4314
4316
|
const state = {
|
|
4315
4317
|
initialized: false,
|
|
4316
4318
|
config: {},
|
|
4317
4319
|
widgetEl: null,
|
|
4318
4320
|
backdropEl: null,
|
|
4319
|
-
pmUserId: null
|
|
4321
|
+
pmUserId: null,
|
|
4322
|
+
changelogEntries: [],
|
|
4323
|
+
// ✅ store API data
|
|
4324
|
+
titleFontSize: null,
|
|
4325
|
+
// for dynamic spacing when preview styles are applied
|
|
4326
|
+
workspaceId: null
|
|
4327
|
+
// to track current workspace for dynamic updates
|
|
4320
4328
|
};
|
|
4321
4329
|
function mergeConfig(cfg) {
|
|
4322
4330
|
state.config = Object.assign({}, defaults, cfg || {});
|
|
4323
4331
|
}
|
|
4332
|
+
async function fetchCSS(previewId, widget, header, body) {
|
|
4333
|
+
if (!previewId) return;
|
|
4334
|
+
try {
|
|
4335
|
+
console.log("Fetching preview styles for id:", previewId);
|
|
4336
|
+
const res = await fetch(`https://demoapi.rivia.ai/change_logs_preview_by_workspace_name/${previewId}`);
|
|
4337
|
+
if (!res.ok) throw new Error("Failed to fetch preview styles");
|
|
4338
|
+
const response = await res.json();
|
|
4339
|
+
const data = response?.message?.[0];
|
|
4340
|
+
console.log("Applying preview styles:", data);
|
|
4341
|
+
if (data.width) {
|
|
4342
|
+
widget.style.width = data.width;
|
|
4343
|
+
widget.style.maxWidth = data.width;
|
|
4344
|
+
}
|
|
4345
|
+
if (data.backgroundColor)
|
|
4346
|
+
widget.style.backgroundColor = data.backgroundColor;
|
|
4347
|
+
if (data.borderRadius)
|
|
4348
|
+
widget.style.borderRadius = data.borderRadius;
|
|
4349
|
+
if (data.fontFamily)
|
|
4350
|
+
widget.style.fontFamily = data.fontFamily;
|
|
4351
|
+
if (data.padding)
|
|
4352
|
+
body.style.padding = data.padding;
|
|
4353
|
+
if (data.bodyFontSize)
|
|
4354
|
+
body.style.fontSize = data.bodyFontSize;
|
|
4355
|
+
if (data.bodyColor)
|
|
4356
|
+
body.style.color = data.bodyColor;
|
|
4357
|
+
if (data.titleFontSize) {
|
|
4358
|
+
header.style.fontSize = data.titleFontSize;
|
|
4359
|
+
state.titleFontSize = data.titleFontSize;
|
|
4360
|
+
}
|
|
4361
|
+
if (data.titleColor)
|
|
4362
|
+
header.style.color = data.titleColor;
|
|
4363
|
+
} catch (err) {
|
|
4364
|
+
console.error("Preview CSS load failed:", err);
|
|
4365
|
+
}
|
|
4366
|
+
}
|
|
4324
4367
|
function ensureStyles() {
|
|
4325
4368
|
if (document.getElementById("pm-lite-styles")) return;
|
|
4326
4369
|
const css = `
|
|
4327
|
-
.pm-lite-backdrop{position:fixed;inset:0;background:rgba(
|
|
4370
|
+
.pm-lite-backdrop{position:fixed;inset:0;background:rgba(255, 255, 255, 0);display:none;z-index:9998}
|
|
4328
4371
|
.pm-lite-widget{position:fixed;z-index:9999;max-width:420px;width:clamp(280px,30vw,420px);box-shadow:0 10px 40px rgba(0,0,0,0.2);border-radius:12px;overflow:hidden;font-family:Inter,system-ui,Segoe UI,Roboto,Arial,sans-serif}
|
|
4329
4372
|
.pm-lite-widget.light{background:#fff;color:#111}
|
|
4330
4373
|
.pm-lite-widget.dark{background:#111;color:#eee}
|
|
4331
|
-
.pm-lite-header{
|
|
4374
|
+
.pm-lite-header{
|
|
4375
|
+
|
|
4376
|
+
padding:6px;
|
|
4377
|
+
padding-top:15px; /* default is 12px, can be overridden by preview styles */
|
|
4378
|
+
font-weight:600;
|
|
4379
|
+
position:relative;
|
|
4380
|
+
|
|
4381
|
+
display:flex;
|
|
4382
|
+
align-items:center;
|
|
4383
|
+
justify-content:center;
|
|
4384
|
+
}
|
|
4385
|
+
.pm-lite-rivia-btn{
|
|
4386
|
+
display:block;
|
|
4387
|
+
margin-left:auto;
|
|
4388
|
+
color:#2563eb; /* blue */
|
|
4389
|
+
font-style:italic;
|
|
4390
|
+
font-size:13px;
|
|
4391
|
+
background:transparent;
|
|
4392
|
+
border:none;
|
|
4393
|
+
cursor:pointer;
|
|
4394
|
+
font-family: Inter, system-ui, Segoe UI, Roboto, Arial, sans-serif;
|
|
4395
|
+
padding:3px 15px;
|
|
4396
|
+
|
|
4397
|
+
}
|
|
4398
|
+
.pm-lite-rivia-label{
|
|
4399
|
+
display:block;
|
|
4400
|
+
margin-right:auto;
|
|
4401
|
+
color:rgba(0,0,0,0.6);
|
|
4402
|
+
font-style:italic;
|
|
4403
|
+
font-size:12px;
|
|
4404
|
+
font-family: Inter, system-ui, Segoe UI, Roboto, Arial, sans-serif;
|
|
4405
|
+
padding-left:18px;
|
|
4406
|
+
}
|
|
4332
4407
|
.pm-lite-badge{font-size:12px;margin-left:8px;color:rgba(0,0,0,0.6)}
|
|
4333
|
-
.pm-lite-body{max-height:60vh;overflow:auto;
|
|
4334
|
-
|
|
4408
|
+
.pm-lite-body{max-height:60vh;overflow:auto;
|
|
4409
|
+
|
|
4410
|
+
overflow: visible; /* remove scroll */
|
|
4411
|
+
height: auto; /* dynamic height */
|
|
4412
|
+
max-height: none; }
|
|
4413
|
+
.pm-lite-item{
|
|
4414
|
+
box-sizing:border-box;
|
|
4415
|
+
margin-bottom:6px;
|
|
4416
|
+
padding:6px 7px;
|
|
4417
|
+
border:1px solid rgba(0,0,0,0.08);
|
|
4418
|
+
border-radius:8px;
|
|
4419
|
+
background:#ffffff;
|
|
4420
|
+
/* isolate from external CSS */
|
|
4421
|
+
font-family:inherit;
|
|
4422
|
+
line-height:1.4;
|
|
4423
|
+
}
|
|
4335
4424
|
.pm-lite-item.unread{background:linear-gradient(90deg,rgba(255,245,235,0.6),transparent)}
|
|
4336
4425
|
.pm-lite-close{position:absolute;right:8px;top:8px;border:none;background:transparent;font-size:16px;cursor:pointer}
|
|
4337
|
-
.pm-lite-tags{font-size:12px;opacity:0.8;
|
|
4426
|
+
.pm-lite-tags{font-size:12px;opacity:0.8;}
|
|
4338
4427
|
.pm-lite-link{display:inline-block;margin-top:6px;font-size:13px}
|
|
4428
|
+
.pm-lite-tags{
|
|
4429
|
+
display:inline-block;
|
|
4430
|
+
background-color:rgb(220, 252, 231);
|
|
4431
|
+
color:rgb(22, 101, 52);
|
|
4432
|
+
border-radius:999px;
|
|
4433
|
+
padding:2px 8px;
|
|
4434
|
+
font-size:12px;
|
|
4435
|
+
font-weight:bold;
|
|
4436
|
+
font:Verdana, sans-serif;
|
|
4437
|
+
}
|
|
4339
4438
|
`;
|
|
4340
4439
|
const style = document.createElement("style");
|
|
4341
4440
|
style.id = "pm-lite-styles";
|
|
4342
4441
|
style.appendChild(document.createTextNode(css));
|
|
4343
4442
|
document.head.appendChild(style);
|
|
4344
4443
|
}
|
|
4345
|
-
function createWidgetShell() {
|
|
4444
|
+
async function createWidgetShell() {
|
|
4346
4445
|
if (state.widgetEl) return;
|
|
4347
4446
|
ensureStyles();
|
|
4348
4447
|
const backdrop = document.createElement("div");
|
|
@@ -4353,7 +4452,8 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4353
4452
|
widget.setAttribute("role", "dialog");
|
|
4354
4453
|
const header = document.createElement("div");
|
|
4355
4454
|
header.className = "pm-lite-header";
|
|
4356
|
-
header.innerText = "
|
|
4455
|
+
header.innerText = "Latest Updates";
|
|
4456
|
+
header.paddingTop = "10px";
|
|
4357
4457
|
const badge = document.createElement("span");
|
|
4358
4458
|
badge.className = "pm-lite-badge";
|
|
4359
4459
|
badge.style.display = "none";
|
|
@@ -4365,18 +4465,33 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4365
4465
|
const body = document.createElement("div");
|
|
4366
4466
|
body.className = "pm-lite-body";
|
|
4367
4467
|
body.innerHTML = '<div class="pm-lite-loading">Loading\u2026</div>';
|
|
4468
|
+
const footerRow = document.createElement("div");
|
|
4469
|
+
footerRow.style.display = "flex";
|
|
4470
|
+
footerRow.style.alignItems = "center";
|
|
4471
|
+
footerRow.style.justifyContent = "space-between";
|
|
4472
|
+
footerRow.style.marginTop = "5px";
|
|
4473
|
+
footerRow.style.marginBottom = "5px";
|
|
4474
|
+
const riviaLabel = document.createElement("span");
|
|
4475
|
+
riviaLabel.className = "pm-lite-rivia-label";
|
|
4476
|
+
riviaLabel.innerText = "Powered by Rivia";
|
|
4477
|
+
riviaLabel.style.fontSize = "12px";
|
|
4478
|
+
riviaLabel.style.opacity = "0.7";
|
|
4368
4479
|
const riviaBtn = document.createElement("button");
|
|
4369
4480
|
riviaBtn.className = "pm-lite-rivia-btn";
|
|
4370
|
-
riviaBtn.innerText = "
|
|
4481
|
+
riviaBtn.innerText = "See all changes";
|
|
4482
|
+
footerRow.appendChild(riviaLabel);
|
|
4483
|
+
footerRow.appendChild(riviaBtn);
|
|
4371
4484
|
riviaBtn.addEventListener("click", () => {
|
|
4372
|
-
const baseUrl = `http://${state.config.workspace}.rivia.ai/users/changelog?userId=${state.pmUserId || ""}`;
|
|
4485
|
+
const baseUrl = `http://${state.config.workspace}.rivia.ai:8080/users/changelog?userId=${state.pmUserId || ""}`;
|
|
4373
4486
|
const url = new URL(baseUrl);
|
|
4374
4487
|
window.open(url.toString(), "_blank");
|
|
4375
4488
|
});
|
|
4376
4489
|
widget.appendChild(header);
|
|
4377
|
-
|
|
4378
|
-
|
|
4490
|
+
const divider = document.createElement("div");
|
|
4491
|
+
divider.style.borderTop = "1px solid rgba(0,0,0,0.08)";
|
|
4379
4492
|
widget.appendChild(body);
|
|
4493
|
+
widget.appendChild(divider);
|
|
4494
|
+
widget.appendChild(footerRow);
|
|
4380
4495
|
document.body.appendChild(backdrop);
|
|
4381
4496
|
document.body.appendChild(widget);
|
|
4382
4497
|
state.backdropEl = backdrop;
|
|
@@ -4384,6 +4499,8 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4384
4499
|
state.widgetBody = body;
|
|
4385
4500
|
state.widgetHeader = header;
|
|
4386
4501
|
state.widgetBadge = badge;
|
|
4502
|
+
console.log("Widget shell created, now fetching preview CSS if available...", state.config.workspace);
|
|
4503
|
+
await fetchCSS(state.config.workspace, widget, header, body);
|
|
4387
4504
|
positionWidget();
|
|
4388
4505
|
window.addEventListener("resize", positionWidget);
|
|
4389
4506
|
}
|
|
@@ -4412,12 +4529,9 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4412
4529
|
}
|
|
4413
4530
|
async function fetchChangelog(id) {
|
|
4414
4531
|
if (state.config.initialData) {
|
|
4415
|
-
|
|
4416
|
-
if (candidate && (candidate.integration_id === id || candidate.id === id || candidate.integration_id === candidate.id && !id)) {
|
|
4417
|
-
return candidate;
|
|
4418
|
-
}
|
|
4532
|
+
return state.config.initialData;
|
|
4419
4533
|
}
|
|
4420
|
-
let urlStr =
|
|
4534
|
+
let urlStr = `https://demoapi.rivia.ai/change_logs_by_workspace_name`;
|
|
4421
4535
|
if (!urlStr) throw new Error("apiUrl is not configured");
|
|
4422
4536
|
if (id) {
|
|
4423
4537
|
if (urlStr.includes("{id}")) urlStr = urlStr.replace("{id}", encodeURIComponent(id));
|
|
@@ -4429,55 +4543,69 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4429
4543
|
const headers = Object.assign({}, state.config.fetchOptions.headers || {});
|
|
4430
4544
|
const opts = Object.assign({ method: "GET", headers }, state.config.fetchOptions);
|
|
4431
4545
|
const res = await fetch(url.toString(), opts);
|
|
4432
|
-
if (!res.ok)
|
|
4546
|
+
if (!res.ok) {
|
|
4547
|
+
throw new Error("Failed to fetch changelog: " + res.status + " " + res.statusText);
|
|
4548
|
+
}
|
|
4433
4549
|
const payload = await res.json();
|
|
4434
|
-
|
|
4435
|
-
return
|
|
4550
|
+
state.changelogEntries = payload.message || [];
|
|
4551
|
+
return state.changelogEntries;
|
|
4436
4552
|
} catch (err) {
|
|
4437
4553
|
throw err;
|
|
4438
4554
|
}
|
|
4439
4555
|
}
|
|
4440
4556
|
function renderChangelog(data) {
|
|
4441
4557
|
if (!state.widgetBody) return;
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
state.widgetBadge.style.display = "inline-block";
|
|
4445
|
-
state.widgetBadge.innerText = `(${data.unread_count} new)`;
|
|
4446
|
-
} else {
|
|
4447
|
-
state.widgetBadge.style.display = "none";
|
|
4558
|
+
if (state.widgetHeader.childNodes[0]) {
|
|
4559
|
+
state.widgetHeader.childNodes[0].nodeValue = "Latest Updates";
|
|
4448
4560
|
}
|
|
4449
|
-
|
|
4450
|
-
if (!items.length) {
|
|
4561
|
+
if (!data || !data.length) {
|
|
4451
4562
|
state.widgetBody.innerHTML = '<div class="pm-lite-empty">No updates yet.</div>';
|
|
4452
4563
|
return;
|
|
4453
4564
|
}
|
|
4454
4565
|
const frag = document.createDocumentFragment();
|
|
4455
|
-
|
|
4566
|
+
let i = 0;
|
|
4567
|
+
data.forEach((it) => {
|
|
4568
|
+
i++;
|
|
4569
|
+
if (i > 3) return;
|
|
4456
4570
|
const div = document.createElement("div");
|
|
4457
|
-
|
|
4458
|
-
|
|
4571
|
+
div.className = "pm-lite-item";
|
|
4572
|
+
const date = it.created_at ? new Date(it.created_at).toLocaleDateString() : "";
|
|
4573
|
+
if (it.label) {
|
|
4574
|
+
const tag = document.createElement("span");
|
|
4575
|
+
tag.className = "pm-lite-tags";
|
|
4576
|
+
tag.innerText = it.label;
|
|
4577
|
+
tag.style.display = "inline-block";
|
|
4578
|
+
tag.style.borderRadius = "999px";
|
|
4579
|
+
tag.style.fontSize = "11px";
|
|
4580
|
+
tag.style.fontWeight = "bold";
|
|
4581
|
+
tag.style.fontFamily = "Verdana, sans-serif";
|
|
4582
|
+
tag.style.backgroundColor = "rgb(220, 252, 231)";
|
|
4583
|
+
tag.style.color = "rgb(22, 101, 52)";
|
|
4584
|
+
tag.style.border = "1px solid rgb(187, 247, 208)";
|
|
4585
|
+
div.appendChild(tag);
|
|
4586
|
+
}
|
|
4459
4587
|
const header = document.createElement("div");
|
|
4588
|
+
header.className = "pm-lite-item-header";
|
|
4460
4589
|
header.style.fontWeight = "600";
|
|
4461
|
-
header.innerText =
|
|
4590
|
+
header.innerText = `${it.title || "Untitled"} `;
|
|
4591
|
+
header.style.display = "-webkit-box";
|
|
4592
|
+
header.style.webkitLineClamp = "1";
|
|
4593
|
+
header.style.webkitBoxOrient = "vertical";
|
|
4594
|
+
header.style.overflow = "hidden";
|
|
4595
|
+
header.style.textOverflow = "ellipsis";
|
|
4596
|
+
header.style.fontSize = state.titleFontSize;
|
|
4462
4597
|
const content = document.createElement("div");
|
|
4463
|
-
content.innerHTML =
|
|
4598
|
+
content.innerHTML = it.text || "";
|
|
4599
|
+
content.style.display = "-webkit-box";
|
|
4600
|
+
content.style.webkitLineClamp = "3";
|
|
4601
|
+
content.style.webkitBoxOrient = "vertical";
|
|
4602
|
+
content.style.overflow = "hidden";
|
|
4603
|
+
content.style.textOverflow = "ellipsis";
|
|
4604
|
+
content.querySelectorAll("b, strong").forEach((el) => {
|
|
4605
|
+
el.style.fontWeight = "normal";
|
|
4606
|
+
});
|
|
4464
4607
|
div.appendChild(header);
|
|
4465
4608
|
div.appendChild(content);
|
|
4466
|
-
if (Array.isArray(it.tags) && it.tags.length) {
|
|
4467
|
-
const tags = document.createElement("div");
|
|
4468
|
-
tags.className = "pm-lite-tags";
|
|
4469
|
-
tags.innerHTML = it.tags.map((t) => `<span>#${escapeHtml(t)}</span>`).join(" ");
|
|
4470
|
-
div.appendChild(tags);
|
|
4471
|
-
}
|
|
4472
|
-
if (it.url) {
|
|
4473
|
-
const a = document.createElement("a");
|
|
4474
|
-
a.className = "pm-lite-link";
|
|
4475
|
-
a.href = it.url;
|
|
4476
|
-
a.target = "_blank";
|
|
4477
|
-
a.rel = "noopener noreferrer";
|
|
4478
|
-
a.innerText = "Read more";
|
|
4479
|
-
div.appendChild(a);
|
|
4480
|
-
}
|
|
4481
4609
|
frag.appendChild(div);
|
|
4482
4610
|
});
|
|
4483
4611
|
state.widgetBody.innerHTML = "";
|
|
@@ -4492,6 +4620,7 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4492
4620
|
function showWidget() {
|
|
4493
4621
|
if (!state.widgetEl) createWidgetShell();
|
|
4494
4622
|
state.backdropEl.style.display = "block";
|
|
4623
|
+
state.widgetEl.style.visibility = "hidden";
|
|
4495
4624
|
state.widgetEl.style.display = "block";
|
|
4496
4625
|
}
|
|
4497
4626
|
function closeWidget() {
|
|
@@ -4558,11 +4687,8 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4558
4687
|
const el = e.target.closest(state.config.buttonSelector);
|
|
4559
4688
|
if (!el) return;
|
|
4560
4689
|
e.preventDefault();
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
const url = new URL(baseUrl);
|
|
4564
|
-
window.open(url.toString(), "_blank");
|
|
4565
|
-
}
|
|
4690
|
+
const id = el.getAttribute("data-pm-changelog");
|
|
4691
|
+
openWidgetFor(state.config.workspace || id);
|
|
4566
4692
|
});
|
|
4567
4693
|
}
|
|
4568
4694
|
async function syncUserFromConfig() {
|
|
@@ -4580,7 +4706,7 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4580
4706
|
url: cfg.url
|
|
4581
4707
|
};
|
|
4582
4708
|
try {
|
|
4583
|
-
const res = await fetch(
|
|
4709
|
+
const res = await fetch(`https://demoapi.rivia.ai/pm_users`, {
|
|
4584
4710
|
method: "POST",
|
|
4585
4711
|
headers: {
|
|
4586
4712
|
"Content-Type": "application/json"
|
package/index.d.ts
CHANGED
|
@@ -46,6 +46,24 @@ declare function ProductManagement(): {
|
|
|
46
46
|
destroy(): void;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
+
declare global {
|
|
50
|
+
interface Window {
|
|
51
|
+
ProductManagement: {
|
|
52
|
+
init(config: ProductManagementConfig): void;
|
|
53
|
+
open(id?: string): void;
|
|
54
|
+
close(): void;
|
|
55
|
+
setConfig(config: Partial<ProductManagementConfig>): void;
|
|
56
|
+
attachButton(): void;
|
|
57
|
+
destroy(): void;
|
|
58
|
+
name?: string;
|
|
59
|
+
email?: string;
|
|
60
|
+
workspace?: string;
|
|
61
|
+
user_avatar?: string;
|
|
62
|
+
};
|
|
63
|
+
triggerEvent: typeof triggerEvent;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
49
67
|
declare function Tours(tourId: string, userId: object): void ;
|
|
50
68
|
export { Checklist,Banner, Tours, ProductManagement};
|
|
51
69
|
|