@eka-care/medassist-widget-embed 0.2.3 → 0.2.5
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/iframe.js +83 -11
- package/dist/index.d.ts +22 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +59 -29
- package/dist/src/medassist-widget.css +795 -277
- package/dist/src/medassist-widget.js +1074 -458
- package/dist/src/medassist-widget.js.map +1 -1
- package/iframe.ts +110 -10
- package/index.ts +70 -29
- package/package.json +1 -1
- package/src/medassist-widget.css +795 -277
- package/src/medassist-widget.js +1074 -458
- package/src/medassist-widget.js.map +1 -1
- package/test.html +8 -8
package/dist/iframe.js
CHANGED
|
@@ -20,6 +20,53 @@
|
|
|
20
20
|
}
|
|
21
21
|
return undefined;
|
|
22
22
|
};
|
|
23
|
+
const API_FETCH_TIMEOUT_MS = 10000;
|
|
24
|
+
/** Map agent-config API theme to widget theme (mode → textColor: dark→black, light→white) */
|
|
25
|
+
function mapAgentConfigThemeToWidgetTheme(apiTheme) {
|
|
26
|
+
if (!apiTheme)
|
|
27
|
+
return undefined;
|
|
28
|
+
const textColor = apiTheme.mode === "dark"
|
|
29
|
+
? "white"
|
|
30
|
+
: apiTheme.mode === "light"
|
|
31
|
+
? "black"
|
|
32
|
+
: undefined;
|
|
33
|
+
return {
|
|
34
|
+
...(apiTheme.background && { background: apiTheme.background }),
|
|
35
|
+
...(apiTheme.background_img && {
|
|
36
|
+
backgroundImage: apiTheme.background_img,
|
|
37
|
+
}),
|
|
38
|
+
...(apiTheme.accent && { primary: apiTheme.accent }),
|
|
39
|
+
...(textColor && { textColor }),
|
|
40
|
+
...(apiTheme.title_img && { titleImg: apiTheme.title_img }),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Fetch agent-config from API with timeout; aborts if pending > 10s */
|
|
44
|
+
async function fetchAgentConfig(baseUrl, agentId) {
|
|
45
|
+
var _a;
|
|
46
|
+
const url = `${baseUrl.replace(/\/$/, "")}/med-assist/agent-config/${agentId}`;
|
|
47
|
+
const controller = new AbortController();
|
|
48
|
+
const timeoutId = setTimeout(() => controller.abort(), API_FETCH_TIMEOUT_MS);
|
|
49
|
+
try {
|
|
50
|
+
const res = await fetch(url, {
|
|
51
|
+
signal: controller.signal,
|
|
52
|
+
headers: {
|
|
53
|
+
"ngrok-skip-browser-warning": "69420",
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
if (!res.ok)
|
|
57
|
+
return undefined;
|
|
58
|
+
const json = await res.json();
|
|
59
|
+
if ((json === null || json === void 0 ? void 0 : json.success) && ((_a = json === null || json === void 0 ? void 0 : json.data) === null || _a === void 0 ? void 0 : _a.theme))
|
|
60
|
+
return json.data;
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
clearTimeout(timeoutId);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
23
70
|
const DEFAULT_WIDGET_ASSET_BASE = "https://unpkg.com/@eka-care/medassist-widget@latest/dist/";
|
|
24
71
|
const scriptEl = getCurrentScript();
|
|
25
72
|
const scriptBaseUrl = (() => {
|
|
@@ -57,40 +104,65 @@
|
|
|
57
104
|
let widgetCssTextPromise = null;
|
|
58
105
|
// Auto-initialize from URL parameters (no shadow DOM needed in iframe)
|
|
59
106
|
const initializeFromUrlParams = async () => {
|
|
60
|
-
var _a;
|
|
107
|
+
var _a, _b, _c, _d, _e;
|
|
61
108
|
const urlParams = new URLSearchParams(window.location.search);
|
|
62
109
|
const agentId = urlParams.get("agentId");
|
|
63
110
|
if (!agentId) {
|
|
64
111
|
console.error("Agent ID is required in URL parameters");
|
|
65
112
|
return;
|
|
66
113
|
}
|
|
67
|
-
|
|
68
|
-
|
|
114
|
+
let title = urlParams.get("title") || "Medi Clinic";
|
|
115
|
+
let iconUrl = urlParams.get("iconUrl") || undefined;
|
|
69
116
|
const context = urlParams.get("context");
|
|
70
|
-
const baseUrl = urlParams.get("baseUrl") ||
|
|
117
|
+
const baseUrl = urlParams.get("baseUrl") || "https://matrix.eka.care/reloaded";
|
|
71
118
|
const environment = (_a = getEnvironment(urlParams.get("environment"))) !== null && _a !== void 0 ? _a : "production";
|
|
119
|
+
const attributeTheme = urlParams.get("theme")
|
|
120
|
+
? (() => {
|
|
121
|
+
try {
|
|
122
|
+
return JSON.parse(urlParams.get("theme") || "{}");
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
})()
|
|
128
|
+
: undefined;
|
|
72
129
|
const container = document.getElementById("root") || document.body;
|
|
73
130
|
try {
|
|
74
|
-
await Promise.all([
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
]);
|
|
78
|
-
if (!(window === null || window === void 0 ? void 0 : window.renderMedAssist) || typeof (window === null || window === void 0 ? void 0 : window.renderMedAssist) !== "function") {
|
|
131
|
+
await Promise.all([loadWidgetCss(), loadWidgetScript()]);
|
|
132
|
+
if (!(window === null || window === void 0 ? void 0 : window.renderMedAssist) ||
|
|
133
|
+
typeof (window === null || window === void 0 ? void 0 : window.renderMedAssist) !== "function") {
|
|
79
134
|
throw new Error("renderMedAssist is not available on window");
|
|
80
135
|
}
|
|
136
|
+
// Fetch agent-config when baseUrl is available; 10s timeout aborts pending request
|
|
137
|
+
let apiTheme;
|
|
138
|
+
console.log("base url", baseUrl);
|
|
139
|
+
if (baseUrl) {
|
|
140
|
+
try {
|
|
141
|
+
const agentConfig = await fetchAgentConfig(baseUrl, agentId);
|
|
142
|
+
title = (_b = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.name) !== null && _b !== void 0 ? _b : title;
|
|
143
|
+
iconUrl = (_d = (_c = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.theme) === null || _c === void 0 ? void 0 : _c.icon_img) !== null && _d !== void 0 ? _d : iconUrl;
|
|
144
|
+
apiTheme = mapAgentConfigThemeToWidgetTheme((_e = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.theme) !== null && _e !== void 0 ? _e : undefined);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
// ignore; use URL params only
|
|
148
|
+
}
|
|
149
|
+
}
|
|
81
150
|
const config = {
|
|
82
151
|
title,
|
|
83
152
|
iconUrl,
|
|
84
153
|
environment,
|
|
85
154
|
onClose: () => {
|
|
86
|
-
// Send message to parent window to close iframe
|
|
87
155
|
if (window.parent !== window) {
|
|
88
156
|
window.parent.postMessage({ type: "WIDGET_CLOSE" }, "*");
|
|
89
157
|
}
|
|
90
158
|
},
|
|
91
159
|
context: context ? JSON.parse(context) : undefined,
|
|
92
160
|
baseUrl,
|
|
93
|
-
displayMode: "full",
|
|
161
|
+
displayMode: "full",
|
|
162
|
+
theme: {
|
|
163
|
+
...(apiTheme !== null && apiTheme !== void 0 ? apiTheme : {}),
|
|
164
|
+
...(attributeTheme !== null && attributeTheme !== void 0 ? attributeTheme : {}),
|
|
165
|
+
},
|
|
94
166
|
};
|
|
95
167
|
window.renderMedAssist(container, agentId, config);
|
|
96
168
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,18 @@ type WidgetEnvironment = "production" | "development" | "staging";
|
|
|
3
3
|
declare const getEnvironment: (value: string | null) => WidgetEnvironment | undefined;
|
|
4
4
|
declare const scriptEl: HTMLScriptElement | null;
|
|
5
5
|
declare const DEFAULT_WIDGET_ASSET_BASE: string;
|
|
6
|
+
/** Theme from agent-config API (has mode; textColor derived: dark → black, light → white) */
|
|
7
|
+
type AgentConfig = {
|
|
8
|
+
name?: string;
|
|
9
|
+
theme?: {
|
|
10
|
+
background?: string;
|
|
11
|
+
background_img?: string;
|
|
12
|
+
accent?: string;
|
|
13
|
+
mode?: "light" | "dark";
|
|
14
|
+
title_img?: string;
|
|
15
|
+
icon_img?: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
6
18
|
type MedAssistInitConfig = {
|
|
7
19
|
auth?: string;
|
|
8
20
|
agentId?: string;
|
|
@@ -10,8 +22,18 @@ type MedAssistInitConfig = {
|
|
|
10
22
|
title?: string;
|
|
11
23
|
iconUrl?: string;
|
|
12
24
|
baseUrl?: string;
|
|
25
|
+
theme?: {
|
|
26
|
+
background?: string;
|
|
27
|
+
backgroundImage?: string;
|
|
28
|
+
primary?: string;
|
|
29
|
+
textColor?: "black" | "white";
|
|
30
|
+
};
|
|
13
31
|
[key: string]: unknown;
|
|
14
32
|
};
|
|
33
|
+
/** Map agent-config API theme to widget theme (mode → textColor: dark→black, light→white) */
|
|
34
|
+
declare function mapAgentConfigThemeToWidgetTheme(apiTheme: AgentConfig["theme"] | undefined): MedAssistInitConfig["theme"];
|
|
35
|
+
/** Fetch agent-config from API and return theme from response data */
|
|
36
|
+
declare function fetchAgentConfig(baseUrl: string, agentId: string): Promise<AgentConfig | undefined>;
|
|
15
37
|
interface EkaMedAssistWindow extends Window {
|
|
16
38
|
EkaMedAssist?: {
|
|
17
39
|
init: (config: MedAssistInitConfig) => void;
|
|
@@ -35,7 +57,6 @@ declare class MedAssistWidgetLoader extends HTMLElement {
|
|
|
35
57
|
static get observedAttributes(): string[];
|
|
36
58
|
connectedCallback(): void;
|
|
37
59
|
attributeChangedCallback(name: string): void;
|
|
38
|
-
private preloadResources;
|
|
39
60
|
private setupAuthExpirationListener;
|
|
40
61
|
openFromBridge(): void;
|
|
41
62
|
renderButton(): void;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,gBAAgB,QAAO,iBAAiB,GAAG,IAahD,CAAC;AAEF,KAAK,iBAAiB,GAAG,YAAY,GAAG,aAAa,GAAG,SAAS,CAAC;AAElE,QAAA,MAAM,cAAc,GAClB,OAAO,MAAM,GAAG,IAAI,KACnB,iBAAiB,GAAG,SAStB,CAAC;AAEF,QAAA,MAAM,QA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a,IAAI,OAAO,CAAC,IAAI,CAAC;IA4BpC,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;CA0ClC"}
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,35 @@ const DEFAULT_WIDGET_ASSET_BASE = (() => {
|
|
|
28
28
|
}
|
|
29
29
|
return "https://unpkg.com/@eka-care/medassist-widget@latest/dist/";
|
|
30
30
|
})();
|
|
31
|
+
/** Map agent-config API theme to widget theme (mode → textColor: dark→black, light→white) */
|
|
32
|
+
function mapAgentConfigThemeToWidgetTheme(apiTheme) {
|
|
33
|
+
if (!apiTheme)
|
|
34
|
+
return undefined;
|
|
35
|
+
const textColor = apiTheme.mode === "dark" ? "white" : apiTheme.mode === "light" ? "black" : undefined;
|
|
36
|
+
return {
|
|
37
|
+
...(apiTheme.background && { background: apiTheme.background }),
|
|
38
|
+
...(apiTheme.background_img && { backgroundImage: apiTheme.background_img }),
|
|
39
|
+
...(apiTheme.accent && { primary: apiTheme.accent }),
|
|
40
|
+
...(textColor && { textColor }),
|
|
41
|
+
...(apiTheme.title_img && { titleImg: apiTheme.title_img }),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Fetch agent-config from API and return theme from response data */
|
|
45
|
+
async function fetchAgentConfig(baseUrl, agentId) {
|
|
46
|
+
var _a;
|
|
47
|
+
const url = `${baseUrl.replace(/\/$/, "")}/med-assist/agent-config/${agentId}`;
|
|
48
|
+
const res = await fetch(url, {
|
|
49
|
+
headers: {
|
|
50
|
+
"ngrok-skip-browser-warning": "69420",
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
if (!res.ok)
|
|
54
|
+
return undefined;
|
|
55
|
+
const json = await res.json();
|
|
56
|
+
if ((json === null || json === void 0 ? void 0 : json.success) && ((_a = json === null || json === void 0 ? void 0 : json.data) === null || _a === void 0 ? void 0 : _a.theme))
|
|
57
|
+
return json.data;
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
31
60
|
const globalMedAssistConfig = {};
|
|
32
61
|
const getWidgetElement = () => {
|
|
33
62
|
if (typeof document === "undefined") {
|
|
@@ -105,7 +134,6 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
105
134
|
this.defaultIconUrl = "https://cdn.eka.care/bot-icon.svg";
|
|
106
135
|
this.widgetLoaded = false;
|
|
107
136
|
this.displayMode = this.getAttribute("display-mode") === "full" ? "full" : "widget";
|
|
108
|
-
this.preloadResources();
|
|
109
137
|
// Listen for AUTH_EXPIRED events from the widget and forward to parent
|
|
110
138
|
this.setupAuthExpirationListener();
|
|
111
139
|
}
|
|
@@ -139,26 +167,6 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
139
167
|
}
|
|
140
168
|
}
|
|
141
169
|
}
|
|
142
|
-
// Preload resources in the background
|
|
143
|
-
preloadResources() {
|
|
144
|
-
// Preload CSS (browser will cache it)
|
|
145
|
-
if (!document.querySelector(`link[href="${WIDGET_CSS_URL}"]`)) {
|
|
146
|
-
const cssLink = document.createElement("link");
|
|
147
|
-
cssLink.rel = "preload";
|
|
148
|
-
cssLink.href = WIDGET_CSS_URL;
|
|
149
|
-
cssLink.as = "style";
|
|
150
|
-
document.head.appendChild(cssLink);
|
|
151
|
-
}
|
|
152
|
-
// Preload JS (browser will cache it)
|
|
153
|
-
if (!document.querySelector(`link[href="${WIDGET_JS_URL}"]`)) {
|
|
154
|
-
const jsLink = document.createElement("link");
|
|
155
|
-
jsLink.rel = "preload";
|
|
156
|
-
jsLink.href = WIDGET_JS_URL;
|
|
157
|
-
jsLink.as = "script";
|
|
158
|
-
jsLink.crossOrigin = "anonymous";
|
|
159
|
-
document.head.appendChild(jsLink);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
170
|
setupAuthExpirationListener() {
|
|
163
171
|
if (typeof window === "undefined")
|
|
164
172
|
return;
|
|
@@ -181,7 +189,8 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
181
189
|
else {
|
|
182
190
|
this.renderButton();
|
|
183
191
|
}
|
|
184
|
-
|
|
192
|
+
this.loadWidgetCss()
|
|
193
|
+
.then(() => this.loadWidgetScript())
|
|
185
194
|
.then(() => this.loadAndRender())
|
|
186
195
|
.catch((error) => {
|
|
187
196
|
console.error("Failed to open MedAssist widget from bridge", error);
|
|
@@ -275,7 +284,7 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
275
284
|
}
|
|
276
285
|
}
|
|
277
286
|
async loadAndRender() {
|
|
278
|
-
var _a, _b, _c;
|
|
287
|
+
var _a, _b, _c, _d;
|
|
279
288
|
const shadowRoot = this.shadowRoot;
|
|
280
289
|
if (!shadowRoot) {
|
|
281
290
|
console.error("Shadow root is not available");
|
|
@@ -284,13 +293,19 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
284
293
|
const button = shadowRoot.getElementById("medassist-open-btn");
|
|
285
294
|
const rootElement = shadowRoot.getElementById("medassist-widget-root");
|
|
286
295
|
const agentId = this.getAttribute("agent-id");
|
|
287
|
-
|
|
296
|
+
let iconUrl = this.getAttribute("icon-url") || this.defaultIconUrl;
|
|
288
297
|
const environment = (_a = getEnvironment(this.getAttribute("environment"))) !== null && _a !== void 0 ? _a : "production";
|
|
289
|
-
|
|
290
|
-
const baseUrl = this.getAttribute("base-url") ||
|
|
298
|
+
let title = this.getAttribute("title") || "Medi Clinic";
|
|
299
|
+
const baseUrl = this.getAttribute("base-url") || "https://matrix.eka.care/reloaded";
|
|
291
300
|
const displayModeAttribute = this.getAttribute("display-mode");
|
|
292
301
|
const displayMode = displayModeAttribute === "full" ? "full" : "widget";
|
|
293
302
|
const attributeContext = this.getAttribute("context") ? JSON.parse(this.getAttribute("context") || "{}") : undefined;
|
|
303
|
+
const attributeTheme = this.getAttribute("theme") ? (() => { try {
|
|
304
|
+
return JSON.parse(this.getAttribute("theme") || "{}");
|
|
305
|
+
}
|
|
306
|
+
catch {
|
|
307
|
+
return undefined;
|
|
308
|
+
} })() : undefined;
|
|
294
309
|
const initConfig = (typeof window !== "undefined"
|
|
295
310
|
? window.__ekaMedAssistConfig__
|
|
296
311
|
: undefined) || {};
|
|
@@ -300,6 +315,7 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
300
315
|
};
|
|
301
316
|
const auth = initConfig.auth || undefined;
|
|
302
317
|
const resolvedAgentId = initConfig.agentId || agentId;
|
|
318
|
+
const apiBaseUrl = initConfig.baseUrl || baseUrl;
|
|
303
319
|
const customOnClose = typeof window !== "undefined" ? (_b = window.EkaMedAssist) === null || _b === void 0 ? void 0 : _b.onClose : undefined;
|
|
304
320
|
if (!resolvedAgentId) {
|
|
305
321
|
console.error("Agent ID is required");
|
|
@@ -313,6 +329,19 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
313
329
|
button.classList.add("hidden");
|
|
314
330
|
}
|
|
315
331
|
rootElement.classList.remove("hidden");
|
|
332
|
+
// Fetch agent-config when baseUrl is available; derive theme (mode → textColor: dark→black, light→white)
|
|
333
|
+
let apiTheme = undefined;
|
|
334
|
+
if (apiBaseUrl) {
|
|
335
|
+
try {
|
|
336
|
+
const agentConfig = await fetchAgentConfig(apiBaseUrl, resolvedAgentId);
|
|
337
|
+
title = (agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.name) || title;
|
|
338
|
+
iconUrl = ((_c = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.theme) === null || _c === void 0 ? void 0 : _c.icon_img) || iconUrl;
|
|
339
|
+
apiTheme = mapAgentConfigThemeToWidgetTheme((agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.theme) || undefined);
|
|
340
|
+
}
|
|
341
|
+
catch {
|
|
342
|
+
// ignore; use attribute + init theme only
|
|
343
|
+
}
|
|
344
|
+
}
|
|
316
345
|
const widgetConfig = {
|
|
317
346
|
title: initConfig.title || title,
|
|
318
347
|
iconUrl: initConfig.iconUrl || iconUrl,
|
|
@@ -326,13 +355,14 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
326
355
|
}
|
|
327
356
|
rootElement.classList.add("hidden");
|
|
328
357
|
},
|
|
329
|
-
baseUrl:
|
|
358
|
+
baseUrl: apiBaseUrl,
|
|
330
359
|
context: mergedContext,
|
|
331
360
|
displayMode,
|
|
332
|
-
auth
|
|
361
|
+
auth,
|
|
362
|
+
theme: { ...(apiTheme || {}), ...(attributeTheme || {}), ...(initConfig.theme || {}) }
|
|
333
363
|
};
|
|
334
364
|
if (this.widgetLoaded) {
|
|
335
|
-
(
|
|
365
|
+
(_d = window.renderMedAssist) === null || _d === void 0 ? void 0 : _d.call(window, rootElement, resolvedAgentId, widgetConfig);
|
|
336
366
|
return;
|
|
337
367
|
}
|
|
338
368
|
try {
|