prosupportai-widget 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/dist/index.d.ts +83 -0
- package/dist/index.js +125 -0
- package/package.json +40 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @prosupportai/widget
|
|
3
|
+
*
|
|
4
|
+
* Thin npm wrapper for the ProSupportAI browser widget.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import ProSupportAI from "@prosupportai/widget";
|
|
8
|
+
* ProSupportAI.init({ app_id: "YOUR_APP_ID", supabase_url: "https://xyz.supabase.co" });
|
|
9
|
+
*
|
|
10
|
+
* The package dynamically injects the widget runtime script on first init() call,
|
|
11
|
+
* then delegates all API calls to window.ProSupportAI. The browser global path
|
|
12
|
+
* (plain <script> tag install) continues to work completely unchanged.
|
|
13
|
+
*/
|
|
14
|
+
/** Configuration accepted by ProSupportAI.init(). */
|
|
15
|
+
export interface ProSupportAIConfig {
|
|
16
|
+
/** Public app identifier — the preferred single-key install method. */
|
|
17
|
+
app_id?: string;
|
|
18
|
+
/**
|
|
19
|
+
* URL of the hosted widget.js script.
|
|
20
|
+
* Defaults to "https://prosupportai.com/widget.js".
|
|
21
|
+
* Override for self-hosted / staging deployments.
|
|
22
|
+
*/
|
|
23
|
+
widget_url?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Supabase project base URL (e.g. "https://xyz.supabase.co").
|
|
26
|
+
* Required when using app_id so the widget can call widget-resolve.
|
|
27
|
+
* Maps to the data-supabase-url attribute on the injected script tag.
|
|
28
|
+
*/
|
|
29
|
+
supabase_url?: string;
|
|
30
|
+
user_id?: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
email?: string;
|
|
33
|
+
created_at?: string;
|
|
34
|
+
theme?: "system" | "light" | "dark";
|
|
35
|
+
primary_color?: string;
|
|
36
|
+
launcher_position?: "left" | "right";
|
|
37
|
+
side_spacing?: number;
|
|
38
|
+
bottom_spacing?: number;
|
|
39
|
+
match_site_style?: boolean;
|
|
40
|
+
botId?: string;
|
|
41
|
+
token?: string;
|
|
42
|
+
endpoint?: string;
|
|
43
|
+
widgetHost?: string;
|
|
44
|
+
debug?: boolean;
|
|
45
|
+
debugWidget?: boolean;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
type QueueEntry = [string, unknown];
|
|
49
|
+
interface ProSupportAIGlobal {
|
|
50
|
+
_q?: QueueEntry[];
|
|
51
|
+
init(config: ProSupportAIConfig): void;
|
|
52
|
+
update(config: Partial<ProSupportAIConfig>): void;
|
|
53
|
+
show(): void;
|
|
54
|
+
hide(): void;
|
|
55
|
+
shutdown(): void;
|
|
56
|
+
}
|
|
57
|
+
declare global {
|
|
58
|
+
interface Window {
|
|
59
|
+
ProSupportAI?: ProSupportAIGlobal;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
declare const ProSupportAI: {
|
|
63
|
+
/**
|
|
64
|
+
* Initialize the widget. Injects widget.js on first call if not already
|
|
65
|
+
* present, then delegates to window.ProSupportAI.init().
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ProSupportAI.init({ app_id: "YOUR_APP_ID", supabase_url: "https://xyz.supabase.co" });
|
|
69
|
+
*/
|
|
70
|
+
init(config?: ProSupportAIConfig): void;
|
|
71
|
+
/**
|
|
72
|
+
* Send a config update to the running widget (forwarded via postMessage).
|
|
73
|
+
*/
|
|
74
|
+
update(config: Partial<ProSupportAIConfig>): void;
|
|
75
|
+
/** Expand / reveal the widget panel. */
|
|
76
|
+
show(): void;
|
|
77
|
+
/** Collapse / hide the widget panel. */
|
|
78
|
+
hide(): void;
|
|
79
|
+
/** Destroy the iframe and remove the widget container from the DOM. */
|
|
80
|
+
shutdown(): void;
|
|
81
|
+
};
|
|
82
|
+
export default ProSupportAI;
|
|
83
|
+
export { ProSupportAI };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @prosupportai/widget
|
|
3
|
+
*
|
|
4
|
+
* Thin npm wrapper for the ProSupportAI browser widget.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import ProSupportAI from "@prosupportai/widget";
|
|
8
|
+
* ProSupportAI.init({ app_id: "YOUR_APP_ID", supabase_url: "https://xyz.supabase.co" });
|
|
9
|
+
*
|
|
10
|
+
* The package dynamically injects the widget runtime script on first init() call,
|
|
11
|
+
* then delegates all API calls to window.ProSupportAI. The browser global path
|
|
12
|
+
* (plain <script> tag install) continues to work completely unchanged.
|
|
13
|
+
*/
|
|
14
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
15
|
+
var t = {};
|
|
16
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
17
|
+
t[p] = s[p];
|
|
18
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
19
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
20
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
21
|
+
t[p[i]] = s[p[i]];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Constants
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
const DEFAULT_WIDGET_URL = "https://prosupportai.com/widget.js";
|
|
29
|
+
const SCRIPT_ID = "prosupportai-widget-sdk";
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Helpers
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
/**
|
|
34
|
+
* Ensure window.ProSupportAI exists with a pre-load queue so calls made
|
|
35
|
+
* before the script finishes loading are buffered and replayed.
|
|
36
|
+
* The real widget.js drains window.ProSupportAI._q on load.
|
|
37
|
+
*/
|
|
38
|
+
function ensureQueue() {
|
|
39
|
+
if (typeof window === "undefined")
|
|
40
|
+
return;
|
|
41
|
+
if (window.ProSupportAI)
|
|
42
|
+
return;
|
|
43
|
+
const q = [];
|
|
44
|
+
window.ProSupportAI = {
|
|
45
|
+
_q: q,
|
|
46
|
+
init: (c) => { q.push(["init", c]); },
|
|
47
|
+
update: (c) => { q.push(["update", c]); },
|
|
48
|
+
show: () => { q.push(["show", undefined]); },
|
|
49
|
+
hide: () => { q.push(["hide", undefined]); },
|
|
50
|
+
shutdown: () => { q.push(["shutdown", undefined]); },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Inject the widget.js script tag once. No-op if already present. */
|
|
54
|
+
function injectScript(widgetUrl, supabaseUrl) {
|
|
55
|
+
if (typeof document === "undefined")
|
|
56
|
+
return;
|
|
57
|
+
if (document.getElementById(SCRIPT_ID))
|
|
58
|
+
return;
|
|
59
|
+
const script = document.createElement("script");
|
|
60
|
+
script.id = SCRIPT_ID;
|
|
61
|
+
script.src = widgetUrl;
|
|
62
|
+
script.async = true;
|
|
63
|
+
if (supabaseUrl)
|
|
64
|
+
script.setAttribute("data-supabase-url", supabaseUrl);
|
|
65
|
+
document.head.appendChild(script);
|
|
66
|
+
}
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// Public API
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
const ProSupportAI = {
|
|
71
|
+
/**
|
|
72
|
+
* Initialize the widget. Injects widget.js on first call if not already
|
|
73
|
+
* present, then delegates to window.ProSupportAI.init().
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ProSupportAI.init({ app_id: "YOUR_APP_ID", supabase_url: "https://xyz.supabase.co" });
|
|
77
|
+
*/
|
|
78
|
+
init(config = {}) {
|
|
79
|
+
var _a;
|
|
80
|
+
if (typeof window === "undefined")
|
|
81
|
+
return; // SSR guard
|
|
82
|
+
const widgetUrl = (_a = config.widget_url) !== null && _a !== void 0 ? _a : DEFAULT_WIDGET_URL;
|
|
83
|
+
const supabaseUrl = config.supabase_url;
|
|
84
|
+
// Strip sdk-only fields before forwarding to the runtime
|
|
85
|
+
const { widget_url: _w, supabase_url: _s } = config, runtimeConfig = __rest(config, ["widget_url", "supabase_url"]);
|
|
86
|
+
ensureQueue();
|
|
87
|
+
injectScript(widgetUrl, supabaseUrl);
|
|
88
|
+
// At this point window.ProSupportAI is either the real API (if widget.js
|
|
89
|
+
// was already loaded) or the queue stub above. Either way, calling .init()
|
|
90
|
+
// does the right thing.
|
|
91
|
+
window.ProSupportAI.init(runtimeConfig);
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Send a config update to the running widget (forwarded via postMessage).
|
|
95
|
+
*/
|
|
96
|
+
update(config) {
|
|
97
|
+
var _a;
|
|
98
|
+
if (typeof window === "undefined")
|
|
99
|
+
return;
|
|
100
|
+
(_a = window.ProSupportAI) === null || _a === void 0 ? void 0 : _a.update(config);
|
|
101
|
+
},
|
|
102
|
+
/** Expand / reveal the widget panel. */
|
|
103
|
+
show() {
|
|
104
|
+
var _a;
|
|
105
|
+
if (typeof window === "undefined")
|
|
106
|
+
return;
|
|
107
|
+
(_a = window.ProSupportAI) === null || _a === void 0 ? void 0 : _a.show();
|
|
108
|
+
},
|
|
109
|
+
/** Collapse / hide the widget panel. */
|
|
110
|
+
hide() {
|
|
111
|
+
var _a;
|
|
112
|
+
if (typeof window === "undefined")
|
|
113
|
+
return;
|
|
114
|
+
(_a = window.ProSupportAI) === null || _a === void 0 ? void 0 : _a.hide();
|
|
115
|
+
},
|
|
116
|
+
/** Destroy the iframe and remove the widget container from the DOM. */
|
|
117
|
+
shutdown() {
|
|
118
|
+
var _a;
|
|
119
|
+
if (typeof window === "undefined")
|
|
120
|
+
return;
|
|
121
|
+
(_a = window.ProSupportAI) === null || _a === void 0 ? void 0 : _a.shutdown();
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
export default ProSupportAI;
|
|
125
|
+
export { ProSupportAI };
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "prosupportai-widget",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "ProSupportAI browser chat widget — npm install wrapper",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"prepublishOnly": "npm run build"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.8.3"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"chat",
|
|
32
|
+
"widget",
|
|
33
|
+
"prosupportai",
|
|
34
|
+
"customer-support",
|
|
35
|
+
"live-chat"
|
|
36
|
+
],
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"author": "ProSupportAI"
|
|
40
|
+
}
|