@zean-chat/js 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +28 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +78 -0
- package/dist/interfaces.d.ts +33 -0
- package/dist/load.d.ts +13 -0
- package/package.json +63 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zean
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zean-chat/js: live chat widget for any website
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Add a free customer support chat to your website in one line, with [Zean](https://zean.chat/?utm_source=npm&utm_medium=readme&utm_campaign=js). Plain JavaScript or TypeScript, any framework or none. Your App key is in your Zean dashboard.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @zean-chat/js
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import { loadZean } from "@zean-chat/js";
|
|
11
|
+
|
|
12
|
+
const zean = loadZean({ appKey: "app_your_app_key" });
|
|
13
|
+
zean.open();
|
|
14
|
+
zean.onUnreadChange(count => console.log(count));
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Methods: `open`, `close`, `toggle`, `getUnreadCount`, `onUnreadChange`, `identify(getToken)`, `signOut`, `setAttributes`. They can be called before the chat has loaded. Full guide: [install the chat on a website](https://zean.chat/docs/install-website), [JavaScript reference](https://zean.chat/docs/reference-js).
|
|
18
|
+
|
|
19
|
+
## Why Zean
|
|
20
|
+
|
|
21
|
+
- Free plan to start. Paid plans in FCFA, payable by Mobile Money.
|
|
22
|
+
- Shared inbox for your team. Reply from your phone.
|
|
23
|
+
- Verified identity, webhooks, French and English. Fast even on 3G.
|
|
24
|
+
|
|
25
|
+
## Links
|
|
26
|
+
|
|
27
|
+
[Zean live chat](https://zean.chat/?utm_source=npm&utm_medium=readme&utm_campaign=js) · [Documentation](https://zean.chat/docs) · [Create a free account](https://zean.chat/sign-in?utm_source=npm&utm_medium=readme&utm_campaign=js) · [Zean vs Intercom](https://zean.chat/compare/intercom) · [Zean vs Crisp](https://zean.chat/compare/crisp)
|
|
28
|
+
|
|
29
|
+
Other SDKs: [@zean-chat/js](https://www.npmjs.com/package/@zean-chat/js) · [@zean-chat/react](https://www.npmjs.com/package/@zean-chat/react) · [@zean-chat/vue](https://www.npmjs.com/package/@zean-chat/vue) · [@zean-chat/react-native](https://www.npmjs.com/package/@zean-chat/react-native)
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// ../shared/src/constants/app.ts
|
|
2
|
+
var APP_NAME = "Zean";
|
|
3
|
+
var PRODUCTION_LOADER_URL = "https://widget.zean.chat/loader.js";
|
|
4
|
+
|
|
5
|
+
// src/load.ts
|
|
6
|
+
var SCRIPT_ATTRIBUTE = "data-zean-sdk";
|
|
7
|
+
var OTHER_LOADER_CHECKS = 300;
|
|
8
|
+
var loadedKey = null;
|
|
9
|
+
var waiting = [];
|
|
10
|
+
var readyApi = () => {
|
|
11
|
+
const current = typeof window === "undefined" ? void 0 : window.zean;
|
|
12
|
+
return typeof current?.open === "function" ? current : null;
|
|
13
|
+
};
|
|
14
|
+
var withApi = (call) => {
|
|
15
|
+
const api = readyApi();
|
|
16
|
+
if (api) call(api);
|
|
17
|
+
else if (typeof window !== "undefined") waiting.push(call);
|
|
18
|
+
};
|
|
19
|
+
var flush = () => {
|
|
20
|
+
const api = readyApi();
|
|
21
|
+
if (api) for (const call of waiting.splice(0)) call(api);
|
|
22
|
+
};
|
|
23
|
+
var waitForOtherLoader = () => {
|
|
24
|
+
let checks = 0;
|
|
25
|
+
const timer = window.setInterval(() => {
|
|
26
|
+
checks += 1;
|
|
27
|
+
if (readyApi() || checks >= OTHER_LOADER_CHECKS) window.clearInterval(timer);
|
|
28
|
+
flush();
|
|
29
|
+
}, 100);
|
|
30
|
+
};
|
|
31
|
+
var zean = {
|
|
32
|
+
open: () => withApi((api) => api.open()),
|
|
33
|
+
close: () => withApi((api) => api.close()),
|
|
34
|
+
toggle: () => withApi((api) => api.toggle()),
|
|
35
|
+
getUnreadCount: () => readyApi()?.getUnreadCount() ?? 0,
|
|
36
|
+
onUnreadChange(listener) {
|
|
37
|
+
let stop = null;
|
|
38
|
+
let stopped = false;
|
|
39
|
+
withApi((api) => {
|
|
40
|
+
if (!stopped) stop = api.onUnreadChange(listener);
|
|
41
|
+
});
|
|
42
|
+
return () => {
|
|
43
|
+
stopped = true;
|
|
44
|
+
stop?.();
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
identify: (getToken) => withApi((api) => api.identify(getToken)),
|
|
48
|
+
signOut: () => withApi((api) => api.signOut()),
|
|
49
|
+
setAttributes: (attributes) => withApi((api) => api.setAttributes(attributes))
|
|
50
|
+
};
|
|
51
|
+
function loadZean({ appKey, getToken, locale, loaderUrl = PRODUCTION_LOADER_URL }) {
|
|
52
|
+
if (typeof window === "undefined" || typeof document === "undefined") return zean;
|
|
53
|
+
if (loadedKey !== null) {
|
|
54
|
+
if (loadedKey !== appKey) console.warn(`${APP_NAME}: the chat is already loaded with the App key ${loadedKey}.`);
|
|
55
|
+
return zean;
|
|
56
|
+
}
|
|
57
|
+
loadedKey = appKey;
|
|
58
|
+
if (window.zean || document.querySelector(`script[${SCRIPT_ATTRIBUTE}]`)) {
|
|
59
|
+
waitForOtherLoader();
|
|
60
|
+
if (getToken) zean.identify(getToken);
|
|
61
|
+
return zean;
|
|
62
|
+
}
|
|
63
|
+
window.zean = { appKey, ...getToken ? { getToken } : {}, ...locale ? { locale } : {} };
|
|
64
|
+
const script = document.createElement("script");
|
|
65
|
+
script.async = true;
|
|
66
|
+
script.src = loaderUrl;
|
|
67
|
+
script.setAttribute(SCRIPT_ATTRIBUTE, "");
|
|
68
|
+
script.addEventListener("load", flush);
|
|
69
|
+
script.addEventListener("error", () => console.error(`${APP_NAME}: the chat could not load from ${loaderUrl}.`), {
|
|
70
|
+
once: true
|
|
71
|
+
});
|
|
72
|
+
document.head.appendChild(script);
|
|
73
|
+
return zean;
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
loadZean,
|
|
77
|
+
zean
|
|
78
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Returns a token the Company's server signed for the signed-in person, or null when there is none. */
|
|
2
|
+
export type ZeanTokenSource = () => Promise<string | null>;
|
|
3
|
+
export type ZeanAttributeValue = string | number | boolean;
|
|
4
|
+
/** What the page knows about the person, shown on the Contact's profile: `{ city: 'Douala', orders: 12 }`. */
|
|
5
|
+
export type ZeanAttributes = Record<string, ZeanAttributeValue>;
|
|
6
|
+
export type ZeanLocale = 'fr' | 'en';
|
|
7
|
+
/** What `window.zean` holds before the loader runs: the install code sets it. */
|
|
8
|
+
export interface ZeanSettings {
|
|
9
|
+
appKey: string;
|
|
10
|
+
/** For a signed-in person. Same as calling `identify` once loaded. */
|
|
11
|
+
getToken?: ZeanTokenSource;
|
|
12
|
+
/** The chat's language. Leave it out: the Contact's browser's, when the chat speaks it, else the App's default. */
|
|
13
|
+
locale?: ZeanLocale;
|
|
14
|
+
}
|
|
15
|
+
/** The chat's methods, on `window.zean` once the loader has run. */
|
|
16
|
+
export interface ZeanApi {
|
|
17
|
+
open: () => void;
|
|
18
|
+
close: () => void;
|
|
19
|
+
toggle: () => void;
|
|
20
|
+
getUnreadCount: () => number;
|
|
21
|
+
/** Called with each new count of replies the Contact has not seen. Returns the way to stop. */
|
|
22
|
+
onUnreadChange: (listener: (count: number) => void) => () => void;
|
|
23
|
+
/** The person signed in: `getToken` is called now and whenever the token expires. */
|
|
24
|
+
identify: (getToken: ZeanTokenSource) => void;
|
|
25
|
+
/** The person signed out: the chat starts over, anonymous. */
|
|
26
|
+
signOut: () => void;
|
|
27
|
+
/** Joined to what was set before. Values the chat cannot keep are refused, and the console says why. */
|
|
28
|
+
setAttributes: (attributes: ZeanAttributes) => void;
|
|
29
|
+
}
|
|
30
|
+
export interface ZeanOptions extends ZeanSettings {
|
|
31
|
+
/** Where the chat loads from. Leave it out: the default is Zean's own. */
|
|
32
|
+
loaderUrl?: string;
|
|
33
|
+
}
|
package/dist/load.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ZeanApi, ZeanOptions, ZeanSettings } from './interfaces.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
zean?: ZeanSettings & Partial<ZeanApi>;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/** The chat's methods. Usable before `loadZean`: what is asked waits for the chat. */
|
|
8
|
+
export declare const zean: ZeanApi;
|
|
9
|
+
/**
|
|
10
|
+
* Shows the chat on the page: adds the hosted loader once, whatever the number of calls. Does nothing on the server,
|
|
11
|
+
* so it is safe in code that also renders there.
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadZean({ appKey, getToken, locale, loaderUrl }: ZeanOptions): ZeanApi;
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@zean-chat/js",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Live chat widget for any website: add a free customer support chat in one line. Vanilla JS, TypeScript, no framework needed. Intercom and Crisp alternative.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"javascript",
|
|
7
|
+
"typescript",
|
|
8
|
+
"vanilla-js",
|
|
9
|
+
"website-chat",
|
|
10
|
+
"chat-bubble",
|
|
11
|
+
"sdk",
|
|
12
|
+
"live-chat",
|
|
13
|
+
"chat-widget",
|
|
14
|
+
"support-chat",
|
|
15
|
+
"customer-support",
|
|
16
|
+
"customer-service",
|
|
17
|
+
"helpdesk",
|
|
18
|
+
"help-desk",
|
|
19
|
+
"in-app-chat",
|
|
20
|
+
"chat",
|
|
21
|
+
"messaging",
|
|
22
|
+
"zean",
|
|
23
|
+
"intercom-alternative",
|
|
24
|
+
"crisp-alternative",
|
|
25
|
+
"tawk-to-alternative",
|
|
26
|
+
"zendesk-alternative"
|
|
27
|
+
],
|
|
28
|
+
"homepage": "https://zean.chat/docs/install-website",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://zean.chat/contact"
|
|
31
|
+
},
|
|
32
|
+
"author": "Zean (https://zean.chat)",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"type": "module",
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"main": "./dist/index.js",
|
|
37
|
+
"module": "./dist/index.js",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"zean-source": "./src/index.ts",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist"
|
|
48
|
+
],
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"prepublishOnly": "npm run build",
|
|
54
|
+
"build": "node ../../scripts/build-sdk.mjs",
|
|
55
|
+
"check-types": "tsc --noEmit"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@zean/config": "*",
|
|
59
|
+
"@zean/shared": "*",
|
|
60
|
+
"happy-dom": "21.0.3",
|
|
61
|
+
"typescript": "6.0.3",
|
|
62
|
+
"vitest": "4.1.11"
|
|
63
|
+
}
|
|
64
|
+
}
|