@chat-leo/chatleolib 2.0.2 → 2.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/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;
@@ -7497,7 +7554,7 @@ class ChatLeoLib {
7497
7554
  this.clients.delete(client);
7498
7555
  }
7499
7556
  async requestConnection(client, options = {}) {
7500
- var _b, _c, _d, _e, _f, _g;
7557
+ var _b, _c, _d, _e, _f, _g, _h;
7501
7558
  console.debug(`requestConnection`, client, options);
7502
7559
  client.chatStore = this.chatStore;
7503
7560
  this.registerClient(client);
@@ -7514,18 +7571,21 @@ class ChatLeoLib {
7514
7571
  console.debug('Already logged in, hydrate client');
7515
7572
  (_b = client.setLoading) === null || _b === void 0 ? void 0 : _b.call(client, false);
7516
7573
  (_c = client.setLoggedIn) === null || _c === void 0 ? void 0 : _c.call(client, true, this.userProfile);
7574
+ // A client that joins an already-connected session must learn the current
7575
+ // status, or it keeps its initial "disconnected" state (stale Offline banner).
7576
+ (_d = client.setConnectionStatus) === null || _d === void 0 ? void 0 : _d.call(client, this.chatStore.connectionStatus);
7517
7577
  return { status: 'connected' };
7518
7578
  }
7519
7579
  // No active session: allow client to wait without triggering login if no credentials
7520
7580
  const hasCreds = Boolean(options.ticket || (options.username && options.password));
7521
7581
  if (!this.loginPromise && !hasCreds) {
7522
7582
  console.debug('No active session, allow client to wait');
7523
- (_d = client.setLoading) === null || _d === void 0 ? void 0 : _d.call(client, false);
7583
+ (_e = client.setLoading) === null || _e === void 0 ? void 0 : _e.call(client, false);
7524
7584
  return { status: 'waiting' };
7525
7585
  }
7526
7586
  console.debug('Requesting connection');
7527
7587
  // Gate concurrent logins
7528
- (_e = client.setLoading) === null || _e === void 0 ? void 0 : _e.call(client, true);
7588
+ (_f = client.setLoading) === null || _f === void 0 ? void 0 : _f.call(client, true);
7529
7589
  if (!this.loginPromise && hasCreds) {
7530
7590
  // Start a new login process
7531
7591
  this.loginPromise = this.performLogin(options)
@@ -7545,8 +7605,8 @@ class ChatLeoLib {
7545
7605
  catch (err) {
7546
7606
  // notify this client of error
7547
7607
  console.error('Login failed', err);
7548
- (_f = client.setLoading) === null || _f === void 0 ? void 0 : _f.call(client, false);
7549
- (_g = client.setLoggedIn) === null || _g === void 0 ? void 0 : _g.call(client, false, null);
7608
+ (_g = client.setLoading) === null || _g === void 0 ? void 0 : _g.call(client, false);
7609
+ (_h = client.setLoggedIn) === null || _h === void 0 ? void 0 : _h.call(client, false, null);
7550
7610
  return { status: 'error' };
7551
7611
  }
7552
7612
  }
@@ -7912,14 +7972,16 @@ async function _ChatLeoLib_scanComponents() {
7912
7972
  const chatComponentElements = document.querySelectorAll('chatleo-component');
7913
7973
  for (let i = 0; i < chatComponentElements.length; i++) {
7914
7974
  const component = chatComponentElements[i];
7915
- if (component.serverUrl) {
7916
- this.serverUrlName = component.serverUrl;
7917
- }
7975
+ __classPrivateFieldGet(this, _ChatLeoLib_instances, "m", _ChatLeoLib_adoptComponentServerUrl).call(this, component.serverUrl);
7918
7976
  if (!component.chatLeoLib) {
7919
7977
  console.debug('chatComponentElement attached', component, component.serverUrl);
7920
7978
  component.chatLeoLib = this;
7921
7979
  }
7922
7980
  }
7981
+ }, _ChatLeoLib_adoptComponentServerUrl = function _ChatLeoLib_adoptComponentServerUrl(serverUrl) {
7982
+ if (!serverUrl || this.serverUrlExplicit)
7983
+ return;
7984
+ this.serverUrlName = serverUrl;
7923
7985
  }, _ChatLeoLib_observeDomChanges = function _ChatLeoLib_observeDomChanges() {
7924
7986
  if (!document.body)
7925
7987
  return;
@@ -7955,6 +8017,9 @@ async function _ChatLeoLib_scanComponents() {
7955
8017
  }, _ChatLeoLib_loginRequest =
7956
8018
  /** POSTs to the login endpoint and turns HTTP/network failures into a typed reason. */
7957
8019
  async function _ChatLeoLib_loginRequest(body, invalidReason) {
8020
+ if (!this.serverUrlName) {
8021
+ throw new Error('No server URL configured. Provide <chatleo-component server-url="…"> or call ChatLeoLib.getInstance().setServerUrl("…") before signing in.');
8022
+ }
7958
8023
  let response;
7959
8024
  try {
7960
8025
  response = await fetch(__classPrivateFieldGet(this, _ChatLeoLib_instances, "m", _ChatLeoLib_buildServerUrl).call(this, '/api/v1/auth/login'), {
@@ -8520,7 +8585,9 @@ ChatLeoLib.MAX_REFRESH_RETRIES = 5;
8520
8585
  ChatLeoLib.RESUME_SYNC_COOLDOWN_MS = 10000;
8521
8586
  ChatLeoLib.READ_MARKER_DEBOUNCE_MS = 2000;
8522
8587
  ChatLeoLib.MESSAGE_PAGE_SIZE = 50;
8523
- new ChatLeoLib();
8588
+ // Created on load so the DOM scan and window listeners start without a caller; application code
8589
+ // reaches it through `ChatLeoLib.getInstance()`.
8590
+ const chatLeoLibSingleton = new ChatLeoLib();
8524
8591
 
8525
8592
  export { ChatCallError, ChatLeoLib, ChatLeoLoginError, ChatRoom, ChatStore, SocketIoTransport, TransportError, WsV2Transport };
8526
8593
  //# sourceMappingURL=index.esm.js.map