o2g-node-sdk 2.5.7 → 2.5.9

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
@@ -54,6 +54,55 @@ await O2G.telephony.makeCall("1234", "5678");
54
54
  await O2G.shutdown();
55
55
  ```
56
56
 
57
+ ## What's New in 2.5.9
58
+
59
+ ### TLS certificate validation — `TlsOptions`
60
+
61
+ The SDK now provides fine-grained control over how the O2G server's TLS
62
+ certificate is validated, via a new `TlsOptions` class passed as the optional
63
+ fourth argument to `O2G.initialize()`.
64
+
65
+ | Mode | How to configure | When to use |
66
+ |---|---|---|
67
+ | Corporate CA (recommended) | `NODE_EXTRA_CA_CERTS=/path/ca.pem` env var | Standard production deployment — CA as a file on disk |
68
+ | Corporate CA (programmatic) | `TlsOptions.Builder.ca(pem).build()` | CA comes from a database, secret manager, or env var containing PEM content |
69
+ | Self-signed (dev only) | `TlsOptions.Builder.allowSelfSigned().build()` | Development and test environments only |
70
+ | Strict mode | `.rejectInsecureEnvironment()` | Refuse to start if `NODE_TLS_REJECT_UNAUTHORIZED=0` is set |
71
+
72
+ > **Note:** Node.js does not read the Windows or system certificate store.
73
+ > Internal CA certificates must always be provided explicitly via
74
+ > `NODE_EXTRA_CA_CERTS` or `TlsOptions.ca`.
75
+
76
+ `allowSelfSigned` is scoped to the SDK only — unlike the global
77
+ `NODE_TLS_REJECT_UNAUTHORIZED=0` environment variable it does not disable TLS
78
+ validation for the entire Node.js process.
79
+
80
+ See the [TLS Configuration](#tls-configuration) section for full examples.
81
+
82
+ ---
83
+
84
+ ## What's New in 2.5.8
85
+
86
+ ### Service instance caching — fixes listeners silenced after recovery
87
+
88
+ Service getters (`O2G.eventSummary`, `O2G.telephony`, …) now return the **same
89
+ instance** for the lifetime of a session. Previously every call created a new
90
+ object, and because each constructor silently overwrites the shared `EventSink`
91
+ registration, any listener attached to an earlier instance would stop receiving
92
+ events — a particularly subtle failure after session recovery.
93
+
94
+ The instances are automatically invalidated on `O2G_SESSION_LOST` and
95
+ `O2G_RECONNECTED`, so the first access after recovery always binds to the new
96
+ session. Re-attach your listeners once in the `O2G_RECONNECTED` handler and they
97
+ will keep working across any number of recovery cycles.
98
+
99
+ ```typescript
100
+ O2G.on(O2G.O2G_RECONNECTED, () => {
101
+ // Re-attach — O2G.eventSummary now returns a fresh instance
102
+ O2G.eventSummary.on(EventSummary.ON_EVENT_SUMMARY_UPDATED, onEventSummary);
103
+ });
104
+ ```
105
+
57
106
  ## What's New in 2.5.7
58
107
 
59
108
  - Add new field `emailAddress` in object `User`
@@ -192,6 +241,103 @@ new Host("10.0.0.1", "93.12.1.1")
192
241
 
193
242
  The SDK tries the private address first, then falls back to the public address.
194
243
 
244
+ ## TLS Configuration
245
+
246
+ O2G servers in enterprise environments typically use certificates signed by an
247
+ internal CA. Node.js **does not read the Windows or system certificate store** —
248
+ it ships with its own Mozilla-derived CA bundle. You therefore need to explicitly
249
+ tell Node.js about your internal CA using one of the approaches below.
250
+
251
+ ### `NODE_EXTRA_CA_CERTS` — recommended for most deployments
252
+
253
+ The standard Node.js mechanism: point to a PEM file on disk before the process
254
+ starts. Node.js adds those certificates to its built-in bundle without replacing
255
+ the existing public CAs.
256
+
257
+ ```bash
258
+ NODE_EXTRA_CA_CERTS=/etc/ssl/certs/corporate-ca.pem node app.js
259
+ ```
260
+
261
+ With this variable set, `O2G.initialize()` requires no `TlsOptions` at all —
262
+ Node.js already trusts the O2G server's certificate:
263
+
264
+ ```typescript
265
+ O2G.initialize("MyApp", O2GServers.Builder
266
+ .primaryHost(new Host("10.0.0.1"))
267
+ .build());
268
+ ```
269
+
270
+ This is the recommended approach for production deployments where the CA
271
+ certificate is a stable file on the server (systemd unit, Docker, PM2
272
+ ecosystem file, etc.).
273
+
274
+ ### `TlsOptions.ca` — programmatic alternative
275
+
276
+ Use this when the CA certificate is not available as a file on disk — for
277
+ example, when it is stored in a database, a secret manager, or an environment
278
+ variable containing the PEM content:
279
+
280
+ ```typescript
281
+ import fs from 'node:fs';
282
+ import { O2G, O2GServers, Host, TlsOptions } from 'o2g-node-sdk';
283
+
284
+ O2G.initialize("MyApp",
285
+ O2GServers.Builder.primaryHost(new Host("10.0.0.1")).build(),
286
+ "1.0",
287
+ TlsOptions.Builder
288
+ .ca(fs.readFileSync('/etc/ssl/certs/o2g-ca.pem'))
289
+ .build()
290
+ );
291
+ ```
292
+
293
+ Unlike `NODE_EXTRA_CA_CERTS`, this is scoped to the SDK only and does not
294
+ affect other HTTPS connections in the same Node.js process.
295
+
296
+ ### Self-signed certificate (development only)
297
+
298
+ If the O2G server uses a self-signed certificate, disable certificate validation
299
+ for the SDK:
300
+
301
+ ```typescript
302
+ import { O2G, O2GServers, Host, TlsOptions } from 'o2g-node-sdk';
303
+
304
+ O2G.initialize("MyApp",
305
+ O2GServers.Builder.primaryHost(new Host("10.0.0.1")).build(),
306
+ "1.0",
307
+ TlsOptions.Builder
308
+ .allowSelfSigned()
309
+ .build()
310
+ );
311
+ ```
312
+
313
+ > **Warning:** `allowSelfSigned` disables certificate validation entirely.
314
+ > Only use this in development or test environments, never in production.
315
+
316
+ Unlike the global `NODE_TLS_REJECT_UNAUTHORIZED=0` environment variable,
317
+ `allowSelfSigned` is scoped to the SDK only and does not affect other HTTPS
318
+ connections in the process.
319
+
320
+ ### Strict mode (production hardening)
321
+
322
+ To ensure that `NODE_TLS_REJECT_UNAUTHORIZED=0` cannot silently bypass TLS
323
+ validation in production, add `.rejectInsecureEnvironment()`:
324
+
325
+ ```typescript
326
+ O2G.initialize("MyApp",
327
+ O2GServers.Builder.primaryHost(new Host("10.0.0.1")).build(),
328
+ "1.0",
329
+ TlsOptions.Builder
330
+ .rejectInsecureEnvironment()
331
+ .build()
332
+ );
333
+ ```
334
+
335
+ If `NODE_TLS_REJECT_UNAUTHORIZED=0` is present in the environment when
336
+ `initialize()` is called, the SDK throws an error and refuses to start.
337
+ This can be combined with `NODE_EXTRA_CA_CERTS` or `TlsOptions.ca`.
338
+
339
+ ---
340
+
195
341
  ## Session Monitoring and Recovery
196
342
 
197
343
  The SDK automatically handles session failures and recovery. When the O2G server
@@ -248,6 +394,10 @@ O2G.on(O2G.O2G_SESSION_LOST, ({ reason }) => {
248
394
 
249
395
  O2G.on(O2G.O2G_RECONNECTED, () => {
250
396
  console.log("Session recovered — resuming activity.");
397
+ // Re-attach service listeners here: each service getter returns a fresh
398
+ // instance after recovery, so listeners registered before the outage must
399
+ // be re-registered (see "Service instance caching" in What's New 2.5.8).
400
+ O2G.eventSummary.on(EventSummary.ON_EVENT_SUMMARY_UPDATED, onEventSummary);
251
401
  });
252
402
 
253
403
  O2G.on(O2G.O2G_SERVER_SWITCHED, ({ from, to }) => {