@go-avro/avro-js 0.0.69 → 0.0.71

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.
@@ -78,9 +78,12 @@ export class AuthManager {
78
78
  const newTokens = await response.json();
79
79
  return newTokens;
80
80
  }
81
+ if (response.status === 401 || response.status === 422) {
82
+ storage.clear();
83
+ }
81
84
  }
82
- catch (error) {
83
- storage.clear();
85
+ catch {
86
+ console.error('Error refreshing tokens from storage:', storage);
84
87
  }
85
88
  }
86
89
  throw new StandardError(410, 'Failed to refresh tokens from all storages');
@@ -695,6 +695,8 @@ export declare class AvroQueryClient {
695
695
  getAuthState(): AuthState;
696
696
  getAuthStateAsync(): Promise<AuthState>;
697
697
  getQueryClient(): QueryClient;
698
+ attachQueryClient(queryClient: QueryClient): void;
699
+ peekQueryClient(): QueryClient | null;
698
700
  _syncEntity(queryClient: QueryClient, params: {
699
701
  action: 'create' | 'update' | 'delete';
700
702
  entityKey: string;
@@ -464,8 +464,7 @@ export class AvroQueryClient {
464
464
  * (old backend), we fall back to full invalidation.
465
465
  */
466
466
  setupSocketInvalidation(queryClient) {
467
- // Prevent double-setup
468
- if (this._queryClient)
467
+ if (this._socketInvalidationCleanup)
469
468
  return;
470
469
  this._queryClient = queryClient;
471
470
  const handlers = [];
@@ -773,6 +772,12 @@ export class AvroQueryClient {
773
772
  getQueryClient() {
774
773
  return useQueryClient();
775
774
  }
775
+ attachQueryClient(queryClient) {
776
+ this._queryClient ?? (this._queryClient = queryClient);
777
+ }
778
+ peekQueryClient() {
779
+ return this._queryClient;
780
+ }
776
781
  async _syncEntity(queryClient, params) {
777
782
  const { action, entityKey, id, fetchPath, construct, matchesQuery } = params;
778
783
  const predicate = (q) => matchesEntityKey(q, entityKey);
@@ -7,7 +7,9 @@ import { Job } from '../../types/api/Job';
7
7
  * location task) where the socket is usually down — sync directly.
8
8
  */
9
9
  const syncCheckinCaches = async (client, jobId) => {
10
- const queryClient = client.getQueryClient();
10
+ const queryClient = client.peekQueryClient();
11
+ if (!queryClient)
12
+ return;
11
13
  queryClient.invalidateQueries({ queryKey: ['checkins'] });
12
14
  if (!jobId)
13
15
  return;
@@ -90,6 +90,24 @@ AvroQueryClient.prototype.useCreateRoute = function () {
90
90
  queryClient.setQueryData(['routes'], context.previousRoutes);
91
91
  }
92
92
  },
93
+ onSettled: () => {
94
+ queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
95
+ if (!oldData)
96
+ return oldData;
97
+ if (oldData.pages) {
98
+ return {
99
+ ...oldData,
100
+ pages: oldData.pages
101
+ .map((page) => page.filter((r) => r.id !== 'temp-id'))
102
+ .filter((page) => page.length > 0),
103
+ };
104
+ }
105
+ if (Array.isArray(oldData)) {
106
+ return oldData.filter((r) => r.id !== 'temp-id');
107
+ }
108
+ return oldData;
109
+ });
110
+ },
93
111
  });
94
112
  };
95
113
  AvroQueryClient.prototype.useScheduleRoutes = function () {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.0.69";
1
+ export declare const AVRO_JS_VERSION = "0.0.71";
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.69';
3
+ export const AVRO_JS_VERSION = '0.0.71';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.69",
3
+ "version": "0.0.71",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",