@careshiphealth/sdk 1.0.0

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/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # SuperCare Embed SDK
2
+
3
+ A lightweight, zero-dependency SDK to dynamically embed the SuperCare widget into any web page.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @supercare/embed-sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Method 1: JavaScript/TypeScript Module
14
+
15
+ ```javascript
16
+ import SuperCareEmbed from '@supercare/embed-sdk';
17
+
18
+ // Embed the widget
19
+ await SuperCareEmbed.embed({
20
+ orgId: 'your-org-id-here',
21
+ apiKey: 'your-api-key-here',
22
+ widgetUrl: '/widget/supercare-widget.iife.js', // optional
23
+ cssUrl: '/widget/widget.css', // optional
24
+ containerId: 'supercare-widget-container' // optional
25
+ });
26
+
27
+ // Check if widget is embedded
28
+ if (SuperCareEmbed.isEmbedded()) {
29
+ console.log('Widget is embedded');
30
+ }
31
+
32
+ // Remove the widget
33
+ SuperCareEmbed.remove();
34
+ ```
35
+
36
+ ### Method 2: Direct Script Tag with Data Attributes
37
+
38
+ ```html
39
+ <!DOCTYPE html>
40
+ <html>
41
+ <head>
42
+ <title>Your App</title>
43
+ </head>
44
+ <body>
45
+ <!-- Your content -->
46
+
47
+ <!-- Load the embed SDK script with data attributes -->
48
+ <script
49
+ src="path/to/supercare-embed-sdk.js"
50
+ data-supercare-org-id="545a71ce-dab2-4ce3-b33b-83326eff6a36"
51
+ data-supercare-api-key="9991a016cb88421e8da4048b19f9a576"
52
+ data-supercare-widget-url="/widget/supercare-widget.iife.js"
53
+ data-supercare-css-url="/widget/widget.css"
54
+ data-supercare-container-id="my-widget-container">
55
+ </script>
56
+ </body>
57
+ </html>
58
+ ```
59
+
60
+ ### Method 3: Global Window Object
61
+
62
+ ```html
63
+ <script src="path/to/supercare-embed-sdk.js"></script>
64
+ <script>
65
+ // SDK is available as window.SuperCareEmbed
66
+ window.SuperCareEmbed.embed({
67
+ orgId: '545a71ce-dab2-4ce3-b33b-83326eff6a36',
68
+ apiKey: '9991a016cb88421e8da4048b19f9a576',
69
+ }).then(() => {
70
+ console.log('Widget embedded successfully');
71
+ }).catch((error) => {
72
+ console.error('Failed to embed widget:', error);
73
+ });
74
+ </script>
75
+ ```
76
+
77
+ ## Configuration Options
78
+
79
+ | Option | Type | Default | Description |
80
+ |--------|------|---------|-------------|
81
+ | `orgId` | `string` | **Required** | Your organization ID |
82
+ | `widgetUrl` | `string` | `/widget/supercare-widget.iife.js` | URL to the widget JavaScript file |
83
+ | `cssUrl` | `string` | `/widget/widget.css` | URL to the widget CSS file |
84
+ | `containerId` | `string` | `supercare-09u2ekhbpo-body` | ID of the container element for the widget |
85
+ | `autoInit` | `boolean` | `true` | Whether to automatically initialize the widget |
86
+
87
+ ## API Reference
88
+
89
+ ### `SuperCareEmbed.embed(config: SuperCareEmbedConfig): Promise<void>`
90
+
91
+ Embeds the SuperCare widget with the provided configuration.
92
+
93
+ **Parameters:**
94
+ - `config`: Configuration object containing orgId and optional settings
95
+
96
+ **Returns:** Promise that resolves when the widget is embedded
97
+
98
+ **Example:**
99
+ ```javascript
100
+ await SuperCareEmbed.embed({
101
+ orgId: 'your-org-id',
102
+ widgetUrl: 'https://cdn.example.com/widget.js'
103
+ });
104
+ ```
105
+
106
+ ### `SuperCareEmbed.remove(): void`
107
+
108
+ Removes the widget and cleans up all injected elements.
109
+
110
+ **Example:**
111
+ ```javascript
112
+ SuperCareEmbed.remove();
113
+ ```
114
+
115
+ ### `SuperCareEmbed.isEmbedded(): boolean`
116
+
117
+ Returns whether the widget is currently embedded.
118
+
119
+ **Returns:** `true` if embedded, `false` otherwise
120
+
121
+ **Example:**
122
+ ```javascript
123
+ if (SuperCareEmbed.isEmbedded()) {
124
+ console.log('Widget is active');
125
+ }
126
+ ```
127
+
128
+ ## What the SDK Does
129
+
130
+ The embed SDK automatically:
131
+
132
+ 1. **Injects CSS**: Adds the widget stylesheet to the document head
133
+ 2. **Creates Container**: Adds the required container div to the document body
134
+ 3. **Loads Script**: Injects the widget JavaScript with the proper org ID parameter
135
+ 4. **Handles Cleanup**: Provides methods to cleanly remove all injected elements
136
+
137
+ ## Generated HTML Structure
138
+
139
+ When embedded, the SDK creates the following structure:
140
+
141
+ ```html
142
+ <head>
143
+ <!-- Injected CSS -->
144
+ <link rel="stylesheet" href="/widget/widget.css" />
145
+ </head>
146
+ <body>
147
+ <!-- Your existing content -->
148
+
149
+ <!-- Injected container -->
150
+ <div id="supercare-09u2ekhbpo-body"></div>
151
+
152
+ <!-- Injected script -->
153
+ <script
154
+ id="supercare-09u2ekhbpo-script"
155
+ type="module"
156
+ src="/widget/supercare-widget.iife.js?ORG_ID=your-org-id">
157
+ </script>
158
+ </body>
159
+ ```
160
+
161
+ ## Error Handling
162
+
163
+ The embed SDK includes comprehensive error handling:
164
+
165
+ ```javascript
166
+ try {
167
+ await SuperCareEmbed.embed({
168
+ orgId: 'invalid-org-id',
169
+ widgetUrl: 'https://nonexistent.com/widget.js'
170
+ });
171
+ } catch (error) {
172
+ console.error('Widget embedding failed:', error.message);
173
+ // Handle the error appropriately
174
+ }
175
+ ```
176
+
177
+ ## TypeScript Support
178
+
179
+ The package includes full TypeScript definitions:
180
+
181
+ ```typescript
182
+ import SuperCareEmbed, { SuperCareEmbedConfig } from '@supercare/embed-sdk';
183
+
184
+ const config: SuperCareEmbedConfig = {
185
+ orgId: 'your-org-id',
186
+ widgetUrl: '/custom/path/widget.js'
187
+ };
188
+
189
+ await SuperCareEmbed.embed(config);
190
+ ```
191
+
192
+ ## Browser Compatibility
193
+
194
+ - Modern browsers with ES2015+ support
195
+ - Internet Explorer 11+ (with polyfills)
196
+ - All major mobile browsers
197
+
198
+ ## License
199
+
200
+ MIT
@@ -0,0 +1,32 @@
1
+ export declare class SuperCareEmbed implements SuperCareEmbedSDK {
2
+ private isWidgetEmbedded;
3
+ private scriptElement;
4
+ private cssElement;
5
+ private containerElement;
6
+ private config;
7
+ embed(config: SuperCareEmbedConfig): Promise<void>;
8
+ remove(): void;
9
+ isEmbedded(): boolean;
10
+ private injectCSS;
11
+ private injectContainer;
12
+ private injectScript;
13
+ private cleanup;
14
+ }
15
+
16
+ declare const superCareEmbed: SuperCareEmbed;
17
+ export default superCareEmbed;
18
+
19
+ export declare interface SuperCareEmbedConfig {
20
+ orgId: string;
21
+ apiKey: string;
22
+ containerId?: string;
23
+ autoInit?: boolean;
24
+ }
25
+
26
+ export declare interface SuperCareEmbedSDK {
27
+ embed: (config: SuperCareEmbedConfig) => Promise<void>;
28
+ remove: () => void;
29
+ isEmbedded: () => boolean;
30
+ }
31
+
32
+ export { }
@@ -0,0 +1,201 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __async = (__this, __arguments, generator) => {
18
+ return new Promise((resolve, reject) => {
19
+ var fulfilled = (value) => {
20
+ try {
21
+ step(generator.next(value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ };
26
+ var rejected = (value) => {
27
+ try {
28
+ step(generator.throw(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
+ step((generator = generator.apply(__this, __arguments)).next());
35
+ });
36
+ };
37
+ const CONSTANTS = {
38
+ WIDGET_JS: "https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.iife.js",
39
+ WIDGET_CSS: "https://cdn.jsdelivr.net/npm/@careshiphealth/widget/dist/supercare-widget.css"
40
+ };
41
+ class SuperCareEmbed {
42
+ constructor() {
43
+ this.isWidgetEmbedded = false;
44
+ this.scriptElement = null;
45
+ this.cssElement = null;
46
+ this.containerElement = null;
47
+ this.config = null;
48
+ }
49
+ embed(config) {
50
+ return __async(this, null, function* () {
51
+ if (this.isWidgetEmbedded) {
52
+ console.warn("SuperCare widget is already embedded");
53
+ return;
54
+ }
55
+ this.config = __spreadValues({
56
+ // widgetUrl: defaultWidgetUrl,
57
+ // cssUrl: defaultCssUrl,
58
+ containerId: "supercare-09u2ekhbpo-body",
59
+ autoInit: true
60
+ }, config);
61
+ try {
62
+ yield this.injectCSS();
63
+ yield this.injectContainer();
64
+ yield this.injectScript();
65
+ this.isWidgetEmbedded = true;
66
+ } catch (error) {
67
+ console.error("Failed to embed SuperCare widget:", error);
68
+ this.cleanup();
69
+ throw error;
70
+ }
71
+ });
72
+ }
73
+ remove() {
74
+ if (!this.isWidgetEmbedded) {
75
+ console.warn("SuperCare widget is not embedded");
76
+ return;
77
+ }
78
+ this.cleanup();
79
+ this.isWidgetEmbedded = false;
80
+ }
81
+ isEmbedded() {
82
+ return this.isWidgetEmbedded;
83
+ }
84
+ injectCSS() {
85
+ return __async(this, null, function* () {
86
+ return new Promise((resolve, reject) => {
87
+ const existingCSS = document.querySelector(
88
+ `link[href="${CONSTANTS.WIDGET_CSS}"]`
89
+ );
90
+ if (existingCSS) {
91
+ resolve();
92
+ return;
93
+ }
94
+ const link = document.createElement("link");
95
+ link.rel = "stylesheet";
96
+ link.href = CONSTANTS.WIDGET_CSS;
97
+ link.onload = () => {
98
+ this.cssElement = link;
99
+ resolve();
100
+ };
101
+ link.onerror = () => {
102
+ reject(new Error(`Failed to load CSS from ${CONSTANTS.WIDGET_CSS}`));
103
+ };
104
+ document.head.appendChild(link);
105
+ });
106
+ });
107
+ }
108
+ injectContainer() {
109
+ return __async(this, null, function* () {
110
+ var _a;
111
+ if (!((_a = this.config) == null ? void 0 : _a.containerId)) {
112
+ throw new Error("Container ID is required");
113
+ }
114
+ const existingContainer = document.getElementById(this.config.containerId);
115
+ if (existingContainer) {
116
+ this.containerElement = existingContainer;
117
+ return;
118
+ }
119
+ const container = document.createElement("div");
120
+ container.id = this.config.containerId;
121
+ document.body.appendChild(container);
122
+ this.containerElement = container;
123
+ });
124
+ }
125
+ injectScript() {
126
+ return __async(this, null, function* () {
127
+ return new Promise((resolve, reject) => {
128
+ var _a, _b;
129
+ if (!((_a = this.config) == null ? void 0 : _a.orgId) || !((_b = this.config) == null ? void 0 : _b.apiKey)) {
130
+ reject(new Error("Org ID and API Key are required"));
131
+ return;
132
+ }
133
+ const existingScript = document.getElementById(
134
+ "supercare-09u2ekhbpo-script"
135
+ );
136
+ if (existingScript) {
137
+ resolve();
138
+ return;
139
+ }
140
+ const script = document.createElement("script");
141
+ script.id = "supercare-09u2ekhbpo-script";
142
+ script.type = "module";
143
+ script.src = `${CONSTANTS.WIDGET_JS}?orgId=${this.config.orgId}&apiKey=${this.config.apiKey}`;
144
+ script.onload = () => {
145
+ this.scriptElement = script;
146
+ resolve();
147
+ };
148
+ script.onerror = () => {
149
+ reject(
150
+ new Error(`Failed to load script from ${CONSTANTS.WIDGET_JS}`)
151
+ );
152
+ };
153
+ document.body.appendChild(script);
154
+ });
155
+ });
156
+ }
157
+ cleanup() {
158
+ if (this.scriptElement) {
159
+ this.scriptElement.remove();
160
+ this.scriptElement = null;
161
+ }
162
+ if (this.cssElement) {
163
+ this.cssElement.remove();
164
+ this.cssElement = null;
165
+ }
166
+ if (this.containerElement) {
167
+ this.containerElement.remove();
168
+ this.containerElement = null;
169
+ }
170
+ this.config = null;
171
+ }
172
+ }
173
+ const superCareEmbed = new SuperCareEmbed();
174
+ if (typeof window !== "undefined") {
175
+ window.addEventListener("DOMContentLoaded", () => {
176
+ const scriptTag = document.querySelector("script[data-supercare-org-id]");
177
+ if (scriptTag) {
178
+ const orgId = scriptTag.getAttribute("data-supercare-org-id");
179
+ scriptTag.getAttribute("data-supercare-widget-url") || void 0;
180
+ scriptTag.getAttribute("data-supercare-css-url") || void 0;
181
+ const containerId = scriptTag.getAttribute("data-supercare-container-id") || void 0;
182
+ if (orgId) {
183
+ superCareEmbed.embed({
184
+ orgId,
185
+ apiKey: scriptTag.getAttribute("data-supercare-api-key") || "",
186
+ // widgetUrl,
187
+ // cssUrl,
188
+ containerId
189
+ }).catch(console.error);
190
+ }
191
+ }
192
+ });
193
+ }
194
+ if (typeof window !== "undefined") {
195
+ window.SuperCareEmbed = superCareEmbed;
196
+ }
197
+ export {
198
+ SuperCareEmbed,
199
+ superCareEmbed as default
200
+ };
201
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +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.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) {\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;ACa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W,OAAA;AAChB,WAAK,aAAa;AAAA,IACpB;AAEA,QAAI,KAAK,kBAAkB;AACzB,WAAK,iBAAiB,OAAA;AACtB,WAAK,mBAAmB;AAAA,IAC1B;AAEA,SAAK,SAAS;AAAA,EAChB;AACF;AAEA,MAAM,iBAAiB,IAAI,eAAA;AAK3B,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,iBAAiB,oBAAoB,MAAM;AAChD,UAAM,YAAY,SAAS,cAAc,+BAA+B;AACxE,QAAI,WAAW;AACb,YAAM,QAAQ,UAAU,aAAa,uBAAuB;AAE1D,gBAAU,aAAa,2BAA2B,KAAK;AAEvD,gBAAU,aAAa,wBAAwB,KAAK;AACtD,YAAM,cACJ,UAAU,aAAa,6BAA6B,KAAK;AAE3D,UAAI,OAAO;AACT,uBACG,MAAM;AAAA,UACL;AAAA,UACA,QAAQ,UAAU,aAAa,wBAAwB,KAAK;AAAA;AAAA;AAAA,UAG5D;AAAA,QAAA,CACD,EACA,MAAM,QAAQ,KAAK;AAAA,MACxB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,IAAI,OAAO,WAAW,aAAa;AAChC,SAAe,iBAAiB;AACnC;"}
@@ -0,0 +1,2 @@
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})({containerId:"supercare-09u2ekhbpo-body",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.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&&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
+ //# sourceMappingURL=supercare-embed-sdk.iife.js.map
@@ -0,0 +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.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) {\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","containerId","autoInit","injectCSS","injectContainer","injectScript","error","cleanup","remove","isEmbedded","Promise","resolve","reject","document","querySelector","link","createElement","rel","href","onload","onerror","Error","head","appendChild","_a","existingContainer","getElementById","container","id","body","orgId","_b","apiKey","script","type","src","superCareEmbed","window","addEventListener","script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EAEvDV,GACFM,EACGxC,MAAM,CACLkC,QACAE,OAAQO,EAAUC,aAAa,2BAA6B,GAG5DvC,gBAEDwC,MAAM3C,QAAQQ,MAErB,IAIkB,oBAAX+B,SACRA,OAAejD,eAAiBgD"}
@@ -0,0 +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,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})({containerId:"supercare-09u2ekhbpo-body",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.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&&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
+ //# sourceMappingURL=supercare-embed-sdk.umd.js.map
@@ -0,0 +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.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) {\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","containerId","autoInit","injectCSS","injectContainer","injectScript","error","cleanup","remove","isEmbedded","Promise","resolve","reject","document","querySelector","link","createElement","rel","href","onload","onerror","Error","head","appendChild","_a","existingContainer","getElementById","container","id","body","orgId","_b","apiKey","script","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,CAGZC,YAAa,4BACbC,UAAU,GACPP,GAGL,UACQL,KAAKa,kBACLb,KAAKc,wBACLd,KAAKe,eACXf,KAAKC,kBAAmB,CAC1B,OAASe,GAGP,MAFAR,QAAQQ,M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AAc,UACtCiB,EAAOL,GAAK,8BACZK,EAAOC,KAAO,SACdD,EAAOE,IAAM,GAAGhD,WAA6BG,KAAKK,OAAOmC,gBAAgBxC,KAAKK,OAAOqC,SAErFC,EAAOd,OAAS,KACd7B,KAAKE,cAAgByC,EACrBtB,KAGFsB,EAAOb,QAAU,KACfR,EACE,IAAIS,MAAM,8BAA8BlC,OAI5C0B,SAASgB,KAAKN,YAAYU,IAE9B,EAAA,CAGQ,OAAA1B,GACFjB,KAAKE,gBACPF,KAAKE,cAAcgB,SACnBlB,KAAKE,cAAgB,MAGnBF,KAAKG,aACPH,KAAKG,WAAWe,SAChBlB,KAAKG,WAAa,MAGhBH,KAAKI,mBACPJ,KAAKI,iBAAiBc,SACtBlB,KAAKI,iBAAmB,MAG1BJ,KAAKK,OAAS,IAChB,EAGF,MAAMyC,EAAiB,IAAIhD,EAKL,oBAAXiD,QACTA,OAAOC,iBAAiB,mBAAoB,KAC1C,MAAMC,EAAY1B,SAASC,cAAc,iCACzC,GAAIyB,EAAW,CACb,MAAMT,EAAQS,EAAUC,aAAa,yBAEnCD,EAAUC,aAAa,6BAEvBD,EAAUC,aAAa,0BACzB,MAAMvC,EACJsC,EAAUC,aAAa,qCAAkC,EAEvDV,GACFM,EACGxC,MAAM,CACLkC,QACAE,OAAQO,EAAUC,aAAa,2BAA6B,GAG5DvC,gBAEDwC,MAAM3C,QAAQQ,MAErB,IAIkB,oBAAX+B,SACRA,OAAejD,eAAiBgD"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@careshiphealth/sdk",
3
+ "version": "1.0.0",
4
+ "description": "A lightweight SDK to dynamically embed the SuperCare widget into any web page",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": "./src/index.ts"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "scripts": {
15
+ "build": "vite build",
16
+ "dev": "vite build --watch",
17
+ "preview": "vite preview",
18
+ "publish": "npm publish --access public",
19
+ "prepublishOnly": "npm run build"
20
+ },
21
+ "keywords": [
22
+ "supercare",
23
+ "embed",
24
+ "sdk",
25
+ "healthcare",
26
+ "widget",
27
+ "integration"
28
+ ],
29
+ "author": "zxen",
30
+ "license": "MIT",
31
+ "devDependencies": {
32
+ "typescript": "^5.2.2",
33
+ "vite": "^5.0.0",
34
+ "vite-plugin-dts": "^3.6.3"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/supercare/embed-sdk.git"
39
+ },
40
+ "bugs": {
41
+ "url": "https://github.com/supercare/embed-sdk/issues"
42
+ },
43
+ "homepage": "beta.careshiphealth.com"
44
+ }