@careshiphealth/sdk 1.0.3 → 2.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.
package/dist/index.esm.js
CHANGED
|
@@ -172,6 +172,29 @@ class SuperCareEmbed {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
const superCareEmbed = new SuperCareEmbed();
|
|
175
|
+
if (typeof window !== "undefined") {
|
|
176
|
+
window.addEventListener("DOMContentLoaded", () => {
|
|
177
|
+
const scriptTag = document.querySelector("script[data-supercare-org-id]");
|
|
178
|
+
if (scriptTag) {
|
|
179
|
+
const orgId = scriptTag.getAttribute("data-supercare-org-id");
|
|
180
|
+
scriptTag.getAttribute("data-supercare-widget-url") || void 0;
|
|
181
|
+
scriptTag.getAttribute("data-supercare-css-url") || void 0;
|
|
182
|
+
const containerId = scriptTag.getAttribute("data-supercare-container-id") || void 0;
|
|
183
|
+
if (orgId && containerId) {
|
|
184
|
+
superCareEmbed.embed({
|
|
185
|
+
orgId,
|
|
186
|
+
apiKey: scriptTag.getAttribute("data-supercare-api-key") || "",
|
|
187
|
+
// widgetUrl,
|
|
188
|
+
// cssUrl,
|
|
189
|
+
containerId
|
|
190
|
+
}).catch(console.error);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (typeof window !== "undefined") {
|
|
196
|
+
window.SuperCareEmbed = superCareEmbed;
|
|
197
|
+
}
|
|
175
198
|
export {
|
|
176
199
|
SuperCareEmbed,
|
|
177
200
|
superCareEmbed as default
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/constant.ts","../src/index.ts"],"sourcesContent":["export const CONSTANTS = {\n WIDGET_CDN_URL: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget\",\n WIDGET_JS: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.iife.js\",\n WIDGET_CSS: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.css\",\n}","import { CONSTANTS } from \"./constant\";\n\nexport interface SuperCareEmbedConfig {\n orgId: string;\n apiKey: string;\n // cssUrl?: string;\n // widgetUrl?: string;\n containerId: string;\n autoInit?: boolean;\n}\n\nexport interface SuperCareEmbedSDK {\n embed: (config: SuperCareEmbedConfig) => Promise<void>;\n remove: () => void;\n isEmbedded: () => boolean;\n}\n\nclass SuperCareEmbed implements SuperCareEmbedSDK {\n private isWidgetEmbedded = false;\n private scriptElement: HTMLScriptElement | null = null;\n private cssElement: HTMLLinkElement | null = null;\n private containerElement: HTMLDivElement | null = null;\n private config: SuperCareEmbedConfig | null = null;\n\n\n\n async embed(config: SuperCareEmbedConfig): Promise<void> {\n if (this.isWidgetEmbedded) {\n console.warn(\"SuperCare widget is already embedded\");\n return;\n }\n\n this.config = {\n // widgetUrl: defaultWidgetUrl,\n // cssUrl: defaultCssUrl,\n // containerId: \"supercare-09u2ekhbpo-body\",\n autoInit: true,\n ...config,\n };\n\n try {\n await this.injectCSS();\n await this.injectContainer();\n await this.injectScript();\n this.isWidgetEmbedded = true;\n } catch (error) {\n console.error(\"Failed to embed SuperCare widget:\", error);\n this.cleanup();\n throw error;\n }\n }\n\n\n remove(): void {\n if (!this.isWidgetEmbedded) {\n console.warn(\"SuperCare widget is not embedded\");\n return;\n }\n\n this.cleanup();\n this.isWidgetEmbedded = false;\n }\n\n\n isEmbedded(): boolean {\n return this.isWidgetEmbedded;\n }\n\n\n private async injectCSS(): Promise<void> {\n return new Promise((resolve, reject) => {\n // if (!this.config?.cssUrl) {\n // resolve();\n // return;\n // }\n\n const existingCSS = document.querySelector(\n `link[href=\"${CONSTANTS.WIDGET_CSS}\"]`\n );\n if (existingCSS) {\n resolve();\n return;\n }\n\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = CONSTANTS.WIDGET_CSS;\n\n link.onload = () => {\n this.cssElement = link;\n resolve();\n };\n\n link.onerror = () => {\n reject(new Error(`Failed to load CSS from ${CONSTANTS.WIDGET_CSS}`));\n };\n\n document.head.appendChild(link);\n });\n }\n\n private async injectContainer(): Promise<void> {\n if (!this.config?.containerId) {\n throw new Error(\"Container ID is required\");\n }\n\n const existingContainer = document.getElementById(this.config.containerId);\n if (existingContainer) {\n this.containerElement = existingContainer as HTMLDivElement;\n return;\n }\n\n const container = document.createElement(\"div\");\n container.id = this.config.containerId;\n document.body.appendChild(container);\n this.containerElement = container;\n }\n\n\n private async injectScript(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (!this.config?.orgId || !this.config?.apiKey) {\n reject(new Error(\"Org ID and API Key are required\"));\n return;\n }\n\n // Check if script is already loaded\n const existingScript = document.getElementById(\n \"supercare-09u2ekhbpo-script\"\n );\n if (existingScript) {\n resolve();\n return;\n }\n\n const script = document.createElement(\"script\");\n script.id = \"supercare-09u2ekhbpo-script\";\n script.dataset['']\n script.type = \"module\";\n script.src = `${CONSTANTS.WIDGET_JS}?orgId=${this.config.orgId}&apiKey=${this.config.apiKey}`;\n\n script.onload = () => {\n this.scriptElement = script;\n resolve();\n };\n\n script.onerror = () => {\n reject(\n new Error(`Failed to load script from ${CONSTANTS.WIDGET_JS}`)\n );\n };\n\n document.body.appendChild(script);\n });\n }\n\n\n private cleanup(): void {\n if (this.scriptElement) {\n this.scriptElement.remove();\n this.scriptElement = null;\n }\n\n if (this.cssElement) {\n this.cssElement.remove();\n this.cssElement = null;\n }\n\n if (this.containerElement) {\n this.containerElement.remove();\n this.containerElement = null;\n }\n\n this.config = null;\n }\n}\n\nconst superCareEmbed = new SuperCareEmbed();\n\nexport { SuperCareEmbed };\nexport default superCareEmbed;\n\
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/constant.ts","../src/index.ts"],"sourcesContent":["export const CONSTANTS = {\n WIDGET_CDN_URL: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget\",\n WIDGET_JS: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.iife.js\",\n WIDGET_CSS: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.css\",\n}","import { CONSTANTS } from \"./constant\";\n\nexport interface SuperCareEmbedConfig {\n orgId: string;\n apiKey: string;\n // cssUrl?: string;\n // widgetUrl?: string;\n containerId: string;\n autoInit?: boolean;\n}\n\nexport interface SuperCareEmbedSDK {\n embed: (config: SuperCareEmbedConfig) => Promise<void>;\n remove: () => void;\n isEmbedded: () => boolean;\n}\n\nclass SuperCareEmbed implements SuperCareEmbedSDK {\n private isWidgetEmbedded = false;\n private scriptElement: HTMLScriptElement | null = null;\n private cssElement: HTMLLinkElement | null = null;\n private containerElement: HTMLDivElement | null = null;\n private config: SuperCareEmbedConfig | null = null;\n\n\n\n async embed(config: SuperCareEmbedConfig): Promise<void> {\n if (this.isWidgetEmbedded) {\n console.warn(\"SuperCare widget is already embedded\");\n return;\n }\n\n this.config = {\n // widgetUrl: defaultWidgetUrl,\n // cssUrl: defaultCssUrl,\n // containerId: \"supercare-09u2ekhbpo-body\",\n autoInit: true,\n ...config,\n };\n\n try {\n await this.injectCSS();\n await this.injectContainer();\n await this.injectScript();\n this.isWidgetEmbedded = true;\n } catch (error) {\n console.error(\"Failed to embed SuperCare widget:\", error);\n this.cleanup();\n throw error;\n }\n }\n\n\n remove(): void {\n if (!this.isWidgetEmbedded) {\n console.warn(\"SuperCare widget is not embedded\");\n return;\n }\n\n this.cleanup();\n this.isWidgetEmbedded = false;\n }\n\n\n isEmbedded(): boolean {\n return this.isWidgetEmbedded;\n }\n\n\n private async injectCSS(): Promise<void> {\n return new Promise((resolve, reject) => {\n // if (!this.config?.cssUrl) {\n // resolve();\n // return;\n // }\n\n const existingCSS = document.querySelector(\n `link[href=\"${CONSTANTS.WIDGET_CSS}\"]`\n );\n if (existingCSS) {\n resolve();\n return;\n }\n\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = CONSTANTS.WIDGET_CSS;\n\n link.onload = () => {\n this.cssElement = link;\n resolve();\n };\n\n link.onerror = () => {\n reject(new Error(`Failed to load CSS from ${CONSTANTS.WIDGET_CSS}`));\n };\n\n document.head.appendChild(link);\n });\n }\n\n private async injectContainer(): Promise<void> {\n if (!this.config?.containerId) {\n throw new Error(\"Container ID is required\");\n }\n\n const existingContainer = document.getElementById(this.config.containerId);\n if (existingContainer) {\n this.containerElement = existingContainer as HTMLDivElement;\n return;\n }\n\n const container = document.createElement(\"div\");\n container.id = this.config.containerId;\n document.body.appendChild(container);\n this.containerElement = container;\n }\n\n\n private async injectScript(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (!this.config?.orgId || !this.config?.apiKey) {\n reject(new Error(\"Org ID and API Key are required\"));\n return;\n }\n\n // Check if script is already loaded\n const existingScript = document.getElementById(\n \"supercare-09u2ekhbpo-script\"\n );\n if (existingScript) {\n resolve();\n return;\n }\n\n const script = document.createElement(\"script\");\n script.id = \"supercare-09u2ekhbpo-script\";\n script.dataset['']\n script.type = \"module\";\n script.src = `${CONSTANTS.WIDGET_JS}?orgId=${this.config.orgId}&apiKey=${this.config.apiKey}`;\n\n script.onload = () => {\n this.scriptElement = script;\n resolve();\n };\n\n script.onerror = () => {\n reject(\n new Error(`Failed to load script from ${CONSTANTS.WIDGET_JS}`)\n );\n };\n\n document.body.appendChild(script);\n });\n }\n\n\n private cleanup(): void {\n if (this.scriptElement) {\n this.scriptElement.remove();\n this.scriptElement = null;\n }\n\n if (this.cssElement) {\n this.cssElement.remove();\n this.cssElement = null;\n }\n\n if (this.containerElement) {\n this.containerElement.remove();\n this.containerElement = null;\n }\n\n this.config = null;\n }\n}\n\nconst superCareEmbed = new SuperCareEmbed();\n\nexport { SuperCareEmbed };\nexport default superCareEmbed;\n\nif (typeof window !== \"undefined\") {\n window.addEventListener(\"DOMContentLoaded\", () => {\n const scriptTag = document.querySelector(\"script[data-supercare-org-id]\");\n if (scriptTag) {\n const orgId = scriptTag.getAttribute(\"data-supercare-org-id\");\n const widgetUrl =\n scriptTag.getAttribute(\"data-supercare-widget-url\") || undefined;\n const cssUrl =\n scriptTag.getAttribute(\"data-supercare-css-url\") || undefined;\n const containerId =\n scriptTag.getAttribute(\"data-supercare-container-id\") || undefined;\n\n if (orgId && containerId) {\n superCareEmbed\n .embed({\n orgId,\n apiKey: scriptTag.getAttribute(\"data-supercare-api-key\") || \"\",\n // widgetUrl,\n // cssUrl,\n containerId,\n })\n .catch(console.error);\n }\n }\n });\n}\n\nif (typeof window !== \"undefined\") {\n (window as any).SuperCareEmbed = superCareEmbed;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,MAAM,YAAY;AAAA,EAErB,WAAW;AAAA,EACX,YAAY;AAChB;ACaA,MAAM,eAA4C;AAAA,EAAlD,cAAA;AACE,SAAQ,mBAAmB;AAC3B,SAAQ,gBAA0C;AAClD,SAAQ,aAAqC;AAC7C,SAAQ,mBAA0C;AAClD,SAAQ,SAAsC;AAAA,EAAA;AAAA,EAIxC,MAAM,QAA6C;AAAA;AACvD,UAAI,KAAK,kBAAkB;AACzB,gBAAQ,KAAK,sCAAsC;AACnD;AAAA,MACF;AAEA,WAAK,SAAS;AAAA;AAAA;AAAA;AAAA,QAIZ,UAAU;AAAA,SACP;AAGL,UAAI;AACF,cAAM,KAAK,UAAA;AACX,cAAM,KAAK,gBAAA;AACX,cAAM,KAAK,aAAA;AACX,aAAK,mBAAmB;AAAA,MAC1B,SAAS,OAAO;AACd,gBAAQ,MAAM,qCAAqC,KAAK;AACxD,aAAK,QAAA;AACL,cAAM;AAAA,MACR;AAAA,IACF;AAAA;AAAA,EAGA,SAAe;AACb,QAAI,CAAC,KAAK,kBAAkB;AAC1B,cAAQ,KAAK,kCAAkC;AAC/C;AAAA,IACF;AAEA,SAAK,QAAA;AACL,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAGA,aAAsB;AACpB,WAAO,KAAK;AAAA,EACd;AAAA,EAGc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;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var SuperCareEmbedSDK=function(e){"use strict";var t=Object.defineProperty,
|
|
1
|
+
var SuperCareEmbedSDK=function(e){"use strict";var t=Object.defineProperty,r=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,o=(e,r,i)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,d=(e,t,r)=>new Promise((i,n)=>{var o=e=>{try{s(r.next(e))}catch(t){n(t)}},d=e=>{try{s(r.throw(e))}catch(t){n(t)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,d);s((r=r.apply(e,t)).next())});const s="https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.iife.js",c="https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.css";class l{constructor(){this.isWidgetEmbedded=!1,this.scriptElement=null,this.cssElement=null,this.containerElement=null,this.config=null}embed(e){return d(this,null,function*(){if(this.isWidgetEmbedded)console.warn("SuperCare widget is already embedded");else{this.config=((e,t)=>{for(var d in t||(t={}))i.call(t,d)&&o(e,d,t[d]);if(r)for(var d of r(t))n.call(t,d)&&o(e,d,t[d]);return e})({autoInit:!0},e);try{yield this.injectCSS(),yield this.injectContainer(),yield this.injectScript(),this.isWidgetEmbedded=!0}catch(t){throw console.error("Failed to embed SuperCare widget:",t),this.cleanup(),t}}})}remove(){this.isWidgetEmbedded?(this.cleanup(),this.isWidgetEmbedded=!1):console.warn("SuperCare widget is not embedded")}isEmbedded(){return this.isWidgetEmbedded}injectCSS(){return d(this,null,function*(){return new Promise((e,t)=>{if(document.querySelector(`link[href="${c}"]`))return void e();const r=document.createElement("link");r.rel="stylesheet",r.href=c,r.onload=()=>{this.cssElement=r,e()},r.onerror=()=>{t(new Error(`Failed to load CSS from ${c}`))},document.head.appendChild(r)})})}injectContainer(){return d(this,null,function*(){var e;if(!(null==(e=this.config)?void 0:e.containerId))throw new Error("Container ID is required");const t=document.getElementById(this.config.containerId);if(t)return void(this.containerElement=t);const r=document.createElement("div");r.id=this.config.containerId,document.body.appendChild(r),this.containerElement=r})}injectScript(){return d(this,null,function*(){return new Promise((e,t)=>{var r,i;if(!(null==(r=this.config)?void 0:r.orgId)||!(null==(i=this.config)?void 0:i.apiKey))return void t(new Error("Org ID and API Key are required"));if(document.getElementById("supercare-09u2ekhbpo-script"))return void e();const n=document.createElement("script");n.id="supercare-09u2ekhbpo-script",n.dataset[""],n.type="module",n.src=`${s}?orgId=${this.config.orgId}&apiKey=${this.config.apiKey}`,n.onload=()=>{this.scriptElement=n,e()},n.onerror=()=>{t(new Error(`Failed to load script from ${s}`))},document.body.appendChild(n)})})}cleanup(){this.scriptElement&&(this.scriptElement.remove(),this.scriptElement=null),this.cssElement&&(this.cssElement.remove(),this.cssElement=null),this.containerElement&&(this.containerElement.remove(),this.containerElement=null),this.config=null}}const a=new l;return"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",()=>{const e=document.querySelector("script[data-supercare-org-id]");if(e){const t=e.getAttribute("data-supercare-org-id");e.getAttribute("data-supercare-widget-url"),e.getAttribute("data-supercare-css-url");const r=e.getAttribute("data-supercare-container-id")||void 0;t&&r&&a.embed({orgId:t,apiKey:e.getAttribute("data-supercare-api-key")||"",containerId:r}).catch(console.error)}}),"undefined"!=typeof window&&(window.SuperCareEmbed=a),e.SuperCareEmbed=l,e.default=a,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),e}({});
|
|
2
2
|
//# sourceMappingURL=supercare-embed-sdk.iife.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supercare-embed-sdk.iife.js","sources":["../src/constant.ts","../src/index.ts"],"sourcesContent":["export const CONSTANTS = {\n WIDGET_CDN_URL: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget\",\n WIDGET_JS: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.iife.js\",\n WIDGET_CSS: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.css\",\n}","import { CONSTANTS } from \"./constant\";\n\nexport interface SuperCareEmbedConfig {\n orgId: string;\n apiKey: string;\n // cssUrl?: string;\n // widgetUrl?: string;\n containerId: string;\n autoInit?: boolean;\n}\n\nexport interface SuperCareEmbedSDK {\n embed: (config: SuperCareEmbedConfig) => Promise<void>;\n remove: () => void;\n isEmbedded: () => boolean;\n}\n\nclass SuperCareEmbed implements SuperCareEmbedSDK {\n private isWidgetEmbedded = false;\n private scriptElement: HTMLScriptElement | null = null;\n private cssElement: HTMLLinkElement | null = null;\n private containerElement: HTMLDivElement | null = null;\n private config: SuperCareEmbedConfig | null = null;\n\n\n\n async embed(config: SuperCareEmbedConfig): Promise<void> {\n if (this.isWidgetEmbedded) {\n console.warn(\"SuperCare widget is already embedded\");\n return;\n }\n\n this.config = {\n // widgetUrl: defaultWidgetUrl,\n // cssUrl: defaultCssUrl,\n // containerId: \"supercare-09u2ekhbpo-body\",\n autoInit: true,\n ...config,\n };\n\n try {\n await this.injectCSS();\n await this.injectContainer();\n await this.injectScript();\n this.isWidgetEmbedded = true;\n } catch (error) {\n console.error(\"Failed to embed SuperCare widget:\", error);\n this.cleanup();\n throw error;\n }\n }\n\n\n remove(): void {\n if (!this.isWidgetEmbedded) {\n console.warn(\"SuperCare widget is not embedded\");\n return;\n }\n\n this.cleanup();\n this.isWidgetEmbedded = false;\n }\n\n\n isEmbedded(): boolean {\n return this.isWidgetEmbedded;\n }\n\n\n private async injectCSS(): Promise<void> {\n return new Promise((resolve, reject) => {\n // if (!this.config?.cssUrl) {\n // resolve();\n // return;\n // }\n\n const existingCSS = document.querySelector(\n `link[href=\"${CONSTANTS.WIDGET_CSS}\"]`\n );\n if (existingCSS) {\n resolve();\n return;\n }\n\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = CONSTANTS.WIDGET_CSS;\n\n link.onload = () => {\n this.cssElement = link;\n resolve();\n };\n\n link.onerror = () => {\n reject(new Error(`Failed to load CSS from ${CONSTANTS.WIDGET_CSS}`));\n };\n\n document.head.appendChild(link);\n });\n }\n\n private async injectContainer(): Promise<void> {\n if (!this.config?.containerId) {\n throw new Error(\"Container ID is required\");\n }\n\n const existingContainer = document.getElementById(this.config.containerId);\n if (existingContainer) {\n this.containerElement = existingContainer as HTMLDivElement;\n return;\n }\n\n const container = document.createElement(\"div\");\n container.id = this.config.containerId;\n document.body.appendChild(container);\n this.containerElement = container;\n }\n\n\n private async injectScript(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (!this.config?.orgId || !this.config?.apiKey) {\n reject(new Error(\"Org ID and API Key are required\"));\n return;\n }\n\n // Check if script is already loaded\n const existingScript = document.getElementById(\n \"supercare-09u2ekhbpo-script\"\n );\n if (existingScript) {\n resolve();\n return;\n }\n\n const script = document.createElement(\"script\");\n script.id = \"supercare-09u2ekhbpo-script\";\n script.dataset['']\n script.type = \"module\";\n script.src = `${CONSTANTS.WIDGET_JS}?orgId=${this.config.orgId}&apiKey=${this.config.apiKey}`;\n\n script.onload = () => {\n this.scriptElement = script;\n resolve();\n };\n\n script.onerror = () => {\n reject(\n new Error(`Failed to load script from ${CONSTANTS.WIDGET_JS}`)\n );\n };\n\n document.body.appendChild(script);\n });\n }\n\n\n private cleanup(): void {\n if (this.scriptElement) {\n this.scriptElement.remove();\n this.scriptElement = null;\n }\n\n if (this.cssElement) {\n this.cssElement.remove();\n this.cssElement = null;\n }\n\n if (this.containerElement) {\n this.containerElement.remove();\n this.containerElement = null;\n }\n\n this.config = null;\n }\n}\n\nconst superCareEmbed = new SuperCareEmbed();\n\nexport { SuperCareEmbed };\nexport default superCareEmbed;\n\
|
|
1
|
+
{"version":3,"file":"supercare-embed-sdk.iife.js","sources":["../src/constant.ts","../src/index.ts"],"sourcesContent":["export const CONSTANTS = {\n WIDGET_CDN_URL: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget\",\n WIDGET_JS: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.iife.js\",\n WIDGET_CSS: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.css\",\n}","import { CONSTANTS } from \"./constant\";\n\nexport interface SuperCareEmbedConfig {\n orgId: string;\n apiKey: string;\n // cssUrl?: string;\n // widgetUrl?: string;\n containerId: string;\n autoInit?: boolean;\n}\n\nexport interface SuperCareEmbedSDK {\n embed: (config: SuperCareEmbedConfig) => Promise<void>;\n remove: () => void;\n isEmbedded: () => boolean;\n}\n\nclass SuperCareEmbed implements SuperCareEmbedSDK {\n private isWidgetEmbedded = false;\n private scriptElement: HTMLScriptElement | null = null;\n private cssElement: HTMLLinkElement | null = null;\n private containerElement: HTMLDivElement | null = null;\n private config: SuperCareEmbedConfig | null = null;\n\n\n\n async embed(config: SuperCareEmbedConfig): Promise<void> {\n if (this.isWidgetEmbedded) {\n console.warn(\"SuperCare widget is already embedded\");\n return;\n }\n\n this.config = {\n // widgetUrl: defaultWidgetUrl,\n // cssUrl: defaultCssUrl,\n // containerId: \"supercare-09u2ekhbpo-body\",\n autoInit: true,\n ...config,\n };\n\n try {\n await this.injectCSS();\n await this.injectContainer();\n await this.injectScript();\n this.isWidgetEmbedded = true;\n } catch (error) {\n console.error(\"Failed to embed SuperCare widget:\", error);\n this.cleanup();\n throw error;\n }\n }\n\n\n remove(): void {\n if (!this.isWidgetEmbedded) {\n console.warn(\"SuperCare widget is not embedded\");\n return;\n }\n\n this.cleanup();\n this.isWidgetEmbedded = false;\n }\n\n\n isEmbedded(): boolean {\n return this.isWidgetEmbedded;\n }\n\n\n private async injectCSS(): Promise<void> {\n return new Promise((resolve, reject) => {\n // if (!this.config?.cssUrl) {\n // resolve();\n // return;\n // }\n\n const existingCSS = document.querySelector(\n `link[href=\"${CONSTANTS.WIDGET_CSS}\"]`\n );\n if (existingCSS) {\n resolve();\n return;\n }\n\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = CONSTANTS.WIDGET_CSS;\n\n link.onload = () => {\n this.cssElement = link;\n resolve();\n };\n\n link.onerror = () => {\n reject(new Error(`Failed to load CSS from ${CONSTANTS.WIDGET_CSS}`));\n };\n\n document.head.appendChild(link);\n });\n }\n\n private async injectContainer(): Promise<void> {\n if (!this.config?.containerId) {\n throw new Error(\"Container ID is required\");\n }\n\n const existingContainer = document.getElementById(this.config.containerId);\n if (existingContainer) {\n this.containerElement = existingContainer as HTMLDivElement;\n return;\n }\n\n const container = document.createElement(\"div\");\n container.id = this.config.containerId;\n document.body.appendChild(container);\n this.containerElement = container;\n }\n\n\n private async injectScript(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (!this.config?.orgId || !this.config?.apiKey) {\n reject(new Error(\"Org ID and API Key are required\"));\n return;\n }\n\n // Check if script is already loaded\n const existingScript = document.getElementById(\n \"supercare-09u2ekhbpo-script\"\n );\n if (existingScript) {\n resolve();\n return;\n }\n\n const script = document.createElement(\"script\");\n script.id = \"supercare-09u2ekhbpo-script\";\n script.dataset['']\n script.type = \"module\";\n script.src = `${CONSTANTS.WIDGET_JS}?orgId=${this.config.orgId}&apiKey=${this.config.apiKey}`;\n\n script.onload = () => {\n this.scriptElement = script;\n resolve();\n };\n\n script.onerror = () => {\n reject(\n new Error(`Failed to load script from ${CONSTANTS.WIDGET_JS}`)\n );\n };\n\n document.body.appendChild(script);\n });\n }\n\n\n private cleanup(): void {\n if (this.scriptElement) {\n this.scriptElement.remove();\n this.scriptElement = null;\n }\n\n if (this.cssElement) {\n this.cssElement.remove();\n this.cssElement = null;\n }\n\n if (this.containerElement) {\n this.containerElement.remove();\n this.containerElement = null;\n }\n\n this.config = null;\n }\n}\n\nconst superCareEmbed = new SuperCareEmbed();\n\nexport { SuperCareEmbed };\nexport default superCareEmbed;\n\nif (typeof window !== \"undefined\") {\n window.addEventListener(\"DOMContentLoaded\", () => {\n const scriptTag = document.querySelector(\"script[data-supercare-org-id]\");\n if (scriptTag) {\n const orgId = scriptTag.getAttribute(\"data-supercare-org-id\");\n const widgetUrl =\n scriptTag.getAttribute(\"data-supercare-widget-url\") || undefined;\n const cssUrl =\n scriptTag.getAttribute(\"data-supercare-css-url\") || undefined;\n const containerId =\n scriptTag.getAttribute(\"data-supercare-container-id\") || undefined;\n\n if (orgId && containerId) {\n superCareEmbed\n .embed({\n orgId,\n apiKey: scriptTag.getAttribute(\"data-supercare-api-key\") || \"\",\n // widgetUrl,\n // cssUrl,\n containerId,\n })\n .catch(console.error);\n }\n }\n });\n}\n\nif (typeof window !== \"undefined\") {\n (window as any).SuperCareEmbed = superCareEmbed;\n}\n"],"names":["CONSTANTS","SuperCareEmbed","constructor","this","isWidgetEmbedded","scriptElement","cssElement","containerElement","config","embed","__async","console","warn","__spreadValues","autoInit","injectCSS","injectContainer","injectScript","error","cleanup","remove","isEmbedded","Promise","resolve","reject","document","querySelector","link","createElement","rel","href","onload","onerror","Error","head","appendChild","_a","containerId","existingContainer","getElementById","container","id","body","orgId","_b","apiKey","script","dataset","type","src","superCareEmbed","window","addEventListener","scriptTag","getAttribute","catch"],"mappings":"idAAO,MAAMA,EAEE,oFAFFA,EAGG,gFCchB,MAAMC,EAAN,WAAAC,GACEC,KAAQC,kBAAmB,EAC3BD,KAAQE,cAA0C,KAClDF,KAAQG,WAAqC,KAC7CH,KAAQI,iBAA0C,KAClDJ,KAAQK,OAAsC,IAAA,CAIxC,KAAAC,CAAMD,GAA6C,OAAAE,EAAAP,KAAA,KAAA,YACvD,GAAIA,KAAKC,iBACPO,QAAQC,KAAK,4CADf,CAKAT,KAAKK,0HAASK,CAAA,CAIZC,UAAU,GACPN,GAGL,UACQL,KAAKY,kBACLZ,KAAKa,wBACLb,KAAKc,eACXd,KAAKC,kBAAmB,CAC1B,OAASc,GAGP,MAFAP,QAAQO,MAAM,oCAAqCA,GACnDf,KAAKgB,UACCD,CACR,CAnBA,CAoBF,EAAA,CAGA,MAAAE,GACOjB,KAAKC,kBAKVD,KAAKgB,UACLhB,KAAKC,k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AAgBxC,KAAKK,OAAOqC,SAErFC,EAAOf,OAAS,KACd5B,KAAKE,cAAgByC,EACrBvB,KAGFuB,EAAOd,QAAU,KACfR,EACE,IAAIS,MAAM,8BAA8BjC,OAI5CyB,SAASiB,KAAKP,YAAYW,IAE9B,EAAA,CAGQ,OAAA3B,GACFhB,KAAKE,gBACPF,KAAKE,cAAce,SACnBjB,KAAKE,cAAgB,MAGnBF,KAAKG,aACPH,KAAKG,WAAWc,SAChBjB,KAAKG,WAAa,MAGhBH,KAAKI,mBACPJ,KAAKI,iBAAiBa,SACtBjB,KAAKI,iBAAmB,MAG1BJ,KAAKK,OAAS,IAChB,EAGF,MAAM0C,EAAiB,IAAIjD,QAKL,oBAAXkD,QACTA,OAAOC,iBAAiB,mBAAoB,KAC1C,MAAMC,EAAY5B,SAASC,cAAc,iCACzC,GAAI2B,EAAW,CACb,MAAMV,EAAQU,EAAUC,aAAa,yBAEnCD,EAAUC,aAAa,6BAEvBD,EAAUC,aAAa,0BACzB,MAAMjB,EACJgB,EAAUC,aAAa,qCAAkC,EAEvDX,GAASN,GACXa,EACGzC,MAAM,CACLkC,QACAE,OAAQQ,EAAUC,aAAa,2BAA6B,GAG5DjB,gBAEDkB,MAAM5C,QAAQO,MAErB,IAIkB,oBAAXiC,SACRA,OAAelD,eAAiBiD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).SuperCareEmbedSDK={})}(this,function(e){"use strict";var t=Object.defineProperty,i=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,o=(e,i,n)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n,
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).SuperCareEmbedSDK={})}(this,function(e){"use strict";var t=Object.defineProperty,i=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,o=(e,i,n)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n,d=(e,t,i)=>new Promise((n,r)=>{var o=e=>{try{s(i.next(e))}catch(t){r(t)}},d=e=>{try{s(i.throw(e))}catch(t){r(t)}},s=e=>e.done?n(e.value):Promise.resolve(e.value).then(o,d);s((i=i.apply(e,t)).next())});const s="https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.iife.js",c="https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.css";class l{constructor(){this.isWidgetEmbedded=!1,this.scriptElement=null,this.cssElement=null,this.containerElement=null,this.config=null}embed(e){return d(this,null,function*(){if(this.isWidgetEmbedded)console.warn("SuperCare widget is already embedded");else{this.config=((e,t)=>{for(var d in t||(t={}))n.call(t,d)&&o(e,d,t[d]);if(i)for(var d of i(t))r.call(t,d)&&o(e,d,t[d]);return e})({autoInit:!0},e);try{yield this.injectCSS(),yield this.injectContainer(),yield this.injectScript(),this.isWidgetEmbedded=!0}catch(t){throw console.error("Failed to embed SuperCare widget:",t),this.cleanup(),t}}})}remove(){this.isWidgetEmbedded?(this.cleanup(),this.isWidgetEmbedded=!1):console.warn("SuperCare widget is not embedded")}isEmbedded(){return this.isWidgetEmbedded}injectCSS(){return d(this,null,function*(){return new Promise((e,t)=>{if(document.querySelector(`link[href="${c}"]`))return void e();const i=document.createElement("link");i.rel="stylesheet",i.href=c,i.onload=()=>{this.cssElement=i,e()},i.onerror=()=>{t(new Error(`Failed to load CSS from ${c}`))},document.head.appendChild(i)})})}injectContainer(){return d(this,null,function*(){var e;if(!(null==(e=this.config)?void 0:e.containerId))throw new Error("Container ID is required");const t=document.getElementById(this.config.containerId);if(t)return void(this.containerElement=t);const i=document.createElement("div");i.id=this.config.containerId,document.body.appendChild(i),this.containerElement=i})}injectScript(){return d(this,null,function*(){return new Promise((e,t)=>{var i,n;if(!(null==(i=this.config)?void 0:i.orgId)||!(null==(n=this.config)?void 0:n.apiKey))return void t(new Error("Org ID and API Key are required"));if(document.getElementById("supercare-09u2ekhbpo-script"))return void e();const r=document.createElement("script");r.id="supercare-09u2ekhbpo-script",r.dataset[""],r.type="module",r.src=`${s}?orgId=${this.config.orgId}&apiKey=${this.config.apiKey}`,r.onload=()=>{this.scriptElement=r,e()},r.onerror=()=>{t(new Error(`Failed to load script from ${s}`))},document.body.appendChild(r)})})}cleanup(){this.scriptElement&&(this.scriptElement.remove(),this.scriptElement=null),this.cssElement&&(this.cssElement.remove(),this.cssElement=null),this.containerElement&&(this.containerElement.remove(),this.containerElement=null),this.config=null}}const a=new l;"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",()=>{const e=document.querySelector("script[data-supercare-org-id]");if(e){const t=e.getAttribute("data-supercare-org-id");e.getAttribute("data-supercare-widget-url"),e.getAttribute("data-supercare-css-url");const i=e.getAttribute("data-supercare-container-id")||void 0;t&&i&&a.embed({orgId:t,apiKey:e.getAttribute("data-supercare-api-key")||"",containerId:i}).catch(console.error)}}),"undefined"!=typeof window&&(window.SuperCareEmbed=a),e.SuperCareEmbed=l,e.default=a,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
2
2
|
//# sourceMappingURL=supercare-embed-sdk.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supercare-embed-sdk.umd.js","sources":["../src/constant.ts","../src/index.ts"],"sourcesContent":["export const CONSTANTS = {\n WIDGET_CDN_URL: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget\",\n WIDGET_JS: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.iife.js\",\n WIDGET_CSS: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.css\",\n}","import { CONSTANTS } from \"./constant\";\n\nexport interface SuperCareEmbedConfig {\n orgId: string;\n apiKey: string;\n // cssUrl?: string;\n // widgetUrl?: string;\n containerId: string;\n autoInit?: boolean;\n}\n\nexport interface SuperCareEmbedSDK {\n embed: (config: SuperCareEmbedConfig) => Promise<void>;\n remove: () => void;\n isEmbedded: () => boolean;\n}\n\nclass SuperCareEmbed implements SuperCareEmbedSDK {\n private isWidgetEmbedded = false;\n private scriptElement: HTMLScriptElement | null = null;\n private cssElement: HTMLLinkElement | null = null;\n private containerElement: HTMLDivElement | null = null;\n private config: SuperCareEmbedConfig | null = null;\n\n\n\n async embed(config: SuperCareEmbedConfig): Promise<void> {\n if (this.isWidgetEmbedded) {\n console.warn(\"SuperCare widget is already embedded\");\n return;\n }\n\n this.config = {\n // widgetUrl: defaultWidgetUrl,\n // cssUrl: defaultCssUrl,\n // containerId: \"supercare-09u2ekhbpo-body\",\n autoInit: true,\n ...config,\n };\n\n try {\n await this.injectCSS();\n await this.injectContainer();\n await this.injectScript();\n this.isWidgetEmbedded = true;\n } catch (error) {\n console.error(\"Failed to embed SuperCare widget:\", error);\n this.cleanup();\n throw error;\n }\n }\n\n\n remove(): void {\n if (!this.isWidgetEmbedded) {\n console.warn(\"SuperCare widget is not embedded\");\n return;\n }\n\n this.cleanup();\n this.isWidgetEmbedded = false;\n }\n\n\n isEmbedded(): boolean {\n return this.isWidgetEmbedded;\n }\n\n\n private async injectCSS(): Promise<void> {\n return new Promise((resolve, reject) => {\n // if (!this.config?.cssUrl) {\n // resolve();\n // return;\n // }\n\n const existingCSS = document.querySelector(\n `link[href=\"${CONSTANTS.WIDGET_CSS}\"]`\n );\n if (existingCSS) {\n resolve();\n return;\n }\n\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = CONSTANTS.WIDGET_CSS;\n\n link.onload = () => {\n this.cssElement = link;\n resolve();\n };\n\n link.onerror = () => {\n reject(new Error(`Failed to load CSS from ${CONSTANTS.WIDGET_CSS}`));\n };\n\n document.head.appendChild(link);\n });\n }\n\n private async injectContainer(): Promise<void> {\n if (!this.config?.containerId) {\n throw new Error(\"Container ID is required\");\n }\n\n const existingContainer = document.getElementById(this.config.containerId);\n if (existingContainer) {\n this.containerElement = existingContainer as HTMLDivElement;\n return;\n }\n\n const container = document.createElement(\"div\");\n container.id = this.config.containerId;\n document.body.appendChild(container);\n this.containerElement = container;\n }\n\n\n private async injectScript(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (!this.config?.orgId || !this.config?.apiKey) {\n reject(new Error(\"Org ID and API Key are required\"));\n return;\n }\n\n // Check if script is already loaded\n const existingScript = document.getElementById(\n \"supercare-09u2ekhbpo-script\"\n );\n if (existingScript) {\n resolve();\n return;\n }\n\n const script = document.createElement(\"script\");\n script.id = \"supercare-09u2ekhbpo-script\";\n script.dataset['']\n script.type = \"module\";\n script.src = `${CONSTANTS.WIDGET_JS}?orgId=${this.config.orgId}&apiKey=${this.config.apiKey}`;\n\n script.onload = () => {\n this.scriptElement = script;\n resolve();\n };\n\n script.onerror = () => {\n reject(\n new Error(`Failed to load script from ${CONSTANTS.WIDGET_JS}`)\n );\n };\n\n document.body.appendChild(script);\n });\n }\n\n\n private cleanup(): void {\n if (this.scriptElement) {\n this.scriptElement.remove();\n this.scriptElement = null;\n }\n\n if (this.cssElement) {\n this.cssElement.remove();\n this.cssElement = null;\n }\n\n if (this.containerElement) {\n this.containerElement.remove();\n this.containerElement = null;\n }\n\n this.config = null;\n }\n}\n\nconst superCareEmbed = new SuperCareEmbed();\n\nexport { SuperCareEmbed };\nexport default superCareEmbed;\n\
|
|
1
|
+
{"version":3,"file":"supercare-embed-sdk.umd.js","sources":["../src/constant.ts","../src/index.ts"],"sourcesContent":["export const CONSTANTS = {\n WIDGET_CDN_URL: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget\",\n WIDGET_JS: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.iife.js\",\n WIDGET_CSS: \"https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.css\",\n}","import { CONSTANTS } from \"./constant\";\n\nexport interface SuperCareEmbedConfig {\n orgId: string;\n apiKey: string;\n // cssUrl?: string;\n // widgetUrl?: string;\n containerId: string;\n autoInit?: boolean;\n}\n\nexport interface SuperCareEmbedSDK {\n embed: (config: SuperCareEmbedConfig) => Promise<void>;\n remove: () => void;\n isEmbedded: () => boolean;\n}\n\nclass SuperCareEmbed implements SuperCareEmbedSDK {\n private isWidgetEmbedded = false;\n private scriptElement: HTMLScriptElement | null = null;\n private cssElement: HTMLLinkElement | null = null;\n private containerElement: HTMLDivElement | null = null;\n private config: SuperCareEmbedConfig | null = null;\n\n\n\n async embed(config: SuperCareEmbedConfig): Promise<void> {\n if (this.isWidgetEmbedded) {\n console.warn(\"SuperCare widget is already embedded\");\n return;\n }\n\n this.config = {\n // widgetUrl: defaultWidgetUrl,\n // cssUrl: defaultCssUrl,\n // containerId: \"supercare-09u2ekhbpo-body\",\n autoInit: true,\n ...config,\n };\n\n try {\n await this.injectCSS();\n await this.injectContainer();\n await this.injectScript();\n this.isWidgetEmbedded = true;\n } catch (error) {\n console.error(\"Failed to embed SuperCare widget:\", error);\n this.cleanup();\n throw error;\n }\n }\n\n\n remove(): void {\n if (!this.isWidgetEmbedded) {\n console.warn(\"SuperCare widget is not embedded\");\n return;\n }\n\n this.cleanup();\n this.isWidgetEmbedded = false;\n }\n\n\n isEmbedded(): boolean {\n return this.isWidgetEmbedded;\n }\n\n\n private async injectCSS(): Promise<void> {\n return new Promise((resolve, reject) => {\n // if (!this.config?.cssUrl) {\n // resolve();\n // return;\n // }\n\n const existingCSS = document.querySelector(\n `link[href=\"${CONSTANTS.WIDGET_CSS}\"]`\n );\n if (existingCSS) {\n resolve();\n return;\n }\n\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = CONSTANTS.WIDGET_CSS;\n\n link.onload = () => {\n this.cssElement = link;\n resolve();\n };\n\n link.onerror = () => {\n reject(new Error(`Failed to load CSS from ${CONSTANTS.WIDGET_CSS}`));\n };\n\n document.head.appendChild(link);\n });\n }\n\n private async injectContainer(): Promise<void> {\n if (!this.config?.containerId) {\n throw new Error(\"Container ID is required\");\n }\n\n const existingContainer = document.getElementById(this.config.containerId);\n if (existingContainer) {\n this.containerElement = existingContainer as HTMLDivElement;\n return;\n }\n\n const container = document.createElement(\"div\");\n container.id = this.config.containerId;\n document.body.appendChild(container);\n this.containerElement = container;\n }\n\n\n private async injectScript(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (!this.config?.orgId || !this.config?.apiKey) {\n reject(new Error(\"Org ID and API Key are required\"));\n return;\n }\n\n // Check if script is already loaded\n const existingScript = document.getElementById(\n \"supercare-09u2ekhbpo-script\"\n );\n if (existingScript) {\n resolve();\n return;\n }\n\n const script = document.createElement(\"script\");\n script.id = \"supercare-09u2ekhbpo-script\";\n script.dataset['']\n script.type = \"module\";\n script.src = `${CONSTANTS.WIDGET_JS}?orgId=${this.config.orgId}&apiKey=${this.config.apiKey}`;\n\n script.onload = () => {\n this.scriptElement = script;\n resolve();\n };\n\n script.onerror = () => {\n reject(\n new Error(`Failed to load script from ${CONSTANTS.WIDGET_JS}`)\n );\n };\n\n document.body.appendChild(script);\n });\n }\n\n\n private cleanup(): void {\n if (this.scriptElement) {\n this.scriptElement.remove();\n this.scriptElement = null;\n }\n\n if (this.cssElement) {\n this.cssElement.remove();\n this.cssElement = null;\n }\n\n if (this.containerElement) {\n this.containerElement.remove();\n this.containerElement = null;\n }\n\n this.config = null;\n }\n}\n\nconst superCareEmbed = new SuperCareEmbed();\n\nexport { SuperCareEmbed };\nexport default superCareEmbed;\n\nif (typeof window !== \"undefined\") {\n window.addEventListener(\"DOMContentLoaded\", () => {\n const scriptTag = document.querySelector(\"script[data-supercare-org-id]\");\n if (scriptTag) {\n const orgId = scriptTag.getAttribute(\"data-supercare-org-id\");\n const widgetUrl =\n scriptTag.getAttribute(\"data-supercare-widget-url\") || undefined;\n const cssUrl =\n scriptTag.getAttribute(\"data-supercare-css-url\") || undefined;\n const containerId =\n scriptTag.getAttribute(\"data-supercare-container-id\") || undefined;\n\n if (orgId && containerId) {\n superCareEmbed\n .embed({\n orgId,\n apiKey: scriptTag.getAttribute(\"data-supercare-api-key\") || \"\",\n // widgetUrl,\n // cssUrl,\n containerId,\n })\n .catch(console.error);\n }\n }\n });\n}\n\nif (typeof window !== \"undefined\") {\n (window as any).SuperCareEmbed = superCareEmbed;\n}\n"],"names":["CONSTANTS","SuperCareEmbed","constructor","this","isWidgetEmbedded","scriptElement","cssElement","containerElement","config","embed","__async","console","warn","__spreadValues","autoInit","injectCSS","injectContainer","injectScript","error","cleanup","remove","isEmbedded","Promise","resolve","reject","document","querySelector","link","createElement","rel","href","onload","onerror","Error","head","appendChild","_a","containerId","existingContainer","getElementById","container","id","body","orgId","_b","apiKey","script","dataset","type","src","superCareEmbed","window","addEventListener","scriptTag","getAttribute","catch"],"mappings":"0pBAAO,MAAMA,EAEE,oFAFFA,EAGG,gFCchB,MAAMC,EAAN,WAAAC,GACEC,KAAQC,kBAAmB,EAC3BD,KAAQE,cAA0C,KAClDF,KAAQG,WAAqC,KAC7CH,KAAQI,iBAA0C,KAClDJ,KAAQK,OAAsC,IAAA,CAIxC,KAAAC,CAAMD,GAA6C,OAAAE,EAAAP,KAAA,KAAA,YACvD,GAAIA,KAAKC,iBACPO,QAAQC,KAAK,4CADf,CAKAT,KAAKK,0HAASK,CAAA,CAIZC,UAAU,GACPN,GAGL,UACQL,KAAKY,kBACLZ,KAAKa,wBACLb,KAAKc,eACXd,KAAKC,kBAAmB,CAC1B,OAASc,GAGP,MAFAP,QAAQO,MAAM,oCAAqCA,GACnDf,KAAKgB,UACCD,CACR,CAnBA,CAoBF,EAAA,CAGA,MAAAE,GACOjB,KAAKC,kBAKVD,KAAKgB,UACLhB,KAAKC,kBAAmB,GALtBO,QAAQC,KAAK,mCAMjB,CAGA,UAAAS,GACE,OAAOlB,KAAKC,gBACd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