@insight-health/aura 0.0.7 → 0.0.8
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/auraWidget.d.ts +7 -0
- package/dist/auraWidget.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +96 -79
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/dist/auraWidget.d.ts
CHANGED
|
@@ -8,10 +8,17 @@ declare class AuraWidgetService {
|
|
|
8
8
|
private config;
|
|
9
9
|
private widgetFrame;
|
|
10
10
|
private unsubsciptions;
|
|
11
|
+
private messageQueue;
|
|
12
|
+
private isQueueingEnabled;
|
|
11
13
|
isFrameReady: boolean;
|
|
12
14
|
isFrameAuthenticated: boolean;
|
|
13
15
|
constructor();
|
|
14
16
|
private postMessage;
|
|
17
|
+
private enableQueue;
|
|
18
|
+
private disableQueue;
|
|
19
|
+
private flushQueue;
|
|
20
|
+
private clearQueue;
|
|
21
|
+
private sendOrQueue;
|
|
15
22
|
init: (params: AuraWidgetInitParams) => Promise<void>;
|
|
16
23
|
setUser: (params: AuthParams) => void;
|
|
17
24
|
show: () => void;
|
package/dist/auraWidget.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auraWidget.d.ts","sourceRoot":"","sources":["../src/auraWidget.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,EAEpB,mBAAmB,EACnB,UAAU,EACX,MAAM,SAAS,CAAC;AA0BjB;;;GAGG;AACH,cAAM,iBAAiB;IACrB,OAAO,CAAC,MAAM,CAAqC;IACnD,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,cAAc,CAAsB;IAC5C,YAAY,EAAE,OAAO,CAAS;IAC9B,oBAAoB,EAAE,OAAO,CAAS;;IAatC,OAAO,CAAC,WAAW,CASjB;IAEF,IAAI,GAAI,QAAQ,oBAAoB,
|
|
1
|
+
{"version":3,"file":"auraWidget.d.ts","sourceRoot":"","sources":["../src/auraWidget.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,EAEpB,mBAAmB,EACnB,UAAU,EACX,MAAM,SAAS,CAAC;AA0BjB;;;GAGG;AACH,cAAM,iBAAiB;IACrB,OAAO,CAAC,MAAM,CAAqC;IACnD,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,iBAAiB,CAAkB;IAC3C,YAAY,EAAE,OAAO,CAAS;IAC9B,oBAAoB,EAAE,OAAO,CAAS;;IAatC,OAAO,CAAC,WAAW,CASjB;IAEF,OAAO,CAAC,WAAW,CAEjB;IAEF,OAAO,CAAC,YAAY,CAKlB;IAEF,OAAO,CAAC,UAAU,CAMhB;IAEF,OAAO,CAAC,UAAU,CAEhB;IAEF,OAAO,CAAC,WAAW,CAMjB;IAEF,IAAI,GAAI,QAAQ,oBAAoB,mBAqElC;IAEF,OAAO,GAAI,QAAQ,UAAU,UAkB3B;IAEF,IAAI,aAeF;IAEF,IAAI,aAIF;IAEF,KAAK,aAWH;IAEF,OAAO,GAAI,OAAO,mBAAmB,UAGnC;IAGF,IAAI,UANc,mBAAmB,UAMjB;IAEpB,EAAE,GAAI,MAAM,MAAM,EAAE,UAAU,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAAG,CAAC,MAAM,IAAI,CAAC,CAErE;IAEF,iBAAiB,GAAI,SAAS,2BAA2B,UAKvD;IAEF;;OAEG;IACH,SAAS,oCAEP;IACF,UAAU,eAER;CACH;AAgBD,eAAO,MAAM,UAAU,mBAAgB,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C={insightBaseUrl:"https://anywhere.insighthealth.ai"};let w=null;function E(){return w}function B(s){w={...C,...s}}function I(s){B(s)}function g(){const s=E();if(!s)throw new Error("Aura SDK not configured. Call configure() first to set global configuration.");return s}function b(){return"0.0.8"}class S{constructor(){this.events={},this.subscribe=(e,t)=>(this.events[e]||(this.events[e]=[]),this.events[e].push(t),()=>{this.events[e]=this.events[e].filter(i=>i!==t)}),this.emit=(e,t)=>{this.events[e]&&this.events[e].forEach(i=>i(t))}}}const o=new S,f={log:s=>{console.log(`[Insight Health Aura Widget]: ${s}`)},warn:s=>{console.warn(`[Insight Health Aura Widget]: ${s}`)},error:s=>{console.error(`[Insight Health Aura Widget]: ${s}`)}},m={opacity:"0",pointerEvents:"none",width:"0",height:"0",maxWidth:"0",maxHeight:"0"},U={border:"none",borderRadius:"10px",boxShadow:"0 0 10px 0 rgba(0, 0, 0, 0.1)",overflow:"hidden",background:"#fff",position:"fixed",bottom:"20px",right:"20px",transition:"opacity 0.2s ease-in-out, width 0.2s ease-in-out, height 0.2s ease-in-out, max-width 0.2s ease-in-out, max-height 0.2s ease-in-out",zIndex:"9999"};class v{constructor(){this.config=null,this.widgetFrame=null,this.unsubsciptions=[],this.messageQueue=[],this.isQueueingEnabled=!1,this.isFrameReady=!1,this.isFrameAuthenticated=!1,this.postMessage=e=>{var i;if(!((i=this.widgetFrame)!=null&&i.contentWindow)){f.warn("No widget iframe to communicate with");return}const t=g();this.widgetFrame.contentWindow.postMessage(e,{targetOrigin:t.insightBaseUrl})},this.enableQueue=()=>{this.isQueueingEnabled=!0},this.disableQueue=(e=!1)=>{this.isQueueingEnabled=!1,e&&this.flushQueue()},this.flushQueue=()=>{const e=[...this.messageQueue];this.clearQueue(),e.forEach(t=>{this.postMessage(t)})},this.clearQueue=()=>{this.messageQueue=[]},this.sendOrQueue=e=>{if(this.isQueueingEnabled){this.messageQueue.push(e);return}this.postMessage(e)},this.init=e=>new Promise(t=>{if(!this.widgetFrame){this.reset(),this.enableQueue();const i=g(),{tenantId:r,tenantName:a,user:h,language:p,container:d,widgetId:F,widgetStyles:n}=e;this.config=e,this.isFrameReady=!1,this.widgetFrame=document.createElement("iframe");const y=(n==null?void 0:n.width)||"350px",Q=(n==null?void 0:n.height)||"600px",A={...U,...n,...m};Object.assign(this.widgetFrame.style,A),this.widgetFrame.id=F||"aura-widget",this.widgetFrame.setAttribute("allow",`microphone ${i.insightBaseUrl}; camera ${i.insightBaseUrl}; clipboard-read ${i.insightBaseUrl}; clipboard-write ${i.insightBaseUrl};`),this.widgetFrame.src=`${i.insightBaseUrl}`,this.widgetFrame.__desiredWidth=y,this.widgetFrame.__desiredHeight=Q,this.widgetFrame.onerror=()=>{f.error(`Failed to load iframe. Please ensure your Content Security Policy includes:
|
|
2
2
|
frame-src ${i.insightBaseUrl}
|
|
3
|
-
`)},(
|
|
3
|
+
`)},(d&&document.querySelector(d)||document.body).appendChild(this.widgetFrame);const x=o.subscribe("Auth.Ready",()=>{this.isFrameReady=!0,this.setUser({tenantId:r,tenantName:a,user:h,language:p})}),W=o.subscribe("Auth.Complete",l=>{var c;this.isFrameAuthenticated=!0,this.disableQueue(!0),t(l),(c=e.onAuthenticated)==null||c.call(e,l)});this.unsubsciptions.push(x,W)}}),this.setUser=e=>{const t=this.config.partnerKey,{tenantId:i,tenantName:r,user:a,language:h}=e;this.config.tenantId=i,this.config.tenantName=r,this.config.user=a,this.config.language=h,this.isFrameAuthenticated=!1,this.postMessage({type:"Auth.Login",payload:{partnerKey:t,tenantId:i,tenantName:r,user:a,language:h}})},this.show=()=>{if(this.widgetFrame){const e=this.widgetFrame.__desiredWidth||"350px",t=this.widgetFrame.__desiredHeight||"600px",i={opacity:"1",pointerEvents:"auto",width:e,height:t,maxWidth:e,maxHeight:t};Object.assign(this.widgetFrame.style,{...i})}},this.hide=()=>{this.widgetFrame&&Object.assign(this.widgetFrame.style,{...m})},this.reset=()=>{this.widgetFrame&&this.widgetFrame.remove(),this.widgetFrame=null,this.isFrameReady=!1,this.isFrameAuthenticated=!1,this.unsubsciptions.forEach(e=>e==null?void 0:e()),this.unsubsciptions=[],this.disableQueue(),this.clearQueue()},this.command=e=>{this.sendOrQueue(e),this.show()},this.emit=this.command,this.on=(e,t)=>o.subscribe(e,t),this.registerTemplates=e=>{this.sendOrQueue({type:"Template.Register",payload:e})},this.getConfig=()=>this.config,this.getVersion=()=>b(),window.addEventListener("message",e=>{var t;e.source!==((t=this.widgetFrame)==null?void 0:t.contentWindow)||!e.data||o.emit(e.data.type,e.data.payload)})}}let u=null;function H(){return u||(u=new v),u}const $=H();exports.AuraWidget=$;exports.configure=I;exports.getConfig=g;exports.getVersion=b;
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
const
|
|
1
|
+
const W = {
|
|
2
2
|
insightBaseUrl: "https://anywhere.insighthealth.ai"
|
|
3
3
|
};
|
|
4
4
|
let w = null;
|
|
5
|
-
function
|
|
5
|
+
function C() {
|
|
6
6
|
return w;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
w = { ...
|
|
8
|
+
function E(s) {
|
|
9
|
+
w = { ...W, ...s };
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
11
|
+
function v(s) {
|
|
12
|
+
E(s);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
const s =
|
|
14
|
+
function c() {
|
|
15
|
+
const s = C();
|
|
16
16
|
if (!s)
|
|
17
17
|
throw new Error(
|
|
18
18
|
"Aura SDK not configured. Call configure() first to set global configuration."
|
|
19
19
|
);
|
|
20
20
|
return s;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
return "0.0.
|
|
22
|
+
function B() {
|
|
23
|
+
return "0.0.8";
|
|
24
24
|
}
|
|
25
|
-
class
|
|
25
|
+
class I {
|
|
26
26
|
constructor() {
|
|
27
|
-
this.events = {}, this.subscribe = (
|
|
28
|
-
this.events[
|
|
29
|
-
}), this.emit = (
|
|
30
|
-
this.events[
|
|
27
|
+
this.events = {}, this.subscribe = (e, t) => (this.events[e] || (this.events[e] = []), this.events[e].push(t), () => {
|
|
28
|
+
this.events[e] = this.events[e].filter((i) => i !== t);
|
|
29
|
+
}), this.emit = (e, t) => {
|
|
30
|
+
this.events[e] && this.events[e].forEach((i) => i(t));
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
const
|
|
34
|
+
const o = new I(), f = {
|
|
35
35
|
log: (s) => {
|
|
36
36
|
console.log(`[Insight Health Aura Widget]: ${s}`);
|
|
37
37
|
},
|
|
@@ -41,14 +41,14 @@ const h = new v(), m = {
|
|
|
41
41
|
error: (s) => {
|
|
42
42
|
console.error(`[Insight Health Aura Widget]: ${s}`);
|
|
43
43
|
}
|
|
44
|
-
},
|
|
44
|
+
}, m = {
|
|
45
45
|
opacity: "0",
|
|
46
46
|
pointerEvents: "none",
|
|
47
47
|
width: "0",
|
|
48
48
|
height: "0",
|
|
49
49
|
maxWidth: "0",
|
|
50
50
|
maxHeight: "0"
|
|
51
|
-
},
|
|
51
|
+
}, U = {
|
|
52
52
|
border: "none",
|
|
53
53
|
borderRadius: "10px",
|
|
54
54
|
boxShadow: "0 0 10px 0 rgba(0, 0, 0, 0.1)",
|
|
@@ -60,109 +60,126 @@ const h = new v(), m = {
|
|
|
60
60
|
transition: "opacity 0.2s ease-in-out, width 0.2s ease-in-out, height 0.2s ease-in-out, max-width 0.2s ease-in-out, max-height 0.2s ease-in-out",
|
|
61
61
|
zIndex: "9999"
|
|
62
62
|
};
|
|
63
|
-
class
|
|
63
|
+
class H {
|
|
64
64
|
constructor() {
|
|
65
|
-
this.config = null, this.widgetFrame = null, this.unsubsciptions = [], this.isFrameReady = !1, this.isFrameAuthenticated = !1, this.postMessage = (
|
|
65
|
+
this.config = null, this.widgetFrame = null, this.unsubsciptions = [], this.messageQueue = [], this.isQueueingEnabled = !1, this.isFrameReady = !1, this.isFrameAuthenticated = !1, this.postMessage = (e) => {
|
|
66
66
|
var i;
|
|
67
67
|
if (!((i = this.widgetFrame) != null && i.contentWindow)) {
|
|
68
|
-
|
|
68
|
+
f.warn("No widget iframe to communicate with");
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
const
|
|
72
|
-
this.widgetFrame.contentWindow.postMessage(
|
|
73
|
-
targetOrigin:
|
|
71
|
+
const t = c();
|
|
72
|
+
this.widgetFrame.contentWindow.postMessage(e, {
|
|
73
|
+
targetOrigin: t.insightBaseUrl
|
|
74
74
|
});
|
|
75
|
-
}, this.
|
|
75
|
+
}, this.enableQueue = () => {
|
|
76
|
+
this.isQueueingEnabled = !0;
|
|
77
|
+
}, this.disableQueue = (e = !1) => {
|
|
78
|
+
this.isQueueingEnabled = !1, e && this.flushQueue();
|
|
79
|
+
}, this.flushQueue = () => {
|
|
80
|
+
const e = [...this.messageQueue];
|
|
81
|
+
this.clearQueue(), e.forEach((t) => {
|
|
82
|
+
this.postMessage(t);
|
|
83
|
+
});
|
|
84
|
+
}, this.clearQueue = () => {
|
|
85
|
+
this.messageQueue = [];
|
|
86
|
+
}, this.sendOrQueue = (e) => {
|
|
87
|
+
if (this.isQueueingEnabled) {
|
|
88
|
+
this.messageQueue.push(e);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this.postMessage(e);
|
|
92
|
+
}, this.init = (e) => new Promise((t) => {
|
|
76
93
|
if (!this.widgetFrame) {
|
|
77
|
-
this.reset();
|
|
78
|
-
const i =
|
|
79
|
-
tenantId:
|
|
80
|
-
tenantName:
|
|
81
|
-
user:
|
|
94
|
+
this.reset(), this.enableQueue();
|
|
95
|
+
const i = c(), {
|
|
96
|
+
tenantId: a,
|
|
97
|
+
tenantName: r,
|
|
98
|
+
user: h,
|
|
82
99
|
language: p,
|
|
83
|
-
container:
|
|
84
|
-
widgetId:
|
|
100
|
+
container: d,
|
|
101
|
+
widgetId: b,
|
|
85
102
|
widgetStyles: n
|
|
86
|
-
} =
|
|
87
|
-
this.config =
|
|
88
|
-
const
|
|
89
|
-
...
|
|
103
|
+
} = e;
|
|
104
|
+
this.config = e, this.isFrameReady = !1, this.widgetFrame = document.createElement("iframe");
|
|
105
|
+
const F = (n == null ? void 0 : n.width) || "350px", y = (n == null ? void 0 : n.height) || "600px", Q = {
|
|
106
|
+
...U,
|
|
90
107
|
...n,
|
|
91
|
-
...
|
|
108
|
+
...m
|
|
92
109
|
};
|
|
93
|
-
Object.assign(this.widgetFrame.style,
|
|
110
|
+
Object.assign(this.widgetFrame.style, Q), this.widgetFrame.id = b || "aura-widget", this.widgetFrame.setAttribute(
|
|
94
111
|
"allow",
|
|
95
112
|
`microphone ${i.insightBaseUrl}; camera ${i.insightBaseUrl}; clipboard-read ${i.insightBaseUrl}; clipboard-write ${i.insightBaseUrl};`
|
|
96
|
-
), this.widgetFrame.src = `${i.insightBaseUrl}`, this.widgetFrame.__desiredWidth =
|
|
97
|
-
|
|
113
|
+
), this.widgetFrame.src = `${i.insightBaseUrl}`, this.widgetFrame.__desiredWidth = F, this.widgetFrame.__desiredHeight = y, this.widgetFrame.onerror = () => {
|
|
114
|
+
f.error(
|
|
98
115
|
`Failed to load iframe. Please ensure your Content Security Policy includes:
|
|
99
116
|
frame-src ${i.insightBaseUrl}
|
|
100
117
|
`
|
|
101
118
|
);
|
|
102
|
-
}, (
|
|
103
|
-
const
|
|
104
|
-
this.isFrameReady = !0, this.setUser({ tenantId:
|
|
105
|
-
}),
|
|
119
|
+
}, (d && document.querySelector(d) || document.body).appendChild(this.widgetFrame);
|
|
120
|
+
const x = o.subscribe("Auth.Ready", () => {
|
|
121
|
+
this.isFrameReady = !0, this.setUser({ tenantId: a, tenantName: r, user: h, language: p });
|
|
122
|
+
}), A = o.subscribe(
|
|
106
123
|
"Auth.Complete",
|
|
107
|
-
(
|
|
108
|
-
var
|
|
109
|
-
this.isFrameAuthenticated = !0,
|
|
124
|
+
(g) => {
|
|
125
|
+
var l;
|
|
126
|
+
this.isFrameAuthenticated = !0, this.disableQueue(!0), t(g), (l = e.onAuthenticated) == null || l.call(e, g);
|
|
110
127
|
}
|
|
111
128
|
);
|
|
112
|
-
this.unsubsciptions.push(
|
|
129
|
+
this.unsubsciptions.push(x, A);
|
|
113
130
|
}
|
|
114
|
-
}), this.setUser = (
|
|
115
|
-
const
|
|
116
|
-
this.config.tenantId = i, this.config.tenantName =
|
|
131
|
+
}), this.setUser = (e) => {
|
|
132
|
+
const t = this.config.partnerKey, { tenantId: i, tenantName: a, user: r, language: h } = e;
|
|
133
|
+
this.config.tenantId = i, this.config.tenantName = a, this.config.user = r, this.config.language = h, this.isFrameAuthenticated = !1, this.postMessage({
|
|
117
134
|
type: "Auth.Login",
|
|
118
135
|
payload: {
|
|
119
|
-
partnerKey:
|
|
136
|
+
partnerKey: t,
|
|
120
137
|
tenantId: i,
|
|
121
|
-
tenantName:
|
|
122
|
-
user:
|
|
123
|
-
language:
|
|
138
|
+
tenantName: a,
|
|
139
|
+
user: r,
|
|
140
|
+
language: h
|
|
124
141
|
}
|
|
125
142
|
});
|
|
126
143
|
}, this.show = () => {
|
|
127
144
|
if (this.widgetFrame) {
|
|
128
|
-
const
|
|
145
|
+
const e = this.widgetFrame.__desiredWidth || "350px", t = this.widgetFrame.__desiredHeight || "600px", i = {
|
|
129
146
|
opacity: "1",
|
|
130
147
|
pointerEvents: "auto",
|
|
131
|
-
width:
|
|
132
|
-
height:
|
|
133
|
-
maxWidth:
|
|
134
|
-
maxHeight:
|
|
148
|
+
width: e,
|
|
149
|
+
height: t,
|
|
150
|
+
maxWidth: e,
|
|
151
|
+
maxHeight: t
|
|
135
152
|
};
|
|
136
153
|
Object.assign(this.widgetFrame.style, { ...i });
|
|
137
154
|
}
|
|
138
155
|
}, this.hide = () => {
|
|
139
|
-
this.widgetFrame && Object.assign(this.widgetFrame.style, { ...
|
|
156
|
+
this.widgetFrame && Object.assign(this.widgetFrame.style, { ...m });
|
|
140
157
|
}, this.reset = () => {
|
|
141
|
-
this.widgetFrame && this.widgetFrame.remove(), this.widgetFrame = null, this.isFrameReady = !1, this.isFrameAuthenticated = !1, this.unsubsciptions.forEach((
|
|
142
|
-
}, this.command = (
|
|
143
|
-
this.
|
|
144
|
-
}, this.emit = this.command, this.on = (
|
|
145
|
-
this.
|
|
158
|
+
this.widgetFrame && this.widgetFrame.remove(), this.widgetFrame = null, this.isFrameReady = !1, this.isFrameAuthenticated = !1, this.unsubsciptions.forEach((e) => e == null ? void 0 : e()), this.unsubsciptions = [], this.disableQueue(), this.clearQueue();
|
|
159
|
+
}, this.command = (e) => {
|
|
160
|
+
this.sendOrQueue(e), this.show();
|
|
161
|
+
}, this.emit = this.command, this.on = (e, t) => o.subscribe(e, t), this.registerTemplates = (e) => {
|
|
162
|
+
this.sendOrQueue({
|
|
146
163
|
type: "Template.Register",
|
|
147
|
-
payload:
|
|
164
|
+
payload: e
|
|
148
165
|
});
|
|
149
|
-
}, this.getConfig = () => this.config, this.getVersion = () =>
|
|
166
|
+
}, this.getConfig = () => this.config, this.getVersion = () => B(), window.addEventListener(
|
|
150
167
|
"message",
|
|
151
|
-
(
|
|
152
|
-
var
|
|
153
|
-
|
|
168
|
+
(e) => {
|
|
169
|
+
var t;
|
|
170
|
+
e.source !== ((t = this.widgetFrame) == null ? void 0 : t.contentWindow) || !e.data || o.emit(e.data.type, e.data.payload);
|
|
154
171
|
}
|
|
155
172
|
);
|
|
156
173
|
}
|
|
157
174
|
}
|
|
158
|
-
let
|
|
159
|
-
function
|
|
160
|
-
return
|
|
175
|
+
let u = null;
|
|
176
|
+
function $() {
|
|
177
|
+
return u || (u = new H()), u;
|
|
161
178
|
}
|
|
162
|
-
const
|
|
179
|
+
const R = $();
|
|
163
180
|
export {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
181
|
+
R as AuraWidget,
|
|
182
|
+
v as configure,
|
|
183
|
+
c as getConfig,
|
|
184
|
+
B as getVersion
|
|
168
185
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(n,
|
|
1
|
+
(function(n,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(n=typeof globalThis<"u"?globalThis:n||self,a(n.InsightAura={}))})(this,function(n){"use strict";const a={insightBaseUrl:"https://anywhere.insighthealth.ai"};let c=null;function y(){return c}function Q(s){c={...a,...s}}function A(s){Q(s)}function g(){const s=y();if(!s)throw new Error("Aura SDK not configured. Call configure() first to set global configuration.");return s}function f(){return"0.0.8"}class x{constructor(){this.events={},this.subscribe=(e,t)=>(this.events[e]||(this.events[e]=[]),this.events[e].push(t),()=>{this.events[e]=this.events[e].filter(i=>i!==t)}),this.emit=(e,t)=>{this.events[e]&&this.events[e].forEach(i=>i(t))}}}const h=new x,m={log:s=>{console.log(`[Insight Health Aura Widget]: ${s}`)},warn:s=>{console.warn(`[Insight Health Aura Widget]: ${s}`)},error:s=>{console.error(`[Insight Health Aura Widget]: ${s}`)}},w={opacity:"0",pointerEvents:"none",width:"0",height:"0",maxWidth:"0",maxHeight:"0"},W={border:"none",borderRadius:"10px",boxShadow:"0 0 10px 0 rgba(0, 0, 0, 0.1)",overflow:"hidden",background:"#fff",position:"fixed",bottom:"20px",right:"20px",transition:"opacity 0.2s ease-in-out, width 0.2s ease-in-out, height 0.2s ease-in-out, max-width 0.2s ease-in-out, max-height 0.2s ease-in-out",zIndex:"9999"};class C{constructor(){this.config=null,this.widgetFrame=null,this.unsubsciptions=[],this.messageQueue=[],this.isQueueingEnabled=!1,this.isFrameReady=!1,this.isFrameAuthenticated=!1,this.postMessage=e=>{var i;if(!((i=this.widgetFrame)!=null&&i.contentWindow)){m.warn("No widget iframe to communicate with");return}const t=g();this.widgetFrame.contentWindow.postMessage(e,{targetOrigin:t.insightBaseUrl})},this.enableQueue=()=>{this.isQueueingEnabled=!0},this.disableQueue=(e=!1)=>{this.isQueueingEnabled=!1,e&&this.flushQueue()},this.flushQueue=()=>{const e=[...this.messageQueue];this.clearQueue(),e.forEach(t=>{this.postMessage(t)})},this.clearQueue=()=>{this.messageQueue=[]},this.sendOrQueue=e=>{if(this.isQueueingEnabled){this.messageQueue.push(e);return}this.postMessage(e)},this.init=e=>new Promise(t=>{if(!this.widgetFrame){this.reset(),this.enableQueue();const i=g(),{tenantId:o,tenantName:u,user:d,language:B,container:p,widgetId:S,widgetStyles:r}=e;this.config=e,this.isFrameReady=!1,this.widgetFrame=document.createElement("iframe");const U=(r==null?void 0:r.width)||"350px",v=(r==null?void 0:r.height)||"600px",H={...W,...r,...w};Object.assign(this.widgetFrame.style,H),this.widgetFrame.id=S||"aura-widget",this.widgetFrame.setAttribute("allow",`microphone ${i.insightBaseUrl}; camera ${i.insightBaseUrl}; clipboard-read ${i.insightBaseUrl}; clipboard-write ${i.insightBaseUrl};`),this.widgetFrame.src=`${i.insightBaseUrl}`,this.widgetFrame.__desiredWidth=U,this.widgetFrame.__desiredHeight=v,this.widgetFrame.onerror=()=>{m.error(`Failed to load iframe. Please ensure your Content Security Policy includes:
|
|
2
2
|
frame-src ${i.insightBaseUrl}
|
|
3
|
-
`)},(p&&document.querySelector(p)||document.body).appendChild(this.widgetFrame);const
|
|
3
|
+
`)},(p&&document.querySelector(p)||document.body).appendChild(this.widgetFrame);const $=h.subscribe("Auth.Ready",()=>{this.isFrameReady=!0,this.setUser({tenantId:o,tenantName:u,user:d,language:B})}),O=h.subscribe("Auth.Complete",b=>{var F;this.isFrameAuthenticated=!0,this.disableQueue(!0),t(b),(F=e.onAuthenticated)==null||F.call(e,b)});this.unsubsciptions.push($,O)}}),this.setUser=e=>{const t=this.config.partnerKey,{tenantId:i,tenantName:o,user:u,language:d}=e;this.config.tenantId=i,this.config.tenantName=o,this.config.user=u,this.config.language=d,this.isFrameAuthenticated=!1,this.postMessage({type:"Auth.Login",payload:{partnerKey:t,tenantId:i,tenantName:o,user:u,language:d}})},this.show=()=>{if(this.widgetFrame){const e=this.widgetFrame.__desiredWidth||"350px",t=this.widgetFrame.__desiredHeight||"600px",i={opacity:"1",pointerEvents:"auto",width:e,height:t,maxWidth:e,maxHeight:t};Object.assign(this.widgetFrame.style,{...i})}},this.hide=()=>{this.widgetFrame&&Object.assign(this.widgetFrame.style,{...w})},this.reset=()=>{this.widgetFrame&&this.widgetFrame.remove(),this.widgetFrame=null,this.isFrameReady=!1,this.isFrameAuthenticated=!1,this.unsubsciptions.forEach(e=>e==null?void 0:e()),this.unsubsciptions=[],this.disableQueue(),this.clearQueue()},this.command=e=>{this.sendOrQueue(e),this.show()},this.emit=this.command,this.on=(e,t)=>h.subscribe(e,t),this.registerTemplates=e=>{this.sendOrQueue({type:"Template.Register",payload:e})},this.getConfig=()=>this.config,this.getVersion=()=>f(),window.addEventListener("message",e=>{var t;e.source!==((t=this.widgetFrame)==null?void 0:t.contentWindow)||!e.data||h.emit(e.data.type,e.data.payload)})}}let l=null;function E(){return l||(l=new C),l}const I=E();n.AuraWidget=I,n.configure=A,n.getConfig=g,n.getVersion=f,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
|