@insight-health/aura 0.0.1 → 0.0.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.
@@ -1,27 +1,44 @@
1
1
  type AuraWidgetEmitEvent<T = any> = {
2
2
  type: string;
3
- data: T;
3
+ payload: T;
4
4
  };
5
5
  type AuraWidgetOpenParams = {
6
- id?: string;
7
- styles?: Partial<Pick<CSSStyleDeclaration, "width" | "height" | "borderRadius" | "boxShadow" | "top" | "bottom" | "left" | "right">>;
6
+ partnerKey: string;
7
+ subTenantId: string;
8
+ user: {
9
+ email: string;
10
+ firstName?: string;
11
+ lastName?: string;
12
+ };
13
+ language?: string;
14
+ container?: string;
15
+ widgetId?: string;
16
+ widgetStyles?: Partial<Pick<CSSStyleDeclaration, 'width' | 'height' | 'borderRadius' | 'boxShadow' | 'top' | 'bottom' | 'left' | 'right'>>;
17
+ onAuthenticated?: () => void;
8
18
  };
9
19
  /**
10
20
  * Aura service class
11
21
  * Singleton pattern - all imports reference the same instance
12
22
  */
13
23
  declare class AuraWidgetService {
24
+ private config;
14
25
  private widgetFrame;
26
+ private unsubsciptions;
27
+ isFrameReady: boolean;
28
+ isFrameAuthenticated: boolean;
15
29
  constructor();
30
+ private postMessage;
16
31
  init: (params: AuraWidgetOpenParams) => Promise<void>;
32
+ setUser: (params: Pick<AuraWidgetOpenParams, "user" | "subTenantId" | "language">) => void;
17
33
  show: () => void;
18
34
  hide: () => void;
19
- destroy: () => void;
35
+ reset: () => void;
20
36
  emit: (event: AuraWidgetEmitEvent) => void;
21
37
  on: (event: string, callback: (data: any) => void) => () => void;
22
38
  /**
23
39
  * Get SDK version
24
40
  */
41
+ getConfig: () => AuraWidgetOpenParams | null;
25
42
  getVersion: () => string;
26
43
  }
27
44
  export declare const AuraWidget: AuraWidgetService;
@@ -1 +1 @@
1
- {"version":3,"file":"auraWidget.d.ts","sourceRoot":"","sources":["../src/auraWidget.ts"],"names":[],"mappings":"AAMA,KAAK,mB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C;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,MAAM,IAAI,CAAC;CAC9B,CAAC;AA8BF;;;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,mBA2DlC;IAEF,OAAO,GACL,QAAQ,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,aAAa,GAAG,UAAU,CAAC,UAcvE;IAEF,IAAI,aAeF;IAEF,IAAI,aAIF;IAEF,KAAK,aASH;IAEF,IAAI,GAAI,OAAO,mBAAmB,UAGhC;IAEF,EAAE,GAAI,OAAO,MAAM,EAAE,UAAU,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,gBAEhD;IAEF;;OAEG;IACH,SAAS,oCAEP;IACF,UAAU,eAER;CACH;AAgBD,eAAO,MAAM,UAAU,mBAAgB,CAAC"}
@@ -7,7 +7,6 @@
7
7
  */
8
8
  export interface GlobalConfig {
9
9
  insightBaseUrl?: string;
10
- clientToken: string;
11
10
  }
12
11
  /**
13
12
  * Get the global configuration
@@ -1 +1 @@
1
- {"version":3,"file":"globalConfig.d.ts","sourceRoot":"","sources":["../src/globalConfig.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CAErB;AAQD;;GAEG;AACH,wBAAgB,eAAe,IAAI,YAAY,GAAG,IAAI,CAErD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAE1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAEzC"}
1
+ {"version":3,"file":"globalConfig.d.ts","sourceRoot":"","sources":["../src/globalConfig.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;CAEzB;AAQD;;GAEG;AACH,wBAAgB,eAAe,IAAI,YAAY,GAAG,IAAI,CAErD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAE1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAEzC"}
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f={insightBaseUrl:"https://app.lumi.build"};let h=null;function m(){return h}function b(i){h={...f,...i}}function p(i){b(i)}function o(){const i=m();if(!i)throw new Error("Aura SDK not configured. Call configure() first to set global configuration.");return i}function c(){return"0.0.1"}class F{constructor(){this.events={},this.subscribe=(t,e)=>(this.events[t]||(this.events[t]=[]),this.events[t].push(e),()=>{this.events[t]=this.events[t].filter(s=>s!==e)}),this.emit=(t,e)=>{this.events[t]&&this.events[t].forEach(s=>s(e))}}}const a=new F,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}`)}},g={opacity:"0",pointerEvents:"none",width:"0",height:"0",maxWidth:"0",maxHeight:"0"},x={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 y{constructor(){this.widgetFrame=null,this.init=async t=>{const e=o(),{id:s,styles:n}=t;if(!this.widgetFrame){this.widgetFrame=document.createElement("iframe");const u=(n==null?void 0:n.width)||"350px",l=(n==null?void 0:n.height)||"600px",w={...x,...n,...g};Object.assign(this.widgetFrame.style,w),this.widgetFrame.id=s||"aura-widget",this.widgetFrame.src=`${e.insightBaseUrl}`,this.widgetFrame.__desiredWidth=u,this.widgetFrame.__desiredHeight=l,this.widgetFrame.onerror=()=>{d.error(`Failed to load iframe. Please ensure your Content Security Policy includes:
2
- frame-src ${e.insightBaseUrl}
3
- `)},document.body.appendChild(this.widgetFrame)}},this.show=()=>{if(this.widgetFrame){const t=this.widgetFrame.__desiredWidth||"350px",e=this.widgetFrame.__desiredHeight||"600px",s={opacity:"1",pointerEvents:"auto",width:t,height:e,maxWidth:t,maxHeight:e};Object.assign(this.widgetFrame.style,s)}},this.hide=()=>{this.widgetFrame&&Object.assign(this.widgetFrame.style,{...g})},this.destroy=()=>{this.widgetFrame&&(this.widgetFrame.remove(),this.widgetFrame=null)},this.emit=t=>{var s;if(!((s=this.widgetFrame)!=null&&s.contentWindow)){d.warn("No widget iframe to communicate with");return}const e=o();this.widgetFrame.contentWindow.postMessage(t,{targetOrigin:e.insightBaseUrl}),this.show()},this.on=(t,e)=>a.subscribe(t,e),this.getVersion=()=>c(),window.addEventListener("message",t=>{var e;t.source!==((e=this.widgetFrame)==null?void 0:e.contentWindow)||!t.data||a.emit(t.data.type,t.data.data)})}}let r=null;function W(){return r||(r=new y),r}const C=W();exports.AuraWidget=C;exports.configure=p;exports.getConfig=o;exports.getVersion=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W={insightBaseUrl:"https://anywhere.insighthealth.ai"};let f=null;function C(){return f}function v(i){f={...W,...i}}function H(i){v(i)}function d(){const i=C();if(!i)throw new Error("Aura SDK not configured. Call configure() first to set global configuration.");return i}function m(){return"0.0.2"}class I{constructor(){this.events={},this.subscribe=(t,e)=>(this.events[t]||(this.events[t]=[]),this.events[t].push(e),()=>{this.events[t]=this.events[t].filter(s=>s!==e)}),this.emit=(t,e)=>{this.events[t]&&this.events[t].forEach(s=>s(e))}}}const r=new I,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}`)}},l={opacity:"0",pointerEvents:"none",width:"0",height:"0",maxWidth:"0",maxHeight:"0"},S={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.isFrameReady=!1,this.isFrameAuthenticated=!1,this.postMessage=t=>{var s;if(!((s=this.widgetFrame)!=null&&s.contentWindow)){c.warn("No widget iframe to communicate with");return}const e=d();this.widgetFrame.contentWindow.postMessage(t,{targetOrigin:e.insightBaseUrl})},this.init=t=>new Promise(e=>{if(!this.widgetFrame){const s=d(),{subTenantId:o,user:a,language:w,container:g,widgetId:F,widgetStyles:n}=t;this.config=t,this.isFrameReady=!1,this.widgetFrame=document.createElement("iframe");const p=(n==null?void 0:n.width)||"350px",b=(n==null?void 0:n.height)||"600px",y={...S,...n,...l};Object.assign(this.widgetFrame.style,y),this.widgetFrame.id=F||"aura-widget",this.widgetFrame.src=`${s.insightBaseUrl}/aura`,this.widgetFrame.__desiredWidth=p,this.widgetFrame.__desiredHeight=b,this.widgetFrame.onerror=()=>{c.error(`Failed to load iframe. Please ensure your Content Security Policy includes:
2
+ frame-src ${s.insightBaseUrl}
3
+ `)},(g&&document.querySelector(g)||document.body).appendChild(this.widgetFrame);const x=r.subscribe("Auth.Ready",()=>{this.isFrameReady=!0,this.setUser({subTenantId:o,user:a,language:w})}),A=r.subscribe("Auth.Complete",()=>{var u;this.isFrameAuthenticated=!0,e(),(u=t.onAuthenticated)==null||u.call(t)});this.unsubsciptions.push(x,A)}}),this.setUser=t=>{const e=this.config.partnerKey,{subTenantId:s,user:o,language:a}=t;this.isFrameAuthenticated=!1,this.postMessage({type:"Auth.Login",payload:{partnerKey:e,subTenantId:s,user:o,language:a}})},this.show=()=>{if(this.widgetFrame){const t=this.widgetFrame.__desiredWidth||"350px",e=this.widgetFrame.__desiredHeight||"600px",s={opacity:"1",pointerEvents:"auto",width:t,height:e,maxWidth:t,maxHeight:e};Object.assign(this.widgetFrame.style,{...s})}},this.hide=()=>{this.widgetFrame&&Object.assign(this.widgetFrame.style,{...l})},this.reset=()=>{this.widgetFrame&&this.widgetFrame.remove(),this.widgetFrame=null,this.isFrameReady=!1,this.isFrameAuthenticated=!1,this.unsubsciptions.forEach(t=>t==null?void 0:t()),this.unsubsciptions=[]},this.emit=t=>{this.postMessage(t),this.show()},this.on=(t,e)=>r.subscribe(t,e),this.getConfig=()=>this.config,this.getVersion=()=>m(),window.addEventListener("message",t=>{var e;t.source!==((e=this.widgetFrame)==null?void 0:e.contentWindow)||!t.data||r.emit(t.data.type,t.data.payload)})}}let h=null;function _(){return h||(h=new E),h}const R=_();exports.AuraWidget=R;exports.configure=H;exports.getConfig=d;exports.getVersion=m;
4
4
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/globalConfig.ts","../src/root.ts","../src/utils/eventBus.ts","../src/utils/logger.ts","../src/auraWidget.ts"],"sourcesContent":["/**\n * Global storage for Aura SDK configuration\n */\n\n/**\n * Root-level global configuration\n * Shared across all services/interfaces\n */\nexport interface GlobalConfig {\n insightBaseUrl?: string;\n clientToken: string;\n // Add other global config options here\n}\n\nconst defaultConfig: Partial<GlobalConfig> = {\n insightBaseUrl: \"https://app.lumi.build\",\n};\n\nlet globalConfig: GlobalConfig | null = null;\n\n/**\n * Get the global configuration\n */\nexport function getGlobalConfig(): GlobalConfig | null {\n return globalConfig;\n}\n\n/**\n * Set the global configuration\n */\nexport function setGlobalConfig(config: GlobalConfig): void {\n globalConfig = { ...defaultConfig, ...config };\n}\n\n/**\n * Clear the global configuration\n */\nexport function clearGlobalConfig(): void {\n globalConfig = null;\n}\n\n/**\n * Check if global configuration is set\n */\nexport function hasGlobalConfig(): boolean {\n return globalConfig !== null;\n}\n","/// <reference types=\"vite/client\" />\n\nimport { getGlobalConfig, GlobalConfig, setGlobalConfig } from './globalConfig'\n\n/**\n * Configure the Aura SDK globally (root-level)\n * Sets base configuration like baseUrl, apiKey, etc.\n * This configuration is shared across all services\n */\nexport function configure(config: GlobalConfig): void {\n setGlobalConfig(config)\n}\n\nexport function getConfig(): GlobalConfig {\n const globalConfig = getGlobalConfig()\n if (!globalConfig) {\n throw new Error(\n 'Aura SDK not configured. Call configure() first to set global configuration.'\n )\n }\n return globalConfig\n}\n\nexport function getVersion(): string {\n return import.meta.env.PACKAGE_VERSION\n}\n","class EventBus {\n private events: Record<string, ((data: any) => void)[]> = {};\n\n subscribe = (event: string, callback: (data: any) => void) => {\n if (!this.events[event]) {\n this.events[event] = [];\n }\n this.events[event].push(callback);\n\n return () => {\n this.events[event] = this.events[event].filter((cb) => cb !== callback);\n };\n };\n\n emit = (event: string, data: any) => {\n if (!this.events[event]) {\n return;\n }\n this.events[event].forEach((callback) => callback(data));\n };\n}\n\nexport const eventBus = new EventBus();","export const logger = {\n log: (message: string) => {\n console.log(`[Insight Health Aura Widget]: ${message}`);\n },\n warn: (message: string) => {\n console.warn(`[Insight Health Aura Widget]: ${message}`);\n },\n error: (message: string) => {\n console.error(`[Insight Health Aura Widget]: ${message}`);\n },\n};","/**\n * Aura SDK for Insight Health AI\n */\nimport { getVersion, getConfig } from \"./root\";\nimport { eventBus, logger } from \"./utils\";\n\ntype AuraWidgetEmitEvent<T = any> = {\n type: string;\n data: T;\n};\n\ntype AuraWidgetOpenParams = {\n id?: string;\n styles?: Partial<\n Pick<\n CSSStyleDeclaration,\n | \"width\"\n | \"height\"\n | \"borderRadius\"\n | \"boxShadow\"\n | \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n >\n >;\n};\n\ntype AuraWidgetMessageEvent<T = any> = {\n type: string;\n data: T;\n};\n\nconst hiddenStyles: Partial<CSSStyleDeclaration> = {\n opacity: \"0\",\n pointerEvents: \"none\",\n width: \"0\",\n height: \"0\",\n maxWidth: \"0\",\n maxHeight: \"0\",\n};\n\nconst defaultStyles: Partial<CSSStyleDeclaration> = {\n border: \"none\",\n borderRadius: \"10px\",\n boxShadow: \"0 0 10px 0 rgba(0, 0, 0, 0.1)\",\n overflow: \"hidden\",\n background: \"#fff\",\n position: \"fixed\",\n bottom: \"20px\",\n right: \"20px\",\n transition:\n \"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\",\n zIndex: \"9999\",\n};\n\n/**\n * Aura service class\n * Singleton pattern - all imports reference the same instance\n */\nclass AuraWidgetService {\n private widgetFrame: HTMLIFrameElement | null = null;\n\n constructor() {\n window.addEventListener(\n \"message\",\n (event: MessageEvent<AuraWidgetMessageEvent>) => {\n if (event.source !== this.widgetFrame?.contentWindow || !event.data) {\n return;\n }\n eventBus.emit(event.data.type, event.data.data);\n }\n );\n }\n\n init = async (params: AuraWidgetOpenParams) => {\n const globalConfig = getConfig();\n const { id, styles } = params;\n if (!this.widgetFrame) {\n this.widgetFrame = document.createElement(\"iframe\");\n // Store the desired dimensions from styles or use defaults\n const desiredWidth = styles?.width || \"350px\";\n const desiredHeight = styles?.height || \"600px\";\n const initialStyles = { ...defaultStyles, ...styles, ...hiddenStyles };\n Object.assign(this.widgetFrame.style, initialStyles);\n this.widgetFrame.id = id || `aura-widget`;\n this.widgetFrame.src = `${globalConfig.insightBaseUrl}`;\n\n // Store desired dimensions for show/hide\n (this.widgetFrame as any).__desiredWidth = desiredWidth;\n (this.widgetFrame as any).__desiredHeight = desiredHeight;\n\n // Add error handler for CSP violations\n this.widgetFrame.onerror = () => {\n logger.error(\n `Failed to load iframe. Please ensure your Content Security Policy includes:\\n` +\n ` frame-src ${globalConfig.insightBaseUrl}\\n`\n );\n };\n\n document.body.appendChild(this.widgetFrame);\n }\n };\n\n show = () => {\n if (this.widgetFrame) {\n const desiredWidth = (this.widgetFrame as any).__desiredWidth || \"350px\";\n const desiredHeight =\n (this.widgetFrame as any).__desiredHeight || \"600px\";\n const showStyles = {\n opacity: \"1\",\n pointerEvents: \"auto\",\n width: desiredWidth,\n height: desiredHeight,\n maxWidth: desiredWidth,\n maxHeight: desiredHeight,\n };\n Object.assign(this.widgetFrame.style, showStyles);\n }\n };\n\n hide = () => {\n if (this.widgetFrame) {\n Object.assign(this.widgetFrame.style, { ...hiddenStyles });\n }\n };\n\n destroy = () => {\n if (this.widgetFrame) {\n this.widgetFrame.remove();\n this.widgetFrame = null;\n }\n };\n\n emit = (event: AuraWidgetEmitEvent) => {\n if (!this.widgetFrame?.contentWindow) {\n logger.warn(\"No widget iframe to communicate with\");\n return;\n }\n const globalConfig = getConfig();\n this.widgetFrame.contentWindow.postMessage(event, {\n targetOrigin: globalConfig.insightBaseUrl,\n });\n this.show();\n };\n\n on = (event: string, callback: (data: any) => void) => {\n return eventBus.subscribe(event, callback);\n };\n\n /**\n * Get SDK version\n */\n getVersion = () => {\n return getVersion();\n };\n}\n\n// Singleton instance\nlet auraWidgetServiceInstance: AuraWidgetService | null = null;\n\n/**\n * Get the singleton Aura instance\n * All imports will reference the same instance\n */\nfunction getInstance(): AuraWidgetService {\n if (!auraWidgetServiceInstance) {\n auraWidgetServiceInstance = new AuraWidgetService();\n }\n return auraWidgetServiceInstance;\n}\n\nexport const AuraWidget = getInstance();\n"],"names":["defaultConfig","globalConfig","getGlobalConfig","setGlobalConfig","config","configure","getConfig","getVersion","EventBus","event","callback","cb","data","eventBus","logger","message","hiddenStyles","defaultStyles","AuraWidgetService","params","id","styles","desiredWidth","desiredHeight","initialStyles","showStyles","_a","auraWidgetServiceInstance","getInstance","AuraWidget"],"mappings":"gFAcA,MAAMA,EAAuC,CAC3C,eAAgB,wBAClB,EAEA,IAAIC,EAAoC,KAKjC,SAASC,GAAuC,CACrD,OAAOD,CACT,CAKO,SAASE,EAAgBC,EAA4B,CAC1DH,EAAe,CAAE,GAAGD,EAAe,GAAGI,CAAA,CACxC,CCvBO,SAASC,EAAUD,EAA4B,CACpDD,EAAgBC,CAAM,CACxB,CAEO,SAASE,GAA0B,CACxC,MAAML,EAAeC,EAAA,EACrB,GAAI,CAACD,EACH,MAAM,IAAI,MACR,8EAAA,EAGJ,OAAOA,CACT,CAEO,SAASM,GAAqB,CACnC,MAAO,OACT,CCzBA,MAAMC,CAAS,CAAf,aAAA,CACE,KAAQ,OAAkD,CAAA,EAE1D,KAAA,UAAY,CAACC,EAAeC,KACrB,KAAK,OAAOD,CAAK,IACpB,KAAK,OAAOA,CAAK,EAAI,CAAA,GAEvB,KAAK,OAAOA,CAAK,EAAE,KAAKC,CAAQ,EAEzB,IAAM,CACX,KAAK,OAAOD,CAAK,EAAI,KAAK,OAAOA,CAAK,EAAE,OAAQE,GAAOA,IAAOD,CAAQ,CACxE,GAGF,KAAA,KAAO,CAACD,EAAeG,IAAc,CAC9B,KAAK,OAAOH,CAAK,GAGtB,KAAK,OAAOA,CAAK,EAAE,QAASC,GAAaA,EAASE,CAAI,CAAC,CACzD,CAAA,CACF,CAEO,MAAMC,EAAW,IAAIL,ECtBfM,EAAS,CACpB,IAAMC,GAAoB,CACxB,QAAQ,IAAI,iCAAiCA,CAAO,EAAE,CACxD,EACA,KAAOA,GAAoB,CACzB,QAAQ,KAAK,iCAAiCA,CAAO,EAA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AO,OAAO,KAAK,YAAY,MAAOE,CAAU,CAClD,CACF,EAEA,KAAA,KAAO,IAAM,CACP,KAAK,aACP,OAAO,OAAO,KAAK,YAAY,MAAO,CAAE,GAAGT,EAAc,CAE7D,EAEA,KAAA,QAAU,IAAM,CACV,KAAK,cACP,KAAK,YAAY,OAAA,EACjB,KAAK,YAAc,KAEvB,EAEA,KAAA,KAAQP,GAA+B,OACrC,GAAI,GAACiB,EAAA,KAAK,cAAL,MAAAA,EAAkB,eAAe,CACpCZ,EAAO,KAAK,sCAAsC,EAClD,MACF,CACA,MAAMb,EAAeK,EAAA,EACrB,KAAK,YAAY,cAAc,YAAYG,EAAO,CAChD,aAAcR,EAAa,cAAA,CAC5B,EACD,KAAK,KAAA,CACP,EAEA,KAAA,GAAK,CAACQ,EAAeC,IACZG,EAAS,UAAUJ,EAAOC,CAAQ,EAM3C,KAAA,WAAa,IACJH,EAAA,EA1FP,OAAO,iBACL,UACCE,GAAgD,OAC3CA,EAAM,WAAWiB,EAAA,KAAK,cAAL,YAAAA,EAAkB,gBAAiB,CAACjB,EAAM,MAG/DI,EAAS,KAAKJ,EAAM,KAAK,KAAMA,EAAM,KAAK,IAAI,CAChD,CAAA,CAEJ,CAmFF,CAGA,IAAIkB,EAAsD,KAM1D,SAASC,GAAiC,CACxC,OAAKD,IACHA,EAA4B,IAAIT,GAE3BS,CACT,CAEO,MAAME,EAAaD,EAAA"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/globalConfig.ts","../src/root.ts","../src/utils/eventBus.ts","../src/utils/logger.ts","../src/auraWidget.ts"],"sourcesContent":["/**\n * Global storage for Aura SDK configuration\n */\n\n/**\n * Root-level global configuration\n * Shared across all services/interfaces\n */\nexport interface GlobalConfig {\n insightBaseUrl?: string;\n // Add other global config options here\n}\n\nconst defaultConfig: Partial<GlobalConfig> = {\n insightBaseUrl: 'https://anywhere.insighthealth.ai',\n};\n\nlet globalConfig: GlobalConfig | null = null;\n\n/**\n * Get the global configuration\n */\nexport function getGlobalConfig(): GlobalConfig | null {\n return globalConfig;\n}\n\n/**\n * Set the global configuration\n */\nexport function setGlobalConfig(config: GlobalConfig): void {\n globalConfig = { ...defaultConfig, ...config };\n}\n\n/**\n * Clear the global configuration\n */\nexport function clearGlobalConfig(): void {\n globalConfig = null;\n}\n\n/**\n * Check if global configuration is set\n */\nexport function hasGlobalConfig(): boolean {\n return globalConfig !== null;\n}\n","/// <reference types=\"vite/client\" />\n\nimport { getGlobalConfig, GlobalConfig, setGlobalConfig } from './globalConfig';\n\n/**\n * Configure the Aura SDK globally (root-level)\n * Sets base configuration like baseUrl, apiKey, etc.\n * This configuration is shared across all services\n */\nexport function configure(config: GlobalConfig): void {\n setGlobalConfig(config);\n}\n\nexport function getConfig(): GlobalConfig {\n const globalConfig = getGlobalConfig();\n if (!globalConfig) {\n throw new Error(\n 'Aura SDK not configured. Call configure() first to set global configuration.'\n );\n }\n return globalConfig;\n}\n\nexport function getVersion(): string {\n return import.meta.env.PACKAGE_VERSION;\n}\n","class EventBus {\n private events: Record<string, ((data: any) => void)[]> = {};\n\n subscribe = (event: string, callback: (data: any) => void) => {\n if (!this.events[event]) {\n this.events[event] = [];\n }\n this.events[event].push(callback);\n\n return () => {\n this.events[event] = this.events[event].filter((cb) => cb !== callback);\n };\n };\n\n emit = (event: string, data: any) => {\n if (!this.events[event]) {\n return;\n }\n this.events[event].forEach((callback) => callback(data));\n };\n}\n\nexport const eventBus = new EventBus();\n","export const logger = {\n log: (message: string) => {\n console.log(`[Insight Health Aura Widget]: ${message}`);\n },\n warn: (message: string) => {\n console.warn(`[Insight Health Aura Widget]: ${message}`);\n },\n error: (message: string) => {\n console.error(`[Insight Health Aura Widget]: ${message}`);\n },\n};\n","/**\n * Aura SDK for Insight Health AI\n */\nimport { getVersion, getConfig } from './root';\nimport { eventBus, logger } from './utils';\n\ntype AuraWidgetEmitEvent<T = any> = {\n type: string;\n payload: T;\n};\n\ntype AuraWidgetOpenParams = {\n partnerKey: string;\n subTenantId: string;\n user: {\n email: string;\n firstName?: string;\n lastName?: string;\n };\n language?: string;\n container?: string;\n widgetId?: string;\n widgetStyles?: Partial<\n Pick<\n CSSStyleDeclaration,\n | 'width'\n | 'height'\n | 'borderRadius'\n | 'boxShadow'\n | 'top'\n | 'bottom'\n | 'left'\n | 'right'\n >\n >;\n onAuthenticated?: () => void;\n};\n\ntype AuraWidgetMessageEvent<T = any> = {\n type: string;\n payload: T;\n};\n\nconst hiddenStyles: Partial<CSSStyleDeclaration> = {\n opacity: '0',\n pointerEvents: 'none',\n width: '0',\n height: '0',\n maxWidth: '0',\n maxHeight: '0',\n};\n\nconst defaultStyles: Partial<CSSStyleDeclaration> = {\n border: 'none',\n borderRadius: '10px',\n boxShadow: '0 0 10px 0 rgba(0, 0, 0, 0.1)',\n overflow: 'hidden',\n background: '#fff',\n position: 'fixed',\n bottom: '20px',\n right: '20px',\n transition:\n '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',\n zIndex: '9999',\n};\n\n/**\n * Aura service class\n * Singleton pattern - all imports reference the same instance\n */\nclass AuraWidgetService {\n private config: AuraWidgetOpenParams | null = null;\n private widgetFrame: HTMLIFrameElement | null = null;\n private unsubsciptions: (() => void)[] = [];\n isFrameReady: boolean = false;\n isFrameAuthenticated: boolean = false;\n constructor() {\n window.addEventListener(\n 'message',\n (event: MessageEvent<AuraWidgetMessageEvent>) => {\n if (event.source !== this.widgetFrame?.contentWindow || !event.data) {\n return;\n }\n eventBus.emit(event.data.type, event.data.payload);\n }\n );\n }\n\n private postMessage = (event: AuraWidgetEmitEvent) => {\n if (!this.widgetFrame?.contentWindow) {\n logger.warn('No widget iframe to communicate with');\n return;\n }\n const globalConfig = getConfig();\n this.widgetFrame.contentWindow.postMessage(event, {\n targetOrigin: globalConfig.insightBaseUrl,\n });\n };\n\n init = (params: AuraWidgetOpenParams) => {\n return new Promise<void>((resolve) => {\n if (!this.widgetFrame) {\n const globalConfig = getConfig();\n const {\n subTenantId,\n user,\n language,\n container,\n widgetId,\n widgetStyles,\n } = params;\n this.config = params;\n this.isFrameReady = false;\n this.widgetFrame = document.createElement('iframe');\n // Store the desired dimensions from styles or use defaults\n const desiredWidth = widgetStyles?.width || '350px';\n const desiredHeight = widgetStyles?.height || '600px';\n const initialStyles = {\n ...defaultStyles,\n ...widgetStyles,\n ...hiddenStyles,\n };\n Object.assign(this.widgetFrame.style, initialStyles);\n this.widgetFrame.id = widgetId || `aura-widget`;\n this.widgetFrame.src = `${globalConfig.insightBaseUrl}/aura`;\n // Store desired dimensions for show/hide\n (this.widgetFrame as any).__desiredWidth = desiredWidth;\n (this.widgetFrame as any).__desiredHeight = desiredHeight;\n\n // Add error handler for CSP violations\n this.widgetFrame.onerror = () => {\n logger.error(\n `Failed to load iframe. Please ensure your Content Security Policy includes:\\n` +\n ` frame-src ${globalConfig.insightBaseUrl}\\n`\n );\n };\n\n (\n (container && document.querySelector(container)) ||\n document.body\n ).appendChild(this.widgetFrame);\n\n const unsubscribeAuthReady = eventBus.subscribe('Auth.Ready', () => {\n this.isFrameReady = true;\n this.setUser({ subTenantId, user, language });\n });\n\n const unsubscribeAuthComplete = eventBus.subscribe(\n 'Auth.Complete',\n () => {\n this.isFrameAuthenticated = true;\n resolve();\n params.onAuthenticated?.();\n }\n );\n this.unsubsciptions.push(unsubscribeAuthReady, unsubscribeAuthComplete);\n }\n });\n };\n\n setUser = (\n params: Pick<AuraWidgetOpenParams, 'user' | 'subTenantId' | 'language'>\n ) => {\n const partnerKey = this.config!.partnerKey;\n const { subTenantId, user, language } = params;\n this.isFrameAuthenticated = false;\n this.postMessage({\n type: 'Auth.Login',\n payload: {\n partnerKey,\n subTenantId,\n user,\n language,\n },\n });\n };\n\n show = () => {\n if (this.widgetFrame) {\n const desiredWidth = (this.widgetFrame as any).__desiredWidth || '350px';\n const desiredHeight =\n (this.widgetFrame as any).__desiredHeight || '600px';\n const showStyles = {\n opacity: '1',\n pointerEvents: 'auto',\n width: desiredWidth,\n height: desiredHeight,\n maxWidth: desiredWidth,\n maxHeight: desiredHeight,\n };\n Object.assign(this.widgetFrame.style, { ...showStyles });\n }\n };\n\n hide = () => {\n if (this.widgetFrame) {\n Object.assign(this.widgetFrame.style, { ...hiddenStyles });\n }\n };\n\n reset = () => {\n if (this.widgetFrame) {\n this.widgetFrame.remove();\n }\n this.widgetFrame = null;\n this.isFrameReady = false;\n this.isFrameAuthenticated = false;\n this.unsubsciptions.forEach((unsubscribe) => unsubscribe?.());\n this.unsubsciptions = [];\n };\n\n emit = (event: AuraWidgetEmitEvent) => {\n this.postMessage(event);\n this.show();\n };\n\n on = (event: string, callback: (data: any) => void) => {\n return eventBus.subscribe(event, callback);\n };\n\n /**\n * Get SDK version\n */\n getConfig = () => {\n return this.config;\n };\n getVersion = () => {\n return getVersion();\n };\n}\n\n// Singleton instance\nlet auraWidgetServiceInstance: AuraWidgetService | null = null;\n\n/**\n * Get the singleton Aura instance\n * All imports will reference the same instance\n */\nfunction getInstance(): AuraWidgetService {\n if (!auraWidgetServiceInstance) {\n auraWidgetServiceInstance = new AuraWidgetService();\n }\n return auraWidgetServiceInstance;\n}\n\nexport const AuraWidget = getInstance();\n"],"names":["defaultConfig","globalConfig","getGlobalConfig","setGlobalConfig","config","configure","getConfig","getVersion","EventBus","event","callback","cb","data","eventBus","logger","message","hiddenStyles","defaultStyles","AuraWidgetService","_a","params","resolve","subTenantId","user","language","container","widgetId","widgetStyles","desiredWidth","desiredHeight","initialStyles","unsubscribeAuthReady","unsubscribeAuthComplete","partnerKey","showStyles","unsubscribe","auraWidgetServiceInstance","getInstance","AuraWidget"],"mappings":"gFAaA,MAAMA,EAAuC,CAC3C,eAAgB,mCAClB,EAEA,IAAIC,EAAoC,KAKjC,SAASC,GAAuC,CACrD,OAAOD,CACT,CAKO,SAASE,EAAgBC,EAA4B,CAC1DH,EAAe,CAAE,GAAGD,EAAe,GAAGI,CAAA,CACxC,CCtBO,SAASC,E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EAAM,MAG/DI,EAAS,KAAKJ,EAAM,KAAK,KAAMA,EAAM,KAAK,OAAO,CACnD,CAAA,CAEJ,CA+IF,CAGA,IAAI2B,EAAsD,KAM1D,SAASC,GAAiC,CACxC,OAAKD,IACHA,EAA4B,IAAIlB,GAE3BkB,CACT,CAEO,MAAME,EAAaD,EAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,28 +1,28 @@
1
- const w = {
2
- insightBaseUrl: "https://app.lumi.build"
1
+ const A = {
2
+ insightBaseUrl: "https://anywhere.insighthealth.ai"
3
3
  };
4
- let g = null;
5
- function m() {
6
- return g;
4
+ let f = null;
5
+ function W() {
6
+ return f;
7
7
  }
8
- function f(i) {
9
- g = { ...w, ...i };
8
+ function C(i) {
9
+ f = { ...A, ...i };
10
10
  }
11
- function y(i) {
12
- f(i);
11
+ function R(i) {
12
+ C(i);
13
13
  }
14
- function o() {
15
- const i = m();
14
+ function u() {
15
+ const i = W();
16
16
  if (!i)
17
17
  throw new Error(
18
18
  "Aura SDK not configured. Call configure() first to set global configuration."
19
19
  );
20
20
  return i;
21
21
  }
22
- function p() {
23
- return "0.0.1";
22
+ function v() {
23
+ return "0.0.2";
24
24
  }
25
- class F {
25
+ class H {
26
26
  constructor() {
27
27
  this.events = {}, this.subscribe = (t, e) => (this.events[t] || (this.events[t] = []), this.events[t].push(e), () => {
28
28
  this.events[t] = this.events[t].filter((s) => s !== e);
@@ -31,7 +31,7 @@ class F {
31
31
  };
32
32
  }
33
33
  }
34
- const a = new F(), d = {
34
+ const r = new H(), c = {
35
35
  log: (i) => {
36
36
  console.log(`[Insight Health Aura Widget]: ${i}`);
37
37
  },
@@ -41,14 +41,14 @@ const a = new F(), d = {
41
41
  error: (i) => {
42
42
  console.error(`[Insight Health Aura Widget]: ${i}`);
43
43
  }
44
- }, h = {
44
+ }, l = {
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
- }, b = {
51
+ }, I = {
52
52
  border: "none",
53
53
  borderRadius: "10px",
54
54
  boxShadow: "0 0 10px 0 rgba(0, 0, 0, 0.1)",
@@ -60,21 +60,63 @@ const a = new F(), d = {
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 x {
63
+ class E {
64
64
  constructor() {
65
- this.widgetFrame = null, this.init = async (t) => {
66
- const e = o(), { id: s, styles: n } = t;
65
+ this.config = null, this.widgetFrame = null, this.unsubsciptions = [], this.isFrameReady = !1, this.isFrameAuthenticated = !1, this.postMessage = (t) => {
66
+ var s;
67
+ if (!((s = this.widgetFrame) != null && s.contentWindow)) {
68
+ c.warn("No widget iframe to communicate with");
69
+ return;
70
+ }
71
+ const e = u();
72
+ this.widgetFrame.contentWindow.postMessage(t, {
73
+ targetOrigin: e.insightBaseUrl
74
+ });
75
+ }, this.init = (t) => new Promise((e) => {
67
76
  if (!this.widgetFrame) {
68
- this.widgetFrame = document.createElement("iframe");
69
- const c = (n == null ? void 0 : n.width) || "350px", u = (n == null ? void 0 : n.height) || "600px", l = { ...b, ...n, ...h };
70
- Object.assign(this.widgetFrame.style, l), this.widgetFrame.id = s || "aura-widget", this.widgetFrame.src = `${e.insightBaseUrl}`, this.widgetFrame.__desiredWidth = c, this.widgetFrame.__desiredHeight = u, this.widgetFrame.onerror = () => {
71
- d.error(
77
+ const s = u(), {
78
+ subTenantId: o,
79
+ user: a,
80
+ language: m,
81
+ container: d,
82
+ widgetId: w,
83
+ widgetStyles: n
84
+ } = t;
85
+ this.config = t, this.isFrameReady = !1, this.widgetFrame = document.createElement("iframe");
86
+ const F = (n == null ? void 0 : n.width) || "350px", p = (n == null ? void 0 : n.height) || "600px", b = {
87
+ ...I,
88
+ ...n,
89
+ ...l
90
+ };
91
+ Object.assign(this.widgetFrame.style, b), this.widgetFrame.id = w || "aura-widget", this.widgetFrame.src = `${s.insightBaseUrl}/aura`, this.widgetFrame.__desiredWidth = F, this.widgetFrame.__desiredHeight = p, this.widgetFrame.onerror = () => {
92
+ c.error(
72
93
  `Failed to load iframe. Please ensure your Content Security Policy includes:
73
- frame-src ${e.insightBaseUrl}
94
+ frame-src ${s.insightBaseUrl}
74
95
  `
75
96
  );
76
- }, document.body.appendChild(this.widgetFrame);
97
+ }, (d && document.querySelector(d) || document.body).appendChild(this.widgetFrame);
98
+ const y = r.subscribe("Auth.Ready", () => {
99
+ this.isFrameReady = !0, this.setUser({ subTenantId: o, user: a, language: m });
100
+ }), x = r.subscribe(
101
+ "Auth.Complete",
102
+ () => {
103
+ var g;
104
+ this.isFrameAuthenticated = !0, e(), (g = t.onAuthenticated) == null || g.call(t);
105
+ }
106
+ );
107
+ this.unsubsciptions.push(y, x);
77
108
  }
109
+ }), this.setUser = (t) => {
110
+ const e = this.config.partnerKey, { subTenantId: s, user: o, language: a } = t;
111
+ this.isFrameAuthenticated = !1, this.postMessage({
112
+ type: "Auth.Login",
113
+ payload: {
114
+ partnerKey: e,
115
+ subTenantId: s,
116
+ user: o,
117
+ language: a
118
+ }
119
+ });
78
120
  }, this.show = () => {
79
121
  if (this.widgetFrame) {
80
122
  const t = this.widgetFrame.__desiredWidth || "350px", e = this.widgetFrame.__desiredHeight || "600px", s = {
@@ -85,40 +127,32 @@ class x {
85
127
  maxWidth: t,
86
128
  maxHeight: e
87
129
  };
88
- Object.assign(this.widgetFrame.style, s);
130
+ Object.assign(this.widgetFrame.style, { ...s });
89
131
  }
90
132
  }, this.hide = () => {
91
- this.widgetFrame && Object.assign(this.widgetFrame.style, { ...h });
92
- }, this.destroy = () => {
93
- this.widgetFrame && (this.widgetFrame.remove(), this.widgetFrame = null);
133
+ this.widgetFrame && Object.assign(this.widgetFrame.style, { ...l });
134
+ }, this.reset = () => {
135
+ this.widgetFrame && this.widgetFrame.remove(), this.widgetFrame = null, this.isFrameReady = !1, this.isFrameAuthenticated = !1, this.unsubsciptions.forEach((t) => t == null ? void 0 : t()), this.unsubsciptions = [];
94
136
  }, this.emit = (t) => {
95
- var s;
96
- if (!((s = this.widgetFrame) != null && s.contentWindow)) {
97
- d.warn("No widget iframe to communicate with");
98
- return;
99
- }
100
- const e = o();
101
- this.widgetFrame.contentWindow.postMessage(t, {
102
- targetOrigin: e.insightBaseUrl
103
- }), this.show();
104
- }, this.on = (t, e) => a.subscribe(t, e), this.getVersion = () => p(), window.addEventListener(
137
+ this.postMessage(t), this.show();
138
+ }, this.on = (t, e) => r.subscribe(t, e), this.getConfig = () => this.config, this.getVersion = () => v(), window.addEventListener(
105
139
  "message",
106
140
  (t) => {
107
141
  var e;
108
- t.source !== ((e = this.widgetFrame) == null ? void 0 : e.contentWindow) || !t.data || a.emit(t.data.type, t.data.data);
142
+ t.source !== ((e = this.widgetFrame) == null ? void 0 : e.contentWindow) || !t.data || r.emit(t.data.type, t.data.payload);
109
143
  }
110
144
  );
111
145
  }
112
146
  }
113
- let r = null;
114
- function W() {
115
- return r || (r = new x()), r;
147
+ let h = null;
148
+ function _() {
149
+ return h || (h = new E()), h;
116
150
  }
117
- const C = W();
151
+ const S = _();
118
152
  export {
119
- C as AuraWidget,
120
- y as configure,
121
- o as getConfig,
122
- p as getVersion
153
+ S as AuraWidget,
154
+ R as configure,
155
+ u as getConfig,
156
+ v as getVersion
123
157
  };
124
158
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/globalConfig.ts","../src/root.ts","../src/utils/eventBus.ts","../src/utils/logger.ts","../src/auraWidget.ts"],"sourcesContent":["/**\n * Global storage for Aura SDK configuration\n */\n\n/**\n * Root-level global configuration\n * Shared across all services/interfaces\n */\nexport interface GlobalConfig {\n insightBaseUrl?: string;\n clientToken: string;\n // Add other global config options here\n}\n\nconst defaultConfig: Partial<GlobalConfig> = {\n insightBaseUrl: \"https://app.lumi.build\",\n};\n\nlet globalConfig: GlobalConfig | null = null;\n\n/**\n * Get the global configuration\n */\nexport function getGlobalConfig(): GlobalConfig | null {\n return globalConfig;\n}\n\n/**\n * Set the global configuration\n */\nexport function setGlobalConfig(config: GlobalConfig): void {\n globalConfig = { ...defaultConfig, ...config };\n}\n\n/**\n * Clear the global configuration\n */\nexport function clearGlobalConfig(): void {\n globalConfig = null;\n}\n\n/**\n * Check if global configuration is set\n */\nexport function hasGlobalConfig(): boolean {\n return globalConfig !== null;\n}\n","/// <reference types=\"vite/client\" />\n\nimport { getGlobalConfig, GlobalConfig, setGlobalConfig } from './globalConfig'\n\n/**\n * Configure the Aura SDK globally (root-level)\n * Sets base configuration like baseUrl, apiKey, etc.\n * This configuration is shared across all services\n */\nexport function configure(config: GlobalConfig): void {\n setGlobalConfig(config)\n}\n\nexport function getConfig(): GlobalConfig {\n const globalConfig = getGlobalConfig()\n if (!globalConfig) {\n throw new Error(\n 'Aura SDK not configured. Call configure() first to set global configuration.'\n )\n }\n return globalConfig\n}\n\nexport function getVersion(): string {\n return import.meta.env.PACKAGE_VERSION\n}\n","class EventBus {\n private events: Record<string, ((data: any) => void)[]> = {};\n\n subscribe = (event: string, callback: (data: any) => void) => {\n if (!this.events[event]) {\n this.events[event] = [];\n }\n this.events[event].push(callback);\n\n return () => {\n this.events[event] = this.events[event].filter((cb) => cb !== callback);\n };\n };\n\n emit = (event: string, data: any) => {\n if (!this.events[event]) {\n return;\n }\n this.events[event].forEach((callback) => callback(data));\n };\n}\n\nexport const eventBus = new EventBus();","export const logger = {\n log: (message: string) => {\n console.log(`[Insight Health Aura Widget]: ${message}`);\n },\n warn: (message: string) => {\n console.warn(`[Insight Health Aura Widget]: ${message}`);\n },\n error: (message: string) => {\n console.error(`[Insight Health Aura Widget]: ${message}`);\n },\n};","/**\n * Aura SDK for Insight Health AI\n */\nimport { getVersion, getConfig } from \"./root\";\nimport { eventBus, logger } from \"./utils\";\n\ntype AuraWidgetEmitEvent<T = any> = {\n type: string;\n data: T;\n};\n\ntype AuraWidgetOpenParams = {\n id?: string;\n styles?: Partial<\n Pick<\n CSSStyleDeclaration,\n | \"width\"\n | \"height\"\n | \"borderRadius\"\n | \"boxShadow\"\n | \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n >\n >;\n};\n\ntype AuraWidgetMessageEvent<T = any> = {\n type: string;\n data: T;\n};\n\nconst hiddenStyles: Partial<CSSStyleDeclaration> = {\n opacity: \"0\",\n pointerEvents: \"none\",\n width: \"0\",\n height: \"0\",\n maxWidth: \"0\",\n maxHeight: \"0\",\n};\n\nconst defaultStyles: Partial<CSSStyleDeclaration> = {\n border: \"none\",\n borderRadius: \"10px\",\n boxShadow: \"0 0 10px 0 rgba(0, 0, 0, 0.1)\",\n overflow: \"hidden\",\n background: \"#fff\",\n position: \"fixed\",\n bottom: \"20px\",\n right: \"20px\",\n transition:\n \"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\",\n zIndex: \"9999\",\n};\n\n/**\n * Aura service class\n * Singleton pattern - all imports reference the same instance\n */\nclass AuraWidgetService {\n private widgetFrame: HTMLIFrameElement | null = null;\n\n constructor() {\n window.addEventListener(\n \"message\",\n (event: MessageEvent<AuraWidgetMessageEvent>) => {\n if (event.source !== this.widgetFrame?.contentWindow || !event.data) {\n return;\n }\n eventBus.emit(event.data.type, event.data.data);\n }\n );\n }\n\n init = async (params: AuraWidgetOpenParams) => {\n const globalConfig = getConfig();\n const { id, styles } = params;\n if (!this.widgetFrame) {\n this.widgetFrame = document.createElement(\"iframe\");\n // Store the desired dimensions from styles or use defaults\n const desiredWidth = styles?.width || \"350px\";\n const desiredHeight = styles?.height || \"600px\";\n const initialStyles = { ...defaultStyles, ...styles, ...hiddenStyles };\n Object.assign(this.widgetFrame.style, initialStyles);\n this.widgetFrame.id = id || `aura-widget`;\n this.widgetFrame.src = `${globalConfig.insightBaseUrl}`;\n\n // Store desired dimensions for show/hide\n (this.widgetFrame as any).__desiredWidth = desiredWidth;\n (this.widgetFrame as any).__desiredHeight = desiredHeight;\n\n // Add error handler for CSP violations\n this.widgetFrame.onerror = () => {\n logger.error(\n `Failed to load iframe. Please ensure your Content Security Policy includes:\\n` +\n ` frame-src ${globalConfig.insightBaseUrl}\\n`\n );\n };\n\n document.body.appendChild(this.widgetFrame);\n }\n };\n\n show = () => {\n if (this.widgetFrame) {\n const desiredWidth = (this.widgetFrame as any).__desiredWidth || \"350px\";\n const desiredHeight =\n (this.widgetFrame as any).__desiredHeight || \"600px\";\n const showStyles = {\n opacity: \"1\",\n pointerEvents: \"auto\",\n width: desiredWidth,\n height: desiredHeight,\n maxWidth: desiredWidth,\n maxHeight: desiredHeight,\n };\n Object.assign(this.widgetFrame.style, showStyles);\n }\n };\n\n hide = () => {\n if (this.widgetFrame) {\n Object.assign(this.widgetFrame.style, { ...hiddenStyles });\n }\n };\n\n destroy = () => {\n if (this.widgetFrame) {\n this.widgetFrame.remove();\n this.widgetFrame = null;\n }\n };\n\n emit = (event: AuraWidgetEmitEvent) => {\n if (!this.widgetFrame?.contentWindow) {\n logger.warn(\"No widget iframe to communicate with\");\n return;\n }\n const globalConfig = getConfig();\n this.widgetFrame.contentWindow.postMessage(event, {\n targetOrigin: globalConfig.insightBaseUrl,\n });\n this.show();\n };\n\n on = (event: string, callback: (data: any) => void) => {\n return eventBus.subscribe(event, callback);\n };\n\n /**\n * Get SDK version\n */\n getVersion = () => {\n return getVersion();\n };\n}\n\n// Singleton instance\nlet auraWidgetServiceInstance: AuraWidgetService | null = null;\n\n/**\n * Get the singleton Aura instance\n * All imports will reference the same instance\n */\nfunction getInstance(): AuraWidgetService {\n if (!auraWidgetServiceInstance) {\n auraWidgetServiceInstance = new AuraWidgetService();\n }\n return auraWidgetServiceInstance;\n}\n\nexport const AuraWidget = getInstance();\n"],"names":["defaultConfig","globalConfig","getGlobalConfig","setGlobalConfig","config","configure","getConfig","getVersion","EventBus","event","callback","cb","data","eventBus","logger","message","hiddenStyles","defaultStyles","AuraWidgetService","params","id","styles","desiredWidth","desiredHeight","initialStyles","showStyles","_a","auraWidgetServiceInstance","getInstance","AuraWidget"],"mappings":"AAcA,MAAMA,IAAuC;AAAA,EAC3C,gBAAgB;AAClB;AAEA,IAAIC,IAAoC;AAKjC,SAASC,IAAuC;AACrD,SAAOD;AACT;AAKO,SAASE,EAAgBC,GAA4B;AAC1D,EAAAH,IAAe,EAAE,GAAGD,GAAe,GAAGI,EAAA;AACxC;ACvBO,SAASC,EAAUD,GAA4B;AACpD,EAAAD,EAAgBC,CAAM;AACxB;AAEO,SAASE,IAA0B;AACxC,QAAML,IAAeC,EAAA;AACrB,MAAI,CAACD;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGJ,SAAOA;AACT;AAEO,SAASM,IAAqB;AACnC,SAAO;AACT;ACzBA,MAAMC,EAAS;AAAA,EAAf,cAAA;AACE,SAAQ,SAAkD,CAAA,GAE1D,KAAA,YAAY,CAACC,GAAeC,OACrB,KAAK,OAAOD,CAAK,MACpB,KAAK,OAAOA,CAAK,IAAI,CAAA,IAEvB,KAAK,OAAOA,CAAK,EAAE,KAAKC,CAAQ,GAEzB,MAAM;AACX,WAAK,OAAOD,CAAK,IAAI,KAAK,OAAOA,CAAK,EAAE,OAAO,CAACE,MAAOA,MAAOD,CAAQ;AAAA,IACxE,IAGF,KAAA,OAAO,CAACD,GAAeG,MAAc;AACnC,MAAK,KAAK,OAAOH,CAAK,KAGtB,KAAK,OAAOA,CAAK,EAAE,QAAQ,CAACC,MAAaA,EAASE,CAAI,CAAC;AAAA,IACzD;AAAA,E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AAS,KAAKJ,EAAM,KAAK,MAAMA,EAAM,KAAK,IAAI;AAAA,MAChD;AAAA,IAAA;AAAA,EAEJ;AAmFF;AAGA,IAAIkB,IAAsD;AAM1D,SAASC,IAAiC;AACxC,SAAKD,MACHA,IAA4B,IAAIT,EAAA,IAE3BS;AACT;AAEO,MAAME,IAAaD,EAAA;"}
1
+ {"version":3,"file":"index.js","sources":["../src/globalConfig.ts","../src/root.ts","../src/utils/eventBus.ts","../src/utils/logger.ts","../src/auraWidget.ts"],"sourcesContent":["/**\n * Global storage for Aura SDK configuration\n */\n\n/**\n * Root-level global configuration\n * Shared across all services/interfaces\n */\nexport interface GlobalConfig {\n insightBaseUrl?: string;\n // Add other global config options here\n}\n\nconst defaultConfig: Partial<GlobalConfig> = {\n insightBaseUrl: 'https://anywhere.insighthealth.ai',\n};\n\nlet globalConfig: GlobalConfig | null = null;\n\n/**\n * Get the global configuration\n */\nexport function getGlobalConfig(): GlobalConfig | null {\n return globalConfig;\n}\n\n/**\n * Set the global configuration\n */\nexport function setGlobalConfig(config: GlobalConfig): void {\n globalConfig = { ...defaultConfig, ...config };\n}\n\n/**\n * Clear the global configuration\n */\nexport function clearGlobalConfig(): void {\n globalConfig = null;\n}\n\n/**\n * Check if global configuration is set\n */\nexport function hasGlobalConfig(): boolean {\n return globalConfig !== null;\n}\n","/// <reference types=\"vite/client\" />\n\nimport { getGlobalConfig, GlobalConfig, setGlobalConfig } from './globalConfig';\n\n/**\n * Configure the Aura SDK globally (root-level)\n * Sets base configuration like baseUrl, apiKey, etc.\n * This configuration is shared across all services\n */\nexport function configure(config: GlobalConfig): void {\n setGlobalConfig(config);\n}\n\nexport function getConfig(): GlobalConfig {\n const globalConfig = getGlobalConfig();\n if (!globalConfig) {\n throw new Error(\n 'Aura SDK not configured. Call configure() first to set global configuration.'\n );\n }\n return globalConfig;\n}\n\nexport function getVersion(): string {\n return import.meta.env.PACKAGE_VERSION;\n}\n","class EventBus {\n private events: Record<string, ((data: any) => void)[]> = {};\n\n subscribe = (event: string, callback: (data: any) => void) => {\n if (!this.events[event]) {\n this.events[event] = [];\n }\n this.events[event].push(callback);\n\n return () => {\n this.events[event] = this.events[event].filter((cb) => cb !== callback);\n };\n };\n\n emit = (event: string, data: any) => {\n if (!this.events[event]) {\n return;\n }\n this.events[event].forEach((callback) => callback(data));\n };\n}\n\nexport const eventBus = new EventBus();\n","export const logger = {\n log: (message: string) => {\n console.log(`[Insight Health Aura Widget]: ${message}`);\n },\n warn: (message: string) => {\n console.warn(`[Insight Health Aura Widget]: ${message}`);\n },\n error: (message: string) => {\n console.error(`[Insight Health Aura Widget]: ${message}`);\n },\n};\n","/**\n * Aura SDK for Insight Health AI\n */\nimport { getVersion, getConfig } from './root';\nimport { eventBus, logger } from './utils';\n\ntype AuraWidgetEmitEvent<T = any> = {\n type: string;\n payload: T;\n};\n\ntype AuraWidgetOpenParams = {\n partnerKey: string;\n subTenantId: string;\n user: {\n email: string;\n firstName?: string;\n lastName?: string;\n };\n language?: string;\n container?: string;\n widgetId?: string;\n widgetStyles?: Partial<\n Pick<\n CSSStyleDeclaration,\n | 'width'\n | 'height'\n | 'borderRadius'\n | 'boxShadow'\n | 'top'\n | 'bottom'\n | 'left'\n | 'right'\n >\n >;\n onAuthenticated?: () => void;\n};\n\ntype AuraWidgetMessageEvent<T = any> = {\n type: string;\n payload: T;\n};\n\nconst hiddenStyles: Partial<CSSStyleDeclaration> = {\n opacity: '0',\n pointerEvents: 'none',\n width: '0',\n height: '0',\n maxWidth: '0',\n maxHeight: '0',\n};\n\nconst defaultStyles: Partial<CSSStyleDeclaration> = {\n border: 'none',\n borderRadius: '10px',\n boxShadow: '0 0 10px 0 rgba(0, 0, 0, 0.1)',\n overflow: 'hidden',\n background: '#fff',\n position: 'fixed',\n bottom: '20px',\n right: '20px',\n transition:\n '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',\n zIndex: '9999',\n};\n\n/**\n * Aura service class\n * Singleton pattern - all imports reference the same instance\n */\nclass AuraWidgetService {\n private config: AuraWidgetOpenParams | null = null;\n private widgetFrame: HTMLIFrameElement | null = null;\n private unsubsciptions: (() => void)[] = [];\n isFrameReady: boolean = false;\n isFrameAuthenticated: boolean = false;\n constructor() {\n window.addEventListener(\n 'message',\n (event: MessageEvent<AuraWidgetMessageEvent>) => {\n if (event.source !== this.widgetFrame?.contentWindow || !event.data) {\n return;\n }\n eventBus.emit(event.data.type, event.data.payload);\n }\n );\n }\n\n private postMessage = (event: AuraWidgetEmitEvent) => {\n if (!this.widgetFrame?.contentWindow) {\n logger.warn('No widget iframe to communicate with');\n return;\n }\n const globalConfig = getConfig();\n this.widgetFrame.contentWindow.postMessage(event, {\n targetOrigin: globalConfig.insightBaseUrl,\n });\n };\n\n init = (params: AuraWidgetOpenParams) => {\n return new Promise<void>((resolve) => {\n if (!this.widgetFrame) {\n const globalConfig = getConfig();\n const {\n subTenantId,\n user,\n language,\n container,\n widgetId,\n widgetStyles,\n } = params;\n this.config = params;\n this.isFrameReady = false;\n this.widgetFrame = document.createElement('iframe');\n // Store the desired dimensions from styles or use defaults\n const desiredWidth = widgetStyles?.width || '350px';\n const desiredHeight = widgetStyles?.height || '600px';\n const initialStyles = {\n ...defaultStyles,\n ...widgetStyles,\n ...hiddenStyles,\n };\n Object.assign(this.widgetFrame.style, initialStyles);\n this.widgetFrame.id = widgetId || `aura-widget`;\n this.widgetFrame.src = `${globalConfig.insightBaseUrl}/aura`;\n // Store desired dimensions for show/hide\n (this.widgetFrame as any).__desiredWidth = desiredWidth;\n (this.widgetFrame as any).__desiredHeight = desiredHeight;\n\n // Add error handler for CSP violations\n this.widgetFrame.onerror = () => {\n logger.error(\n `Failed to load iframe. Please ensure your Content Security Policy includes:\\n` +\n ` frame-src ${globalConfig.insightBaseUrl}\\n`\n );\n };\n\n (\n (container && document.querySelector(container)) ||\n document.body\n ).appendChild(this.widgetFrame);\n\n const unsubscribeAuthReady = eventBus.subscribe('Auth.Ready', () => {\n this.isFrameReady = true;\n this.setUser({ subTenantId, user, language });\n });\n\n const unsubscribeAuthComplete = eventBus.subscribe(\n 'Auth.Complete',\n () => {\n this.isFrameAuthenticated = true;\n resolve();\n params.onAuthenticated?.();\n }\n );\n this.unsubsciptions.push(unsubscribeAuthReady, unsubscribeAuthComplete);\n }\n });\n };\n\n setUser = (\n params: Pick<AuraWidgetOpenParams, 'user' | 'subTenantId' | 'language'>\n ) => {\n const partnerKey = this.config!.partnerKey;\n const { subTenantId, user, language } = params;\n this.isFrameAuthenticated = false;\n this.postMessage({\n type: 'Auth.Login',\n payload: {\n partnerKey,\n subTenantId,\n user,\n language,\n },\n });\n };\n\n show = () => {\n if (this.widgetFrame) {\n const desiredWidth = (this.widgetFrame as any).__desiredWidth || '350px';\n const desiredHeight =\n (this.widgetFrame as any).__desiredHeight || '600px';\n const showStyles = {\n opacity: '1',\n pointerEvents: 'auto',\n width: desiredWidth,\n height: desiredHeight,\n maxWidth: desiredWidth,\n maxHeight: desiredHeight,\n };\n Object.assign(this.widgetFrame.style, { ...showStyles });\n }\n };\n\n hide = () => {\n if (this.widgetFrame) {\n Object.assign(this.widgetFrame.style, { ...hiddenStyles });\n }\n };\n\n reset = () => {\n if (this.widgetFrame) {\n this.widgetFrame.remove();\n }\n this.widgetFrame = null;\n this.isFrameReady = false;\n this.isFrameAuthenticated = false;\n this.unsubsciptions.forEach((unsubscribe) => unsubscribe?.());\n this.unsubsciptions = [];\n };\n\n emit = (event: AuraWidgetEmitEvent) => {\n this.postMessage(event);\n this.show();\n };\n\n on = (event: string, callback: (data: any) => void) => {\n return eventBus.subscribe(event, callback);\n };\n\n /**\n * Get SDK version\n */\n getConfig = () => {\n return this.config;\n };\n getVersion = () => {\n return getVersion();\n };\n}\n\n// Singleton instance\nlet auraWidgetServiceInstance: AuraWidgetService | null = null;\n\n/**\n * Get the singleton Aura instance\n * All imports will reference the same instance\n */\nfunction getInstance(): AuraWidgetService {\n if (!auraWidgetServiceInstance) {\n auraWidgetServiceInstance = new AuraWidgetService();\n }\n return auraWidgetServiceInstance;\n}\n\nexport const AuraWidget = getInstance();\n"],"names":["defaultConfig","globalConfig","getGlobalConfig","setGlobalConfig","config","configure","getConfig","getVersion","EventBus","event","callback","cb","data","eventBus","logger","message","hiddenStyles","defaultStyles","AuraWidgetService","_a","params","resolve","subTenantId","user","language","container","widgetId","widgetStyles","desiredWidth","desiredHeight","initialStyles","unsubscribeAuthReady","unsubscribeAuthComplete","partnerKey","showStyles","unsubscribe","auraWidgetServiceInstance","getInstance","AuraWidget"],"mappings":"AAaA,MAAMA,IAAuC;AAAA,EAC3C,gBAAgB;AAClB;AAEA,IAAIC,IAAoC;AAKjC,SAASC,IAAuC;AACrD,SAAOD;AACT;AAKO,SAASE,EAAgBC,GAA4B;AAC1D,EAAAH,IAAe,EAAE,GAAGD,GAAe,GAAGI,EAAA;AACxC;ACtBO,SAASC,EAAUD,GAA4B;AACpD,EAAAD,EAAgBC,CAAM;AACxB;AAEO,SAASE,IAA0B;AACxC,QAAML,IAAeC,EAAA;AACrB,MAAI,CAACD;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGJ,SAAOA;AACT;AAEO,SAASM,IAAqB;AACnC,SAAO;AACT;ACzBA,MAAMC,EAAS;AAAA,EAAf,cAAA;AACE,SAAQ,SAAkD,CAAA,GAE1D,KAAA,YAAY,CAACC,GAAeC,OACrB,KAAK,OAAOD,CAAK,MACpB,KAAK,OAAOA,CAAK,IAAI,CAAA,IAEvB,KAAK,OAAOA,CAAK,EAAE,KAAKC,CAAQ,GAEzB,MAAM;AACX,WAAK,OAAOD,CAAK,IAAI,KAAK,OAAOA,CAAK,EAAE,OAAO,CAACE,MAAOA,MAAOD,CAAQ;AAAA,IACxE,IAGF,KAAA,OAAO,CAACD,GAAeG,MAAc;AACnC,MAAK,KAAK,OAAOH,CAAK,KAGtB,KAAK,OAAOA,CAAK,EAAE,QAAQ,CAACC,MAAaA,EAAS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S,KAAKJ,EAAM,KAAK,MAAMA,EAAM,KAAK,OAAO;AAAA,MACnD;AAAA,IAAA;AAAA,EAEJ;AA+IF;AAGA,IAAI2B,IAAsD;AAM1D,SAASC,IAAiC;AACxC,SAAKD,MACHA,IAA4B,IAAIlB,EAAA,IAE3BkB;AACT;AAEO,MAAME,IAAaD,EAAA;"}
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(n,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(n=typeof globalThis<"u"?globalThis:n||self,r(n.InsightAura={}))})(this,function(n){"use strict";const r={insightBaseUrl:"https://app.lumi.build"};let h=null;function f(){return h}function m(i){h={...r,...i}}function w(i){m(i)}function a(){const i=f();if(!i)throw new Error("Aura SDK not configured. Call configure() first to set global configuration.");return i}function g(){return"0.0.1"}class p{constructor(){this.events={},this.subscribe=(t,e)=>(this.events[t]||(this.events[t]=[]),this.events[t].push(e),()=>{this.events[t]=this.events[t].filter(s=>s!==e)}),this.emit=(t,e)=>{this.events[t]&&this.events[t].forEach(s=>s(e))}}}const u=new p,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}`)}},l={opacity:"0",pointerEvents:"none",width:"0",height:"0",maxWidth:"0",maxHeight:"0"},b={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 F{constructor(){this.widgetFrame=null,this.init=async t=>{const e=a(),{id:s,styles:o}=t;if(!this.widgetFrame){this.widgetFrame=document.createElement("iframe");const W=(o==null?void 0:o.width)||"350px",C=(o==null?void 0:o.height)||"600px",S={...b,...o,...l};Object.assign(this.widgetFrame.style,S),this.widgetFrame.id=s||"aura-widget",this.widgetFrame.src=`${e.insightBaseUrl}`,this.widgetFrame.__desiredWidth=W,this.widgetFrame.__desiredHeight=C,this.widgetFrame.onerror=()=>{c.error(`Failed to load iframe. Please ensure your Content Security Policy includes:
2
- frame-src ${e.insightBaseUrl}
3
- `)},document.body.appendChild(this.widgetFrame)}},this.show=()=>{if(this.widgetFrame){const t=this.widgetFrame.__desiredWidth||"350px",e=this.widgetFrame.__desiredHeight||"600px",s={opacity:"1",pointerEvents:"auto",width:t,height:e,maxWidth:t,maxHeight:e};Object.assign(this.widgetFrame.style,s)}},this.hide=()=>{this.widgetFrame&&Object.assign(this.widgetFrame.style,{...l})},this.destroy=()=>{this.widgetFrame&&(this.widgetFrame.remove(),this.widgetFrame=null)},this.emit=t=>{var s;if(!((s=this.widgetFrame)!=null&&s.contentWindow)){c.warn("No widget iframe to communicate with");return}const e=a();this.widgetFrame.contentWindow.postMessage(t,{targetOrigin:e.insightBaseUrl}),this.show()},this.on=(t,e)=>u.subscribe(t,e),this.getVersion=()=>g(),window.addEventListener("message",t=>{var e;t.source!==((e=this.widgetFrame)==null?void 0:e.contentWindow)||!t.data||u.emit(t.data.type,t.data.data)})}}let d=null;function y(){return d||(d=new F),d}const x=y();n.AuraWidget=x,n.configure=w,n.getConfig=a,n.getVersion=g,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
1
+ (function(n,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(n=typeof globalThis<"u"?globalThis:n||self,r(n.InsightAura={}))})(this,function(n){"use strict";const r={insightBaseUrl:"https://anywhere.insighthealth.ai"};let c=null;function F(){return c}function b(i){c={...r,...i}}function y(i){b(i)}function h(){const i=F();if(!i)throw new Error("Aura SDK not configured. Call configure() first to set global configuration.");return i}function l(){return"0.0.2"}class A{constructor(){this.events={},this.subscribe=(t,e)=>(this.events[t]||(this.events[t]=[]),this.events[t].push(e),()=>{this.events[t]=this.events[t].filter(s=>s!==e)}),this.emit=(t,e)=>{this.events[t]&&this.events[t].forEach(s=>s(e))}}}const a=new A,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}`)}},m={opacity:"0",pointerEvents:"none",width:"0",height:"0",maxWidth:"0",maxHeight:"0"},x={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 W{constructor(){this.config=null,this.widgetFrame=null,this.unsubsciptions=[],this.isFrameReady=!1,this.isFrameAuthenticated=!1,this.postMessage=t=>{var s;if(!((s=this.widgetFrame)!=null&&s.contentWindow)){f.warn("No widget iframe to communicate with");return}const e=h();this.widgetFrame.contentWindow.postMessage(t,{targetOrigin:e.insightBaseUrl})},this.init=t=>new Promise(e=>{if(!this.widgetFrame){const s=h(),{subTenantId:g,user:u,language:I,container:w,widgetId:H,widgetStyles:o}=t;this.config=t,this.isFrameReady=!1,this.widgetFrame=document.createElement("iframe");const S=(o==null?void 0:o.width)||"350px",E=(o==null?void 0:o.height)||"600px",_={...x,...o,...m};Object.assign(this.widgetFrame.style,_),this.widgetFrame.id=H||"aura-widget",this.widgetFrame.src=`${s.insightBaseUrl}/aura`,this.widgetFrame.__desiredWidth=S,this.widgetFrame.__desiredHeight=E,this.widgetFrame.onerror=()=>{f.error(`Failed to load iframe. Please ensure your Content Security Policy includes:
2
+ frame-src ${s.insightBaseUrl}
3
+ `)},(w&&document.querySelector(w)||document.body).appendChild(this.widgetFrame);const R=a.subscribe("Auth.Ready",()=>{this.isFrameReady=!0,this.setUser({subTenantId:g,user:u,language:I})}),B=a.subscribe("Auth.Complete",()=>{var p;this.isFrameAuthenticated=!0,e(),(p=t.onAuthenticated)==null||p.call(t)});this.unsubsciptions.push(R,B)}}),this.setUser=t=>{const e=this.config.partnerKey,{subTenantId:s,user:g,language:u}=t;this.isFrameAuthenticated=!1,this.postMessage({type:"Auth.Login",payload:{partnerKey:e,subTenantId:s,user:g,language:u}})},this.show=()=>{if(this.widgetFrame){const t=this.widgetFrame.__desiredWidth||"350px",e=this.widgetFrame.__desiredHeight||"600px",s={opacity:"1",pointerEvents:"auto",width:t,height:e,maxWidth:t,maxHeight:e};Object.assign(this.widgetFrame.style,{...s})}},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(t=>t==null?void 0:t()),this.unsubsciptions=[]},this.emit=t=>{this.postMessage(t),this.show()},this.on=(t,e)=>a.subscribe(t,e),this.getConfig=()=>this.config,this.getVersion=()=>l(),window.addEventListener("message",t=>{var e;t.source!==((e=this.widgetFrame)==null?void 0:e.contentWindow)||!t.data||a.emit(t.data.type,t.data.payload)})}}let d=null;function C(){return d||(d=new W),d}const v=C();n.AuraWidget=v,n.configure=y,n.getConfig=h,n.getVersion=l,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
4
4
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/globalConfig.ts","../src/root.ts","../src/utils/eventBus.ts","../src/utils/logger.ts","../src/auraWidget.ts"],"sourcesContent":["/**\n * Global storage for Aura SDK configuration\n */\n\n/**\n * Root-level global configuration\n * Shared across all services/interfaces\n */\nexport interface GlobalConfig {\n insightBaseUrl?: string;\n clientToken: string;\n // Add other global config options here\n}\n\nconst defaultConfig: Partial<GlobalConfig> = {\n insightBaseUrl: \"https://app.lumi.build\",\n};\n\nlet globalConfig: GlobalConfig | null = null;\n\n/**\n * Get the global configuration\n */\nexport function getGlobalConfig(): GlobalConfig | null {\n return globalConfig;\n}\n\n/**\n * Set the global configuration\n */\nexport function setGlobalConfig(config: GlobalConfig): void {\n globalConfig = { ...defaultConfig, ...config };\n}\n\n/**\n * Clear the global configuration\n */\nexport function clearGlobalConfig(): void {\n globalConfig = null;\n}\n\n/**\n * Check if global configuration is set\n */\nexport function hasGlobalConfig(): boolean {\n return globalConfig !== null;\n}\n","/// <reference types=\"vite/client\" />\n\nimport { getGlobalConfig, GlobalConfig, setGlobalConfig } from './globalConfig'\n\n/**\n * Configure the Aura SDK globally (root-level)\n * Sets base configuration like baseUrl, apiKey, etc.\n * This configuration is shared across all services\n */\nexport function configure(config: GlobalConfig): void {\n setGlobalConfig(config)\n}\n\nexport function getConfig(): GlobalConfig {\n const globalConfig = getGlobalConfig()\n if (!globalConfig) {\n throw new Error(\n 'Aura SDK not configured. Call configure() first to set global configuration.'\n )\n }\n return globalConfig\n}\n\nexport function getVersion(): string {\n return import.meta.env.PACKAGE_VERSION\n}\n","class EventBus {\n private events: Record<string, ((data: any) => void)[]> = {};\n\n subscribe = (event: string, callback: (data: any) => void) => {\n if (!this.events[event]) {\n this.events[event] = [];\n }\n this.events[event].push(callback);\n\n return () => {\n this.events[event] = this.events[event].filter((cb) => cb !== callback);\n };\n };\n\n emit = (event: string, data: any) => {\n if (!this.events[event]) {\n return;\n }\n this.events[event].forEach((callback) => callback(data));\n };\n}\n\nexport const eventBus = new EventBus();","export const logger = {\n log: (message: string) => {\n console.log(`[Insight Health Aura Widget]: ${message}`);\n },\n warn: (message: string) => {\n console.warn(`[Insight Health Aura Widget]: ${message}`);\n },\n error: (message: string) => {\n console.error(`[Insight Health Aura Widget]: ${message}`);\n },\n};","/**\n * Aura SDK for Insight Health AI\n */\nimport { getVersion, getConfig } from \"./root\";\nimport { eventBus, logger } from \"./utils\";\n\ntype AuraWidgetEmitEvent<T = any> = {\n type: string;\n data: T;\n};\n\ntype AuraWidgetOpenParams = {\n id?: string;\n styles?: Partial<\n Pick<\n CSSStyleDeclaration,\n | \"width\"\n | \"height\"\n | \"borderRadius\"\n | \"boxShadow\"\n | \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n >\n >;\n};\n\ntype AuraWidgetMessageEvent<T = any> = {\n type: string;\n data: T;\n};\n\nconst hiddenStyles: Partial<CSSStyleDeclaration> = {\n opacity: \"0\",\n pointerEvents: \"none\",\n width: \"0\",\n height: \"0\",\n maxWidth: \"0\",\n maxHeight: \"0\",\n};\n\nconst defaultStyles: Partial<CSSStyleDeclaration> = {\n border: \"none\",\n borderRadius: \"10px\",\n boxShadow: \"0 0 10px 0 rgba(0, 0, 0, 0.1)\",\n overflow: \"hidden\",\n background: \"#fff\",\n position: \"fixed\",\n bottom: \"20px\",\n right: \"20px\",\n transition:\n \"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\",\n zIndex: \"9999\",\n};\n\n/**\n * Aura service class\n * Singleton pattern - all imports reference the same instance\n */\nclass AuraWidgetService {\n private widgetFrame: HTMLIFrameElement | null = null;\n\n constructor() {\n window.addEventListener(\n \"message\",\n (event: MessageEvent<AuraWidgetMessageEvent>) => {\n if (event.source !== this.widgetFrame?.contentWindow || !event.data) {\n return;\n }\n eventBus.emit(event.data.type, event.data.data);\n }\n );\n }\n\n init = async (params: AuraWidgetOpenParams) => {\n const globalConfig = getConfig();\n const { id, styles } = params;\n if (!this.widgetFrame) {\n this.widgetFrame = document.createElement(\"iframe\");\n // Store the desired dimensions from styles or use defaults\n const desiredWidth = styles?.width || \"350px\";\n const desiredHeight = styles?.height || \"600px\";\n const initialStyles = { ...defaultStyles, ...styles, ...hiddenStyles };\n Object.assign(this.widgetFrame.style, initialStyles);\n this.widgetFrame.id = id || `aura-widget`;\n this.widgetFrame.src = `${globalConfig.insightBaseUrl}`;\n\n // Store desired dimensions for show/hide\n (this.widgetFrame as any).__desiredWidth = desiredWidth;\n (this.widgetFrame as any).__desiredHeight = desiredHeight;\n\n // Add error handler for CSP violations\n this.widgetFrame.onerror = () => {\n logger.error(\n `Failed to load iframe. Please ensure your Content Security Policy includes:\\n` +\n ` frame-src ${globalConfig.insightBaseUrl}\\n`\n );\n };\n\n document.body.appendChild(this.widgetFrame);\n }\n };\n\n show = () => {\n if (this.widgetFrame) {\n const desiredWidth = (this.widgetFrame as any).__desiredWidth || \"350px\";\n const desiredHeight =\n (this.widgetFrame as any).__desiredHeight || \"600px\";\n const showStyles = {\n opacity: \"1\",\n pointerEvents: \"auto\",\n width: desiredWidth,\n height: desiredHeight,\n maxWidth: desiredWidth,\n maxHeight: desiredHeight,\n };\n Object.assign(this.widgetFrame.style, showStyles);\n }\n };\n\n hide = () => {\n if (this.widgetFrame) {\n Object.assign(this.widgetFrame.style, { ...hiddenStyles });\n }\n };\n\n destroy = () => {\n if (this.widgetFrame) {\n this.widgetFrame.remove();\n this.widgetFrame = null;\n }\n };\n\n emit = (event: AuraWidgetEmitEvent) => {\n if (!this.widgetFrame?.contentWindow) {\n logger.warn(\"No widget iframe to communicate with\");\n return;\n }\n const globalConfig = getConfig();\n this.widgetFrame.contentWindow.postMessage(event, {\n targetOrigin: globalConfig.insightBaseUrl,\n });\n this.show();\n };\n\n on = (event: string, callback: (data: any) => void) => {\n return eventBus.subscribe(event, callback);\n };\n\n /**\n * Get SDK version\n */\n getVersion = () => {\n return getVersion();\n };\n}\n\n// Singleton instance\nlet auraWidgetServiceInstance: AuraWidgetService | null = null;\n\n/**\n * Get the singleton Aura instance\n * All imports will reference the same instance\n */\nfunction getInstance(): AuraWidgetService {\n if (!auraWidgetServiceInstance) {\n auraWidgetServiceInstance = new AuraWidgetService();\n }\n return auraWidgetServiceInstance;\n}\n\nexport const AuraWidget = getInstance();\n"],"names":["defaultConfig","globalConfig","getGlobalConfig","setGlobalConfig","config","configure","getConfig","getVersion","EventBus","event","callback","cb","data","eventBus","logger","message","hiddenStyles","defaultStyles","AuraWidgetService","params","id","styles","desiredWidth","desiredHeight","initialStyles","showStyles","_a","auraWidgetServiceInstance","getInstance","AuraWidget"],"mappings":"mOAcA,MAAMA,EAAuC,CAC3C,eAAgB,wBAClB,EAEA,IAAIC,EAAoC,KAKjC,SAASC,GAAuC,CACrD,OAAOD,CACT,CAKO,SAASE,EAAgBC,EAA4B,CAC1DH,EAAe,CAAE,GAAGD,EAAe,GAAGI,CAAA,CACxC,CCvBO,SAASC,EAAUD,EAA4B,CACpDD,EAAgBC,CAAM,CACxB,CAEO,SAASE,GAA0B,CACxC,MAAML,EAAeC,EAAA,EACrB,GAAI,CAACD,EACH,MAAM,IAAI,MACR,8EAAA,EAGJ,OAAOA,CACT,CAEO,SAASM,GAAqB,CACnC,MAAO,OACT,CCzBA,MAAMC,CAAS,CAAf,aAAA,CACE,KAAQ,OAAkD,CAAA,EAE1D,KAAA,UAAY,CAACC,EAAeC,KACrB,KAAK,OAAOD,CAAK,IACpB,KAAK,OAAOA,CAAK,EAAI,CAAA,GAEvB,KAAK,OAAOA,CAAK,EAAE,KAAKC,CAAQ,EAEzB,IAAM,CACX,KAAK,OAAOD,CAAK,EAAI,KAAK,OAAOA,CAAK,EAAE,OAAQE,GAAOA,IAAOD,CAAQ,CACxE,GAGF,KAAA,KAAO,CAACD,EAAeG,IAAc,CAC9B,KAAK,OAAOH,CAAK,GAGtB,KAAK,OAAOA,CAAK,EAAE,QAASC,GAAaA,EAASE,CAAI,CAAC,CACzD,CAAA,CACF,CAEO,MAAMC,EAAW,IAAIL,ECtBfM,EAAS,CACpB,IAAMC,GAAoB,CACxB,QAAQ,IAAI,iCAAiCA,CAAO,EAAE,CACxD,EACA,KAAOA,GAAoB,CACzB,QAAQ,KAAK,iCAAiCA,CAAO,EAAE,CACzD,EACA,MAAQA,GAAoB,CAC1B,QAAQ,MAAM,iCAAiCA,CAAO,EAAE,CAC1D,CACF,ECuBMC,EAA6C,CACjD,QAAS,IACT,cAAe,OACf,MAAO,IACP,OAAQ,IACR,SA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AA,QAAU,IAAM,CACV,KAAK,cACP,KAAK,YAAY,OAAA,EACjB,KAAK,YAAc,KAEvB,EAEA,KAAA,KAAQP,GAA+B,OACrC,GAAI,GAACiB,EAAA,KAAK,cAAL,MAAAA,EAAkB,eAAe,CACpCZ,EAAO,KAAK,sCAAsC,EAClD,MACF,CACA,MAAMb,EAAeK,EAAA,EACrB,KAAK,YAAY,cAAc,YAAYG,EAAO,CAChD,aAAcR,EAAa,cAAA,CAC5B,EACD,KAAK,KAAA,CACP,EAEA,KAAA,GAAK,CAACQ,EAAeC,IACZG,EAAS,UAAUJ,EAAOC,CAAQ,EAM3C,KAAA,WAAa,IACJH,EAAA,EA1FP,OAAO,iBACL,UACCE,GAAgD,OAC3CA,EAAM,WAAWiB,EAAA,KAAK,cAAL,YAAAA,EAAkB,gBAAiB,CAACjB,EAAM,MAG/DI,EAAS,KAAKJ,EAAM,KAAK,KAAMA,EAAM,KAAK,IAAI,CAChD,CAAA,CAEJ,CAmFF,CAGA,IAAIkB,EAAsD,KAM1D,SAASC,GAAiC,CACxC,OAAKD,IACHA,EAA4B,IAAIT,GAE3BS,CACT,CAEO,MAAME,EAAaD,EAAA"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/globalConfig.ts","../src/root.ts","../src/utils/eventBus.ts","../src/utils/logger.ts","../src/auraWidget.ts"],"sourcesContent":["/**\n * Global storage for Aura SDK configuration\n */\n\n/**\n * Root-level global configuration\n * Shared across all services/interfaces\n */\nexport interface GlobalConfig {\n insightBaseUrl?: string;\n // Add other global config options here\n}\n\nconst defaultConfig: Partial<GlobalConfig> = {\n insightBaseUrl: 'https://anywhere.insighthealth.ai',\n};\n\nlet globalConfig: GlobalConfig | null = null;\n\n/**\n * Get the global configuration\n */\nexport function getGlobalConfig(): GlobalConfig | null {\n return globalConfig;\n}\n\n/**\n * Set the global configuration\n */\nexport function setGlobalConfig(config: GlobalConfig): void {\n globalConfig = { ...defaultConfig, ...config };\n}\n\n/**\n * Clear the global configuration\n */\nexport function clearGlobalConfig(): void {\n globalConfig = null;\n}\n\n/**\n * Check if global configuration is set\n */\nexport function hasGlobalConfig(): boolean {\n return globalConfig !== null;\n}\n","/// <reference types=\"vite/client\" />\n\nimport { getGlobalConfig, GlobalConfig, setGlobalConfig } from './globalConfig';\n\n/**\n * Configure the Aura SDK globally (root-level)\n * Sets base configuration like baseUrl, apiKey, etc.\n * This configuration is shared across all services\n */\nexport function configure(config: GlobalConfig): void {\n setGlobalConfig(config);\n}\n\nexport function getConfig(): GlobalConfig {\n const globalConfig = getGlobalConfig();\n if (!globalConfig) {\n throw new Error(\n 'Aura SDK not configured. Call configure() first to set global configuration.'\n );\n }\n return globalConfig;\n}\n\nexport function getVersion(): string {\n return import.meta.env.PACKAGE_VERSION;\n}\n","class EventBus {\n private events: Record<string, ((data: any) => void)[]> = {};\n\n subscribe = (event: string, callback: (data: any) => void) => {\n if (!this.events[event]) {\n this.events[event] = [];\n }\n this.events[event].push(callback);\n\n return () => {\n this.events[event] = this.events[event].filter((cb) => cb !== callback);\n };\n };\n\n emit = (event: string, data: any) => {\n if (!this.events[event]) {\n return;\n }\n this.events[event].forEach((callback) => callback(data));\n };\n}\n\nexport const eventBus = new EventBus();\n","export const logger = {\n log: (message: string) => {\n console.log(`[Insight Health Aura Widget]: ${message}`);\n },\n warn: (message: string) => {\n console.warn(`[Insight Health Aura Widget]: ${message}`);\n },\n error: (message: string) => {\n console.error(`[Insight Health Aura Widget]: ${message}`);\n },\n};\n","/**\n * Aura SDK for Insight Health AI\n */\nimport { getVersion, getConfig } from './root';\nimport { eventBus, logger } from './utils';\n\ntype AuraWidgetEmitEvent<T = any> = {\n type: string;\n payload: T;\n};\n\ntype AuraWidgetOpenParams = {\n partnerKey: string;\n subTenantId: string;\n user: {\n email: string;\n firstName?: string;\n lastName?: string;\n };\n language?: string;\n container?: string;\n widgetId?: string;\n widgetStyles?: Partial<\n Pick<\n CSSStyleDeclaration,\n | 'width'\n | 'height'\n | 'borderRadius'\n | 'boxShadow'\n | 'top'\n | 'bottom'\n | 'left'\n | 'right'\n >\n >;\n onAuthenticated?: () => void;\n};\n\ntype AuraWidgetMessageEvent<T = any> = {\n type: string;\n payload: T;\n};\n\nconst hiddenStyles: Partial<CSSStyleDeclaration> = {\n opacity: '0',\n pointerEvents: 'none',\n width: '0',\n height: '0',\n maxWidth: '0',\n maxHeight: '0',\n};\n\nconst defaultStyles: Partial<CSSStyleDeclaration> = {\n border: 'none',\n borderRadius: '10px',\n boxShadow: '0 0 10px 0 rgba(0, 0, 0, 0.1)',\n overflow: 'hidden',\n background: '#fff',\n position: 'fixed',\n bottom: '20px',\n right: '20px',\n transition:\n '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',\n zIndex: '9999',\n};\n\n/**\n * Aura service class\n * Singleton pattern - all imports reference the same instance\n */\nclass AuraWidgetService {\n private config: AuraWidgetOpenParams | null = null;\n private widgetFrame: HTMLIFrameElement | null = null;\n private unsubsciptions: (() => void)[] = [];\n isFrameReady: boolean = false;\n isFrameAuthenticated: boolean = false;\n constructor() {\n window.addEventListener(\n 'message',\n (event: MessageEvent<AuraWidgetMessageEvent>) => {\n if (event.source !== this.widgetFrame?.contentWindow || !event.data) {\n return;\n }\n eventBus.emit(event.data.type, event.data.payload);\n }\n );\n }\n\n private postMessage = (event: AuraWidgetEmitEvent) => {\n if (!this.widgetFrame?.contentWindow) {\n logger.warn('No widget iframe to communicate with');\n return;\n }\n const globalConfig = getConfig();\n this.widgetFrame.contentWindow.postMessage(event, {\n targetOrigin: globalConfig.insightBaseUrl,\n });\n };\n\n init = (params: AuraWidgetOpenParams) => {\n return new Promise<void>((resolve) => {\n if (!this.widgetFrame) {\n const globalConfig = getConfig();\n const {\n subTenantId,\n user,\n language,\n container,\n widgetId,\n widgetStyles,\n } = params;\n this.config = params;\n this.isFrameReady = false;\n this.widgetFrame = document.createElement('iframe');\n // Store the desired dimensions from styles or use defaults\n const desiredWidth = widgetStyles?.width || '350px';\n const desiredHeight = widgetStyles?.height || '600px';\n const initialStyles = {\n ...defaultStyles,\n ...widgetStyles,\n ...hiddenStyles,\n };\n Object.assign(this.widgetFrame.style, initialStyles);\n this.widgetFrame.id = widgetId || `aura-widget`;\n this.widgetFrame.src = `${globalConfig.insightBaseUrl}/aura`;\n // Store desired dimensions for show/hide\n (this.widgetFrame as any).__desiredWidth = desiredWidth;\n (this.widgetFrame as any).__desiredHeight = desiredHeight;\n\n // Add error handler for CSP violations\n this.widgetFrame.onerror = () => {\n logger.error(\n `Failed to load iframe. Please ensure your Content Security Policy includes:\\n` +\n ` frame-src ${globalConfig.insightBaseUrl}\\n`\n );\n };\n\n (\n (container && document.querySelector(container)) ||\n document.body\n ).appendChild(this.widgetFrame);\n\n const unsubscribeAuthReady = eventBus.subscribe('Auth.Ready', () => {\n this.isFrameReady = true;\n this.setUser({ subTenantId, user, language });\n });\n\n const unsubscribeAuthComplete = eventBus.subscribe(\n 'Auth.Complete',\n () => {\n this.isFrameAuthenticated = true;\n resolve();\n params.onAuthenticated?.();\n }\n );\n this.unsubsciptions.push(unsubscribeAuthReady, unsubscribeAuthComplete);\n }\n });\n };\n\n setUser = (\n params: Pick<AuraWidgetOpenParams, 'user' | 'subTenantId' | 'language'>\n ) => {\n const partnerKey = this.config!.partnerKey;\n const { subTenantId, user, language } = params;\n this.isFrameAuthenticated = false;\n this.postMessage({\n type: 'Auth.Login',\n payload: {\n partnerKey,\n subTenantId,\n user,\n language,\n },\n });\n };\n\n show = () => {\n if (this.widgetFrame) {\n const desiredWidth = (this.widgetFrame as any).__desiredWidth || '350px';\n const desiredHeight =\n (this.widgetFrame as any).__desiredHeight || '600px';\n const showStyles = {\n opacity: '1',\n pointerEvents: 'auto',\n width: desiredWidth,\n height: desiredHeight,\n maxWidth: desiredWidth,\n maxHeight: desiredHeight,\n };\n Object.assign(this.widgetFrame.style, { ...showStyles });\n }\n };\n\n hide = () => {\n if (this.widgetFrame) {\n Object.assign(this.widgetFrame.style, { ...hiddenStyles });\n }\n };\n\n reset = () => {\n if (this.widgetFrame) {\n this.widgetFrame.remove();\n }\n this.widgetFrame = null;\n this.isFrameReady = false;\n this.isFrameAuthenticated = false;\n this.unsubsciptions.forEach((unsubscribe) => unsubscribe?.());\n this.unsubsciptions = [];\n };\n\n emit = (event: AuraWidgetEmitEvent) => {\n this.postMessage(event);\n this.show();\n };\n\n on = (event: string, callback: (data: any) => void) => {\n return eventBus.subscribe(event, callback);\n };\n\n /**\n * Get SDK version\n */\n getConfig = () => {\n return this.config;\n };\n getVersion = () => {\n return getVersion();\n };\n}\n\n// Singleton instance\nlet auraWidgetServiceInstance: AuraWidgetService | null = null;\n\n/**\n * Get the singleton Aura instance\n * All imports will reference the same instance\n */\nfunction getInstance(): AuraWidgetService {\n if (!auraWidgetServiceInstance) {\n auraWidgetServiceInstance = new AuraWidgetService();\n }\n return auraWidgetServiceInstance;\n}\n\nexport const AuraWidget = getInstance();\n"],"names":["defaultConfig","globalConfig","getGlobalConfig","setGlobalConfig","config","configure","getConfig","getVersion","EventBus","event","callback","cb","data","eventBus","logger","message","hiddenStyles","defaultStyles","AuraWidgetService","_a","params","resolve","subTenantId","user","language","container","widgetId","widgetStyles","desiredWidth","desiredHeight","initialStyles","unsubscribeAuthReady","unsubscribeAuthComplete","partnerKey","showStyles","unsubscribe","auraWidgetServiceInstance","getInstance","AuraWidget"],"mappings":"mOAaA,MAAMA,EAAuC,CAC3C,eAAgB,mCAClB,EAEA,IAAIC,EAAoC,KAKjC,SAASC,GAAuC,CACrD,OAAOD,CACT,CAKO,SAASE,EAAgBC,EAA4B,CAC1DH,EAAe,CAAE,GAAGD,EAAe,GAAGI,CAAA,CACxC,CCtBO,SAASC,EAAUD,EAA4B,CACpDD,EAAgBC,CAAM,CACxB,CAEO,SAASE,GAA0B,CACxC,MAAML,EAAeC,EAAA,EACrB,GAAI,CAACD,EACH,MAAM,IAAI,MACR,8EAAA,EAGJ,OAAOA,CAC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ACHA,EAA4B,IAAIlB,GAE3BkB,CACT,CAEO,MAAME,EAAaD,EAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,YAAY,EAAmB,MAAM,gBAAgB,CAAA;AAE/E;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAEpD;AAED,wBAAgB,SAAS,IAAI,YAAY,CAQxC;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC"}
1
+ {"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,YAAY,EAAmB,MAAM,gBAAgB,CAAC;AAEhF;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAEpD;AAED,wBAAgB,SAAS,IAAI,YAAY,CAQxC;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insight-health/aura",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Aura SDK package for Insight Health AI",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",