@go-avro/avro-js 0.0.12 → 0.0.13

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,7 +1,7 @@
1
1
  import { Socket } from 'socket.io-client';
2
2
  import { InfiniteData, QueryClient, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
3
3
  import { AuthManager } from '../auth/AuthManager';
4
- import { _Event, ApiInfo, Avro, Bill, Break, Chat, Company, FinancialInsightData, Job, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group, Label, RouteScheduleConfig, CatalogItem, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api';
4
+ import { _Event, ApiInfo, Avro, Bill, Break, Chat, Company, FinancialInsightData, RevenueInsightData, Job, EventInsightData, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation, Skill, Group, Label, RouteScheduleConfig, CatalogItem, Prepayment, Timecard, TimecardActionType, TimecardStatus } from '../types/api';
5
5
  import { AuthState, Tokens } from '../types/auth';
6
6
  import { CancelToken, RetryStrategy } from '../types/client';
7
7
  import { StandardError } from '../types/error';
@@ -142,6 +142,9 @@ declare module '../client/QueryClient' {
142
142
  useEventAnalytics({ periods }: {
143
143
  periods: number[][];
144
144
  }): UseQueryResult<EventInsightData[], StandardError>;
145
+ useRevenueAnalytics({ periods }: {
146
+ periods: number[][];
147
+ }): UseQueryResult<RevenueInsightData[], StandardError>;
145
148
  useGetCompany(companyId: string): UseQueryResult<Company, StandardError>;
146
149
  useGetCurrentCompany(): UseQueryResult<Company, StandardError>;
147
150
  useGetJob(jobId: string): UseQueryResult<Job, StandardError>;
@@ -34,3 +34,16 @@ AvroQueryClient.prototype.useEventAnalytics = function ({ periods }) {
34
34
  enabled: Boolean(this.companyId),
35
35
  });
36
36
  };
37
+ AvroQueryClient.prototype.useRevenueAnalytics = function ({ periods }) {
38
+ return useQuery({
39
+ queryKey: ['analytics', 'revenue', this.companyId, periods],
40
+ queryFn: () => this.post({
41
+ path: `/company/${this.companyId}/analytics/revenue`,
42
+ data: JSON.stringify({ periods }),
43
+ headers: {
44
+ 'Content-Type': 'application/json',
45
+ }
46
+ }),
47
+ enabled: Boolean(this.companyId),
48
+ });
49
+ };
@@ -33,5 +33,4 @@ export declare class Route {
33
33
  constructor(init?: Partial<Route>);
34
34
  getNextOccurrences: (count?: number) => (Date | null)[];
35
35
  getNextOccurrence: (after?: Date) => Date | null;
36
- getIndicatorExpiration: () => Date;
37
36
  }
@@ -41,39 +41,6 @@ export class Route {
41
41
  }
42
42
  return next_occurrence;
43
43
  };
44
- this.getIndicatorExpiration = () => {
45
- const start_time = new Date(this.start_time * 1000);
46
- if (this.frequency === FrequencyType.ONCE) {
47
- return start_time;
48
- }
49
- // if the route is currently active, return the start time as the indicator expiration
50
- if (Date.now() > start_time.getTime()) {
51
- return start_time;
52
- }
53
- // else compute the previous occurrence and return that as the indicator expiration
54
- const prev = new Date(start_time);
55
- switch (this.frequency) {
56
- case FrequencyType.DAILY:
57
- prev.setHours(prev.getHours() - 4);
58
- prev.setDate(prev.getDate() - 1);
59
- break;
60
- case FrequencyType.WEEKLY:
61
- prev.setDate(prev.getDate() - 8);
62
- break;
63
- case FrequencyType.BIWEEKLY:
64
- prev.setDate(prev.getDate() - 15);
65
- break;
66
- case FrequencyType.MONTHLY:
67
- prev.setDate(prev.getDate() - 1);
68
- prev.setMonth(prev.getMonth() - 1);
69
- break;
70
- case FrequencyType.YEARLY:
71
- prev.setDate(prev.getDate() - 1);
72
- prev.setFullYear(prev.getFullYear() - 1);
73
- break;
74
- }
75
- return prev;
76
- };
77
44
  Object.assign(this, init);
78
45
  if (init?.jobs) {
79
46
  this.jobs = init.jobs.map(j => new RouteJob(j));
@@ -219,3 +219,26 @@ export interface EventInsightData {
219
219
  }[];
220
220
  total_events: number;
221
221
  }
222
+ export interface RevenueByTeam {
223
+ team_id: string | null;
224
+ team_name: string;
225
+ revenue: number;
226
+ event_count: number;
227
+ }
228
+ export interface RevenueByUser {
229
+ user_id: string | null;
230
+ user_name: string;
231
+ revenue: number;
232
+ event_count: number;
233
+ }
234
+ export interface UserSeconds {
235
+ user_id: string | null;
236
+ seconds: number;
237
+ }
238
+ export interface RevenueInsightData {
239
+ start: number;
240
+ end: number;
241
+ by_team: RevenueByTeam[];
242
+ by_user: RevenueByUser[];
243
+ user_seconds: UserSeconds[];
244
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",