@eka-care/medassist-widget-embed 0.2.4 → 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 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -7
- 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 +69 -6
- 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;
|
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,QAAQ,0BAAqB,CAAC;AAGpC,QAAA,MAAM,yBAAyB,QAK3B,CAAC;AAEL,KAAK,mBAAmB,GAAG;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,KAAK,CAAC,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AI,OAAO,CAAC,IAAI,CAAC;IA0G9B,aAAa,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") {
|
|
@@ -255,7 +284,7 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
255
284
|
}
|
|
256
285
|
}
|
|
257
286
|
async loadAndRender() {
|
|
258
|
-
var _a, _b, _c;
|
|
287
|
+
var _a, _b, _c, _d;
|
|
259
288
|
const shadowRoot = this.shadowRoot;
|
|
260
289
|
if (!shadowRoot) {
|
|
261
290
|
console.error("Shadow root is not available");
|
|
@@ -264,13 +293,19 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
264
293
|
const button = shadowRoot.getElementById("medassist-open-btn");
|
|
265
294
|
const rootElement = shadowRoot.getElementById("medassist-widget-root");
|
|
266
295
|
const agentId = this.getAttribute("agent-id");
|
|
267
|
-
|
|
296
|
+
let iconUrl = this.getAttribute("icon-url") || this.defaultIconUrl;
|
|
268
297
|
const environment = (_a = getEnvironment(this.getAttribute("environment"))) !== null && _a !== void 0 ? _a : "production";
|
|
269
|
-
|
|
270
|
-
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";
|
|
271
300
|
const displayModeAttribute = this.getAttribute("display-mode");
|
|
272
301
|
const displayMode = displayModeAttribute === "full" ? "full" : "widget";
|
|
273
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;
|
|
274
309
|
const initConfig = (typeof window !== "undefined"
|
|
275
310
|
? window.__ekaMedAssistConfig__
|
|
276
311
|
: undefined) || {};
|
|
@@ -280,6 +315,7 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
280
315
|
};
|
|
281
316
|
const auth = initConfig.auth || undefined;
|
|
282
317
|
const resolvedAgentId = initConfig.agentId || agentId;
|
|
318
|
+
const apiBaseUrl = initConfig.baseUrl || baseUrl;
|
|
283
319
|
const customOnClose = typeof window !== "undefined" ? (_b = window.EkaMedAssist) === null || _b === void 0 ? void 0 : _b.onClose : undefined;
|
|
284
320
|
if (!resolvedAgentId) {
|
|
285
321
|
console.error("Agent ID is required");
|
|
@@ -293,6 +329,19 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
293
329
|
button.classList.add("hidden");
|
|
294
330
|
}
|
|
295
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
|
+
}
|
|
296
345
|
const widgetConfig = {
|
|
297
346
|
title: initConfig.title || title,
|
|
298
347
|
iconUrl: initConfig.iconUrl || iconUrl,
|
|
@@ -306,13 +355,14 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
306
355
|
}
|
|
307
356
|
rootElement.classList.add("hidden");
|
|
308
357
|
},
|
|
309
|
-
baseUrl:
|
|
358
|
+
baseUrl: apiBaseUrl,
|
|
310
359
|
context: mergedContext,
|
|
311
360
|
displayMode,
|
|
312
|
-
auth
|
|
361
|
+
auth,
|
|
362
|
+
theme: { ...(apiTheme || {}), ...(attributeTheme || {}), ...(initConfig.theme || {}) }
|
|
313
363
|
};
|
|
314
364
|
if (this.widgetLoaded) {
|
|
315
|
-
(
|
|
365
|
+
(_d = window.renderMedAssist) === null || _d === void 0 ? void 0 : _d.call(window, rootElement, resolvedAgentId, widgetConfig);
|
|
316
366
|
return;
|
|
317
367
|
}
|
|
318
368
|
try {
|