@go-avro/avro-js 0.0.1 → 0.0.2-beta.2

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.
package/README.md CHANGED
@@ -14,4 +14,5 @@ This SDK provides:
14
14
  ## Installation
15
15
 
16
16
  ```bash
17
- npm install avro-client
17
+ npm i @go-avro/avro-js
18
+ ```
@@ -1,9 +1,15 @@
1
- import { TokenStorage, Tokens } from '@/types/auth';
1
+ import { TokenStorage, Tokens } from '../types/auth';
2
2
  export declare class AuthManager {
3
- private fetchNewTokens;
4
3
  private storages;
5
- constructor(fetchNewTokens: () => Promise<Tokens>, storageOrStorages: TokenStorage | TokenStorage[]);
6
- accessToken(): Promise<string>;
7
- refreshTokens(): Promise<Tokens>;
8
- clearToken(): Promise<void>;
4
+ private baseUrl;
5
+ constructor({ baseUrl, storage, }: {
6
+ baseUrl: string;
7
+ storage: TokenStorage | TokenStorage[];
8
+ });
9
+ hasTokens(): Promise<boolean>;
10
+ fetchNewTokens(): Promise<Tokens>;
11
+ accessToken(): Promise<string | undefined>;
12
+ refreshTokens(): Promise<Tokens | null>;
13
+ setTokens(tokens: Tokens): Promise<void>;
14
+ clearTokens(): Promise<void>;
9
15
  }
@@ -1,10 +1,51 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthManager = void 0;
4
- class AuthManager {
5
- constructor(fetchNewTokens, storageOrStorages) {
6
- this.fetchNewTokens = fetchNewTokens;
7
- this.storages = Array.isArray(storageOrStorages) ? storageOrStorages : [storageOrStorages];
1
+ export class AuthManager {
2
+ constructor({ baseUrl, storage, }) {
3
+ this.storages = Array.isArray(storage) ? storage : [storage];
4
+ if (this.storages.length === 0) {
5
+ throw new Error('At least one token storage must be provided');
6
+ }
7
+ this.storages.forEach(storage => {
8
+ if (!storage || typeof storage.get !== 'function' || typeof storage.set !== 'function' || typeof storage.clear !== 'function') {
9
+ throw new Error('Invalid token storage provided');
10
+ }
11
+ });
12
+ this.baseUrl = baseUrl;
13
+ }
14
+ async hasTokens() {
15
+ for (const storage of this.storages) {
16
+ const tokens = await storage.get();
17
+ if (tokens && tokens.access_token) {
18
+ return true;
19
+ }
20
+ }
21
+ return false;
22
+ }
23
+ async fetchNewTokens() {
24
+ const refreshToken = await new Promise((resolve, reject) => {
25
+ this.storages.map(async (storage) => {
26
+ const tokens = await storage.get();
27
+ if (tokens) {
28
+ resolve(tokens.refresh_token);
29
+ }
30
+ });
31
+ reject(new Error('No valid refresh token found'));
32
+ });
33
+ if (!refreshToken) {
34
+ throw new Error('No refresh token available');
35
+ }
36
+ const response = await fetch(`${this.baseUrl}/refresh`, {
37
+ method: 'POST',
38
+ headers: {
39
+ 'Content-Type': 'application/json',
40
+ 'Accept': 'application/json',
41
+ 'Authorization': `Bearer ${refreshToken}`,
42
+ },
43
+ });
44
+ if (!response.ok) {
45
+ throw new Error('Failed to refresh tokens');
46
+ }
47
+ const tokens = await response.json();
48
+ return tokens;
8
49
  }
9
50
  async accessToken() {
10
51
  if (!this.storages.length) {
@@ -13,18 +54,26 @@ class AuthManager {
13
54
  for (const storage of this.storages) {
14
55
  const token = await storage.get();
15
56
  if (token)
16
- return token;
57
+ return token.access_token;
17
58
  }
18
- const newToken = await this.fetchNewTokens();
19
- return newToken.accessToken;
59
+ const newToken = await this.refreshTokens();
60
+ return newToken?.access_token;
20
61
  }
21
62
  async refreshTokens() {
22
- const newToken = await this.fetchNewTokens();
23
- await Promise.all(this.storages.map(s => s.set(newToken)));
24
- return newToken;
63
+ try {
64
+ const newToken = await this.fetchNewTokens();
65
+ await Promise.all(this.storages.map(s => s.set(newToken)));
66
+ return newToken;
67
+ }
68
+ catch (error) {
69
+ console.error('Failed to refresh tokens:', error);
70
+ return null;
71
+ }
72
+ }
73
+ async setTokens(tokens) {
74
+ await Promise.all(this.storages.map(s => s.set(tokens)));
25
75
  }
26
- async clearToken() {
76
+ async clearTokens() {
27
77
  await Promise.all(this.storages.map(s => s.clear()));
28
78
  }
29
79
  }
30
- exports.AuthManager = AuthManager;
@@ -1,14 +1,13 @@
1
- import { Tokens, TokenStorage } from '@/types/auth';
1
+ import { Tokens, TokenStorage } from '../types/auth';
2
2
  export declare class MemoryStorage implements TokenStorage {
3
3
  private tokens;
4
- get(): Promise<string | null>;
4
+ get(): Promise<Tokens | null>;
5
5
  set(tokens: Tokens): Promise<void>;
6
6
  clear(): Promise<void>;
7
7
  }
8
8
  export declare class LocalStorage implements TokenStorage {
9
9
  private key;
10
- constructor(key: string);
11
- get(): Promise<string | null>;
10
+ get(): Promise<Tokens | null>;
12
11
  set(tokens: Tokens): Promise<void>;
13
12
  clear(): Promise<void>;
14
13
  }
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocalStorage = exports.MemoryStorage = void 0;
4
- class MemoryStorage {
1
+ export class MemoryStorage {
5
2
  constructor() {
6
- // @ts-ignore: no-unused-vars
7
3
  this.tokens = null;
8
4
  }
9
5
  async get() {
10
- return this.tokens ? this.tokens.accessToken : null;
6
+ return this.tokens ? this.tokens : null;
11
7
  }
12
8
  async set(tokens) {
13
9
  this.tokens = tokens;
@@ -16,14 +12,13 @@ class MemoryStorage {
16
12
  this.tokens = null;
17
13
  }
18
14
  }
19
- exports.MemoryStorage = MemoryStorage;
20
- class LocalStorage {
21
- constructor(key) {
22
- this.key = key;
15
+ export class LocalStorage {
16
+ constructor() {
17
+ this.key = 'auth_tokens';
23
18
  }
24
19
  async get() {
25
20
  const item = localStorage.getItem(this.key);
26
- return item ? JSON.parse(item).accessToken : null;
21
+ return item ? JSON.parse(item) : null;
27
22
  }
28
23
  async set(tokens) {
29
24
  localStorage.setItem(this.key, JSON.stringify(tokens));
@@ -32,4 +27,3 @@ class LocalStorage {
32
27
  localStorage.removeItem(this.key);
33
28
  }
34
29
  }
35
- exports.LocalStorage = LocalStorage;
@@ -1,19 +1,24 @@
1
- import { AuthManager } from '@/auth/AuthManager';
2
- import { CancelToken, RetryStrategy } from '@/types/client';
3
- export interface QueryClientConfig {
1
+ import { AuthManager } from '../auth/AuthManager';
2
+ import { CancelToken, RetryStrategy } from '../types/client';
3
+ export interface AvroQueryClientConfig {
4
4
  baseUrl: string;
5
5
  authManager: AuthManager;
6
6
  maxRetries?: number;
7
7
  retryStrategy?: RetryStrategy;
8
8
  timeout?: number;
9
9
  }
10
- export declare class QueryClient {
10
+ export declare class AvroQueryClient {
11
11
  private config;
12
- constructor(config: QueryClientConfig);
12
+ constructor(config: AvroQueryClientConfig);
13
13
  getDelay(strategy: RetryStrategy, attempt: number): number;
14
14
  private _xhr;
15
- get<T>(path: string, cancelToken?: CancelToken): Promise<T>;
16
- post<T>(path: string, data: any, cancelToken?: CancelToken): Promise<T>;
17
- put<T>(path: string, data: any, cancelToken?: CancelToken): Promise<T>;
18
- delete<T>(path: string, cancelToken?: CancelToken): Promise<T>;
15
+ private _fetch;
16
+ get<T>(path: string, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<T>;
17
+ post<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<T>;
18
+ put<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<T>;
19
+ delete<T>(path: string, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<T>;
20
+ login(data: {
21
+ username: string;
22
+ password: string;
23
+ }, cancelToken?: CancelToken): Promise<Boolean>;
19
24
  }
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryClient = void 0;
4
- const error_1 = require("@/types/error");
5
- class QueryClient {
1
+ import { StandardError } from '../types/error';
2
+ export class AvroQueryClient {
6
3
  constructor(config) {
7
4
  this.config = {
8
5
  baseUrl: config.baseUrl,
@@ -24,10 +21,10 @@ class QueryClient {
24
21
  }
25
22
  throw new Error(`Invalid retry strategy: ${strategy}`);
26
23
  }
27
- _xhr(method, path, body, cancelToken, retryCount = 0) {
24
+ _xhr(method, path, body, cancelToken, headers = {}, isIdempotent = false, retryCount = 0) {
28
25
  const checkCancelled = () => {
29
26
  if (cancelToken?.isCancelled()) {
30
- return new error_1.StandardError(0, 'Request cancelled');
27
+ return new StandardError(0, 'Request cancelled');
31
28
  }
32
29
  return null;
33
30
  };
@@ -39,8 +36,12 @@ class QueryClient {
39
36
  const xhr = new XMLHttpRequest();
40
37
  const url = this.config.baseUrl + path;
41
38
  xhr.open(method, url, true);
42
- xhr.setRequestHeader('Content-Type', 'application/json');
43
- xhr.setRequestHeader('Authorization', `Bearer ${token}`);
39
+ if (token) {
40
+ xhr.setRequestHeader('Authorization', `Bearer ${token}`);
41
+ }
42
+ Object.entries(headers).forEach(([key, value]) => {
43
+ xhr.setRequestHeader(key, value);
44
+ });
44
45
  xhr.onload = () => {
45
46
  const cancelErr = checkCancelled();
46
47
  if (cancelErr)
@@ -49,10 +50,10 @@ class QueryClient {
49
50
  this.config.authManager
50
51
  .refreshTokens()
51
52
  .then(() => {
52
- this._xhr(method, path, body, cancelToken, retryCount + 1).then(resolve, reject);
53
+ this._xhr(method, path, body, cancelToken, headers, isIdempotent, retryCount + 1).then(resolve, reject);
53
54
  })
54
55
  .catch(() => {
55
- reject(new error_1.StandardError(401, 'Unauthorized (refresh failed)'));
56
+ reject(new StandardError(401, 'Unauthorized (refresh failed)'));
56
57
  });
57
58
  return;
58
59
  }
@@ -68,7 +69,7 @@ class QueryClient {
68
69
  if (retryCount < this.config.maxRetries) {
69
70
  const delay = this.getDelay(this.config.retryStrategy, retryCount);
70
71
  setTimeout(() => {
71
- this._xhr(method, path, body, cancelToken, retryCount + 1).then(resolve, reject);
72
+ this._xhr(method, path, body, cancelToken, headers, isIdempotent, retryCount + 1).then(resolve, reject);
72
73
  }, delay);
73
74
  }
74
75
  else {
@@ -80,7 +81,7 @@ class QueryClient {
80
81
  catch {
81
82
  console.warn('Failed to parse error response:', xhr.responseText);
82
83
  }
83
- reject(new error_1.StandardError(xhr.status, msg));
84
+ reject(new StandardError(xhr.status, msg));
84
85
  }
85
86
  }
86
87
  };
@@ -88,32 +89,105 @@ class QueryClient {
88
89
  if (retryCount < this.config.maxRetries) {
89
90
  const delay = this.getDelay(this.config.retryStrategy, retryCount);
90
91
  setTimeout(() => {
91
- this._xhr(method, path, body, cancelToken, retryCount + 1).then(resolve, reject);
92
+ this._xhr(method, path, body, cancelToken, headers, isIdempotent, retryCount + 1).then(resolve, reject);
92
93
  }, delay);
93
94
  }
94
95
  else {
95
- reject(new error_1.StandardError(0, 'Network Error'));
96
+ reject(new StandardError(0, 'Network Error'));
96
97
  }
97
98
  };
98
99
  if (this.config.timeout) {
99
100
  xhr.timeout = this.config.timeout;
100
- xhr.ontimeout = () => reject(new error_1.StandardError(0, 'Request timed out'));
101
+ xhr.ontimeout = () => reject(new StandardError(0, 'Request timed out'));
102
+ }
103
+ xhr.send(body);
104
+ });
105
+ });
106
+ }
107
+ _fetch(method, path, body, cancelToken, headers = {}, isIdempotent = false, retryCount = 0) {
108
+ const checkCancelled = () => {
109
+ if (cancelToken?.isCancelled()) {
110
+ return new StandardError(0, 'Request cancelled');
111
+ }
112
+ return null;
113
+ };
114
+ return this.config.authManager.accessToken().then(token => {
115
+ const cancelErr = checkCancelled();
116
+ if (cancelErr)
117
+ return Promise.reject(cancelErr);
118
+ const url = this.config.baseUrl + path;
119
+ const requestHeaders = {
120
+ 'Content-Type': 'application/json',
121
+ ...headers,
122
+ };
123
+ if (token) {
124
+ requestHeaders['Authorization'] = `Bearer ${token}`;
125
+ }
126
+ const options = {
127
+ method,
128
+ headers: requestHeaders,
129
+ body: body ? JSON.stringify(body) : null,
130
+ };
131
+ return fetch(url, options).then(response => {
132
+ if (response.status === 401 && this.config.authManager.refreshTokens && retryCount === 0) {
133
+ return this.config.authManager
134
+ .refreshTokens()
135
+ .then(() => this._fetch(method, path, body, cancelToken, headers, isIdempotent, retryCount + 1))
136
+ .catch(() => Promise.reject(new StandardError(401, 'Unauthorized (refresh failed)')));
137
+ }
138
+ if (!response.ok) {
139
+ if (retryCount < this.config.maxRetries) {
140
+ const delay = this.getDelay(this.config.retryStrategy, retryCount);
141
+ return new Promise((resolve, reject) => {
142
+ setTimeout(() => {
143
+ this._fetch(method, path, body, cancelToken, headers, isIdempotent, retryCount + 1)
144
+ .then(resolve)
145
+ .catch(reject);
146
+ }, delay);
147
+ });
148
+ }
149
+ else {
150
+ return response.text().then(text => {
151
+ let msg = response.statusText;
152
+ try {
153
+ const parsed = JSON.parse(text);
154
+ msg = parsed.message || msg;
155
+ }
156
+ catch {
157
+ console.warn('Failed to parse error response:', text);
158
+ }
159
+ throw new StandardError(response.status, msg);
160
+ });
161
+ }
101
162
  }
102
- xhr.send(body ? JSON.stringify(body) : null);
163
+ return response.json();
103
164
  });
104
165
  });
105
166
  }
106
- get(path, cancelToken) {
107
- return this._xhr('GET', path, null, cancelToken);
167
+ get(path, cancelToken, headers = {}) {
168
+ return this._xhr('GET', path, null, cancelToken, headers, true);
108
169
  }
109
- post(path, data, cancelToken) {
110
- return this._xhr('POST', path, data, cancelToken);
170
+ post(path, data, cancelToken, headers = {}) {
171
+ return this._xhr('POST', path, data, cancelToken, headers, false);
111
172
  }
112
- put(path, data, cancelToken) {
113
- return this._xhr('PUT', path, data, cancelToken);
173
+ put(path, data, cancelToken, headers = {}) {
174
+ return this._xhr('PUT', path, data, cancelToken, headers, true);
114
175
  }
115
- delete(path, cancelToken) {
116
- return this._xhr('DELETE', path, null, cancelToken);
176
+ delete(path, cancelToken, headers = {}) {
177
+ return this._xhr('DELETE', path, null, cancelToken, headers, false);
178
+ }
179
+ // add login that uses fetch and sets the tokens in the auth manager
180
+ login(data, cancelToken) {
181
+ return this._fetch('POST', '/login', data, cancelToken)
182
+ .then(tokens => {
183
+ if (!tokens || !tokens.access_token || !tokens.refresh_token) {
184
+ throw new StandardError(401, 'Invalid login response');
185
+ }
186
+ return this.config.authManager.setTokens(tokens).then(() => true);
187
+ })
188
+ .catch(err => {
189
+ console.error('Login failed:', err);
190
+ throw new StandardError(401, 'Login failed');
191
+ });
117
192
  }
118
193
  }
119
- exports.QueryClient = QueryClient;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { QueryClientConfig, QueryClient } from './client/QueryClient';
1
+ export { AvroQueryClientConfig, AvroQueryClient } from './client/QueryClient';
2
2
  export { AuthManager } from './auth/AuthManager';
3
- export { MemoryStorage } from './auth/storage';
4
- export * from '@/types/api';
5
- export * from '@/types/error';
6
- export * from '@/types/client';
3
+ export { MemoryStorage, LocalStorage } from './auth/storage';
4
+ export * from './types/api';
5
+ export * from './types/error';
6
+ export * from './types/client';
package/dist/index.js CHANGED
@@ -1,26 +1,6 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.MemoryStorage = exports.AuthManager = exports.QueryClient = void 0;
18
- var QueryClient_1 = require("./client/QueryClient");
19
- Object.defineProperty(exports, "QueryClient", { enumerable: true, get: function () { return QueryClient_1.QueryClient; } });
20
- var AuthManager_1 = require("./auth/AuthManager");
21
- Object.defineProperty(exports, "AuthManager", { enumerable: true, get: function () { return AuthManager_1.AuthManager; } });
22
- var storage_1 = require("./auth/storage");
23
- Object.defineProperty(exports, "MemoryStorage", { enumerable: true, get: function () { return storage_1.MemoryStorage; } });
24
- __exportStar(require("@/types/api"), exports);
25
- __exportStar(require("@/types/error"), exports);
26
- __exportStar(require("@/types/client"), exports);
1
+ export { AvroQueryClient } from './client/QueryClient';
2
+ export { AuthManager } from './auth/AuthManager';
3
+ export { MemoryStorage, LocalStorage } from './auth/storage';
4
+ export * from './types/api';
5
+ export * from './types/error';
6
+ export * from './types/client';
@@ -1,19 +1,506 @@
1
- export interface AvroUser {
1
+ export interface PaymentMethod {
2
+ allow_redisplay: string;
3
+ autopay: boolean;
4
+ billing_details: {
5
+ email: string;
6
+ name: string;
7
+ };
8
+ created: number;
9
+ customer: string;
10
+ id: string;
11
+ type: "us_bank_account" | "card";
12
+ us_bank_account: {
13
+ account_holder_type: string;
14
+ account_type: string;
15
+ bank_name: string;
16
+ financial_connections_account: string;
17
+ fingerprint: string;
18
+ last4: string;
19
+ networks: {
20
+ preferred: string;
21
+ supported: string[];
22
+ };
23
+ routing_number: string;
24
+ status_details: object;
25
+ } | null;
26
+ card: {
27
+ brand: string;
28
+ checks: {
29
+ address_line1_check: string;
30
+ address_postal_code_check: string;
31
+ cvc_check: string;
32
+ };
33
+ country: string;
34
+ exp_month: number;
35
+ exp_year: number;
36
+ fingerprint: string;
37
+ funding: string;
38
+ last4: string;
39
+ networks: {
40
+ preferred: string;
41
+ supported: string[];
42
+ };
43
+ three_d_secure_usage: {
44
+ supported: boolean;
45
+ };
46
+ wallet: {
47
+ type: string;
48
+ } | null;
49
+ } | null;
50
+ }
51
+ export interface Avro {
52
+ id: string;
53
+ name: string;
54
+ time_created: number;
55
+ time_updated: number;
56
+ emails: Email[];
57
+ totp_email_id: string;
58
+ billing_email_id: string;
59
+ join_email_id: string;
60
+ }
61
+ export interface Friendship {
62
+ }
63
+ export interface MemberState {
64
+ id: string;
65
+ state: string;
66
+ friendship: Friendship | null;
67
+ last_message_read_at: number | null;
68
+ }
69
+ export interface LineItem {
70
+ id: string;
71
+ name: string;
72
+ description: string;
73
+ cost: number | null;
74
+ amount: number | null;
75
+ time_created: number;
76
+ }
77
+ export interface Reaction {
78
+ id: string;
79
+ message_id: string;
80
+ sender_id: string;
81
+ reaction: string;
82
+ time_created: number;
83
+ time_updated: number;
84
+ }
85
+ export interface Message {
86
+ id: string;
87
+ chat_id: string;
88
+ sender_id: string;
89
+ reply_to_id: string;
90
+ content: string;
91
+ reactions: Reaction[];
92
+ time_created: number;
93
+ time_updated: number;
94
+ time_sent: number;
95
+ message: string;
96
+ }
97
+ export interface Chat {
98
+ id: string;
99
+ name: string;
100
+ company_id: string;
101
+ time_created: number;
102
+ time_updated: number;
103
+ last_message: Message;
104
+ user_state: MemberState[];
105
+ messages: Message[];
106
+ }
107
+ export interface TeamLocation {
108
+ accuracy: number;
109
+ heading: number;
110
+ id: string;
111
+ latitude: number;
112
+ longitude: number;
113
+ time_collected: number;
114
+ time_created: number;
115
+ time_updated: number | null;
116
+ }
117
+ export interface Team {
118
+ autoconfigure: boolean;
119
+ company_id: string;
120
+ description: string;
121
+ end: number[];
122
+ end_time: number;
123
+ fixed_cost: number;
124
+ hourly_cost: number;
125
+ id: string;
126
+ items: string[];
127
+ km_cost: number;
128
+ max_distance: number;
129
+ max_jobs: number;
130
+ max_travel_time: number;
131
+ color: string;
132
+ name: string;
133
+ profile: string;
134
+ routes: string[];
135
+ skills: string[];
136
+ speed_factor: number;
137
+ start_latitude: number;
138
+ start_longitude: number;
139
+ end_latitude: number;
140
+ end_longitude: number;
141
+ start_time: number;
142
+ users: string[];
143
+ current_location: TeamLocation;
144
+ start_address: string;
145
+ end_address: string;
146
+ }
147
+ export interface Subscription {
148
+ time_created: number;
149
+ time_updated: string;
150
+ user: User;
151
+ user_company_id: string;
152
+ job_id: string;
153
+ id: string;
154
+ notifications: number;
155
+ }
156
+ export interface Plan {
157
+ id: string;
158
+ name: string;
159
+ base_rate: number;
160
+ price_per_job: number;
161
+ description: string;
162
+ referral_codes: string[];
163
+ trial_period_days: number;
164
+ time_created: number;
165
+ time_updated: number;
166
+ }
167
+ export interface BillPayment {
168
+ id: string;
169
+ amount: number;
170
+ stripe_pi_id: string;
171
+ bill_user_id: string;
172
+ status: "created" | "processing" | "succeeded" | "failed" | "canceled" | "requires_action";
173
+ type: "us_bank_account" | "card";
174
+ action_required_at: number;
175
+ time_created: number;
176
+ time_updated: number | null;
177
+ }
178
+ export interface BillUser {
179
+ id: string;
180
+ user_id: string;
181
+ bill_id: string;
182
+ invoice_id: string;
183
+ payment_attempts: BillPayment[];
184
+ time_created: number;
185
+ time_updated: number | null;
186
+ amount: number;
187
+ }
188
+ export interface User {
189
+ id: string;
190
+ username: string;
191
+ name: string;
192
+ verified: boolean;
193
+ companies: UserCompanyAssociation[] | null;
194
+ email: string | null;
195
+ phone_number: string | null;
196
+ time_created: string | null;
197
+ time_updated: string | null;
198
+ can_send_emails: boolean | null;
199
+ payment_methods: PaymentMethod[];
200
+ autopay_payment_types: string[];
201
+ autopay: boolean | null;
202
+ chats: Chat[];
203
+ bills: BillUser[];
204
+ }
205
+ export interface Break {
206
+ id: string;
207
+ time_started: number;
208
+ time_ended: number;
209
+ company_billable: boolean;
210
+ client_billable: boolean;
211
+ }
212
+ export interface ServiceMonth {
213
+ id: string;
214
+ job_name: string;
215
+ job_id: string | null;
216
+ bill_id: string | null;
217
+ cost: number;
218
+ billed: boolean;
219
+ paid: boolean;
220
+ amount: number;
221
+ time_created: number;
222
+ time_updated: number | null;
223
+ }
224
+ export interface Session {
225
+ session_id: string;
226
+ user_id: string;
227
+ company_id: string;
228
+ time_started: number;
229
+ time_ended: number;
230
+ break_id: string;
231
+ is_paused: boolean;
232
+ team_id: string;
233
+ current_route_id: string;
234
+ breaks: Break[];
235
+ }
236
+ export interface Group {
237
+ id: string;
238
+ name: string;
239
+ is_active: boolean;
240
+ is_user_type: boolean;
241
+ users: string[];
242
+ permissions: string[];
243
+ company_id: string;
244
+ time_created: number;
245
+ time_updated: number;
246
+ }
247
+ export interface UserCompanyAssociation {
248
+ id: string;
249
+ user: User;
250
+ company: string;
251
+ permissions: string[];
252
+ effective_permissions: string[];
253
+ time_created: number | null;
254
+ time_updated: number | null;
255
+ notification_setting: number[];
256
+ share_email_company_wide: boolean;
257
+ notifications: number[];
258
+ groups: string[];
259
+ }
260
+ export interface Email {
261
+ id: string;
262
+ company_id: string;
263
+ name: string;
264
+ mail_server: string;
265
+ mail_port: number;
266
+ mail_username: string;
267
+ mail_password: string | null;
268
+ mail_default_sender: string;
269
+ mail_use_tls: boolean;
270
+ mail_use_ssl: boolean;
271
+ mail_api_key: string;
272
+ is_company_wide: boolean;
273
+ users: User[];
274
+ type: "OUTLOOK" | "SMTP" | "GMAIL";
275
+ access_token?: string;
276
+ access_token_expiry?: number;
277
+ refresh_token?: string;
278
+ refresh_token_expiry?: number;
279
+ }
280
+ export interface Label {
281
+ name: string;
282
+ id: string;
283
+ company_id: string;
284
+ color: string;
285
+ jobs: string[];
286
+ }
287
+ export interface Bill {
288
+ id: string;
289
+ invoice_id: number;
290
+ intuit_id: string | null;
291
+ name: string;
292
+ amount: number;
293
+ billed_by: string;
294
+ customer_email: string | null;
295
+ manual_emails: string[][];
296
+ users: BillUser[];
297
+ paid_at: number;
298
+ time_created: number;
299
+ time_updated: number;
300
+ events: string[];
301
+ intent_created_at: number;
302
+ intent_last_created_at: number;
303
+ payment: BillPayment | null;
304
+ line_items: LineItem[];
305
+ months: string[];
306
+ due_date: number;
307
+ }
308
+ export interface Skill {
2
309
  id: string;
3
310
  name: string;
311
+ company_id: string;
312
+ time_created: number;
313
+ time_updated: number;
314
+ }
315
+ export interface PlanPayment {
316
+ id: string;
317
+ amount: number;
318
+ stripe_pi_id: string;
319
+ company_id: string;
320
+ plan_id: string;
321
+ status: "created" | "processing" | "succeeded" | "failed" | "canceled";
322
+ time_created: number;
323
+ time_updated: number;
324
+ }
325
+ export interface Company {
326
+ events: _Event[];
327
+ months: ServiceMonth[];
328
+ id: string;
329
+ jobs: Job[];
330
+ name: string;
4
331
  email: string;
5
- teams: AvroTeam[];
332
+ routes: Route[];
333
+ teams: Team[];
334
+ emails: Email[];
335
+ skills: Skill[];
336
+ time_created: string;
337
+ time_updated: string | null;
338
+ users: UserCompanyAssociation[];
339
+ use_client_side_customer_start_billing: boolean;
340
+ use_client_side_customer_stop_billing: boolean;
341
+ use_client_side_employee_start_billing: boolean;
342
+ use_client_side_employee_stop_billing: boolean;
343
+ logo_url: string;
344
+ delay_scalar: number;
345
+ incomplete_payments: PlanPayment[];
346
+ overdue_threshold: number;
347
+ stripe_account_id: string;
348
+ is_restricted: false;
349
+ disabled_reason: string;
350
+ completed_onboarding: boolean;
351
+ restricted_soon: boolean;
352
+ service_email_id: string;
353
+ billing_email_id: string;
354
+ num_events: number;
355
+ num_jobs: number;
356
+ bills: Bill[];
357
+ enabled_payment_methods: string[];
358
+ sessions: Session[];
359
+ num_sessions: number;
360
+ labels: Label[];
361
+ groups: Group[];
362
+ indicator_lifetime: number;
363
+ available_plans: Plan[];
364
+ last_payment: number;
365
+ last_charged: number;
366
+ balance: number;
367
+ plan_id: string;
368
+ payment_methods: PaymentMethod[];
369
+ autopay_payment_id: string;
370
+ intuit_connected: boolean;
371
+ }
372
+ export interface RouteJob {
373
+ time_created: number;
374
+ route_id: string;
375
+ job_id: string;
376
+ id: string;
377
+ order: number;
378
+ estimated_arrival_time: number;
379
+ scheduled_arrival_time: number;
380
+ tasks: string[];
6
381
  }
7
- export interface AvroTeam {
382
+ export interface Route {
383
+ company: string;
8
384
  id: string;
385
+ is_internal: boolean;
386
+ jobs: RouteJob[];
9
387
  name: string;
10
- members: AvroUser[];
388
+ time_created: number;
389
+ time_updated: number | null;
390
+ teams: string[];
391
+ polyline: string;
392
+ is_optimized: boolean;
393
+ start_time: number;
394
+ end_time: number;
395
+ start_latitude: number;
396
+ start_longitude: number;
397
+ end_latitude: number;
398
+ end_longitude: number;
11
399
  }
12
- export interface AvroJob {
400
+ export interface Job {
401
+ address: string;
402
+ company: string;
403
+ description: string;
13
404
  id: string;
14
- location: {
15
- lat: number;
16
- lng: number;
17
- };
18
- status: 'active' | 'pending' | 'complete';
405
+ is_one_time: boolean;
406
+ autostart_radius: number;
407
+ latitude: number;
408
+ longitude: number;
409
+ name: string;
410
+ internal_notes: string;
411
+ external_notes: string;
412
+ priority: number;
413
+ tasks: Task[];
414
+ time_created: number;
415
+ time_updated: number | null;
416
+ routes: RouteJob[];
417
+ subscribers: Subscription[];
418
+ manual_emails: string[][];
419
+ last_completed_event: _Event | null;
420
+ last_event: _Event | null;
421
+ labels: string[];
422
+ owner: string;
423
+ }
424
+ export interface Task {
425
+ enforce_proof_amount: boolean;
426
+ events: _Event[];
427
+ frequency: number;
428
+ id: string;
429
+ job_id: string;
430
+ name: string;
431
+ internal_notes: string;
432
+ external_notes: string;
433
+ proof_amt: number;
434
+ images: string[];
435
+ time_created: number;
436
+ time_updated: number | null;
437
+ status: "PENDING_CUSTOMER" | "PENDING_COMPANY" | "ACTIVE" | "ARCHIVED" | "DRAFT";
438
+ created_by: UserCompanyAssociation | null;
439
+ overdueness: number | null;
440
+ overdue_time: number;
441
+ last_event: _Event | null;
442
+ delay: number;
443
+ skills: string[];
444
+ service: number;
445
+ bill_mode: "MONTH" | "SERVICE" | "NONE";
446
+ price: number;
447
+ services_remaining: number;
448
+ expire_on: number | null;
449
+ bill_day: number | null;
450
+ services_prepaid: number;
451
+ months_prepaid: number;
452
+ priority: boolean;
453
+ }
454
+ export interface TaskWrapper {
455
+ latestEvent: number;
456
+ task: Task;
457
+ }
458
+ export interface JobWrapper {
459
+ latestEvent: number;
460
+ routeIndex: number;
461
+ job: Job;
462
+ frequency: number;
463
+ isOverdue: boolean;
464
+ }
465
+ export interface taskStartInfo {
466
+ name: string;
467
+ start: number;
468
+ }
469
+ export interface taskEndInfo {
470
+ end: number;
471
+ internal_notes: string;
472
+ external_notes: string;
473
+ }
474
+ export interface AdditionalCharge {
475
+ id: string;
476
+ time_created: number;
477
+ time_updated: number | null;
478
+ name: string;
479
+ amount: number;
480
+ }
481
+ export interface _Event {
482
+ breaks: string[];
483
+ id: string;
484
+ name: string;
485
+ internal_notes: string;
486
+ external_notes: string;
487
+ proofs: string[];
488
+ tasks: string[];
489
+ time_created: number;
490
+ time_ended: number;
491
+ time_started: number;
492
+ time_updated: number | null;
493
+ job_id: string;
494
+ job_name: string;
495
+ job_address: string;
496
+ bill_id: string;
497
+ billed_amount: number;
498
+ additional_charges: AdditionalCharge[];
499
+ user_id: string;
500
+ team_id: string;
501
+ cost: number;
502
+ billed: boolean;
503
+ paid: boolean;
504
+ autostart: boolean;
505
+ job_labels: string[];
19
506
  }
package/dist/types/api.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,9 +1,9 @@
1
1
  export interface Tokens {
2
- accessToken: string;
3
- refreshToken: string;
2
+ access_token: string;
3
+ refresh_token: string;
4
4
  }
5
5
  export interface TokenStorage {
6
- get(): Promise<string | null>;
6
+ get(): Promise<Tokens | null>;
7
7
  set(tokens: Tokens): Promise<void>;
8
8
  clear(): Promise<void>;
9
9
  }
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StandardError = void 0;
4
- class StandardError extends Error {
1
+ export class StandardError extends Error {
5
2
  constructor(status, message) {
6
3
  super(message);
7
4
  this.status = status;
8
5
  Object.setPrototypeOf(this, StandardError.prototype);
9
6
  }
10
7
  }
11
- exports.StandardError = StandardError;
package/package.json CHANGED
@@ -1,14 +1,22 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.1",
3
+ "version": "0.0.2-beta.2",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
- "build": "tsc",
8
+ "build": "tsc && tsc-alias",
9
9
  "lint": "eslint src",
10
10
  "test": "jest",
11
- "prepublishOnly": "npm run build"
11
+ "prepublishOnly": "npm run lint && npm run build"
12
+ },
13
+ "type": "module",
14
+ "module": "./dist/index.js",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.js",
18
+ "types": "./dist/index.d.ts"
19
+ }
12
20
  },
13
21
  "repository": {
14
22
  "type": "git",
@@ -33,6 +41,7 @@
33
41
  "eslint-plugin-react": "^7.37.5",
34
42
  "jest": "^29.0.0",
35
43
  "ts-jest": "^29.0.0",
44
+ "tsc-alias": "^1.8.16",
36
45
  "typescript": "^5.8.3",
37
46
  "typescript-eslint": "^8.38.0"
38
47
  },