sessioncontact 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.mts +75 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.js +95 -0
- package/dist/index.mjs +74 -0
- package/package.json +45 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sessioncontact/sdk
|
|
3
|
+
*
|
|
4
|
+
* Official SessionContact Messenger SDK.
|
|
5
|
+
* Works with any JavaScript framework (React, Vue, Angular, Next.js, etc.)
|
|
6
|
+
*
|
|
7
|
+
* @example Basic Usage
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import SessionContact from '@sessioncontact/sdk';
|
|
10
|
+
*
|
|
11
|
+
* SessionContact({
|
|
12
|
+
* app_id: 'your_app_id'
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @example With User Identity
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import SessionContact from '@sessioncontact/sdk';
|
|
19
|
+
*
|
|
20
|
+
* SessionContact({
|
|
21
|
+
* app_id: 'your_app_id',
|
|
22
|
+
* user_id: 'user_123',
|
|
23
|
+
* email: 'john@example.com',
|
|
24
|
+
* name: 'John Doe'
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example Methods
|
|
29
|
+
* ```typescript
|
|
30
|
+
* SessionContact.show(); // Show messenger
|
|
31
|
+
* SessionContact.hide(); // Hide messenger
|
|
32
|
+
* SessionContact.update({ email: 'new@email.com' }); // Update user
|
|
33
|
+
* SessionContact.shutdown(); // Clear session
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
interface SessionContactSettings {
|
|
37
|
+
/** Your SessionContact app ID (required) */
|
|
38
|
+
app_id: string;
|
|
39
|
+
/** Unique identifier for the user */
|
|
40
|
+
user_id?: string;
|
|
41
|
+
/** User's email address */
|
|
42
|
+
email?: string;
|
|
43
|
+
/** User's display name */
|
|
44
|
+
name?: string;
|
|
45
|
+
/** Server-generated hash for identity verification */
|
|
46
|
+
user_hash?: string;
|
|
47
|
+
/** Custom attributes for the user */
|
|
48
|
+
custom_attributes?: Record<string, any>;
|
|
49
|
+
/** Any additional properties */
|
|
50
|
+
[key: string]: any;
|
|
51
|
+
}
|
|
52
|
+
declare global {
|
|
53
|
+
interface Window {
|
|
54
|
+
sessionContactSettings?: SessionContactSettings;
|
|
55
|
+
SessionContactWidget?: {
|
|
56
|
+
(command: string, data?: any): void;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Initialize SessionContact Messenger
|
|
62
|
+
*/
|
|
63
|
+
declare function SessionContact(settings: SessionContactSettings): void;
|
|
64
|
+
declare namespace SessionContact {
|
|
65
|
+
var show: () => void;
|
|
66
|
+
var hide: () => void;
|
|
67
|
+
var update: (data: Partial<SessionContactSettings>) => void;
|
|
68
|
+
var shutdown: () => void;
|
|
69
|
+
var onShow: (callback: () => void) => void;
|
|
70
|
+
var onHide: (callback: () => void) => void;
|
|
71
|
+
var onMessage: (callback: (message: any) => void) => void;
|
|
72
|
+
var getUnreadCount: () => number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { type SessionContactSettings, SessionContact as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sessioncontact/sdk
|
|
3
|
+
*
|
|
4
|
+
* Official SessionContact Messenger SDK.
|
|
5
|
+
* Works with any JavaScript framework (React, Vue, Angular, Next.js, etc.)
|
|
6
|
+
*
|
|
7
|
+
* @example Basic Usage
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import SessionContact from '@sessioncontact/sdk';
|
|
10
|
+
*
|
|
11
|
+
* SessionContact({
|
|
12
|
+
* app_id: 'your_app_id'
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @example With User Identity
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import SessionContact from '@sessioncontact/sdk';
|
|
19
|
+
*
|
|
20
|
+
* SessionContact({
|
|
21
|
+
* app_id: 'your_app_id',
|
|
22
|
+
* user_id: 'user_123',
|
|
23
|
+
* email: 'john@example.com',
|
|
24
|
+
* name: 'John Doe'
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example Methods
|
|
29
|
+
* ```typescript
|
|
30
|
+
* SessionContact.show(); // Show messenger
|
|
31
|
+
* SessionContact.hide(); // Hide messenger
|
|
32
|
+
* SessionContact.update({ email: 'new@email.com' }); // Update user
|
|
33
|
+
* SessionContact.shutdown(); // Clear session
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
interface SessionContactSettings {
|
|
37
|
+
/** Your SessionContact app ID (required) */
|
|
38
|
+
app_id: string;
|
|
39
|
+
/** Unique identifier for the user */
|
|
40
|
+
user_id?: string;
|
|
41
|
+
/** User's email address */
|
|
42
|
+
email?: string;
|
|
43
|
+
/** User's display name */
|
|
44
|
+
name?: string;
|
|
45
|
+
/** Server-generated hash for identity verification */
|
|
46
|
+
user_hash?: string;
|
|
47
|
+
/** Custom attributes for the user */
|
|
48
|
+
custom_attributes?: Record<string, any>;
|
|
49
|
+
/** Any additional properties */
|
|
50
|
+
[key: string]: any;
|
|
51
|
+
}
|
|
52
|
+
declare global {
|
|
53
|
+
interface Window {
|
|
54
|
+
sessionContactSettings?: SessionContactSettings;
|
|
55
|
+
SessionContactWidget?: {
|
|
56
|
+
(command: string, data?: any): void;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Initialize SessionContact Messenger
|
|
62
|
+
*/
|
|
63
|
+
declare function SessionContact(settings: SessionContactSettings): void;
|
|
64
|
+
declare namespace SessionContact {
|
|
65
|
+
var show: () => void;
|
|
66
|
+
var hide: () => void;
|
|
67
|
+
var update: (data: Partial<SessionContactSettings>) => void;
|
|
68
|
+
var shutdown: () => void;
|
|
69
|
+
var onShow: (callback: () => void) => void;
|
|
70
|
+
var onHide: (callback: () => void) => void;
|
|
71
|
+
var onMessage: (callback: (message: any) => void) => void;
|
|
72
|
+
var getUnreadCount: () => number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { type SessionContactSettings, SessionContact as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
default: () => index_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var initialized = false;
|
|
27
|
+
var pendingCallbacks = [];
|
|
28
|
+
function SessionContact(settings) {
|
|
29
|
+
var _a;
|
|
30
|
+
if (typeof window === "undefined") return;
|
|
31
|
+
window.sessionContactSettings = settings;
|
|
32
|
+
if (!initialized) {
|
|
33
|
+
const script = document.createElement("script");
|
|
34
|
+
script.src = `https://widget.sessioncontact.com/v1/${settings.app_id}.js`;
|
|
35
|
+
script.async = true;
|
|
36
|
+
script.onload = () => {
|
|
37
|
+
pendingCallbacks.forEach(({ event, callback }) => {
|
|
38
|
+
var _a2;
|
|
39
|
+
(_a2 = window.SessionContactWidget) == null ? void 0 : _a2.call(window, event, callback);
|
|
40
|
+
});
|
|
41
|
+
pendingCallbacks = [];
|
|
42
|
+
};
|
|
43
|
+
document.head.appendChild(script);
|
|
44
|
+
initialized = true;
|
|
45
|
+
} else {
|
|
46
|
+
(_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "update", settings);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
SessionContact.show = () => {
|
|
50
|
+
var _a;
|
|
51
|
+
(_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "show");
|
|
52
|
+
};
|
|
53
|
+
SessionContact.hide = () => {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "hide");
|
|
56
|
+
};
|
|
57
|
+
SessionContact.update = (data) => {
|
|
58
|
+
var _a;
|
|
59
|
+
if (window.sessionContactSettings) {
|
|
60
|
+
window.sessionContactSettings = { ...window.sessionContactSettings, ...data };
|
|
61
|
+
}
|
|
62
|
+
(_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "update", data);
|
|
63
|
+
};
|
|
64
|
+
SessionContact.shutdown = () => {
|
|
65
|
+
var _a;
|
|
66
|
+
(_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "shutdown");
|
|
67
|
+
window.sessionContactSettings = void 0;
|
|
68
|
+
initialized = false;
|
|
69
|
+
};
|
|
70
|
+
SessionContact.onShow = (callback) => {
|
|
71
|
+
if (window.SessionContactWidget) {
|
|
72
|
+
window.SessionContactWidget("onShow", callback);
|
|
73
|
+
} else {
|
|
74
|
+
pendingCallbacks.push({ event: "onShow", callback });
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
SessionContact.onHide = (callback) => {
|
|
78
|
+
if (window.SessionContactWidget) {
|
|
79
|
+
window.SessionContactWidget("onHide", callback);
|
|
80
|
+
} else {
|
|
81
|
+
pendingCallbacks.push({ event: "onHide", callback });
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
SessionContact.onMessage = (callback) => {
|
|
85
|
+
if (window.SessionContactWidget) {
|
|
86
|
+
window.SessionContactWidget("onMessage", callback);
|
|
87
|
+
} else {
|
|
88
|
+
pendingCallbacks.push({ event: "onMessage", callback });
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
SessionContact.getUnreadCount = () => {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
return (_b = (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "getUnreadCount")) != null ? _b : 0;
|
|
94
|
+
};
|
|
95
|
+
var index_default = SessionContact;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var initialized = false;
|
|
3
|
+
var pendingCallbacks = [];
|
|
4
|
+
function SessionContact(settings) {
|
|
5
|
+
var _a;
|
|
6
|
+
if (typeof window === "undefined") return;
|
|
7
|
+
window.sessionContactSettings = settings;
|
|
8
|
+
if (!initialized) {
|
|
9
|
+
const script = document.createElement("script");
|
|
10
|
+
script.src = `https://widget.sessioncontact.com/v1/${settings.app_id}.js`;
|
|
11
|
+
script.async = true;
|
|
12
|
+
script.onload = () => {
|
|
13
|
+
pendingCallbacks.forEach(({ event, callback }) => {
|
|
14
|
+
var _a2;
|
|
15
|
+
(_a2 = window.SessionContactWidget) == null ? void 0 : _a2.call(window, event, callback);
|
|
16
|
+
});
|
|
17
|
+
pendingCallbacks = [];
|
|
18
|
+
};
|
|
19
|
+
document.head.appendChild(script);
|
|
20
|
+
initialized = true;
|
|
21
|
+
} else {
|
|
22
|
+
(_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "update", settings);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
SessionContact.show = () => {
|
|
26
|
+
var _a;
|
|
27
|
+
(_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "show");
|
|
28
|
+
};
|
|
29
|
+
SessionContact.hide = () => {
|
|
30
|
+
var _a;
|
|
31
|
+
(_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "hide");
|
|
32
|
+
};
|
|
33
|
+
SessionContact.update = (data) => {
|
|
34
|
+
var _a;
|
|
35
|
+
if (window.sessionContactSettings) {
|
|
36
|
+
window.sessionContactSettings = { ...window.sessionContactSettings, ...data };
|
|
37
|
+
}
|
|
38
|
+
(_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "update", data);
|
|
39
|
+
};
|
|
40
|
+
SessionContact.shutdown = () => {
|
|
41
|
+
var _a;
|
|
42
|
+
(_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "shutdown");
|
|
43
|
+
window.sessionContactSettings = void 0;
|
|
44
|
+
initialized = false;
|
|
45
|
+
};
|
|
46
|
+
SessionContact.onShow = (callback) => {
|
|
47
|
+
if (window.SessionContactWidget) {
|
|
48
|
+
window.SessionContactWidget("onShow", callback);
|
|
49
|
+
} else {
|
|
50
|
+
pendingCallbacks.push({ event: "onShow", callback });
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
SessionContact.onHide = (callback) => {
|
|
54
|
+
if (window.SessionContactWidget) {
|
|
55
|
+
window.SessionContactWidget("onHide", callback);
|
|
56
|
+
} else {
|
|
57
|
+
pendingCallbacks.push({ event: "onHide", callback });
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
SessionContact.onMessage = (callback) => {
|
|
61
|
+
if (window.SessionContactWidget) {
|
|
62
|
+
window.SessionContactWidget("onMessage", callback);
|
|
63
|
+
} else {
|
|
64
|
+
pendingCallbacks.push({ event: "onMessage", callback });
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
SessionContact.getUnreadCount = () => {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
return (_b = (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "getUnreadCount")) != null ? _b : 0;
|
|
70
|
+
};
|
|
71
|
+
var index_default = SessionContact;
|
|
72
|
+
export {
|
|
73
|
+
index_default as default
|
|
74
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sessioncontact",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SessionContact Messenger SDK - works with any framework",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
20
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/sessioncontact/sdk"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"sessioncontact",
|
|
29
|
+
"chat",
|
|
30
|
+
"widget",
|
|
31
|
+
"messenger",
|
|
32
|
+
"customer-support",
|
|
33
|
+
"live-chat",
|
|
34
|
+
"react",
|
|
35
|
+
"vue",
|
|
36
|
+
"angular",
|
|
37
|
+
"nextjs"
|
|
38
|
+
],
|
|
39
|
+
"author": "SessionContact",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"tsup": "^8.0.0",
|
|
43
|
+
"typescript": "^5.0.0"
|
|
44
|
+
}
|
|
45
|
+
}
|