@insight-health/aura 0.0.10 → 0.0.11
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 +3 -2
- package/dist/auraWidget.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +50 -42
- package/dist/index.umd.js +2 -2
- package/dist/types.d.ts +16 -4
- 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 { RegisterTemplatesPayload, AuraWidgetInitParams, AuraWidgetEmitEvent, AuthParams, SupportedMethods, AutoRegisterTemplatesPayload } from './types';
|
|
1
|
+
import { RegisterTemplatesPayload, AuraWidgetInitParams, AuraWidgetEmitEvent, AuthParams, SupportedMethods, AutoRegisterTemplatesPayload, AuraWidgetAuthenticatedResponse, ThemeConfig } from './types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Aura service class
|
|
@@ -21,8 +21,9 @@ declare class AuraWidgetService {
|
|
|
21
21
|
private clearQueue;
|
|
22
22
|
private sendOrQueue;
|
|
23
23
|
private handleMethodCall;
|
|
24
|
-
init: (params: AuraWidgetInitParams) => Promise<
|
|
24
|
+
init: (params: AuraWidgetInitParams) => Promise<AuraWidgetAuthenticatedResponse>;
|
|
25
25
|
setUser: (params: AuthParams) => void;
|
|
26
|
+
setTheme: (config: ThemeConfig) => void;
|
|
26
27
|
show: () => void;
|
|
27
28
|
hide: () => void;
|
|
28
29
|
reset: () => 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,wBAAwB,EACxB,oBAAoB,EAEpB,mBAAmB,EACnB,UAAU,EAEV,gBAAgB,EAChB,4BAA4B,
|
|
1
|
+
{"version":3,"file":"auraWidget.d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M,CAAC,EACP,SAAS,gBAAgB,CAAC,CAAC,CAAC,KAC3B,IAAI,CAWL;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 A={insightBaseUrl:"https://anywhere.insighthealth.ai"};let w=null;function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A={insightBaseUrl:"https://anywhere.insighthealth.ai"};let w=null;function x(){return w}function W(i){w={...A,...i}}function O(i){W(i)}function l(){const i=x();if(!i)throw new Error("Aura SDK not configured. Call configure() first to set global configuration.");return i}function y(){return"0.0.11"}class T{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 T,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"},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 I{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=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:r}=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(r||{});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(),{themeConfig:r,tenantId:a,tenantName:n,user:o,language:b,container:c,widgetId:F,widgetStyles:h}=e;this.config=e,this.isFrameReady=!1,this.widgetFrame=document.createElement("iframe");const M=(h==null?void 0:h.width)||"350px",Q=(h==null?void 0:h.height)||"600px",R={...U,...h,...p};Object.assign(this.widgetFrame.style,R),this.widgetFrame.id=F||"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=M,this.widgetFrame.__desiredHeight=Q,this.widgetFrame.onerror=()=>{d.error(`Failed to load iframe. Please ensure your Content Security Policy includes:
|
|
2
2
|
frame-src ${s.insightBaseUrl}
|
|
3
|
-
`)},(
|
|
3
|
+
`)},(c&&document.querySelector(c)||document.body).appendChild(this.widgetFrame);const C=u.subscribe("Auth.Ready",()=>{this.isFrameReady=!0,r&&this.setTheme(r),this.setUser({tenantId:a,tenantName:n,user:o,language:b})}),E=u.subscribe("Auth.Complete",m=>{var f;this.isFrameAuthenticated=!0,this.disableQueue(!0),t(m),(f=e.onAuthenticated)==null||f.call(e,m)});this.unsubsciptions.push(C,E)}}),this.setUser=e=>{const t=this.config.partnerKey,{tenantId:s,tenantName:r,user:a,language:n}=e;this.config.tenantId=s,this.config.tenantName=r,this.config.user=a,this.config.language=n,this.isFrameAuthenticated=!1,this.postMessage({type:"Auth.Login",payload:{partnerKey:t,tenantId:s,tenantName:r,user:a,language:n}})},this.setTheme=e=>{this.postMessage({type:"Theme.Update",payload:{...e}})},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.autoRegisterTemplates=e=>{this.sendOrQueue({type:"Template.AutoRegister",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 I),g}const H=_();exports.AuraWidget=H;exports.configure=O;exports.getConfig=l;exports.getVersion=y;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const C = {
|
|
2
2
|
insightBaseUrl: "https://anywhere.insighthealth.ai"
|
|
3
3
|
};
|
|
4
4
|
let w = null;
|
|
@@ -6,7 +6,7 @@ function x() {
|
|
|
6
6
|
return w;
|
|
7
7
|
}
|
|
8
8
|
function A(i) {
|
|
9
|
-
w = { ...
|
|
9
|
+
w = { ...C, ...i };
|
|
10
10
|
}
|
|
11
11
|
function _(i) {
|
|
12
12
|
A(i);
|
|
@@ -19,10 +19,10 @@ function f() {
|
|
|
19
19
|
);
|
|
20
20
|
return i;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
return "0.0.
|
|
22
|
+
function W() {
|
|
23
|
+
return "0.0.11";
|
|
24
24
|
}
|
|
25
|
-
class
|
|
25
|
+
class O {
|
|
26
26
|
constructor() {
|
|
27
27
|
this.events = {}, this.subscribe = (e, t) => (this.events[e] || (this.events[e] = []), this.events[e].push(t), () => {
|
|
28
28
|
this.events[e] = this.events[e].filter((s) => s !== t);
|
|
@@ -31,7 +31,7 @@ class W {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
const u = new
|
|
34
|
+
const u = new O(), d = {
|
|
35
35
|
log: (i) => {
|
|
36
36
|
console.log(`[Insight Health Aura Widget]: ${i}`);
|
|
37
37
|
},
|
|
@@ -48,7 +48,7 @@ const u = new W(), d = {
|
|
|
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)",
|
|
@@ -90,8 +90,8 @@ 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: r } = e, a = this.methodRegistry[s];
|
|
94
|
+
if (!a) {
|
|
95
95
|
this.postMessage({
|
|
96
96
|
type: "Method.Response",
|
|
97
97
|
payload: {
|
|
@@ -107,7 +107,7 @@ class I {
|
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
109
|
try {
|
|
110
|
-
const n = await r
|
|
110
|
+
const n = await a(r || {});
|
|
111
111
|
this.postMessage({
|
|
112
112
|
type: "Method.Response",
|
|
113
113
|
payload: {
|
|
@@ -118,7 +118,7 @@ class I {
|
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
120
|
} catch (n) {
|
|
121
|
-
const
|
|
121
|
+
const o = n instanceof Error ? n : new Error(String(n));
|
|
122
122
|
this.postMessage({
|
|
123
123
|
type: "Method.Response",
|
|
124
124
|
payload: {
|
|
@@ -126,12 +126,12 @@ class I {
|
|
|
126
126
|
success: !1,
|
|
127
127
|
methodName: s,
|
|
128
128
|
error: {
|
|
129
|
-
message:
|
|
129
|
+
message: o.message,
|
|
130
130
|
code: "METHOD_EXECUTION_ERROR",
|
|
131
|
-
stack:
|
|
132
|
-
name:
|
|
133
|
-
cause:
|
|
134
|
-
apiResponse:
|
|
131
|
+
stack: o.stack,
|
|
132
|
+
name: o.name,
|
|
133
|
+
cause: o.cause,
|
|
134
|
+
apiResponse: o.response
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
});
|
|
@@ -140,53 +140,61 @@ class I {
|
|
|
140
140
|
if (!this.widgetFrame) {
|
|
141
141
|
this.reset(), this.enableQueue();
|
|
142
142
|
const s = f(), {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
themeConfig: r,
|
|
144
|
+
tenantId: a,
|
|
145
|
+
tenantName: n,
|
|
146
|
+
user: o,
|
|
147
|
+
language: y,
|
|
148
|
+
container: l,
|
|
149
|
+
widgetId: b,
|
|
150
|
+
widgetStyles: h
|
|
150
151
|
} = e;
|
|
151
152
|
this.config = e, this.isFrameReady = !1, this.widgetFrame = document.createElement("iframe");
|
|
152
|
-
const
|
|
153
|
-
...
|
|
154
|
-
...
|
|
153
|
+
const F = (h == null ? void 0 : h.width) || "350px", M = (h == null ? void 0 : h.height) || "600px", Q = {
|
|
154
|
+
...U,
|
|
155
|
+
...h,
|
|
155
156
|
...p
|
|
156
157
|
};
|
|
157
|
-
Object.assign(this.widgetFrame.style, Q), this.widgetFrame.id =
|
|
158
|
+
Object.assign(this.widgetFrame.style, Q), this.widgetFrame.id = b || "aura-widget", this.widgetFrame.setAttribute(
|
|
158
159
|
"allow",
|
|
159
160
|
`microphone ${s.insightBaseUrl}; camera ${s.insightBaseUrl}; clipboard-read ${s.insightBaseUrl}; clipboard-write ${s.insightBaseUrl};`
|
|
160
|
-
), this.widgetFrame.src = `${s.insightBaseUrl}`, this.widgetFrame.__desiredWidth =
|
|
161
|
+
), this.widgetFrame.src = `${s.insightBaseUrl}`, this.widgetFrame.__desiredWidth = F, this.widgetFrame.__desiredHeight = M, this.widgetFrame.onerror = () => {
|
|
161
162
|
d.error(
|
|
162
163
|
`Failed to load iframe. Please ensure your Content Security Policy includes:
|
|
163
164
|
frame-src ${s.insightBaseUrl}
|
|
164
165
|
`
|
|
165
166
|
);
|
|
166
|
-
}, (
|
|
167
|
+
}, (l && document.querySelector(l) || document.body).appendChild(this.widgetFrame);
|
|
167
168
|
const R = u.subscribe("Auth.Ready", () => {
|
|
168
|
-
this.isFrameReady = !0, this.setUser({ tenantId:
|
|
169
|
-
}),
|
|
169
|
+
this.isFrameReady = !0, r && this.setTheme(r), this.setUser({ tenantId: a, tenantName: n, user: o, language: y });
|
|
170
|
+
}), E = u.subscribe(
|
|
170
171
|
"Auth.Complete",
|
|
171
|
-
(
|
|
172
|
+
(c) => {
|
|
172
173
|
var m;
|
|
173
|
-
this.isFrameAuthenticated = !0, this.disableQueue(!0), t(
|
|
174
|
+
this.isFrameAuthenticated = !0, this.disableQueue(!0), t(c), (m = e.onAuthenticated) == null || m.call(e, c);
|
|
174
175
|
}
|
|
175
176
|
);
|
|
176
|
-
this.unsubsciptions.push(R,
|
|
177
|
+
this.unsubsciptions.push(R, E);
|
|
177
178
|
}
|
|
178
179
|
}), this.setUser = (e) => {
|
|
179
|
-
const t = this.config.partnerKey, { tenantId: s, tenantName:
|
|
180
|
-
this.config.tenantId = s, this.config.tenantName =
|
|
180
|
+
const t = this.config.partnerKey, { tenantId: s, tenantName: r, user: a, language: n } = e;
|
|
181
|
+
this.config.tenantId = s, this.config.tenantName = r, this.config.user = a, this.config.language = n, this.isFrameAuthenticated = !1, this.postMessage({
|
|
181
182
|
type: "Auth.Login",
|
|
182
183
|
payload: {
|
|
183
184
|
partnerKey: t,
|
|
184
185
|
tenantId: s,
|
|
185
|
-
tenantName:
|
|
186
|
-
user:
|
|
186
|
+
tenantName: r,
|
|
187
|
+
user: a,
|
|
187
188
|
language: n
|
|
188
189
|
}
|
|
189
190
|
});
|
|
191
|
+
}, this.setTheme = (e) => {
|
|
192
|
+
this.postMessage({
|
|
193
|
+
type: "Theme.Update",
|
|
194
|
+
payload: {
|
|
195
|
+
...e
|
|
196
|
+
}
|
|
197
|
+
});
|
|
190
198
|
}, this.show = () => {
|
|
191
199
|
if (this.widgetFrame) {
|
|
192
200
|
const e = this.widgetFrame.__desiredWidth || "350px", t = this.widgetFrame.__desiredHeight || "600px", s = {
|
|
@@ -225,7 +233,7 @@ class I {
|
|
|
225
233
|
return;
|
|
226
234
|
}
|
|
227
235
|
this.methodRegistry[e] = t;
|
|
228
|
-
}, this.unregisterMethod = (e) => delete this.methodRegistry[e], this.getConfig = () => this.config, this.getVersion = () =>
|
|
236
|
+
}, this.unregisterMethod = (e) => delete this.methodRegistry[e], this.getConfig = () => this.config, this.getVersion = () => W(), window.addEventListener(
|
|
229
237
|
"message",
|
|
230
238
|
(e) => {
|
|
231
239
|
var t;
|
|
@@ -243,13 +251,13 @@ class I {
|
|
|
243
251
|
}
|
|
244
252
|
}
|
|
245
253
|
let g = null;
|
|
246
|
-
function
|
|
254
|
+
function T() {
|
|
247
255
|
return g || (g = new I()), g;
|
|
248
256
|
}
|
|
249
|
-
const H =
|
|
257
|
+
const H = T();
|
|
250
258
|
export {
|
|
251
259
|
H as AuraWidget,
|
|
252
260
|
_ as configure,
|
|
253
261
|
f as getConfig,
|
|
254
|
-
|
|
262
|
+
W as getVersion
|
|
255
263
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(r,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(r=typeof globalThis<"u"?globalThis:r||self,d(r.InsightAura={}))})(this,function(r){"use strict";const d={insightBaseUrl:"https://anywhere.insighthealth.ai"};let m=null;function M(){return m}function Q(i){m={...d,...i}}function R(i){Q(i)}function
|
|
1
|
+
(function(r,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(r=typeof globalThis<"u"?globalThis:r||self,d(r.InsightAura={}))})(this,function(r){"use strict";const d={insightBaseUrl:"https://anywhere.insighthealth.ai"};let m=null;function M(){return m}function Q(i){m={...d,...i}}function R(i){Q(i)}function c(){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.11"}class A{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 A,l={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"},C={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 E{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)){l.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:a}=e,o=this.methodRegistry[s];if(!o){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 o(a||{});this.postMessage({type:"Method.Response",payload:{callId:t,methodName:s,success:!0,result:n}})}catch(n){const h=n instanceof Error?n:new Error(String(n));this.postMessage({type:"Method.Response",payload:{callId:t,success:!1,methodName:s,error:{message:h.message,code:"METHOD_EXECUTION_ERROR",stack:h.stack,name:h.name,cause:h.cause,apiResponse:h.response}}})}},this.init=e=>new Promise(t=>{if(!this.widgetFrame){this.reset(),this.enableQueue();const s=c(),{themeConfig:a,tenantId:o,tenantName:n,user:h,language:O,container:y,widgetId:T,widgetStyles:u}=e;this.config=e,this.isFrameReady=!1,this.widgetFrame=document.createElement("iframe");const I=(u==null?void 0:u.width)||"350px",U=(u==null?void 0:u.height)||"600px",_={...C,...u,...w};Object.assign(this.widgetFrame.style,_),this.widgetFrame.id=T||"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=()=>{l.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
|
|
3
|
+
`)},(y&&document.querySelector(y)||document.body).appendChild(this.widgetFrame);const H=g.subscribe("Auth.Ready",()=>{this.isFrameReady=!0,a&&this.setTheme(a),this.setUser({tenantId:o,tenantName:n,user:h,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:a,user:o,language:n}=e;this.config.tenantId=s,this.config.tenantName=a,this.config.user=o,this.config.language=n,this.isFrameAuthenticated=!1,this.postMessage({type:"Auth.Login",payload:{partnerKey:t,tenantId:s,tenantName:a,user:o,language:n}})},this.setTheme=e=>{this.postMessage({type:"Theme.Update",payload:{...e}})},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.autoRegisterTemplates=e=>{this.sendOrQueue({type:"Template.AutoRegister",payload:e})},this.registerMethod=(e,t)=>{if(typeof e!="string"){l.error("Method name must be a string");return}if(typeof t!="function"){l.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 E),f}const W=x();r.AuraWidget=W,r.configure=R,r.getConfig=c,r.getVersion=p,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
CHANGED
|
@@ -12,6 +12,13 @@ export type AuraWidgetEmitEvent<T = any> = {
|
|
|
12
12
|
type: string;
|
|
13
13
|
payload: T;
|
|
14
14
|
};
|
|
15
|
+
export type OverrideThemeColors = 'primary' | 'secondary' | 'success' | 'warning' | 'error' | 'info';
|
|
16
|
+
export type ThemeConfig = {
|
|
17
|
+
/**
|
|
18
|
+
* Override theme colors (hex strings) for the in-frame widget.
|
|
19
|
+
*/
|
|
20
|
+
colors?: Partial<Record<OverrideThemeColors, string>>;
|
|
21
|
+
};
|
|
15
22
|
export type AuraWidgetInitParams = {
|
|
16
23
|
partnerKey: string;
|
|
17
24
|
tenantId: string | number;
|
|
@@ -26,9 +33,11 @@ export type AuraWidgetInitParams = {
|
|
|
26
33
|
container?: string;
|
|
27
34
|
widgetId?: string;
|
|
28
35
|
widgetStyles?: Partial<Pick<CSSStyleDeclaration, 'width' | 'height' | 'borderRadius' | 'boxShadow' | 'top' | 'bottom' | 'left' | 'right'>>;
|
|
29
|
-
onAuthenticated?: (data:
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
onAuthenticated?: (data: AuraWidgetAuthenticatedResponse) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Provide theme options for the in-frame widget.
|
|
39
|
+
*/
|
|
40
|
+
themeConfig?: ThemeConfig;
|
|
32
41
|
};
|
|
33
42
|
export type AuthParams = Pick<AuraWidgetInitParams, 'tenantId' | 'tenantName' | 'user' | 'language'>;
|
|
34
43
|
export type AuraWidgetMessageEvent<T = any> = {
|
|
@@ -37,7 +46,7 @@ export type AuraWidgetMessageEvent<T = any> = {
|
|
|
37
46
|
};
|
|
38
47
|
export type TemplateSectionDefinition = {
|
|
39
48
|
name: string;
|
|
40
|
-
type: 'openText' | 'singleSelect' | 'multiSelect' | 'openSingleSelect' | 'openMultiSelect' | 'boolean';
|
|
49
|
+
type: 'openText' | 'singleSelect' | 'multiSelect' | 'openSingleSelect' | 'openMultiSelect' | 'boolean' | 'number';
|
|
41
50
|
options?: string[];
|
|
42
51
|
meta?: {
|
|
43
52
|
additionalInstructions?: string;
|
|
@@ -56,6 +65,9 @@ export type AuraTemplate = {
|
|
|
56
65
|
sections: Record<string, any>[];
|
|
57
66
|
};
|
|
58
67
|
};
|
|
68
|
+
export type AuraWidgetAuthenticatedResponse = Omit<AuraWidgetInitParams, 'onAuthenticated'> & {
|
|
69
|
+
registeredTemplateIds: AuraTemplate['id'][];
|
|
70
|
+
};
|
|
59
71
|
export type RegisterTemplatesPayload = {
|
|
60
72
|
templates: AuraTemplate[];
|
|
61
73
|
};
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAC3E;KAAG,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,CAAC,CAAC,CAAC;AAE1E,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,C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