@go-avro/avro-js 0.0.112 → 0.0.114

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.
@@ -548,6 +548,11 @@ declare module '../client/QueryClient' {
548
548
  data: Partial<UserCompanyAssociation>;
549
549
  }>>;
550
550
  useDevices(): UseQueryResult<Device[], StandardError>;
551
+ useGetCompanyUsers(body?: {
552
+ query?: string;
553
+ user_ids?: string[];
554
+ enabled?: boolean;
555
+ }): UseQueryResult<UserCompanyAssociation[], StandardError>;
551
556
  useReportDevice(): ReturnType<typeof useMutation<Device, StandardError, DeviceInfo & {
552
557
  location_status?: LocationServicesStatus;
553
558
  }>>;
@@ -132,7 +132,10 @@ const SOCKET_EVENT_CONFIG = {
132
132
  },
133
133
  // ── Users (no single-entity socket events) ──
134
134
  user_updated: { invalidateKeys: [['users'], ['user']] },
135
- update_users: { invalidateKeys: [['users'], ['user'], ['companies', 'current']] },
135
+ // Membership / permission changes.
136
+ update_users: { invalidateKeys: [['users'], ['user']] },
137
+ // Presence / location-status flips: only the member list is affected.
138
+ update_presence: { invalidateKeys: [['users', 'company']] },
136
139
  // ── Jobs ──
137
140
  create_job: {
138
141
  entityKey: 'jobs',
@@ -362,6 +365,9 @@ const SOCKET_EVENT_CONFIG = {
362
365
  invalidateKeys: [['companies'], ['/company/list']],
363
366
  },
364
367
  // ── Location ──
368
+ // Handled surgically in setupSocketInvalidation (patches
369
+ // `current_location` / `last_location` in place); these keys are
370
+ // only the fallback for malformed payloads.
365
371
  location_update: { invalidateKeys: [['teams']] },
366
372
  // ── Prepayments ──
367
373
  update_prepayments: { invalidateKeys: [['prepayments']] },
@@ -513,29 +519,61 @@ export class AvroQueryClient {
513
519
  const patchMemberLocation = (data) => {
514
520
  const userId = data?.user_id;
515
521
  if (!userId || typeof userId !== 'string' || typeof data?.latitude !== 'number') {
516
- queryClient.invalidateQueries({ queryKey: ['companies'] });
522
+ queryClient.invalidateQueries({ queryKey: ['users', 'company'] });
517
523
  return;
518
524
  }
519
- queryClient.setQueriesData({ queryKey: ['companies'] }, (old) => {
520
- if (!old || !Array.isArray(old.users))
521
- return old;
525
+ const patchMembers = (members) => {
522
526
  let changed = false;
523
- const users = old.users.map((u) => {
527
+ const next = members.map((u) => {
524
528
  if (u?.user?.id !== userId)
525
529
  return u;
526
530
  changed = true;
527
531
  return { ...u, last_location: data };
528
532
  });
529
- return changed ? { ...old, users } : old;
533
+ return changed ? next : members;
534
+ };
535
+ queryClient.setQueriesData({ queryKey: ['users', 'company'] }, (old) => Array.isArray(old) ? patchMembers(old) : old);
536
+ };
537
+ const patchTeamLocation = (data) => {
538
+ const teamId = data.team_id;
539
+ if (!teamId || typeof teamId !== 'string')
540
+ return;
541
+ const patchTeams = (teams) => {
542
+ let changed = false;
543
+ const next = teams.map((t) => {
544
+ if (t?.id !== teamId)
545
+ return t;
546
+ changed = true;
547
+ return { ...t, current_location: data };
548
+ });
549
+ return changed ? next : teams;
550
+ };
551
+ queryClient.setQueriesData({ queryKey: ['teams'] }, (old) => {
552
+ if (Array.isArray(old))
553
+ return patchTeams(old);
554
+ if (old?.pages) {
555
+ return {
556
+ ...old,
557
+ pages: old.pages.map((page) => Array.isArray(page) ? patchTeams(page) : page),
558
+ };
559
+ }
560
+ if (old?.id === teamId)
561
+ return { ...old, current_location: data };
562
+ return old;
530
563
  });
531
564
  };
532
565
  for (const [event, config] of Object.entries(SOCKET_EVENT_CONFIG)) {
533
566
  if (event === 'location_update' && isBulkEvent(config)) {
534
567
  const handler = (data) => {
535
- patchMemberLocation(data);
536
- for (const key of config.invalidateKeys) {
537
- queryClient.invalidateQueries({ queryKey: key });
568
+ if (!data || typeof data.latitude !== 'number') {
569
+ for (const key of config.invalidateKeys) {
570
+ queryClient.invalidateQueries({ queryKey: key });
571
+ }
538
572
  }
573
+ else {
574
+ patchTeamLocation(data);
575
+ }
576
+ patchMemberLocation(data);
539
577
  };
540
578
  this.socket.on(event, handler);
541
579
  handlers.push({ event, handler });
@@ -146,14 +146,8 @@ AvroQueryClient.prototype.useCreateUserCompany = function () {
146
146
  queryKey: ['companies', this.companyId],
147
147
  });
148
148
  const previousCompany = queryClient.getQueryData(['companies', this.companyId]);
149
- queryClient.setQueryData(['companies', this.companyId], (oldData) => {
150
- if (!oldData)
151
- return oldData;
152
- return {
153
- ...oldData,
154
- users: [...(oldData.users || []), { id: user_id }],
155
- };
156
- });
149
+ // Members live in their own query now; the server's
150
+ // update_users event refreshes it once the add lands.
157
151
  return { previousCompany };
158
152
  },
159
153
  onSuccess: () => {
@@ -180,14 +174,7 @@ AvroQueryClient.prototype.useRemoveUserCompany = function () {
180
174
  queryKey: ['companies', this.companyId],
181
175
  });
182
176
  const previousCompany = queryClient.getQueryData(['companies', this.companyId]);
183
- queryClient.setQueryData(['companies', this.companyId], (oldData) => {
184
- if (!oldData)
185
- return oldData;
186
- return {
187
- ...oldData,
188
- users: oldData.users.filter((user) => user.id !== userId),
189
- };
190
- });
177
+ queryClient.setQueriesData({ queryKey: ['users', 'company'] }, (old) => old ? old.filter((member) => member.id !== userId) : old);
191
178
  return { previousCompany };
192
179
  },
193
180
  onSuccess: () => {
@@ -175,3 +175,18 @@ AvroQueryClient.prototype.useDeleteSelf = function () {
175
175
  },
176
176
  });
177
177
  };
178
+ /**
179
+ * A company's members on their own, so presence/status flips
180
+ * (`update_presence`) refetch this list instead of the whole company.
181
+ */
182
+ AvroQueryClient.prototype.useGetCompanyUsers = function (body = {}) {
183
+ return useQuery({
184
+ queryKey: ['users', 'company', this.companyId, body.query ?? '', body.user_ids ?? null],
185
+ queryFn: () => this.post({
186
+ path: `/company/${this.companyId}/users`,
187
+ data: JSON.stringify(body),
188
+ headers: { 'Content-Type': 'application/json' },
189
+ }),
190
+ enabled: Boolean(this.companyId) && (body.enabled ?? true),
191
+ });
192
+ };
@@ -8,7 +8,6 @@ import { Plan } from '../../types/api/Plan';
8
8
  import { PlanPayment } from '../../types/api/PlanPayment';
9
9
  import { Session } from '../../types/api/Session';
10
10
  import { Skill } from '../../types/api/Skill';
11
- import { UserCompanyAssociation } from '../../types/api/UserCompanyAssociation';
12
11
  import { CatalogItem } from '../../types/api/CatalogItem';
13
12
  export interface Company {
14
13
  id: string;
@@ -20,7 +19,6 @@ export interface Company {
20
19
  catalog_items: CatalogItem[];
21
20
  time_created: number;
22
21
  time_updated: number | null;
23
- users: UserCompanyAssociation[];
24
22
  use_client_side_customer_start_billing: boolean;
25
23
  use_client_side_customer_stop_billing: boolean;
26
24
  use_client_side_employee_start_billing: boolean;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.0.112";
1
+ export declare const AVRO_JS_VERSION = "0.0.114";
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.112';
3
+ export const AVRO_JS_VERSION = '0.0.114';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.112",
3
+ "version": "0.0.114",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",