@insight-health/aura 0.0.10-beta.0 → 0.0.10-beta.2
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.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -41
- package/dist/index.umd.js +2 -2
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
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,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,
|
|
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,EAC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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 A(){return w}function x(i){w={...C,...i}}function W(i){x(i)}function
|
|
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 c(){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.2"}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 u=new O,d={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)){d.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:h}=e,r=this.methodRegistry[s];if(!r){this.postMessage({type:"Method.Response",payload:{callId:t,methodName:s,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,methodName:s,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=c(),{tenantId:h,tenantName:r,user:n,language:a,container:l,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",M=(o==null?void 0:o.height)||"600px",Q={...I,...o,...p};Object.assign(this.widgetFrame.style,Q),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=M,this.widgetFrame.onerror=()=>{d.error(`Failed to load iframe. Please ensure your Content Security Policy includes:
|
|
2
2
|
frame-src ${s.insightBaseUrl}
|
|
3
|
-
`)},(
|
|
3
|
+
`)},(l&&document.querySelector(l)||document.body).appendChild(this.widgetFrame);const E=u.subscribe("Auth.Ready",()=>{this.isFrameReady=!0,this.setUser({tenantId:h,tenantName:r,user:n,language:a})}),R=u.subscribe("Auth.Complete",f=>{var m;this.isFrameAuthenticated=!0,this.disableQueue(!0),t(f),(m=e.onAuthenticated)==null||m.call(e,f)});this.unsubsciptions.push(E,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)=>u.subscribe(e,t),this.registerTemplates=e=>{this.sendOrQueue({type:"Template.Register",payload:e})},this.registerMethod=(e,t)=>{if(typeof e!="string"){d.error("Method name must be a string");return}if(typeof t!="function"){d.error("Method handler for name "+e+" must be a function");return}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}u.emit(e.data.type,e.data.payload)}})}}let g=null;function _(){return g||(g=new U),g}const H=_();exports.AuraWidget=H;exports.configure=W;exports.getConfig=c;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,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const R = {
|
|
2
2
|
insightBaseUrl: "https://anywhere.insighthealth.ai"
|
|
3
3
|
};
|
|
4
4
|
let w = null;
|
|
@@ -6,12 +6,12 @@ function x() {
|
|
|
6
6
|
return w;
|
|
7
7
|
}
|
|
8
8
|
function C(i) {
|
|
9
|
-
w = { ...
|
|
9
|
+
w = { ...R, ...i };
|
|
10
10
|
}
|
|
11
11
|
function _(i) {
|
|
12
12
|
C(i);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function f() {
|
|
15
15
|
const i = x();
|
|
16
16
|
if (!i)
|
|
17
17
|
throw new Error(
|
|
@@ -20,7 +20,7 @@ function m() {
|
|
|
20
20
|
return i;
|
|
21
21
|
}
|
|
22
22
|
function A() {
|
|
23
|
-
return "0.0.10-beta.
|
|
23
|
+
return "0.0.10-beta.2";
|
|
24
24
|
}
|
|
25
25
|
class W {
|
|
26
26
|
constructor() {
|
|
@@ -31,7 +31,7 @@ class W {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
const d = new W(),
|
|
34
|
+
const d = new W(), u = {
|
|
35
35
|
log: (i) => {
|
|
36
36
|
console.log(`[Insight Health Aura Widget]: ${i}`);
|
|
37
37
|
},
|
|
@@ -65,10 +65,10 @@ class I {
|
|
|
65
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
66
|
var s;
|
|
67
67
|
if (!((s = this.widgetFrame) != null && s.contentWindow)) {
|
|
68
|
-
|
|
68
|
+
u.warn("No widget iframe to communicate with");
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
const t =
|
|
71
|
+
const t = f();
|
|
72
72
|
this.widgetFrame.contentWindow.postMessage(e, {
|
|
73
73
|
targetOrigin: t.insightBaseUrl
|
|
74
74
|
});
|
|
@@ -90,12 +90,13 @@ class I {
|
|
|
90
90
|
}
|
|
91
91
|
this.postMessage(e);
|
|
92
92
|
}, this.handleMethodCall = async (e) => {
|
|
93
|
-
const { callId: t, methodName: s, args:
|
|
94
|
-
if (!
|
|
93
|
+
const { callId: t, methodName: s, args: h } = e, r = this.methodRegistry[s];
|
|
94
|
+
if (!r) {
|
|
95
95
|
this.postMessage({
|
|
96
96
|
type: "Method.Response",
|
|
97
97
|
payload: {
|
|
98
98
|
callId: t,
|
|
99
|
+
methodName: s,
|
|
99
100
|
success: !1,
|
|
100
101
|
error: {
|
|
101
102
|
message: `Method "${s}" is not registered`,
|
|
@@ -106,29 +107,31 @@ class I {
|
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
108
109
|
try {
|
|
109
|
-
const n = await
|
|
110
|
+
const n = await r(h || {});
|
|
110
111
|
this.postMessage({
|
|
111
112
|
type: "Method.Response",
|
|
112
113
|
payload: {
|
|
113
114
|
callId: t,
|
|
115
|
+
methodName: s,
|
|
114
116
|
success: !0,
|
|
115
117
|
result: n
|
|
116
118
|
}
|
|
117
119
|
});
|
|
118
120
|
} catch (n) {
|
|
119
|
-
const
|
|
121
|
+
const a = n instanceof Error ? n : new Error(String(n));
|
|
120
122
|
this.postMessage({
|
|
121
123
|
type: "Method.Response",
|
|
122
124
|
payload: {
|
|
123
125
|
callId: t,
|
|
124
126
|
success: !1,
|
|
127
|
+
methodName: s,
|
|
125
128
|
error: {
|
|
126
|
-
message:
|
|
129
|
+
message: a.message,
|
|
127
130
|
code: "METHOD_EXECUTION_ERROR",
|
|
128
|
-
stack:
|
|
129
|
-
name:
|
|
130
|
-
cause:
|
|
131
|
-
apiResponse:
|
|
131
|
+
stack: a.stack,
|
|
132
|
+
name: a.name,
|
|
133
|
+
cause: a.cause,
|
|
134
|
+
apiResponse: a.response
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
137
|
});
|
|
@@ -136,51 +139,51 @@ class I {
|
|
|
136
139
|
}, this.init = (e) => new Promise((t) => {
|
|
137
140
|
if (!this.widgetFrame) {
|
|
138
141
|
this.reset(), this.enableQueue();
|
|
139
|
-
const s =
|
|
140
|
-
tenantId:
|
|
141
|
-
tenantName:
|
|
142
|
+
const s = f(), {
|
|
143
|
+
tenantId: h,
|
|
144
|
+
tenantName: r,
|
|
142
145
|
user: n,
|
|
143
|
-
language:
|
|
144
|
-
container:
|
|
146
|
+
language: a,
|
|
147
|
+
container: c,
|
|
145
148
|
widgetId: y,
|
|
146
|
-
widgetStyles:
|
|
149
|
+
widgetStyles: o
|
|
147
150
|
} = e;
|
|
148
151
|
this.config = e, this.isFrameReady = !1, this.widgetFrame = document.createElement("iframe");
|
|
149
|
-
const b = (
|
|
152
|
+
const b = (o == null ? void 0 : o.width) || "350px", F = (o == null ? void 0 : o.height) || "600px", M = {
|
|
150
153
|
...O,
|
|
151
|
-
...
|
|
154
|
+
...o,
|
|
152
155
|
...p
|
|
153
156
|
};
|
|
154
|
-
Object.assign(this.widgetFrame.style,
|
|
157
|
+
Object.assign(this.widgetFrame.style, M), this.widgetFrame.id = y || "aura-widget", this.widgetFrame.setAttribute(
|
|
155
158
|
"allow",
|
|
156
159
|
`microphone ${s.insightBaseUrl}; camera ${s.insightBaseUrl}; clipboard-read ${s.insightBaseUrl}; clipboard-write ${s.insightBaseUrl};`
|
|
157
160
|
), this.widgetFrame.src = `${s.insightBaseUrl}`, this.widgetFrame.__desiredWidth = b, this.widgetFrame.__desiredHeight = F, this.widgetFrame.onerror = () => {
|
|
158
|
-
|
|
161
|
+
u.error(
|
|
159
162
|
`Failed to load iframe. Please ensure your Content Security Policy includes:
|
|
160
163
|
frame-src ${s.insightBaseUrl}
|
|
161
164
|
`
|
|
162
165
|
);
|
|
163
|
-
}, (
|
|
164
|
-
const
|
|
165
|
-
this.isFrameReady = !0, this.setUser({ tenantId:
|
|
166
|
-
}),
|
|
166
|
+
}, (c && document.querySelector(c) || document.body).appendChild(this.widgetFrame);
|
|
167
|
+
const Q = d.subscribe("Auth.Ready", () => {
|
|
168
|
+
this.isFrameReady = !0, this.setUser({ tenantId: h, tenantName: r, user: n, language: a });
|
|
169
|
+
}), E = d.subscribe(
|
|
167
170
|
"Auth.Complete",
|
|
168
|
-
(
|
|
169
|
-
var
|
|
170
|
-
this.isFrameAuthenticated = !0, this.disableQueue(!0), t(
|
|
171
|
+
(l) => {
|
|
172
|
+
var m;
|
|
173
|
+
this.isFrameAuthenticated = !0, this.disableQueue(!0), t(l), (m = e.onAuthenticated) == null || m.call(e, l);
|
|
171
174
|
}
|
|
172
175
|
);
|
|
173
|
-
this.unsubsciptions.push(
|
|
176
|
+
this.unsubsciptions.push(Q, E);
|
|
174
177
|
}
|
|
175
178
|
}), this.setUser = (e) => {
|
|
176
|
-
const t = this.config.partnerKey, { tenantId: s, tenantName:
|
|
177
|
-
this.config.tenantId = s, this.config.tenantName =
|
|
179
|
+
const t = this.config.partnerKey, { tenantId: s, tenantName: h, user: r, language: n } = e;
|
|
180
|
+
this.config.tenantId = s, this.config.tenantName = h, this.config.user = r, this.config.language = n, this.isFrameAuthenticated = !1, this.postMessage({
|
|
178
181
|
type: "Auth.Login",
|
|
179
182
|
payload: {
|
|
180
183
|
partnerKey: t,
|
|
181
184
|
tenantId: s,
|
|
182
|
-
tenantName:
|
|
183
|
-
user:
|
|
185
|
+
tenantName: h,
|
|
186
|
+
user: r,
|
|
184
187
|
language: n
|
|
185
188
|
}
|
|
186
189
|
});
|
|
@@ -208,6 +211,14 @@ class I {
|
|
|
208
211
|
payload: e
|
|
209
212
|
});
|
|
210
213
|
}, this.registerMethod = (e, t) => {
|
|
214
|
+
if (typeof e != "string") {
|
|
215
|
+
u.error("Method name must be a string");
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (typeof t != "function") {
|
|
219
|
+
u.error("Method handler for name " + e + " must be a function");
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
211
222
|
this.methodRegistry[e] = t;
|
|
212
223
|
}, this.unregisterMethod = (e) => delete this.methodRegistry[e], this.getConfig = () => this.config, this.getVersion = () => A(), window.addEventListener(
|
|
213
224
|
"message",
|
|
@@ -226,14 +237,14 @@ class I {
|
|
|
226
237
|
);
|
|
227
238
|
}
|
|
228
239
|
}
|
|
229
|
-
let
|
|
240
|
+
let g = null;
|
|
230
241
|
function U() {
|
|
231
|
-
return
|
|
242
|
+
return g || (g = new I()), g;
|
|
232
243
|
}
|
|
233
244
|
const H = U();
|
|
234
245
|
export {
|
|
235
246
|
H as AuraWidget,
|
|
236
247
|
_ as configure,
|
|
237
|
-
|
|
248
|
+
f as getConfig,
|
|
238
249
|
A as getVersion
|
|
239
250
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(r=typeof globalThis<"u"?globalThis:r||self,u(r.InsightAura={}))})(this,function(r){"use strict";const u={insightBaseUrl:"https://anywhere.insighthealth.ai"};let m=null;function M(){return m}function Q(i){m={...u,...i}}function E(i){Q(i)}function l(){const i=M();if(!i)throw new Error("Aura SDK not configured. Call configure() first to set global configuration.");return i}function p(){return"0.0.10-beta.2"}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,c={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)){c.warn("No widget iframe to communicate with");return}const t=l();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,a=this.methodRegistry[s];if(!a){this.postMessage({type:"Method.Response",payload:{callId:t,methodName:s,success:!1,error:{message:`Method "${s}" is not registered`,code:"METHOD_NOT_FOUND"}}});return}try{const n=await a(d||{});this.postMessage({type:"Method.Response",payload:{callId:t,methodName:s,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=l(),{tenantId:d,tenantName:a,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=()=>{c.error(`Failed to load iframe. Please ensure your Content Security Policy includes:
|
|
2
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:
|
|
3
|
+
`)},(y&&document.querySelector(y)||document.body).appendChild(this.widgetFrame);const H=g.subscribe("Auth.Ready",()=>{this.isFrameReady=!0,this.setUser({tenantId:d,tenantName:a,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:a,language:n}=e;this.config.tenantId=s,this.config.tenantName=d,this.config.user=a,this.config.language=n,this.isFrameAuthenticated=!1,this.postMessage({type:"Auth.Login",payload:{partnerKey:t,tenantId:s,tenantName:d,user:a,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)=>{if(typeof e!="string"){c.error("Method name must be a string");return}if(typeof t!="function"){c.error("Method handler for name "+e+" must be a function");return}this.methodRegistry[e]=t},this.unregisterMethod=e=>delete this.methodRegistry[e],this.getConfig=()=>this.config,this.getVersion=()=>p(),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 f=null;function x(){return f||(f=new C),f}const W=x();r.AuraWidget=W,r.configure=E,r.getConfig=l,r.getVersion=p,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
CHANGED
|
@@ -51,9 +51,10 @@ export type MethodCallPayload<N extends keyof SupportedMethods, TArgs = Paramete
|
|
|
51
51
|
methodName: N;
|
|
52
52
|
args?: TArgs;
|
|
53
53
|
};
|
|
54
|
-
export type MethodResponsePayload<N extends keyof SupportedMethods, TResult = ReturnType<SupportedMethods[N]
|
|
54
|
+
export type MethodResponsePayload<N extends keyof SupportedMethods, TResult = Awaited<ReturnType<SupportedMethods[N]>>> = {
|
|
55
55
|
callId: string;
|
|
56
56
|
success: boolean;
|
|
57
|
+
methodName: N;
|
|
57
58
|
result?: TResult;
|
|
58
59
|
error?: {
|
|
59
60
|
message: string;
|
|
@@ -61,7 +62,7 @@ export type MethodResponsePayload<N extends keyof SupportedMethods, TResult = Re
|
|
|
61
62
|
stack?: string;
|
|
62
63
|
name?: string;
|
|
63
64
|
cause?: unknown;
|
|
64
|
-
|
|
65
|
+
apiResponse?: unknown;
|
|
65
66
|
};
|
|
66
67
|
};
|
|
67
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,CA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