@insight-health/aura 0.0.9 → 0.0.10-beta.1
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 +15 -1
- package/dist/auraWidget.d.ts.map +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +127 -72
- package/dist/index.umd.js +3 -3
- package/dist/types.d.ts +30 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/auraWidget.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuraRegisterTemplatePayload, AuraWidgetInitParams, AuraWidgetEmitEvent, AuthParams } from './types';
|
|
1
|
+
import { AuraRegisterTemplatePayload, AuraWidgetInitParams, AuraWidgetEmitEvent, AuthParams, SupportedMethods } from './types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Aura service class
|
|
@@ -10,6 +10,7 @@ declare class AuraWidgetService {
|
|
|
10
10
|
private unsubsciptions;
|
|
11
11
|
private messageQueue;
|
|
12
12
|
private isQueueingEnabled;
|
|
13
|
+
private methodRegistry;
|
|
13
14
|
isFrameReady: boolean;
|
|
14
15
|
isFrameAuthenticated: boolean;
|
|
15
16
|
constructor();
|
|
@@ -19,6 +20,7 @@ declare class AuraWidgetService {
|
|
|
19
20
|
private flushQueue;
|
|
20
21
|
private clearQueue;
|
|
21
22
|
private sendOrQueue;
|
|
23
|
+
private handleMethodCall;
|
|
22
24
|
init: (params: AuraWidgetInitParams) => Promise<void>;
|
|
23
25
|
setUser: (params: AuthParams) => void;
|
|
24
26
|
show: () => void;
|
|
@@ -28,6 +30,18 @@ declare class AuraWidgetService {
|
|
|
28
30
|
emit: (event: AuraWidgetEmitEvent) => void;
|
|
29
31
|
on: (type: string, callback: (payload: unknown) => void) => (() => void);
|
|
30
32
|
registerTemplates: (payload: AuraRegisterTemplatePayload) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Register a method that can be called by the iframe widget
|
|
35
|
+
* @param name - The method name identifier
|
|
36
|
+
* @param handler - The handler function (can be async)
|
|
37
|
+
*/
|
|
38
|
+
registerMethod: <N extends keyof SupportedMethods>(name: N, handler: SupportedMethods[N]) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Unregister a previously registered method
|
|
41
|
+
* @param name - The method name to unregister
|
|
42
|
+
* @returns true if the method was found and removed, false otherwise
|
|
43
|
+
*/
|
|
44
|
+
unregisterMethod: <N extends keyof SupportedMethods>(name: N) => boolean;
|
|
31
45
|
/**
|
|
32
46
|
* Get SDK version
|
|
33
47
|
*/
|
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,
|
|
1
|
+
{"version":3,"file":"auraWidget.d.ts","sourceRoot":"","sources":["../src/auraWidget.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,EAEpB,mBAAmB,EACnB,UAAU,EAEV,gBAAgB,EACjB,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,OAAO,CAAC,cAAc,CAAiC;IACvD,YAAY,EAAE,OAAO,CAAS;IAC9B,oBAAoB,EAAE,OAAO,CAAS;;IAoBtC,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,OAAO,CAAC,gBAAgB,CAkDtB;IAEF,IAAI,GAAI,QAAQ,oBAAoB,mBAqElC;IAEF,OAAO,GAAI,QAAQ,UAAU,UAkB3B;IAEF,IAAI,aAeF;IAEF,IAAI,aAIF;IAEF,KAAK,aAYH;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;;;;OAIG;IACH,cAAc,GAAI,CAAC,SAAS,MAAM,gBAAgB,EAChD,MAAM,CAAC,EACP,SAAS,gBAAgB,CAAC,CAAC,CAAC,KAC3B,IAAI,CAEL;IAEF;;;;OAIG;IACH,gBAAgB,GAAI,CAAC,SAAS,MAAM,gBAAgB,EAAE,MAAM,CAAC,KAAG,OAAO,CAErE;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 C={insightBaseUrl:"https://anywhere.insighthealth.ai"};let w=null;function
|
|
2
|
-
frame-src ${
|
|
3
|
-
`)},(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C={insightBaseUrl:"https://anywhere.insighthealth.ai"};let w=null;function A(){return w}function x(i){w={...C,...i}}function W(i){x(i)}function g(){const i=A();if(!i)throw new Error("Aura SDK not configured. Call configure() first to set global configuration.");return i}function y(){return"0.0.10-beta.1"}class O{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(s=>s!==t)}),this.emit=(e,t)=>{this.events[e]&&this.events[e].forEach(s=>s(t))}}}const d=new O,f={log:i=>{console.log(`[Insight Health Aura Widget]: ${i}`)},warn:i=>{console.warn(`[Insight Health Aura Widget]: ${i}`)},error:i=>{console.error(`[Insight Health Aura Widget]: ${i}`)}},p={opacity:"0",pointerEvents:"none",width:"0",height:"0",maxWidth:"0",maxHeight:"0"},I={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 U{constructor(){this.config=null,this.widgetFrame=null,this.unsubsciptions=[],this.messageQueue=[],this.isQueueingEnabled=!1,this.methodRegistry={},this.isFrameReady=!1,this.isFrameAuthenticated=!1,this.postMessage=e=>{var s;if(!((s=this.widgetFrame)!=null&&s.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.handleMethodCall=async e=>{const{callId:t,methodName:s,args:h}=e,r=this.methodRegistry[s];if(!r){this.postMessage({type:"Method.Response",payload:{callId:t,success:!1,error:{message:`Method "${s}" is not registered`,code:"METHOD_NOT_FOUND"}}});return}try{const n=await r(h||{});this.postMessage({type:"Method.Response",payload:{callId:t,success:!0,result:n}})}catch(n){const a=n instanceof Error?n:new Error(String(n));this.postMessage({type:"Method.Response",payload:{callId:t,success:!1,methodName:s,error:{message:a.message,code:"METHOD_EXECUTION_ERROR",stack:a.stack,name:a.name,cause:a.cause,apiResponse:a.response}}})}},this.init=e=>new Promise(t=>{if(!this.widgetFrame){this.reset(),this.enableQueue();const s=g(),{tenantId:h,tenantName:r,user:n,language:a,container:c,widgetId:b,widgetStyles:o}=e;this.config=e,this.isFrameReady=!1,this.widgetFrame=document.createElement("iframe");const F=(o==null?void 0:o.width)||"350px",Q=(o==null?void 0:o.height)||"600px",E={...I,...o,...p};Object.assign(this.widgetFrame.style,E),this.widgetFrame.id=b||"aura-widget",this.widgetFrame.setAttribute("allow",`microphone ${s.insightBaseUrl}; camera ${s.insightBaseUrl}; clipboard-read ${s.insightBaseUrl}; clipboard-write ${s.insightBaseUrl};`),this.widgetFrame.src=`${s.insightBaseUrl}`,this.widgetFrame.__desiredWidth=F,this.widgetFrame.__desiredHeight=Q,this.widgetFrame.onerror=()=>{f.error(`Failed to load iframe. Please ensure your Content Security Policy includes:
|
|
2
|
+
frame-src ${s.insightBaseUrl}
|
|
3
|
+
`)},(c&&document.querySelector(c)||document.body).appendChild(this.widgetFrame);const M=d.subscribe("Auth.Ready",()=>{this.isFrameReady=!0,this.setUser({tenantId:h,tenantName:r,user:n,language:a})}),R=d.subscribe("Auth.Complete",l=>{var m;this.isFrameAuthenticated=!0,this.disableQueue(!0),t(l),(m=e.onAuthenticated)==null||m.call(e,l)});this.unsubsciptions.push(M,R)}}),this.setUser=e=>{const t=this.config.partnerKey,{tenantId:s,tenantName:h,user:r,language:n}=e;this.config.tenantId=s,this.config.tenantName=h,this.config.user=r,this.config.language=n,this.isFrameAuthenticated=!1,this.postMessage({type:"Auth.Login",payload:{partnerKey:t,tenantId:s,tenantName:h,user:r,language:n}})},this.show=()=>{if(this.widgetFrame){const e=this.widgetFrame.__desiredWidth||"350px",t=this.widgetFrame.__desiredHeight||"600px",s={opacity:"1",pointerEvents:"auto",width:e,height:t,maxWidth:e,maxHeight:t};Object.assign(this.widgetFrame.style,{...s})}},this.hide=()=>{this.widgetFrame&&Object.assign(this.widgetFrame.style,{...p})},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.methodRegistry={}},this.command=e=>{this.sendOrQueue(e),this.show()},this.emit=this.command,this.on=(e,t)=>d.subscribe(e,t),this.registerTemplates=e=>{this.sendOrQueue({type:"Template.Register",payload:e})},this.registerMethod=(e,t)=>{this.methodRegistry[e]=t},this.unregisterMethod=e=>delete this.methodRegistry[e],this.getConfig=()=>this.config,this.getVersion=()=>y(),window.addEventListener("message",e=>{var t;if(!(e.source!==((t=this.widgetFrame)==null?void 0:t.contentWindow)||!e.data)){if(e.data.type==="Method.Call"){this.handleMethodCall(e.data.payload);return}d.emit(e.data.type,e.data.payload)}})}}let u=null;function _(){return u||(u=new U),u}const H=_();exports.AuraWidget=H;exports.configure=W;exports.getConfig=g;exports.getVersion=y;
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
const
|
|
1
|
+
const M = {
|
|
2
2
|
insightBaseUrl: "https://anywhere.insighthealth.ai"
|
|
3
3
|
};
|
|
4
4
|
let w = null;
|
|
5
|
-
function
|
|
5
|
+
function x() {
|
|
6
6
|
return w;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
w = { ...
|
|
8
|
+
function C(i) {
|
|
9
|
+
w = { ...M, ...i };
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
11
|
+
function _(i) {
|
|
12
|
+
C(i);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
14
|
+
function m() {
|
|
15
|
+
const i = x();
|
|
16
|
+
if (!i)
|
|
17
17
|
throw new Error(
|
|
18
18
|
"Aura SDK not configured. Call configure() first to set global configuration."
|
|
19
19
|
);
|
|
20
|
-
return
|
|
20
|
+
return i;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
return "0.0.
|
|
22
|
+
function A() {
|
|
23
|
+
return "0.0.10-beta.1";
|
|
24
24
|
}
|
|
25
|
-
class
|
|
25
|
+
class W {
|
|
26
26
|
constructor() {
|
|
27
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((
|
|
28
|
+
this.events[e] = this.events[e].filter((s) => s !== t);
|
|
29
29
|
}), this.emit = (e, t) => {
|
|
30
|
-
this.events[e] && this.events[e].forEach((
|
|
30
|
+
this.events[e] && this.events[e].forEach((s) => s(t));
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
const
|
|
35
|
-
log: (
|
|
36
|
-
console.log(`[Insight Health Aura Widget]: ${
|
|
34
|
+
const d = new W(), f = {
|
|
35
|
+
log: (i) => {
|
|
36
|
+
console.log(`[Insight Health Aura Widget]: ${i}`);
|
|
37
37
|
},
|
|
38
|
-
warn: (
|
|
39
|
-
console.warn(`[Insight Health Aura Widget]: ${
|
|
38
|
+
warn: (i) => {
|
|
39
|
+
console.warn(`[Insight Health Aura Widget]: ${i}`);
|
|
40
40
|
},
|
|
41
|
-
error: (
|
|
42
|
-
console.error(`[Insight Health Aura Widget]: ${
|
|
41
|
+
error: (i) => {
|
|
42
|
+
console.error(`[Insight Health Aura Widget]: ${i}`);
|
|
43
43
|
}
|
|
44
|
-
},
|
|
44
|
+
}, p = {
|
|
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
|
+
}, O = {
|
|
52
52
|
border: "none",
|
|
53
53
|
borderRadius: "10px",
|
|
54
54
|
boxShadow: "0 0 10px 0 rgba(0, 0, 0, 0.1)",
|
|
@@ -60,15 +60,15 @@ const o = new I(), f = {
|
|
|
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 I {
|
|
64
64
|
constructor() {
|
|
65
|
-
this.config = null, this.widgetFrame = null, this.unsubsciptions = [], this.messageQueue = [], this.isQueueingEnabled = !1, this.isFrameReady = !1, this.isFrameAuthenticated = !1, this.postMessage = (e) => {
|
|
66
|
-
var
|
|
67
|
-
if (!((
|
|
65
|
+
this.config = null, this.widgetFrame = null, this.unsubsciptions = [], this.messageQueue = [], this.isQueueingEnabled = !1, this.methodRegistry = {}, this.isFrameReady = !1, this.isFrameAuthenticated = !1, this.postMessage = (e) => {
|
|
66
|
+
var s;
|
|
67
|
+
if (!((s = this.widgetFrame) != null && s.contentWindow)) {
|
|
68
68
|
f.warn("No widget iframe to communicate with");
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
const t =
|
|
71
|
+
const t = m();
|
|
72
72
|
this.widgetFrame.contentWindow.postMessage(e, {
|
|
73
73
|
targetOrigin: t.insightBaseUrl
|
|
74
74
|
});
|
|
@@ -89,60 +89,105 @@ class H {
|
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
91
|
this.postMessage(e);
|
|
92
|
+
}, this.handleMethodCall = async (e) => {
|
|
93
|
+
const { callId: t, methodName: s, args: o } = e, a = this.methodRegistry[s];
|
|
94
|
+
if (!a) {
|
|
95
|
+
this.postMessage({
|
|
96
|
+
type: "Method.Response",
|
|
97
|
+
payload: {
|
|
98
|
+
callId: t,
|
|
99
|
+
success: !1,
|
|
100
|
+
error: {
|
|
101
|
+
message: `Method "${s}" is not registered`,
|
|
102
|
+
code: "METHOD_NOT_FOUND"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const n = await a(o || {});
|
|
110
|
+
this.postMessage({
|
|
111
|
+
type: "Method.Response",
|
|
112
|
+
payload: {
|
|
113
|
+
callId: t,
|
|
114
|
+
success: !0,
|
|
115
|
+
result: n
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
} catch (n) {
|
|
119
|
+
const r = n instanceof Error ? n : new Error(String(n));
|
|
120
|
+
this.postMessage({
|
|
121
|
+
type: "Method.Response",
|
|
122
|
+
payload: {
|
|
123
|
+
callId: t,
|
|
124
|
+
success: !1,
|
|
125
|
+
methodName: s,
|
|
126
|
+
error: {
|
|
127
|
+
message: r.message,
|
|
128
|
+
code: "METHOD_EXECUTION_ERROR",
|
|
129
|
+
stack: r.stack,
|
|
130
|
+
name: r.name,
|
|
131
|
+
cause: r.cause,
|
|
132
|
+
apiResponse: r.response
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
92
137
|
}, this.init = (e) => new Promise((t) => {
|
|
93
138
|
if (!this.widgetFrame) {
|
|
94
139
|
this.reset(), this.enableQueue();
|
|
95
|
-
const
|
|
96
|
-
tenantId:
|
|
97
|
-
tenantName:
|
|
98
|
-
user:
|
|
99
|
-
language:
|
|
100
|
-
container:
|
|
101
|
-
widgetId:
|
|
102
|
-
widgetStyles:
|
|
140
|
+
const s = m(), {
|
|
141
|
+
tenantId: o,
|
|
142
|
+
tenantName: a,
|
|
143
|
+
user: n,
|
|
144
|
+
language: r,
|
|
145
|
+
container: g,
|
|
146
|
+
widgetId: y,
|
|
147
|
+
widgetStyles: h
|
|
103
148
|
} = e;
|
|
104
149
|
this.config = e, this.isFrameReady = !1, this.widgetFrame = document.createElement("iframe");
|
|
105
|
-
const
|
|
106
|
-
...
|
|
107
|
-
...
|
|
108
|
-
...
|
|
150
|
+
const b = (h == null ? void 0 : h.width) || "350px", F = (h == null ? void 0 : h.height) || "600px", Q = {
|
|
151
|
+
...O,
|
|
152
|
+
...h,
|
|
153
|
+
...p
|
|
109
154
|
};
|
|
110
|
-
Object.assign(this.widgetFrame.style, Q), this.widgetFrame.id =
|
|
155
|
+
Object.assign(this.widgetFrame.style, Q), this.widgetFrame.id = y || "aura-widget", this.widgetFrame.setAttribute(
|
|
111
156
|
"allow",
|
|
112
|
-
`microphone ${
|
|
113
|
-
), this.widgetFrame.src = `${
|
|
157
|
+
`microphone ${s.insightBaseUrl}; camera ${s.insightBaseUrl}; clipboard-read ${s.insightBaseUrl}; clipboard-write ${s.insightBaseUrl};`
|
|
158
|
+
), this.widgetFrame.src = `${s.insightBaseUrl}`, this.widgetFrame.__desiredWidth = b, this.widgetFrame.__desiredHeight = F, this.widgetFrame.onerror = () => {
|
|
114
159
|
f.error(
|
|
115
160
|
`Failed to load iframe. Please ensure your Content Security Policy includes:
|
|
116
|
-
frame-src ${
|
|
161
|
+
frame-src ${s.insightBaseUrl}
|
|
117
162
|
`
|
|
118
163
|
);
|
|
119
|
-
}, (
|
|
120
|
-
const
|
|
121
|
-
this.isFrameReady = !0, this.setUser({ tenantId:
|
|
122
|
-
}),
|
|
164
|
+
}, (g && document.querySelector(g) || document.body).appendChild(this.widgetFrame);
|
|
165
|
+
const E = d.subscribe("Auth.Ready", () => {
|
|
166
|
+
this.isFrameReady = !0, this.setUser({ tenantId: o, tenantName: a, user: n, language: r });
|
|
167
|
+
}), R = d.subscribe(
|
|
123
168
|
"Auth.Complete",
|
|
124
|
-
(
|
|
169
|
+
(c) => {
|
|
125
170
|
var l;
|
|
126
|
-
this.isFrameAuthenticated = !0, this.disableQueue(!0), t(
|
|
171
|
+
this.isFrameAuthenticated = !0, this.disableQueue(!0), t(c), (l = e.onAuthenticated) == null || l.call(e, c);
|
|
127
172
|
}
|
|
128
173
|
);
|
|
129
|
-
this.unsubsciptions.push(
|
|
174
|
+
this.unsubsciptions.push(E, R);
|
|
130
175
|
}
|
|
131
176
|
}), this.setUser = (e) => {
|
|
132
|
-
const t = this.config.partnerKey, { tenantId:
|
|
133
|
-
this.config.tenantId =
|
|
177
|
+
const t = this.config.partnerKey, { tenantId: s, tenantName: o, user: a, language: n } = e;
|
|
178
|
+
this.config.tenantId = s, this.config.tenantName = o, this.config.user = a, this.config.language = n, this.isFrameAuthenticated = !1, this.postMessage({
|
|
134
179
|
type: "Auth.Login",
|
|
135
180
|
payload: {
|
|
136
181
|
partnerKey: t,
|
|
137
|
-
tenantId:
|
|
138
|
-
tenantName:
|
|
139
|
-
user:
|
|
140
|
-
language:
|
|
182
|
+
tenantId: s,
|
|
183
|
+
tenantName: o,
|
|
184
|
+
user: a,
|
|
185
|
+
language: n
|
|
141
186
|
}
|
|
142
187
|
});
|
|
143
188
|
}, this.show = () => {
|
|
144
189
|
if (this.widgetFrame) {
|
|
145
|
-
const e = this.widgetFrame.__desiredWidth || "350px", t = this.widgetFrame.__desiredHeight || "600px",
|
|
190
|
+
const e = this.widgetFrame.__desiredWidth || "350px", t = this.widgetFrame.__desiredHeight || "600px", s = {
|
|
146
191
|
opacity: "1",
|
|
147
192
|
pointerEvents: "auto",
|
|
148
193
|
width: e,
|
|
@@ -150,36 +195,46 @@ class H {
|
|
|
150
195
|
maxWidth: e,
|
|
151
196
|
maxHeight: t
|
|
152
197
|
};
|
|
153
|
-
Object.assign(this.widgetFrame.style, { ...
|
|
198
|
+
Object.assign(this.widgetFrame.style, { ...s });
|
|
154
199
|
}
|
|
155
200
|
}, this.hide = () => {
|
|
156
|
-
this.widgetFrame && Object.assign(this.widgetFrame.style, { ...
|
|
201
|
+
this.widgetFrame && Object.assign(this.widgetFrame.style, { ...p });
|
|
157
202
|
}, this.reset = () => {
|
|
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();
|
|
203
|
+
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.methodRegistry = {};
|
|
159
204
|
}, this.command = (e) => {
|
|
160
205
|
this.sendOrQueue(e), this.show();
|
|
161
|
-
}, this.emit = this.command, this.on = (e, t) =>
|
|
206
|
+
}, this.emit = this.command, this.on = (e, t) => d.subscribe(e, t), this.registerTemplates = (e) => {
|
|
162
207
|
this.sendOrQueue({
|
|
163
208
|
type: "Template.Register",
|
|
164
209
|
payload: e
|
|
165
210
|
});
|
|
166
|
-
}, this.
|
|
211
|
+
}, this.registerMethod = (e, t) => {
|
|
212
|
+
this.methodRegistry[e] = t;
|
|
213
|
+
}, this.unregisterMethod = (e) => delete this.methodRegistry[e], this.getConfig = () => this.config, this.getVersion = () => A(), window.addEventListener(
|
|
167
214
|
"message",
|
|
168
215
|
(e) => {
|
|
169
216
|
var t;
|
|
170
|
-
e.source !== ((t = this.widgetFrame) == null ? void 0 : t.contentWindow) || !e.data
|
|
217
|
+
if (!(e.source !== ((t = this.widgetFrame) == null ? void 0 : t.contentWindow) || !e.data)) {
|
|
218
|
+
if (e.data.type === "Method.Call") {
|
|
219
|
+
this.handleMethodCall(
|
|
220
|
+
e.data.payload
|
|
221
|
+
);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
d.emit(e.data.type, e.data.payload);
|
|
225
|
+
}
|
|
171
226
|
}
|
|
172
227
|
);
|
|
173
228
|
}
|
|
174
229
|
}
|
|
175
230
|
let u = null;
|
|
176
|
-
function
|
|
177
|
-
return u || (u = new
|
|
231
|
+
function U() {
|
|
232
|
+
return u || (u = new I()), u;
|
|
178
233
|
}
|
|
179
|
-
const
|
|
234
|
+
const H = U();
|
|
180
235
|
export {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
236
|
+
H as AuraWidget,
|
|
237
|
+
_ as configure,
|
|
238
|
+
m as getConfig,
|
|
239
|
+
A as getVersion
|
|
185
240
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
frame-src ${
|
|
3
|
-
`)},(
|
|
1
|
+
(function(a,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(a=typeof globalThis<"u"?globalThis:a||self,u(a.InsightAura={}))})(this,function(a){"use strict";const u={insightBaseUrl:"https://anywhere.insighthealth.ai"};let f=null;function Q(){return f}function E(i){f={...u,...i}}function M(i){E(i)}function c(){const i=Q();if(!i)throw new Error("Aura SDK not configured. Call configure() first to set global configuration.");return i}function m(){return"0.0.10-beta.1"}class R{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(s=>s!==t)}),this.emit=(e,t)=>{this.events[e]&&this.events[e].forEach(s=>s(t))}}}const g=new R,p={log:i=>{console.log(`[Insight Health Aura Widget]: ${i}`)},warn:i=>{console.warn(`[Insight Health Aura Widget]: ${i}`)},error:i=>{console.error(`[Insight Health Aura Widget]: ${i}`)}},w={opacity:"0",pointerEvents:"none",width:"0",height:"0",maxWidth:"0",maxHeight:"0"},A={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.methodRegistry={},this.isFrameReady=!1,this.isFrameAuthenticated=!1,this.postMessage=e=>{var s;if(!((s=this.widgetFrame)!=null&&s.contentWindow)){p.warn("No widget iframe to communicate with");return}const t=c();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.handleMethodCall=async e=>{const{callId:t,methodName:s,args:d}=e,r=this.methodRegistry[s];if(!r){this.postMessage({type:"Method.Response",payload:{callId:t,success:!1,error:{message:`Method "${s}" is not registered`,code:"METHOD_NOT_FOUND"}}});return}try{const n=await r(d||{});this.postMessage({type:"Method.Response",payload:{callId:t,success:!0,result:n}})}catch(n){const o=n instanceof Error?n:new Error(String(n));this.postMessage({type:"Method.Response",payload:{callId:t,success:!1,methodName:s,error:{message:o.message,code:"METHOD_EXECUTION_ERROR",stack:o.stack,name:o.name,cause:o.cause,apiResponse:o.response}}})}},this.init=e=>new Promise(t=>{if(!this.widgetFrame){this.reset(),this.enableQueue();const s=c(),{tenantId:d,tenantName:r,user:n,language:o,container:y,widgetId:O,widgetStyles:h}=e;this.config=e,this.isFrameReady=!1,this.widgetFrame=document.createElement("iframe");const I=(h==null?void 0:h.width)||"350px",U=(h==null?void 0:h.height)||"600px",_={...A,...h,...w};Object.assign(this.widgetFrame.style,_),this.widgetFrame.id=O||"aura-widget",this.widgetFrame.setAttribute("allow",`microphone ${s.insightBaseUrl}; camera ${s.insightBaseUrl}; clipboard-read ${s.insightBaseUrl}; clipboard-write ${s.insightBaseUrl};`),this.widgetFrame.src=`${s.insightBaseUrl}`,this.widgetFrame.__desiredWidth=I,this.widgetFrame.__desiredHeight=U,this.widgetFrame.onerror=()=>{p.error(`Failed to load iframe. Please ensure your Content Security Policy includes:
|
|
2
|
+
frame-src ${s.insightBaseUrl}
|
|
3
|
+
`)},(y&&document.querySelector(y)||document.body).appendChild(this.widgetFrame);const H=g.subscribe("Auth.Ready",()=>{this.isFrameReady=!0,this.setUser({tenantId:d,tenantName:r,user:n,language:o})}),S=g.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(H,S)}}),this.setUser=e=>{const t=this.config.partnerKey,{tenantId:s,tenantName:d,user:r,language:n}=e;this.config.tenantId=s,this.config.tenantName=d,this.config.user=r,this.config.language=n,this.isFrameAuthenticated=!1,this.postMessage({type:"Auth.Login",payload:{partnerKey:t,tenantId:s,tenantName:d,user:r,language:n}})},this.show=()=>{if(this.widgetFrame){const e=this.widgetFrame.__desiredWidth||"350px",t=this.widgetFrame.__desiredHeight||"600px",s={opacity:"1",pointerEvents:"auto",width:e,height:t,maxWidth:e,maxHeight:t};Object.assign(this.widgetFrame.style,{...s})}},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.methodRegistry={}},this.command=e=>{this.sendOrQueue(e),this.show()},this.emit=this.command,this.on=(e,t)=>g.subscribe(e,t),this.registerTemplates=e=>{this.sendOrQueue({type:"Template.Register",payload:e})},this.registerMethod=(e,t)=>{this.methodRegistry[e]=t},this.unregisterMethod=e=>delete this.methodRegistry[e],this.getConfig=()=>this.config,this.getVersion=()=>m(),window.addEventListener("message",e=>{var t;if(!(e.source!==((t=this.widgetFrame)==null?void 0:t.contentWindow)||!e.data)){if(e.data.type==="Method.Call"){this.handleMethodCall(e.data.payload);return}g.emit(e.data.type,e.data.payload)}})}}let l=null;function x(){return l||(l=new C),l}const W=x();a.AuraWidget=W,a.configure=M,a.getConfig=c,a.getVersion=m,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
CHANGED
|
@@ -35,4 +35,34 @@ export type AuraTemplate = {
|
|
|
35
35
|
export type AuraRegisterTemplatePayload = {
|
|
36
36
|
templates: AuraTemplate[];
|
|
37
37
|
};
|
|
38
|
+
export type Extended<T> = T & {
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
};
|
|
41
|
+
export type MethodHandler<TArgs extends Extended<unknown>, TResult = unknown> = (args: TArgs) => TResult | Promise<TResult>;
|
|
42
|
+
export type SupportedMethods = {
|
|
43
|
+
getProviderNotes: MethodHandler<{
|
|
44
|
+
providerId: string;
|
|
45
|
+
}, {
|
|
46
|
+
notes: string[];
|
|
47
|
+
}>;
|
|
48
|
+
};
|
|
49
|
+
export type MethodCallPayload<N extends keyof SupportedMethods, TArgs = Parameters<SupportedMethods[N]>[0]> = {
|
|
50
|
+
callId: string;
|
|
51
|
+
methodName: N;
|
|
52
|
+
args?: TArgs;
|
|
53
|
+
};
|
|
54
|
+
export type MethodResponsePayload<N extends keyof SupportedMethods, TResult = Awaited<ReturnType<SupportedMethods[N]>>> = {
|
|
55
|
+
callId: string;
|
|
56
|
+
success: boolean;
|
|
57
|
+
methodName: N;
|
|
58
|
+
result?: TResult;
|
|
59
|
+
error?: {
|
|
60
|
+
message: string;
|
|
61
|
+
code?: string;
|
|
62
|
+
stack?: string;
|
|
63
|
+
name?: string;
|
|
64
|
+
cause?: unknown;
|
|
65
|
+
apiResponse?: number;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
38
68
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,GAAG,IAAI;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CACpB,IAAI,CACF,mBAAmB,EACjB,OAAO,GACP,QAAQ,GACR,cAAc,GACd,WAAW,GACX,KAAK,GACL,QAAQ,GACR,MAAM,GACN,OAAO,CACV,CACF,CAAC;IACF,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,IAAI,CAC3B,oBAAoB,EACpB,UAAU,GAAG,YAAY,GAAG,MAAM,GAAG,UAAU,CAChD,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,CAAC,GAAG,GAAG,IAAI;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,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