sessioncontact 1.0.1 → 1.0.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/dist/index.d.mts CHANGED
@@ -36,13 +36,17 @@
36
36
  interface SessionContactSettings {
37
37
  /** Your SessionContact app ID (required) */
38
38
  app_id: string;
39
+ /** Convex URL for real-time connection */
40
+ convex_url?: string;
41
+ /** JWT identity token for user verification */
42
+ identity_token?: string;
39
43
  /** Unique identifier for the user */
40
44
  user_id?: string;
41
45
  /** User's email address */
42
46
  email?: string;
43
47
  /** User's display name */
44
48
  name?: string;
45
- /** Server-generated hash for identity verification */
49
+ /** Server-generated hash for identity verification (deprecated, use identity_token) */
46
50
  user_hash?: string;
47
51
  /** Custom attributes for the user */
48
52
  custom_attributes?: Record<string, any>;
@@ -52,8 +56,14 @@ interface SessionContactSettings {
52
56
  declare global {
53
57
  interface Window {
54
58
  sessionContactSettings?: SessionContactSettings;
55
- SessionContactWidget?: {
56
- (command: string, data?: any): void;
59
+ sessionChatSettings?: {
60
+ orgId: string;
61
+ convexUrl?: string;
62
+ [key: string]: any;
63
+ };
64
+ SessionChat?: {
65
+ init: (config?: any) => void;
66
+ destroy: () => void;
57
67
  };
58
68
  }
59
69
  }
package/dist/index.d.ts CHANGED
@@ -36,13 +36,17 @@
36
36
  interface SessionContactSettings {
37
37
  /** Your SessionContact app ID (required) */
38
38
  app_id: string;
39
+ /** Convex URL for real-time connection */
40
+ convex_url?: string;
41
+ /** JWT identity token for user verification */
42
+ identity_token?: string;
39
43
  /** Unique identifier for the user */
40
44
  user_id?: string;
41
45
  /** User's email address */
42
46
  email?: string;
43
47
  /** User's display name */
44
48
  name?: string;
45
- /** Server-generated hash for identity verification */
49
+ /** Server-generated hash for identity verification (deprecated, use identity_token) */
46
50
  user_hash?: string;
47
51
  /** Custom attributes for the user */
48
52
  custom_attributes?: Record<string, any>;
@@ -52,8 +56,14 @@ interface SessionContactSettings {
52
56
  declare global {
53
57
  interface Window {
54
58
  sessionContactSettings?: SessionContactSettings;
55
- SessionContactWidget?: {
56
- (command: string, data?: any): void;
59
+ sessionChatSettings?: {
60
+ orgId: string;
61
+ convexUrl?: string;
62
+ [key: string]: any;
63
+ };
64
+ SessionChat?: {
65
+ init: (config?: any) => void;
66
+ destroy: () => void;
57
67
  };
58
68
  }
59
69
  }
package/dist/index.js CHANGED
@@ -24,72 +24,74 @@ __export(index_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(index_exports);
26
26
  var initialized = false;
27
- var pendingCallbacks = [];
28
27
  function SessionContact(settings) {
29
- var _a;
28
+ var _a, _b;
30
29
  if (typeof window === "undefined") return;
31
30
  window.sessionContactSettings = settings;
31
+ window.sessionChatSettings = {
32
+ orgId: settings.app_id,
33
+ // convexUrl is optional - widget uses default if not provided
34
+ ...settings.convex_url && { convexUrl: settings.convex_url },
35
+ // Pass through user identity if provided
36
+ ...settings.identity_token && { identityToken: settings.identity_token },
37
+ ...settings.user_id && { userId: settings.user_id },
38
+ ...settings.email && { email: settings.email },
39
+ ...settings.name && { name: settings.name }
40
+ };
32
41
  if (!initialized) {
33
42
  const script = document.createElement("script");
34
43
  script.src = "https://widget.sessioncontact.com/sessioncontact-widget.js";
35
44
  script.async = true;
36
45
  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 = [];
46
+ if (window.SessionChat && !document.getElementById("sessioncontact-chat-widget")) {
47
+ window.SessionChat.init();
48
+ }
42
49
  };
43
50
  document.head.appendChild(script);
44
51
  initialized = true;
45
52
  } else {
46
- (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "update", settings);
53
+ (_a = window.SessionChat) == null ? void 0 : _a.destroy();
54
+ (_b = window.SessionChat) == null ? void 0 : _b.init();
47
55
  }
48
56
  }
49
57
  SessionContact.show = () => {
50
- var _a;
51
- (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "show");
58
+ console.log("SessionContact.show() - not yet implemented in widget");
52
59
  };
53
60
  SessionContact.hide = () => {
54
- var _a;
55
- (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "hide");
61
+ console.log("SessionContact.hide() - not yet implemented in widget");
56
62
  };
57
63
  SessionContact.update = (data) => {
58
- var _a;
59
64
  if (window.sessionContactSettings) {
60
65
  window.sessionContactSettings = { ...window.sessionContactSettings, ...data };
61
66
  }
62
- (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "update", data);
67
+ if (window.sessionChatSettings) {
68
+ window.sessionChatSettings = {
69
+ ...window.sessionChatSettings,
70
+ ...data.app_id && { orgId: data.app_id },
71
+ ...data.identity_token && { identityToken: data.identity_token },
72
+ ...data.user_id && { userId: data.user_id },
73
+ ...data.email && { email: data.email },
74
+ ...data.name && { name: data.name }
75
+ };
76
+ }
63
77
  };
64
78
  SessionContact.shutdown = () => {
65
79
  var _a;
66
- (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "shutdown");
80
+ (_a = window.SessionChat) == null ? void 0 : _a.destroy();
67
81
  window.sessionContactSettings = void 0;
82
+ window.sessionChatSettings = void 0;
68
83
  initialized = false;
69
84
  };
70
85
  SessionContact.onShow = (callback) => {
71
- if (window.SessionContactWidget) {
72
- window.SessionContactWidget("onShow", callback);
73
- } else {
74
- pendingCallbacks.push({ event: "onShow", callback });
75
- }
86
+ console.log("SessionContact.onShow() - not yet implemented in widget");
76
87
  };
77
88
  SessionContact.onHide = (callback) => {
78
- if (window.SessionContactWidget) {
79
- window.SessionContactWidget("onHide", callback);
80
- } else {
81
- pendingCallbacks.push({ event: "onHide", callback });
82
- }
89
+ console.log("SessionContact.onHide() - not yet implemented in widget");
83
90
  };
84
91
  SessionContact.onMessage = (callback) => {
85
- if (window.SessionContactWidget) {
86
- window.SessionContactWidget("onMessage", callback);
87
- } else {
88
- pendingCallbacks.push({ event: "onMessage", callback });
89
- }
92
+ console.log("SessionContact.onMessage() - not yet implemented in widget");
90
93
  };
91
94
  SessionContact.getUnreadCount = () => {
92
- var _a, _b;
93
- return (_b = (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "getUnreadCount")) != null ? _b : 0;
95
+ return 0;
94
96
  };
95
97
  var index_default = SessionContact;
package/dist/index.mjs CHANGED
@@ -1,72 +1,74 @@
1
1
  // src/index.ts
2
2
  var initialized = false;
3
- var pendingCallbacks = [];
4
3
  function SessionContact(settings) {
5
- var _a;
4
+ var _a, _b;
6
5
  if (typeof window === "undefined") return;
7
6
  window.sessionContactSettings = settings;
7
+ window.sessionChatSettings = {
8
+ orgId: settings.app_id,
9
+ // convexUrl is optional - widget uses default if not provided
10
+ ...settings.convex_url && { convexUrl: settings.convex_url },
11
+ // Pass through user identity if provided
12
+ ...settings.identity_token && { identityToken: settings.identity_token },
13
+ ...settings.user_id && { userId: settings.user_id },
14
+ ...settings.email && { email: settings.email },
15
+ ...settings.name && { name: settings.name }
16
+ };
8
17
  if (!initialized) {
9
18
  const script = document.createElement("script");
10
19
  script.src = "https://widget.sessioncontact.com/sessioncontact-widget.js";
11
20
  script.async = true;
12
21
  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 = [];
22
+ if (window.SessionChat && !document.getElementById("sessioncontact-chat-widget")) {
23
+ window.SessionChat.init();
24
+ }
18
25
  };
19
26
  document.head.appendChild(script);
20
27
  initialized = true;
21
28
  } else {
22
- (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "update", settings);
29
+ (_a = window.SessionChat) == null ? void 0 : _a.destroy();
30
+ (_b = window.SessionChat) == null ? void 0 : _b.init();
23
31
  }
24
32
  }
25
33
  SessionContact.show = () => {
26
- var _a;
27
- (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "show");
34
+ console.log("SessionContact.show() - not yet implemented in widget");
28
35
  };
29
36
  SessionContact.hide = () => {
30
- var _a;
31
- (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "hide");
37
+ console.log("SessionContact.hide() - not yet implemented in widget");
32
38
  };
33
39
  SessionContact.update = (data) => {
34
- var _a;
35
40
  if (window.sessionContactSettings) {
36
41
  window.sessionContactSettings = { ...window.sessionContactSettings, ...data };
37
42
  }
38
- (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "update", data);
43
+ if (window.sessionChatSettings) {
44
+ window.sessionChatSettings = {
45
+ ...window.sessionChatSettings,
46
+ ...data.app_id && { orgId: data.app_id },
47
+ ...data.identity_token && { identityToken: data.identity_token },
48
+ ...data.user_id && { userId: data.user_id },
49
+ ...data.email && { email: data.email },
50
+ ...data.name && { name: data.name }
51
+ };
52
+ }
39
53
  };
40
54
  SessionContact.shutdown = () => {
41
55
  var _a;
42
- (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "shutdown");
56
+ (_a = window.SessionChat) == null ? void 0 : _a.destroy();
43
57
  window.sessionContactSettings = void 0;
58
+ window.sessionChatSettings = void 0;
44
59
  initialized = false;
45
60
  };
46
61
  SessionContact.onShow = (callback) => {
47
- if (window.SessionContactWidget) {
48
- window.SessionContactWidget("onShow", callback);
49
- } else {
50
- pendingCallbacks.push({ event: "onShow", callback });
51
- }
62
+ console.log("SessionContact.onShow() - not yet implemented in widget");
52
63
  };
53
64
  SessionContact.onHide = (callback) => {
54
- if (window.SessionContactWidget) {
55
- window.SessionContactWidget("onHide", callback);
56
- } else {
57
- pendingCallbacks.push({ event: "onHide", callback });
58
- }
65
+ console.log("SessionContact.onHide() - not yet implemented in widget");
59
66
  };
60
67
  SessionContact.onMessage = (callback) => {
61
- if (window.SessionContactWidget) {
62
- window.SessionContactWidget("onMessage", callback);
63
- } else {
64
- pendingCallbacks.push({ event: "onMessage", callback });
65
- }
68
+ console.log("SessionContact.onMessage() - not yet implemented in widget");
66
69
  };
67
70
  SessionContact.getUnreadCount = () => {
68
- var _a, _b;
69
- return (_b = (_a = window.SessionContactWidget) == null ? void 0 : _a.call(window, "getUnreadCount")) != null ? _b : 0;
71
+ return 0;
70
72
  };
71
73
  var index_default = SessionContact;
72
74
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sessioncontact",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "SessionContact Messenger SDK - works with any framework",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",