@zean-chat/js 0.1.1 → 0.1.3
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 +6 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -4
- package/dist/interfaces.d.ts +22 -7
- package/dist/load.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,12 +9,16 @@ npm install @zean-chat/js
|
|
|
9
9
|
```js
|
|
10
10
|
import { loadZean } from "@zean-chat/js";
|
|
11
11
|
|
|
12
|
-
const zean = loadZean({
|
|
12
|
+
const zean = loadZean({
|
|
13
|
+
appKey: "app_your_app_key",
|
|
14
|
+
// Once the person is signed in on your side. Only `id` is required.
|
|
15
|
+
user: { id: "1042", name: "Awa Diallo", email: "awa@example.com" }
|
|
16
|
+
});
|
|
13
17
|
zean.open();
|
|
14
18
|
zean.onUnreadChange(count => console.log(count));
|
|
15
19
|
```
|
|
16
20
|
|
|
17
|
-
Methods: `open`, `close`, `toggle`, `getUnreadCount`, `onUnreadChange`, `identify(
|
|
21
|
+
Methods: `open`, `close`, `toggle`, `getUnreadCount`, `onUnreadChange`, `identify(user)`, `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
22
|
|
|
19
23
|
## Why Zean
|
|
20
24
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { ZeanApi, ZeanAttributeValue, ZeanAttributes, ZeanLocale, ZeanOptions, ZeanSettings,
|
|
1
|
+
export type { ZeanApi, ZeanAttributeValue, ZeanAttributes, ZeanLocale, ZeanOptions, ZeanSettings, ZeanUser } from './interfaces.js';
|
|
2
2
|
export { loadZean, zean } from './load.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
// ../shared/src/constants/app.ts
|
|
2
2
|
var APP_NAME = "Zean";
|
|
3
3
|
var PRODUCTION_LOADER_URL = "https://widget.zean.chat/loader.js";
|
|
4
|
+
var STAGING_APP_KEY_PREFIX = "app_stg_";
|
|
5
|
+
var STAGING_LOADER_URL = "https://widget-stg.zean.chat/loader.js";
|
|
6
|
+
|
|
7
|
+
// ../shared/src/utils/app-keys.ts
|
|
8
|
+
var isStagingKey = (appKey) => appKey.startsWith(STAGING_APP_KEY_PREFIX);
|
|
9
|
+
function loaderUrlFor(appKey) {
|
|
10
|
+
return isStagingKey(appKey) ? STAGING_LOADER_URL : PRODUCTION_LOADER_URL;
|
|
11
|
+
}
|
|
4
12
|
|
|
5
13
|
// src/load.ts
|
|
6
14
|
var SCRIPT_ATTRIBUTE = "data-zean-sdk";
|
|
@@ -44,11 +52,11 @@ var zean = {
|
|
|
44
52
|
stop?.();
|
|
45
53
|
};
|
|
46
54
|
},
|
|
47
|
-
identify: (
|
|
55
|
+
identify: (user) => withApi((api) => api.identify(user)),
|
|
48
56
|
signOut: () => withApi((api) => api.signOut()),
|
|
49
57
|
setAttributes: (attributes) => withApi((api) => api.setAttributes(attributes))
|
|
50
58
|
};
|
|
51
|
-
function loadZean({ appKey,
|
|
59
|
+
function loadZean({ appKey, user, locale, loaderUrl = loaderUrlFor(appKey) }) {
|
|
52
60
|
if (typeof window === "undefined" || typeof document === "undefined") return zean;
|
|
53
61
|
if (loadedKey !== null) {
|
|
54
62
|
if (loadedKey !== appKey) console.warn(`${APP_NAME}: the chat is already loaded with the App key ${loadedKey}.`);
|
|
@@ -57,10 +65,10 @@ function loadZean({ appKey, getToken, locale, loaderUrl = PRODUCTION_LOADER_URL
|
|
|
57
65
|
loadedKey = appKey;
|
|
58
66
|
if (window.zean || document.querySelector(`script[${SCRIPT_ATTRIBUTE}]`)) {
|
|
59
67
|
waitForOtherLoader();
|
|
60
|
-
if (
|
|
68
|
+
if (user) zean.identify(user);
|
|
61
69
|
return zean;
|
|
62
70
|
}
|
|
63
|
-
window.zean = { appKey, ...
|
|
71
|
+
window.zean = { appKey, ...user ? { user } : {}, ...locale ? { locale } : {} };
|
|
64
72
|
const script = document.createElement("script");
|
|
65
73
|
script.async = true;
|
|
66
74
|
script.src = loaderUrl;
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
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
1
|
export type ZeanAttributeValue = string | number | boolean;
|
|
4
2
|
/** What the page knows about the person, shown on the Contact's profile: `{ city: 'Douala', orders: 12 }`. */
|
|
5
3
|
export type ZeanAttributes = Record<string, ZeanAttributeValue>;
|
|
6
4
|
export type ZeanLocale = 'fr' | 'en';
|
|
5
|
+
/** The person signed in to your app. Only `id` is needed; the rest shows on their Contact. */
|
|
6
|
+
export interface ZeanUser {
|
|
7
|
+
/** Your own id for them: text or a number. The same id on the web and in your mobile app is one person. */
|
|
8
|
+
id: string | number;
|
|
9
|
+
name?: string;
|
|
10
|
+
email?: string;
|
|
11
|
+
phone?: string;
|
|
12
|
+
/** Their language, any one, as a tag such as `pt` or `pt-BR`. Leave it out: their device's is kept. */
|
|
13
|
+
language?: string;
|
|
14
|
+
}
|
|
7
15
|
/** What `window.zean` holds before the loader runs: the install code sets it. */
|
|
8
16
|
export interface ZeanSettings {
|
|
9
17
|
appKey: string;
|
|
10
|
-
/**
|
|
11
|
-
|
|
18
|
+
/** The signed-in person. Same as calling `identify` once loaded. */
|
|
19
|
+
user?: ZeanUser;
|
|
12
20
|
/** The chat's language. Leave it out: the Contact's browser's, when the chat speaks it, else the App's default. */
|
|
13
21
|
locale?: ZeanLocale;
|
|
14
22
|
}
|
|
@@ -20,14 +28,21 @@ export interface ZeanApi {
|
|
|
20
28
|
getUnreadCount: () => number;
|
|
21
29
|
/** Called with each new count of replies the Contact has not seen. Returns the way to stop. */
|
|
22
30
|
onUnreadChange: (listener: (count: number) => void) => () => void;
|
|
23
|
-
/**
|
|
24
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The person signed in. The first device to bring their id joins their Conversation at once; another device asks
|
|
33
|
+
* them for a code emailed to them first. Details that do not fit are left out, and the console says why.
|
|
34
|
+
*/
|
|
35
|
+
identify: (user: ZeanUser) => void;
|
|
25
36
|
/** The person signed out: the chat starts over, anonymous. */
|
|
26
37
|
signOut: () => void;
|
|
27
38
|
/** Joined to what was set before. Values the chat cannot keep are refused, and the console says why. */
|
|
28
39
|
setAttributes: (attributes: ZeanAttributes) => void;
|
|
29
40
|
}
|
|
30
41
|
export interface ZeanOptions extends ZeanSettings {
|
|
31
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Where the chat loads from. Leave it out: the App key says which of Zean's own. For local development only, so
|
|
44
|
+
* left out of the documentation.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
32
47
|
loaderUrl?: string;
|
|
33
48
|
}
|
package/dist/load.d.ts
CHANGED
|
@@ -10,4 +10,4 @@ export declare const zean: ZeanApi;
|
|
|
10
10
|
* Shows the chat on the page: adds the hosted loader once, whatever the number of calls. Does nothing on the server,
|
|
11
11
|
* so it is safe in code that also renders there.
|
|
12
12
|
*/
|
|
13
|
-
export declare function loadZean({ appKey,
|
|
13
|
+
export declare function loadZean({ appKey, user, locale, loaderUrl }: ZeanOptions): ZeanApi;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zean-chat/js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
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
5
|
"keywords": [
|
|
6
6
|
"javascript",
|