@go-avro/avro-js 0.0.111 → 0.0.113

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',
@@ -513,21 +516,20 @@ export class AvroQueryClient {
513
516
  const patchMemberLocation = (data) => {
514
517
  const userId = data?.user_id;
515
518
  if (!userId || typeof userId !== 'string' || typeof data?.latitude !== 'number') {
516
- queryClient.invalidateQueries({ queryKey: ['companies'] });
519
+ queryClient.invalidateQueries({ queryKey: ['users', 'company'] });
517
520
  return;
518
521
  }
519
- queryClient.setQueriesData({ queryKey: ['companies'] }, (old) => {
520
- if (!old || !Array.isArray(old.users))
521
- return old;
522
+ const patchMembers = (members) => {
522
523
  let changed = false;
523
- const users = old.users.map((u) => {
524
+ const next = members.map((u) => {
524
525
  if (u?.user?.id !== userId)
525
526
  return u;
526
527
  changed = true;
527
528
  return { ...u, last_location: data };
528
529
  });
529
- return changed ? { ...old, users } : old;
530
- });
530
+ return changed ? next : members;
531
+ };
532
+ queryClient.setQueriesData({ queryKey: ['users', 'company'] }, (old) => Array.isArray(old) ? patchMembers(old) : old);
531
533
  };
532
534
  for (const [event, config] of Object.entries(SOCKET_EVENT_CONFIG)) {
533
535
  if (event === 'location_update' && isBulkEvent(config)) {
@@ -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;
@@ -6,20 +6,15 @@ export declare const DevicePlatform: {
6
6
  readonly WEB: "web";
7
7
  };
8
8
  export type DevicePlatform = (typeof DevicePlatform)[keyof typeof DevicePlatform];
9
- /** What a client tells the server about the install it is running on. */
10
9
  export interface DeviceInfo {
11
- /** Stable per-install id (identifierForVendor, androidId, stored UUID). */
12
10
  device_key: string;
13
11
  platform: DevicePlatform;
14
- /** User-facing label, e.g. "Chris's iPhone". */
15
12
  name?: string;
16
- /** Hardware, e.g. "iPhone 17" or "ASUS Zenbook". */
17
13
  model?: string;
18
- /** OS and version, e.g. "iOS 26.1" or "macOS 15". */
19
14
  os?: string;
20
15
  app_version?: string;
21
- /** Whether the client is on screen (app active / tab visible). */
22
16
  foreground?: boolean;
17
+ headless?: boolean;
23
18
  }
24
19
  /** A device the user has connected from, as tracked by the server. */
25
20
  export interface Device {
@@ -31,9 +26,8 @@ export interface Device {
31
26
  os: string | null;
32
27
  app_version: string | null;
33
28
  location_status: LocationServicesStatus;
34
- /** Whether the device currently holds a socket. */
35
29
  online: boolean;
36
- /** Whether the client is on screen; a backgrounded phone stays online for location. */
30
+ tracking: boolean;
37
31
  foreground: boolean;
38
32
  last_location: Location | null;
39
33
  last_seen: number | null;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.0.111";
1
+ export declare const AVRO_JS_VERSION = "0.0.113";
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.111';
3
+ export const AVRO_JS_VERSION = '0.0.113';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.111",
3
+ "version": "0.0.113",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",