@truenas/api-client 9.0.3 → 9.0.4

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.
@@ -3205,13 +3205,14 @@ function socketScheme(protocol) {
3205
3205
  var tenSeconds = 10 * 1e3;
3206
3206
  var twentySeconds = 20 * 1e3;
3207
3207
  var TrueNasConnection = class {
3208
- constructor(initialEnabled, hostnames, systemUuid, websocketPath, systemName, retryDelay = tenSeconds, maxRetry = 3, logger = noopLogger, protocol = "https:") {
3208
+ constructor(initialEnabled, hostnames, systemUuid, websocketPath, systemName, retryDelay = tenSeconds, maxRetry = 3, logger = noopLogger, protocol = "https:", interceptor) {
3209
3209
  this.systemUuid = systemUuid;
3210
3210
  this.websocketPath = websocketPath;
3211
3211
  this.systemName = systemName;
3212
3212
  this.retryDelay = retryDelay;
3213
3213
  this.maxRetry = maxRetry;
3214
3214
  this.logger = logger;
3215
+ this.interceptor = interceptor;
3215
3216
  // compatibility properties
3216
3217
  this.opened = new rxjs.BehaviorSubject(false);
3217
3218
  this.closed = new rxjs.Subject();
@@ -3269,6 +3270,7 @@ var TrueNasConnection = class {
3269
3270
  const initMessage = createJsonRpcMessage("core.set_options", [
3270
3271
  { legacy_jobs: false }
3271
3272
  ]);
3273
+ this.interceptor?.outgoing?.(initMessage);
3272
3274
  connection.ws.next(initMessage);
3273
3275
  return connection.ws.messages().pipe(
3274
3276
  rxjs.filter((msg) => msg.id === initMessage.id),
@@ -3367,22 +3369,27 @@ var TrueNasConnection = class {
3367
3369
  rxjs.map((conn) => conn.state === "error"),
3368
3370
  rxjs.takeUntil(this.closeConnection)
3369
3371
  );
3370
- /**
3371
- * observable which always emits messages from the current socket.
3372
- */
3373
- this.messages$ = this.ws$.pipe(
3372
+ /** What the appliance sends, on whichever socket is current. */
3373
+ this.socketMessages$ = this.ws$.pipe(
3374
3374
  rxjs.filter((ws) => ws !== null),
3375
3375
  rxjs.switchMap((ws) => ws.messages().pipe(
3376
3376
  rxjs.catchError(() => rxjs.EMPTY)
3377
3377
  ))
3378
3378
  );
3379
+ this.messages$ = interceptor?.injected$ ? rxjs.merge(this.socketMessages$, interceptor.injected$.pipe(rxjs.observeOn(rxjs.asapScheduler), rxjs.share())) : this.socketMessages$;
3379
3380
  this.endpoint$.next(resolveEndpoint(hostnames, protocol));
3380
3381
  this.ws$.pipe(
3381
3382
  rxjs.switchMap((ws) => ws ? rxjs.interval(twentySeconds).pipe(rxjs.map(() => ws)) : rxjs.EMPTY),
3382
3383
  rxjs.takeUntil(this.closeConnection)
3383
3384
  ).subscribe((ws) => {
3384
- ws.next(createJsonRpcMessage("core.ping"));
3385
+ const ping = createJsonRpcMessage("core.ping");
3386
+ this.interceptor?.outgoing?.(ping);
3387
+ ws.next(ping);
3385
3388
  });
3389
+ if (interceptor?.incoming) {
3390
+ const incoming = interceptor.incoming.bind(interceptor);
3391
+ this.messages$.pipe(rxjs.takeUntil(this.closeConnection)).subscribe((message) => incoming(message));
3392
+ }
3386
3393
  this.opened$.subscribe((val) => this.opened.next(val));
3387
3394
  this.closed$.subscribe(() => this.closed.next());
3388
3395
  this.hostname$.pipe(rxjs.filter(Boolean)).subscribe((name) => this.hostname.next(name));
@@ -3451,6 +3458,9 @@ var TrueNasConnection = class {
3451
3458
  * the next `closed$` emission.
3452
3459
  */
3453
3460
  send(message) {
3461
+ if (this.interceptor?.outgoing?.(message) === false) {
3462
+ return rxjs.Subscription.EMPTY;
3463
+ }
3454
3464
  return this.ws$.pipe(
3455
3465
  rxjs.filter((ws) => ws !== null),
3456
3466
  rxjs.take(1)
@@ -3648,7 +3658,8 @@ var TrueNasApiClient = class {
3648
3658
  this.reconnect.retryDelay,
3649
3659
  this.reconnect.maxRetry,
3650
3660
  this.logger,
3651
- this.protocol
3661
+ this.protocol,
3662
+ this.reconnect.interceptor
3652
3663
  );
3653
3664
  }
3654
3665
  /**
@@ -4513,7 +4524,7 @@ function instantiateClientForVersion(version, opts, logger) {
4513
4524
  systemName,
4514
4525
  logger,
4515
4526
  opts.protocol,
4516
- { retryDelay: opts.retryDelay, maxRetry: opts.maxRetry }
4527
+ { retryDelay: opts.retryDelay, maxRetry: opts.maxRetry, interceptor: opts.interceptor }
4517
4528
  );
4518
4529
  }
4519
4530
  function errorMessageOrDefault(error, fallback) {
@@ -4575,5 +4586,5 @@ exports.v25_10_4_exports = v25_10_4_exports;
4575
4586
  exports.v25_10_5_exports = v25_10_5_exports;
4576
4587
  exports.v27_0_0_exports = v27_0_0_exports;
4577
4588
  exports.v28_0_0_exports = v28_0_0_exports;
4578
- //# sourceMappingURL=chunk-DJCZ545I.cjs.map
4579
- //# sourceMappingURL=chunk-DJCZ545I.cjs.map
4589
+ //# sourceMappingURL=chunk-WAVCPALL.cjs.map
4590
+ //# sourceMappingURL=chunk-WAVCPALL.cjs.map