@chat-leo/chatleolib 2.0.2 → 2.1.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # chatleolib
2
2
 
3
- Core library of ChatLeo: login, real-time connection, state (`ChatStore`) and uploads. It is loaded by `<chatleo-component>` and rarely used directly.
3
+ Core library of ChatLeo: login, real-time connection, state (`ChatStore`) and uploads. It is normally loaded by `<chatleo-component>`; an application shell can also drive it directly with `ChatLeoLib.getInstance()` and `setServerUrl()` (see below).
4
4
 
5
5
  ## Real-time transport
6
6
 
@@ -68,3 +68,35 @@ Calls require protocol v2. On Socket.IO the library reports calls as unavailable
68
68
 
69
69
  ### Push notifications
70
70
  `ChatLeoLib.push` exposes `state()`, `enable()`, `disable()` and `syncOnLogin()`; the component uses `pushState`, `enablePush` and `disablePush`. Push requires the server's `push` discovery feature and a served worker (`chatleolib/dist/chatleo-push-sw.js`, or import `chatleolib/push-sw` into an existing worker). Subscriptions always go through the ChatLeo server; the PulseLeo SDK is loaded lazily. See `docs/push.md`.
71
+
72
+ ## Application shell without an embedded component
73
+
74
+ A host that owns the session at the shell level — no chat page and no `<chatleo-component>` in
75
+ the DOM — drives the shared instance directly, points it at the server and signs in:
76
+
77
+ ```ts
78
+ import { ChatLeoLib, ChatLeoLoginError } from '@chat-leo/chatleolib';
79
+
80
+ const lib = ChatLeoLib.getInstance(); // the one instance the page (and its components) share
81
+ lib.setServerUrl('https://chat.example.com'); // origin of the ChatLeo server
82
+
83
+ try {
84
+ const profile = await lib.signIn({ ticket, transport: 'auto' });
85
+ } catch (e) {
86
+ if (e instanceof ChatLeoLoginError) {
87
+ // e.reason: 'invalid_credentials' | 'invalid_ticket' | 'unreachable' | 'server_error'
88
+ }
89
+ }
90
+ ```
91
+
92
+ * `setServerUrl()` is required before the first sign-in when no component provides
93
+ `server-url`. It accepts an origin URL (`https://chat.example.com`) — REST and discovery
94
+ endpoints are resolved from it — and rejects paths, queries, hashes and non-http(s) schemes.
95
+ * A programmatically set URL wins over the DOM scan: a `<chatleo-component>` mounted later
96
+ uses the configured server even if its `server-url` attribute differs (or is absent).
97
+ * Re-setting the current URL is a no-op. Changing it while signed in throws — call `logout()`
98
+ first, because the session's tokens, transport and rooms belong to the previous server.
99
+ * A session returned by `lib.getSession()` can be persisted and restored on the next load
100
+ with `lib.restoreSession(session)`; its server URL is re-applied and stays sticky.
101
+ * Components discovered later are bound to the same instance and join the existing session;
102
+ mount `<chatleo-component chatLeoLib={lib}>` when a chat view is needed.
package/dist/index.d.ts CHANGED
@@ -54,7 +54,18 @@ export declare class ChatLeoLib {
54
54
  * `requestConnection` (the `transport` attribute of `<chatleo-component>`) takes precedence.
55
55
  */
56
56
  static transport: TransportSetting;
57
+ /**
58
+ * The one `ChatLeoLib` bound to this page.
59
+ *
60
+ * A host that owns the session itself — an application shell with no embedded
61
+ * `<chatleo-component>` on the current page — uses this to point the library at a server
62
+ * (`setServerUrl`) and sign in. Components discovered by the DOM scan are bound to the same
63
+ * instance, so they share the session and state.
64
+ */
65
+ static getInstance(): ChatLeoLib;
57
66
  private serverUrlName;
67
+ /** `true` once the host set the server URL itself (programmatic config wins over the DOM scan). */
68
+ private serverUrlExplicit;
58
69
  private accessToken;
59
70
  private refreshToken;
60
71
  private userProfile;
@@ -94,6 +105,17 @@ export declare class ChatLeoLib {
94
105
  private transportKind;
95
106
  private pushServiceInstance?;
96
107
  constructor();
108
+ /**
109
+ * Points the library at a ChatLeo server. Required before the first sign-in when the host
110
+ * has no `<chatleo-component>` on the page; components configure it through their
111
+ * `server-url` attribute otherwise.
112
+ *
113
+ * Accepts an origin URL (`https://chat.example.com`); REST and discovery endpoints are
114
+ * resolved from it. Re-setting the current URL is a no-op. Changing it while signed in
115
+ * throws, because the session's tokens, transport and rooms belong to the previous server —
116
+ * call `logout()` first.
117
+ */
118
+ setServerUrl(serverUrl: string): void;
97
119
  /**
98
120
  * Signs in with credentials and completes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C,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IActD,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,GAAE,OAAe,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAmC9H;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IA+CxB,OAAO,CAAC,mBAAmB;IA8B3B,oEAAoE;IACpE,OAAO,CAAC,cAAc;IAStB,2CAA2C;YAC7B,QAAQ;IA8BtB;;;;OAIG;YACW,gBAAgB;IAY9B,iGAAiG;YACnF,cAAc;IAwY5B,OAAO,CAAC,uBAAuB;IAI/B;;;OAGG;IACH,MAAM;CA2BP;AAED,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/E,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC1G,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,cAAc,gBAAgB,CAAC"}
package/dist/index.esm.js CHANGED
@@ -6994,7 +6994,7 @@ class PushService {
6994
6994
  }
6995
6995
  _PushService_options = new WeakMap(), _PushService_deviceId = new WeakMap(), _PushService_client = new WeakMap();
6996
6996
 
6997
- var _ChatLeoLib_instances, _a, _ChatLeoLib_applySession, _ChatLeoLib_setCallRole, _ChatLeoLib_requireCalls, _ChatLeoLib_callRequest, _ChatLeoLib_scanComponents, _ChatLeoLib_observeDomChanges, _ChatLeoLib_buildServerUrl, _ChatLeoLib_loginWithCredentials, _ChatLeoLib_loginWithTicket, _ChatLeoLib_loginRequest, _ChatLeoLib_selectTransport, _ChatLeoLib_connectChat, _ChatLeoLib_detachTransport, _ChatLeoLib_onTransportEvent, _ChatLeoLib_request, _ChatLeoLib_onMessageSent, _ChatLeoLib_getRooms, _ChatLeoLib_getUsers, _ChatLeoLib_getRoomMessages, _ChatLeoLib_fetchMessagesPage, _ChatLeoLib_completeLogin, _ChatLeoLib_runSync, _ChatLeoLib_runLegacyCatchUp, _ChatLeoLib_detectGap, _ChatLeoLib_repairGap, _ChatLeoLib_loadOlderMessages, _ChatLeoLib_canReportRead, _ChatLeoLib_clearReadMarkerTimers, _ChatLeoLib_scheduleReadMarker, _ChatLeoLib_sendReadMarker, _ChatLeoLib_scheduleTokenRefresh, _ChatLeoLib_clearRefreshTimer, _ChatLeoLib_refreshAccessToken, _ChatLeoLib_performTokenRefresh, _ChatLeoLib_handleSessionExpired;
6997
+ var _ChatLeoLib_instances, _a, _ChatLeoLib_applySession, _ChatLeoLib_setCallRole, _ChatLeoLib_requireCalls, _ChatLeoLib_callRequest, _ChatLeoLib_scanComponents, _ChatLeoLib_adoptComponentServerUrl, _ChatLeoLib_observeDomChanges, _ChatLeoLib_buildServerUrl, _ChatLeoLib_loginWithCredentials, _ChatLeoLib_loginWithTicket, _ChatLeoLib_loginRequest, _ChatLeoLib_selectTransport, _ChatLeoLib_connectChat, _ChatLeoLib_detachTransport, _ChatLeoLib_onTransportEvent, _ChatLeoLib_request, _ChatLeoLib_onMessageSent, _ChatLeoLib_getRooms, _ChatLeoLib_getUsers, _ChatLeoLib_getRoomMessages, _ChatLeoLib_fetchMessagesPage, _ChatLeoLib_completeLogin, _ChatLeoLib_runSync, _ChatLeoLib_runLegacyCatchUp, _ChatLeoLib_detectGap, _ChatLeoLib_repairGap, _ChatLeoLib_loadOlderMessages, _ChatLeoLib_canReportRead, _ChatLeoLib_clearReadMarkerTimers, _ChatLeoLib_scheduleReadMarker, _ChatLeoLib_sendReadMarker, _ChatLeoLib_scheduleTokenRefresh, _ChatLeoLib_clearRefreshTimer, _ChatLeoLib_refreshAccessToken, _ChatLeoLib_performTokenRefresh, _ChatLeoLib_handleSessionExpired;
6998
6998
  /** A sign-in failure with a machine-readable reason. */
6999
6999
  class ChatLeoLoginError extends Error {
7000
7000
  constructor(reason, status, message) {
@@ -7015,10 +7015,23 @@ class ChatCallError extends Error {
7015
7015
  }
7016
7016
  }
7017
7017
  class ChatLeoLib {
7018
+ /**
7019
+ * The one `ChatLeoLib` bound to this page.
7020
+ *
7021
+ * A host that owns the session itself — an application shell with no embedded
7022
+ * `<chatleo-component>` on the current page — uses this to point the library at a server
7023
+ * (`setServerUrl`) and sign in. Components discovered by the DOM scan are bound to the same
7024
+ * instance, so they share the session and state.
7025
+ */
7026
+ static getInstance() {
7027
+ return chatLeoLibSingleton;
7028
+ }
7018
7029
  constructor() {
7019
7030
  // this.serverUrlName = new URL(import.meta.url).searchParams.get("server"); // 5
7020
7031
  _ChatLeoLib_instances.add(this);
7021
7032
  this.serverUrlName = null;
7033
+ /** `true` once the host set the server URL itself (programmatic config wins over the DOM scan). */
7034
+ this.serverUrlExplicit = false;
7022
7035
  this.accessToken = null;
7023
7036
  this.refreshToken = null;
7024
7037
  this.userProfile = null;
@@ -7135,6 +7148,45 @@ class ChatLeoLib {
7135
7148
  });
7136
7149
  }
7137
7150
  // external methods called from components
7151
+ /**
7152
+ * Points the library at a ChatLeo server. Required before the first sign-in when the host
7153
+ * has no `<chatleo-component>` on the page; components configure it through their
7154
+ * `server-url` attribute otherwise.
7155
+ *
7156
+ * Accepts an origin URL (`https://chat.example.com`); REST and discovery endpoints are
7157
+ * resolved from it. Re-setting the current URL is a no-op. Changing it while signed in
7158
+ * throws, because the session's tokens, transport and rooms belong to the previous server —
7159
+ * call `logout()` first.
7160
+ */
7161
+ setServerUrl(serverUrl) {
7162
+ const raw = typeof serverUrl === 'string' ? serverUrl.trim() : '';
7163
+ let parsed;
7164
+ try {
7165
+ parsed = new URL(raw);
7166
+ }
7167
+ catch (_b) {
7168
+ throw new Error(`setServerUrl requires an absolute http(s) URL, received "${String(serverUrl)}".`);
7169
+ }
7170
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
7171
+ throw new Error(`setServerUrl requires an http(s) URL, received "${raw}".`);
7172
+ }
7173
+ if (parsed.pathname !== '/' || parsed.search || parsed.hash) {
7174
+ throw new Error(`setServerUrl requires an origin URL with no path, query or hash (received "${raw}"); REST endpoints are resolved from the origin.`);
7175
+ }
7176
+ const origin = parsed.origin;
7177
+ if (this.serverUrlName === origin) {
7178
+ // The host has confirmed this server; keep it sticky against the DOM scan.
7179
+ this.serverUrlExplicit = true;
7180
+ return;
7181
+ }
7182
+ if (this.isLoggedIn) {
7183
+ throw new Error(`Cannot change the server URL while signed in (currently ${this.serverUrlName}); call logout() first.`);
7184
+ }
7185
+ this.serverUrlName = origin;
7186
+ this.serverUrlExplicit = true;
7187
+ // A different server may advertise a different transport in its discovery document.
7188
+ clearDiscovery(origin);
7189
+ }
7138
7190
  /**
7139
7191
  * Signs in with credentials and completes the session (transport, rooms, users).
7140
7192
  *
@@ -7183,7 +7235,12 @@ class ChatLeoLib {
7183
7235
  return this.userProfile;
7184
7236
  if (!(session === null || session === void 0 ? void 0 : session.refreshToken) || !session.profile)
7185
7237
  return null;
7186
- this.serverUrlName = session.serverUrl || this.serverUrlName;
7238
+ if (session.serverUrl) {
7239
+ // Normalise the stored base so a later setServerUrl() for the same server is a no-op.
7240
+ this.serverUrlName = session.serverUrl.replace(/\/+$/, '');
7241
+ // A restored session's server is host intent; keep it sticky against the DOM scan.
7242
+ this.serverUrlExplicit = true;
7243
+ }
7187
7244
  this.accessToken = session.accessToken || null;
7188
7245
  this.refreshToken = session.refreshToken;
7189
7246
  this.userProfile = session.profile;
@@ -7912,14 +7969,16 @@ async function _ChatLeoLib_scanComponents() {
7912
7969
  const chatComponentElements = document.querySelectorAll('chatleo-component');
7913
7970
  for (let i = 0; i < chatComponentElements.length; i++) {
7914
7971
  const component = chatComponentElements[i];
7915
- if (component.serverUrl) {
7916
- this.serverUrlName = component.serverUrl;
7917
- }
7972
+ __classPrivateFieldGet(this, _ChatLeoLib_instances, "m", _ChatLeoLib_adoptComponentServerUrl).call(this, component.serverUrl);
7918
7973
  if (!component.chatLeoLib) {
7919
7974
  console.debug('chatComponentElement attached', component, component.serverUrl);
7920
7975
  component.chatLeoLib = this;
7921
7976
  }
7922
7977
  }
7978
+ }, _ChatLeoLib_adoptComponentServerUrl = function _ChatLeoLib_adoptComponentServerUrl(serverUrl) {
7979
+ if (!serverUrl || this.serverUrlExplicit)
7980
+ return;
7981
+ this.serverUrlName = serverUrl;
7923
7982
  }, _ChatLeoLib_observeDomChanges = function _ChatLeoLib_observeDomChanges() {
7924
7983
  if (!document.body)
7925
7984
  return;
@@ -7955,6 +8014,9 @@ async function _ChatLeoLib_scanComponents() {
7955
8014
  }, _ChatLeoLib_loginRequest =
7956
8015
  /** POSTs to the login endpoint and turns HTTP/network failures into a typed reason. */
7957
8016
  async function _ChatLeoLib_loginRequest(body, invalidReason) {
8017
+ if (!this.serverUrlName) {
8018
+ throw new Error('No server URL configured. Provide <chatleo-component server-url="…"> or call ChatLeoLib.getInstance().setServerUrl("…") before signing in.');
8019
+ }
7958
8020
  let response;
7959
8021
  try {
7960
8022
  response = await fetch(__classPrivateFieldGet(this, _ChatLeoLib_instances, "m", _ChatLeoLib_buildServerUrl).call(this, '/api/v1/auth/login'), {
@@ -8520,7 +8582,9 @@ ChatLeoLib.MAX_REFRESH_RETRIES = 5;
8520
8582
  ChatLeoLib.RESUME_SYNC_COOLDOWN_MS = 10000;
8521
8583
  ChatLeoLib.READ_MARKER_DEBOUNCE_MS = 2000;
8522
8584
  ChatLeoLib.MESSAGE_PAGE_SIZE = 50;
8523
- new ChatLeoLib();
8585
+ // Created on load so the DOM scan and window listeners start without a caller; application code
8586
+ // reaches it through `ChatLeoLib.getInstance()`.
8587
+ const chatLeoLibSingleton = new ChatLeoLib();
8524
8588
 
8525
8589
  export { ChatCallError, ChatLeoLib, ChatLeoLoginError, ChatRoom, ChatStore, SocketIoTransport, TransportError, WsV2Transport };
8526
8590
  //# sourceMappingURL=index.esm.js.map