@go-avro/avro-js 0.0.2-beta.47 → 0.0.2-beta.49

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.
@@ -1,6 +1,6 @@
1
- import { InfiniteData, UseInfiniteQueryResult, useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
1
+ import { InfiniteData, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
2
2
  import { AuthManager } from '../auth/AuthManager';
3
- import { _Event, Bill, Company, Job, LineItem, Route, ServiceMonth, Session, User } from '../types/api';
3
+ import { _Event, ApiInfo, Bill, Company, Job, LineItem, Route, ServiceMonth, Session, User } from '../types/api';
4
4
  import { CancelToken, RetryStrategy } from '../types/client';
5
5
  import { StandardError } from '../types/error';
6
6
  export interface AvroQueryClientConfig {
@@ -15,7 +15,7 @@ declare module '../client/QueryClient' {
15
15
  _xhr<T>(method: string, path: string, body: any, cancelToken?: CancelToken, headers?: Record<string, string>, isIdempotent?: boolean, retryCount?: number): Promise<T>;
16
16
  _fetch<T>(method: string, path: string, body: any, cancelToken?: CancelToken, headers?: Record<string, string>, isIdempotent?: boolean, retryCount?: number): Promise<T>;
17
17
  getDelay(strategy: RetryStrategy, attempt: number): number;
18
- useGetRoot(): ReturnType<typeof useQuery>;
18
+ useGetRoot(): UseQueryResult<ApiInfo, StandardError>;
19
19
  useGetJobs(companyGuid: string, body: {
20
20
  amt?: number;
21
21
  query?: string;
@@ -153,6 +153,9 @@ declare module '../client/QueryClient' {
153
153
  }, StandardError, {
154
154
  routeId: string;
155
155
  }>>;
156
+ useDeleteSelf(): ReturnType<typeof useMutation<{
157
+ msg: string;
158
+ }, StandardError, void>>;
156
159
  }
157
160
  }
158
161
  export declare class AvroQueryClient {
@@ -3,6 +3,6 @@ import { AvroQueryClient } from '../../client/QueryClient';
3
3
  AvroQueryClient.prototype.useGetRoot = function () {
4
4
  return useQuery({
5
5
  queryKey: ['health'],
6
- queryFn: () => this.get('/', undefined) // your async fetch function
6
+ queryFn: () => this.get('/'),
7
7
  });
8
8
  };
@@ -1,4 +1,4 @@
1
- import { useQuery } from "@tanstack/react-query";
1
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2
2
  import { AvroQueryClient } from "../../client/QueryClient";
3
3
  AvroQueryClient.prototype.useGetUser = function (userId) {
4
4
  return useQuery({
@@ -14,3 +14,25 @@ AvroQueryClient.prototype.useGetSelf = function () {
14
14
  enabled: Boolean(this),
15
15
  });
16
16
  };
17
+ AvroQueryClient.prototype.useDeleteSelf = function () {
18
+ const queryClient = useQueryClient();
19
+ return useMutation({
20
+ mutationFn: async () => {
21
+ return this.delete(`/user`);
22
+ },
23
+ onMutate: async () => {
24
+ await queryClient.cancelQueries({ queryKey: ['user'] });
25
+ const previousUser = queryClient.getQueryData(['user']);
26
+ queryClient.removeQueries({ queryKey: ['user'] });
27
+ return { previousUser };
28
+ },
29
+ onError: (err, _, context) => {
30
+ if (context?.previousUser) {
31
+ queryClient.setQueryData(['user'], context.previousUser);
32
+ }
33
+ },
34
+ onSettled: () => {
35
+ queryClient.invalidateQueries({ queryKey: ['user'] });
36
+ },
37
+ });
38
+ };
@@ -1,3 +1,12 @@
1
+ export interface ApiInfo {
2
+ app_semver: string;
3
+ db_healthy: boolean;
4
+ logged_in_as: string;
5
+ ors_healthy: string;
6
+ pelias_healthy: boolean;
7
+ version: string;
8
+ vroom_healthy: boolean;
9
+ }
1
10
  export interface PaymentMethod {
2
11
  allow_redisplay: string;
3
12
  autopay: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.47",
3
+ "version": "0.0.2-beta.49",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",