@go-avro/avro-js 0.0.108 → 0.0.109

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.
@@ -678,6 +678,8 @@ export declare class AvroQueryClient {
678
678
  /** The install identity sent with sockets and location pings, if any. */
679
679
  get device(): DeviceInfo | undefined;
680
680
  setDevice(device: DeviceInfo | undefined): void;
681
+ /** Tell the server which install this live socket belongs to. */
682
+ private registerDevice;
681
683
  emit(eventName: string, data: unknown): void;
682
684
  on<T>(eventName: string, callback: (data: T) => void): void;
683
685
  off(eventName: string, callback?: Function): void;
@@ -400,6 +400,7 @@ export class AvroQueryClient {
400
400
  autoConnect: false,
401
401
  transports: ['websocket'],
402
402
  });
403
+ this.socket.on('connect', () => this.registerDevice());
403
404
  config.authManager.isAuthenticated().then((isAuth) => {
404
405
  this.setAuthState(isAuth);
405
406
  if (!this.socket.connected && isAuth === AuthState.AUTHENTICATED) {
@@ -455,11 +456,17 @@ export class AvroQueryClient {
455
456
  setDevice(device) {
456
457
  this.config.device = device;
457
458
  const auth = this.socket.auth;
458
- if (!auth?.token)
459
- return;
460
- this.socket.auth = this.socketAuth(auth.token);
461
- if (this.socket.connected || this.socket.active) {
462
- this.socket.disconnect().connect();
459
+ if (auth?.token)
460
+ this.socket.auth = this.socketAuth(auth.token);
461
+ // Don't reconnect: a restart mid-handshake leaks the original
462
+ // connection. Declare the device on whatever socket is live now;
463
+ // the 'connect' handler repeats it on every (re)connect.
464
+ this.registerDevice();
465
+ }
466
+ /** Tell the server which install this live socket belongs to. */
467
+ registerDevice() {
468
+ if (this.config.device && this.socket.connected) {
469
+ this.socket.emit('register_device', this.config.device);
463
470
  }
464
471
  }
465
472
  emit(eventName, data) {
@@ -618,7 +625,7 @@ export class AvroQueryClient {
618
625
  }
619
626
  loginSuccess(tokens) {
620
627
  this.setAuthState(AuthState.AUTHENTICATED);
621
- this.socket.auth = { token: tokens.access_token };
628
+ this.socket.auth = this.socketAuth(tokens.access_token);
622
629
  if (!this.socket.connected) {
623
630
  this.socket.connect();
624
631
  }
@@ -706,7 +713,7 @@ export class AvroQueryClient {
706
713
  throw new StandardError(401, 'Invalid Google login response');
707
714
  }
708
715
  this.setAuthState(AuthState.AUTHENTICATED);
709
- this.socket.auth = { token: resp.access_token };
716
+ this.socket.auth = this.socketAuth(resp.access_token);
710
717
  if (!this.socket.connected) {
711
718
  this.socket.connect();
712
719
  }
@@ -737,7 +744,7 @@ export class AvroQueryClient {
737
744
  throw new StandardError(401, 'Invalid Apple login response');
738
745
  }
739
746
  this.setAuthState(AuthState.AUTHENTICATED);
740
- this.socket.auth = { token: resp.access_token };
747
+ this.socket.auth = this.socketAuth(resp.access_token);
741
748
  if (!this.socket.connected) {
742
749
  this.socket.connect();
743
750
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.0.108";
1
+ export declare const AVRO_JS_VERSION = "0.0.109";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED by scripts/gen-version.js — do not edit by hand.
2
2
  // Regenerated from package.json by the `prebuild` npm hook.
3
- export const AVRO_JS_VERSION = '0.0.108';
3
+ export const AVRO_JS_VERSION = '0.0.109';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.108",
3
+ "version": "0.0.109",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",