@findatruck/aggregator-client 1.1.0 → 1.1.1
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/dist/index.cjs +109 -0
- package/dist/index.d.cts +41 -2
- package/dist/index.d.ts +41 -2
- package/dist/index.js +115 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -22,10 +22,16 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
AggregatorClient: () => AggregatorClient,
|
|
24
24
|
AggregatorClientError: () => AggregatorClientError,
|
|
25
|
+
DriverRankingSchema: () => import_shared_schemas2.DriverRankingSchema,
|
|
26
|
+
DriverRankingsRequestSchema: () => import_shared_schemas2.DriverRankingsRequestSchema,
|
|
27
|
+
DriverRankingsResponseSchema: () => import_shared_schemas2.DriverRankingsResponseSchema,
|
|
25
28
|
NewLoginRequestSchema: () => import_shared_schemas2.NewLoginRequestSchema,
|
|
26
29
|
NewLoginResponseFailureSchema: () => import_shared_schemas2.NewLoginResponseFailureSchema,
|
|
27
30
|
NewLoginResponseSchema: () => import_shared_schemas2.NewLoginResponseSchema,
|
|
28
31
|
NewLoginResponseSuccessSchema: () => import_shared_schemas2.NewLoginResponseSuccessSchema,
|
|
32
|
+
StateHeatmapEntrySchema: () => import_shared_schemas2.StateHeatmapEntrySchema,
|
|
33
|
+
StateHeatmapRequestSchema: () => import_shared_schemas2.StateHeatmapRequestSchema,
|
|
34
|
+
StateHeatmapResponseSchema: () => import_shared_schemas2.StateHeatmapResponseSchema,
|
|
29
35
|
ValidatePasswordRequestSchema: () => import_shared_schemas2.ValidatePasswordRequestSchema,
|
|
30
36
|
ValidatePasswordResponseSchema: () => import_shared_schemas2.ValidatePasswordResponseSchema,
|
|
31
37
|
endpoints: () => endpoints
|
|
@@ -46,6 +52,18 @@ var endpoints = {
|
|
|
46
52
|
method: "POST",
|
|
47
53
|
requestSchema: import_shared_schemas.ValidatePasswordRequestSchema,
|
|
48
54
|
responseSchema: import_shared_schemas.ValidatePasswordResponseSchema
|
|
55
|
+
},
|
|
56
|
+
driverRankings: {
|
|
57
|
+
path: "/telemetry/driver-rankings",
|
|
58
|
+
method: "GET",
|
|
59
|
+
requestSchema: import_shared_schemas.DriverRankingsRequestSchema,
|
|
60
|
+
responseSchema: import_shared_schemas.DriverRankingsResponseSchema
|
|
61
|
+
},
|
|
62
|
+
stateHeatmap: {
|
|
63
|
+
path: "/telemetry/driver/:driver_id/heatmap",
|
|
64
|
+
method: "GET",
|
|
65
|
+
requestSchema: import_shared_schemas.StateHeatmapRequestSchema,
|
|
66
|
+
responseSchema: import_shared_schemas.StateHeatmapResponseSchema
|
|
49
67
|
}
|
|
50
68
|
};
|
|
51
69
|
|
|
@@ -116,6 +134,61 @@ var AggregatorClient = class {
|
|
|
116
134
|
}
|
|
117
135
|
return responseParseResult.data;
|
|
118
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Gets all drivers ranked by miles driven within a time range.
|
|
139
|
+
* Optionally filter by state.
|
|
140
|
+
*/
|
|
141
|
+
async driverRankings(request) {
|
|
142
|
+
const endpoint = endpoints.driverRankings;
|
|
143
|
+
const parseResult = endpoint.requestSchema.safeParse(request);
|
|
144
|
+
if (!parseResult.success) {
|
|
145
|
+
throw new AggregatorClientError(
|
|
146
|
+
`Invalid request: ${parseResult.error.message}`,
|
|
147
|
+
endpoint.path
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
const response = await this.makeGetRequest(endpoint.path, request);
|
|
151
|
+
const responseParseResult = endpoint.responseSchema.safeParse(response);
|
|
152
|
+
if (!responseParseResult.success) {
|
|
153
|
+
throw new AggregatorClientError(
|
|
154
|
+
`Invalid response from aggregator: ${responseParseResult.error.message}`,
|
|
155
|
+
endpoint.path,
|
|
156
|
+
void 0,
|
|
157
|
+
response
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
return responseParseResult.data;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Gets a heatmap of telemetry locations by state for a specific driver.
|
|
164
|
+
* Returns the count and percentage of telemetry points in each state.
|
|
165
|
+
*/
|
|
166
|
+
async stateHeatmap(request) {
|
|
167
|
+
const endpoint = endpoints.stateHeatmap;
|
|
168
|
+
const parseResult = endpoint.requestSchema.safeParse(request);
|
|
169
|
+
if (!parseResult.success) {
|
|
170
|
+
throw new AggregatorClientError(
|
|
171
|
+
`Invalid request: ${parseResult.error.message}`,
|
|
172
|
+
endpoint.path
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
const path = endpoint.path.replace(":driver_id", request.driver_id);
|
|
176
|
+
const queryParams = {
|
|
177
|
+
start_date: request.start_date,
|
|
178
|
+
end_date: request.end_date
|
|
179
|
+
};
|
|
180
|
+
const response = await this.makeGetRequest(path, queryParams);
|
|
181
|
+
const responseParseResult = endpoint.responseSchema.safeParse(response);
|
|
182
|
+
if (!responseParseResult.success) {
|
|
183
|
+
throw new AggregatorClientError(
|
|
184
|
+
`Invalid response from aggregator: ${responseParseResult.error.message}`,
|
|
185
|
+
endpoint.path,
|
|
186
|
+
void 0,
|
|
187
|
+
response
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
return responseParseResult.data;
|
|
191
|
+
}
|
|
119
192
|
async makeRequest(path, method, body) {
|
|
120
193
|
const url = `${this.baseUrl}${path}`;
|
|
121
194
|
const response = await fetch(url, {
|
|
@@ -142,6 +215,36 @@ var AggregatorClient = class {
|
|
|
142
215
|
}
|
|
143
216
|
return response.json();
|
|
144
217
|
}
|
|
218
|
+
async makeGetRequest(path, params) {
|
|
219
|
+
const searchParams = new URLSearchParams();
|
|
220
|
+
for (const [key, value] of Object.entries(params)) {
|
|
221
|
+
if (value !== void 0) {
|
|
222
|
+
searchParams.append(key, value);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const url = `${this.baseUrl}${path}?${searchParams.toString()}`;
|
|
226
|
+
const response = await fetch(url, {
|
|
227
|
+
method: "GET",
|
|
228
|
+
headers: {
|
|
229
|
+
"Authorization": `Bearer ${this.workerSecret}`
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
if (!response.ok) {
|
|
233
|
+
let responseBody;
|
|
234
|
+
try {
|
|
235
|
+
responseBody = await response.json();
|
|
236
|
+
} catch {
|
|
237
|
+
responseBody = await response.text();
|
|
238
|
+
}
|
|
239
|
+
throw new AggregatorClientError(
|
|
240
|
+
`Request to ${path} failed with status ${response.status}`,
|
|
241
|
+
path,
|
|
242
|
+
response.status,
|
|
243
|
+
responseBody
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
return response.json();
|
|
247
|
+
}
|
|
145
248
|
};
|
|
146
249
|
|
|
147
250
|
// src/index.ts
|
|
@@ -150,10 +253,16 @@ var import_shared_schemas2 = require("@findatruck/shared-schemas");
|
|
|
150
253
|
0 && (module.exports = {
|
|
151
254
|
AggregatorClient,
|
|
152
255
|
AggregatorClientError,
|
|
256
|
+
DriverRankingSchema,
|
|
257
|
+
DriverRankingsRequestSchema,
|
|
258
|
+
DriverRankingsResponseSchema,
|
|
153
259
|
NewLoginRequestSchema,
|
|
154
260
|
NewLoginResponseFailureSchema,
|
|
155
261
|
NewLoginResponseSchema,
|
|
156
262
|
NewLoginResponseSuccessSchema,
|
|
263
|
+
StateHeatmapEntrySchema,
|
|
264
|
+
StateHeatmapRequestSchema,
|
|
265
|
+
StateHeatmapResponseSchema,
|
|
157
266
|
ValidatePasswordRequestSchema,
|
|
158
267
|
ValidatePasswordResponseSchema,
|
|
159
268
|
endpoints
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NewLoginRequest, NewLoginResponse, ValidatePasswordRequest, ValidatePasswordResponse } from '@findatruck/shared-schemas';
|
|
2
|
-
export { NewLoginRequest, NewLoginRequestSchema, NewLoginResponse, NewLoginResponseFailure, NewLoginResponseFailureSchema, NewLoginResponseSchema, NewLoginResponseSuccess, NewLoginResponseSuccessSchema, ValidatePasswordRequest, ValidatePasswordRequestSchema, ValidatePasswordResponse, ValidatePasswordResponseSchema } from '@findatruck/shared-schemas';
|
|
1
|
+
import { NewLoginRequest, NewLoginResponse, ValidatePasswordRequest, ValidatePasswordResponse, DriverRankingsRequest, DriverRankingsResponse, StateHeatmapRequest, StateHeatmapResponse } from '@findatruck/shared-schemas';
|
|
2
|
+
export { DriverRanking, DriverRankingSchema, DriverRankingsRequest, DriverRankingsRequestSchema, DriverRankingsResponse, DriverRankingsResponseSchema, NewLoginRequest, NewLoginRequestSchema, NewLoginResponse, NewLoginResponseFailure, NewLoginResponseFailureSchema, NewLoginResponseSchema, NewLoginResponseSuccess, NewLoginResponseSuccessSchema, StateHeatmapEntry, StateHeatmapEntrySchema, StateHeatmapRequest, StateHeatmapRequestSchema, StateHeatmapResponse, StateHeatmapResponseSchema, ValidatePasswordRequest, ValidatePasswordRequestSchema, ValidatePasswordResponse, ValidatePasswordResponseSchema } from '@findatruck/shared-schemas';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -55,7 +55,18 @@ declare class AggregatorClient {
|
|
|
55
55
|
* Returns whether the password is valid and the associated driver IDs.
|
|
56
56
|
*/
|
|
57
57
|
validatePassword(request: ValidatePasswordRequest): Promise<ValidatePasswordResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* Gets all drivers ranked by miles driven within a time range.
|
|
60
|
+
* Optionally filter by state.
|
|
61
|
+
*/
|
|
62
|
+
driverRankings(request: DriverRankingsRequest): Promise<DriverRankingsResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* Gets a heatmap of telemetry locations by state for a specific driver.
|
|
65
|
+
* Returns the count and percentage of telemetry points in each state.
|
|
66
|
+
*/
|
|
67
|
+
stateHeatmap(request: StateHeatmapRequest): Promise<StateHeatmapResponse>;
|
|
58
68
|
private makeRequest;
|
|
69
|
+
private makeGetRequest;
|
|
59
70
|
}
|
|
60
71
|
|
|
61
72
|
/**
|
|
@@ -116,6 +127,34 @@ declare const endpoints: {
|
|
|
116
127
|
driverIds: z.ZodArray<z.ZodString>;
|
|
117
128
|
}, z.core.$strip>;
|
|
118
129
|
};
|
|
130
|
+
readonly driverRankings: {
|
|
131
|
+
readonly path: "/telemetry/driver-rankings";
|
|
132
|
+
readonly method: "GET";
|
|
133
|
+
readonly requestSchema: z.ZodObject<{
|
|
134
|
+
start_date: z.ZodString;
|
|
135
|
+
end_date: z.ZodString;
|
|
136
|
+
state: z.ZodOptional<z.ZodString>;
|
|
137
|
+
}, z.core.$strip>;
|
|
138
|
+
readonly responseSchema: z.ZodArray<z.ZodObject<{
|
|
139
|
+
rank: z.ZodNumber;
|
|
140
|
+
driver_id: z.ZodString;
|
|
141
|
+
driver_name: z.ZodString;
|
|
142
|
+
total_miles: z.ZodNumber;
|
|
143
|
+
}, z.core.$strip>>;
|
|
144
|
+
};
|
|
145
|
+
readonly stateHeatmap: {
|
|
146
|
+
readonly path: "/telemetry/driver/:driver_id/heatmap";
|
|
147
|
+
readonly method: "GET";
|
|
148
|
+
readonly requestSchema: z.ZodObject<{
|
|
149
|
+
driver_id: z.ZodString;
|
|
150
|
+
start_date: z.ZodString;
|
|
151
|
+
end_date: z.ZodString;
|
|
152
|
+
}, z.core.$strip>;
|
|
153
|
+
readonly responseSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
154
|
+
count: z.ZodNumber;
|
|
155
|
+
percentage: z.ZodNumber;
|
|
156
|
+
}, z.core.$strip>>;
|
|
157
|
+
};
|
|
119
158
|
};
|
|
120
159
|
type EndpointName = keyof typeof endpoints;
|
|
121
160
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NewLoginRequest, NewLoginResponse, ValidatePasswordRequest, ValidatePasswordResponse } from '@findatruck/shared-schemas';
|
|
2
|
-
export { NewLoginRequest, NewLoginRequestSchema, NewLoginResponse, NewLoginResponseFailure, NewLoginResponseFailureSchema, NewLoginResponseSchema, NewLoginResponseSuccess, NewLoginResponseSuccessSchema, ValidatePasswordRequest, ValidatePasswordRequestSchema, ValidatePasswordResponse, ValidatePasswordResponseSchema } from '@findatruck/shared-schemas';
|
|
1
|
+
import { NewLoginRequest, NewLoginResponse, ValidatePasswordRequest, ValidatePasswordResponse, DriverRankingsRequest, DriverRankingsResponse, StateHeatmapRequest, StateHeatmapResponse } from '@findatruck/shared-schemas';
|
|
2
|
+
export { DriverRanking, DriverRankingSchema, DriverRankingsRequest, DriverRankingsRequestSchema, DriverRankingsResponse, DriverRankingsResponseSchema, NewLoginRequest, NewLoginRequestSchema, NewLoginResponse, NewLoginResponseFailure, NewLoginResponseFailureSchema, NewLoginResponseSchema, NewLoginResponseSuccess, NewLoginResponseSuccessSchema, StateHeatmapEntry, StateHeatmapEntrySchema, StateHeatmapRequest, StateHeatmapRequestSchema, StateHeatmapResponse, StateHeatmapResponseSchema, ValidatePasswordRequest, ValidatePasswordRequestSchema, ValidatePasswordResponse, ValidatePasswordResponseSchema } from '@findatruck/shared-schemas';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -55,7 +55,18 @@ declare class AggregatorClient {
|
|
|
55
55
|
* Returns whether the password is valid and the associated driver IDs.
|
|
56
56
|
*/
|
|
57
57
|
validatePassword(request: ValidatePasswordRequest): Promise<ValidatePasswordResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* Gets all drivers ranked by miles driven within a time range.
|
|
60
|
+
* Optionally filter by state.
|
|
61
|
+
*/
|
|
62
|
+
driverRankings(request: DriverRankingsRequest): Promise<DriverRankingsResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* Gets a heatmap of telemetry locations by state for a specific driver.
|
|
65
|
+
* Returns the count and percentage of telemetry points in each state.
|
|
66
|
+
*/
|
|
67
|
+
stateHeatmap(request: StateHeatmapRequest): Promise<StateHeatmapResponse>;
|
|
58
68
|
private makeRequest;
|
|
69
|
+
private makeGetRequest;
|
|
59
70
|
}
|
|
60
71
|
|
|
61
72
|
/**
|
|
@@ -116,6 +127,34 @@ declare const endpoints: {
|
|
|
116
127
|
driverIds: z.ZodArray<z.ZodString>;
|
|
117
128
|
}, z.core.$strip>;
|
|
118
129
|
};
|
|
130
|
+
readonly driverRankings: {
|
|
131
|
+
readonly path: "/telemetry/driver-rankings";
|
|
132
|
+
readonly method: "GET";
|
|
133
|
+
readonly requestSchema: z.ZodObject<{
|
|
134
|
+
start_date: z.ZodString;
|
|
135
|
+
end_date: z.ZodString;
|
|
136
|
+
state: z.ZodOptional<z.ZodString>;
|
|
137
|
+
}, z.core.$strip>;
|
|
138
|
+
readonly responseSchema: z.ZodArray<z.ZodObject<{
|
|
139
|
+
rank: z.ZodNumber;
|
|
140
|
+
driver_id: z.ZodString;
|
|
141
|
+
driver_name: z.ZodString;
|
|
142
|
+
total_miles: z.ZodNumber;
|
|
143
|
+
}, z.core.$strip>>;
|
|
144
|
+
};
|
|
145
|
+
readonly stateHeatmap: {
|
|
146
|
+
readonly path: "/telemetry/driver/:driver_id/heatmap";
|
|
147
|
+
readonly method: "GET";
|
|
148
|
+
readonly requestSchema: z.ZodObject<{
|
|
149
|
+
driver_id: z.ZodString;
|
|
150
|
+
start_date: z.ZodString;
|
|
151
|
+
end_date: z.ZodString;
|
|
152
|
+
}, z.core.$strip>;
|
|
153
|
+
readonly responseSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
154
|
+
count: z.ZodNumber;
|
|
155
|
+
percentage: z.ZodNumber;
|
|
156
|
+
}, z.core.$strip>>;
|
|
157
|
+
};
|
|
119
158
|
};
|
|
120
159
|
type EndpointName = keyof typeof endpoints;
|
|
121
160
|
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,11 @@ import {
|
|
|
3
3
|
NewLoginRequestSchema,
|
|
4
4
|
NewLoginResponseSchema,
|
|
5
5
|
ValidatePasswordRequestSchema,
|
|
6
|
-
ValidatePasswordResponseSchema
|
|
6
|
+
ValidatePasswordResponseSchema,
|
|
7
|
+
DriverRankingsRequestSchema,
|
|
8
|
+
DriverRankingsResponseSchema,
|
|
9
|
+
StateHeatmapRequestSchema,
|
|
10
|
+
StateHeatmapResponseSchema
|
|
7
11
|
} from "@findatruck/shared-schemas";
|
|
8
12
|
var endpoints = {
|
|
9
13
|
newLogin: {
|
|
@@ -17,6 +21,18 @@ var endpoints = {
|
|
|
17
21
|
method: "POST",
|
|
18
22
|
requestSchema: ValidatePasswordRequestSchema,
|
|
19
23
|
responseSchema: ValidatePasswordResponseSchema
|
|
24
|
+
},
|
|
25
|
+
driverRankings: {
|
|
26
|
+
path: "/telemetry/driver-rankings",
|
|
27
|
+
method: "GET",
|
|
28
|
+
requestSchema: DriverRankingsRequestSchema,
|
|
29
|
+
responseSchema: DriverRankingsResponseSchema
|
|
30
|
+
},
|
|
31
|
+
stateHeatmap: {
|
|
32
|
+
path: "/telemetry/driver/:driver_id/heatmap",
|
|
33
|
+
method: "GET",
|
|
34
|
+
requestSchema: StateHeatmapRequestSchema,
|
|
35
|
+
responseSchema: StateHeatmapResponseSchema
|
|
20
36
|
}
|
|
21
37
|
};
|
|
22
38
|
|
|
@@ -87,6 +103,61 @@ var AggregatorClient = class {
|
|
|
87
103
|
}
|
|
88
104
|
return responseParseResult.data;
|
|
89
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Gets all drivers ranked by miles driven within a time range.
|
|
108
|
+
* Optionally filter by state.
|
|
109
|
+
*/
|
|
110
|
+
async driverRankings(request) {
|
|
111
|
+
const endpoint = endpoints.driverRankings;
|
|
112
|
+
const parseResult = endpoint.requestSchema.safeParse(request);
|
|
113
|
+
if (!parseResult.success) {
|
|
114
|
+
throw new AggregatorClientError(
|
|
115
|
+
`Invalid request: ${parseResult.error.message}`,
|
|
116
|
+
endpoint.path
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
const response = await this.makeGetRequest(endpoint.path, request);
|
|
120
|
+
const responseParseResult = endpoint.responseSchema.safeParse(response);
|
|
121
|
+
if (!responseParseResult.success) {
|
|
122
|
+
throw new AggregatorClientError(
|
|
123
|
+
`Invalid response from aggregator: ${responseParseResult.error.message}`,
|
|
124
|
+
endpoint.path,
|
|
125
|
+
void 0,
|
|
126
|
+
response
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return responseParseResult.data;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets a heatmap of telemetry locations by state for a specific driver.
|
|
133
|
+
* Returns the count and percentage of telemetry points in each state.
|
|
134
|
+
*/
|
|
135
|
+
async stateHeatmap(request) {
|
|
136
|
+
const endpoint = endpoints.stateHeatmap;
|
|
137
|
+
const parseResult = endpoint.requestSchema.safeParse(request);
|
|
138
|
+
if (!parseResult.success) {
|
|
139
|
+
throw new AggregatorClientError(
|
|
140
|
+
`Invalid request: ${parseResult.error.message}`,
|
|
141
|
+
endpoint.path
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
const path = endpoint.path.replace(":driver_id", request.driver_id);
|
|
145
|
+
const queryParams = {
|
|
146
|
+
start_date: request.start_date,
|
|
147
|
+
end_date: request.end_date
|
|
148
|
+
};
|
|
149
|
+
const response = await this.makeGetRequest(path, queryParams);
|
|
150
|
+
const responseParseResult = endpoint.responseSchema.safeParse(response);
|
|
151
|
+
if (!responseParseResult.success) {
|
|
152
|
+
throw new AggregatorClientError(
|
|
153
|
+
`Invalid response from aggregator: ${responseParseResult.error.message}`,
|
|
154
|
+
endpoint.path,
|
|
155
|
+
void 0,
|
|
156
|
+
response
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
return responseParseResult.data;
|
|
160
|
+
}
|
|
90
161
|
async makeRequest(path, method, body) {
|
|
91
162
|
const url = `${this.baseUrl}${path}`;
|
|
92
163
|
const response = await fetch(url, {
|
|
@@ -113,6 +184,36 @@ var AggregatorClient = class {
|
|
|
113
184
|
}
|
|
114
185
|
return response.json();
|
|
115
186
|
}
|
|
187
|
+
async makeGetRequest(path, params) {
|
|
188
|
+
const searchParams = new URLSearchParams();
|
|
189
|
+
for (const [key, value] of Object.entries(params)) {
|
|
190
|
+
if (value !== void 0) {
|
|
191
|
+
searchParams.append(key, value);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const url = `${this.baseUrl}${path}?${searchParams.toString()}`;
|
|
195
|
+
const response = await fetch(url, {
|
|
196
|
+
method: "GET",
|
|
197
|
+
headers: {
|
|
198
|
+
"Authorization": `Bearer ${this.workerSecret}`
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
if (!response.ok) {
|
|
202
|
+
let responseBody;
|
|
203
|
+
try {
|
|
204
|
+
responseBody = await response.json();
|
|
205
|
+
} catch {
|
|
206
|
+
responseBody = await response.text();
|
|
207
|
+
}
|
|
208
|
+
throw new AggregatorClientError(
|
|
209
|
+
`Request to ${path} failed with status ${response.status}`,
|
|
210
|
+
path,
|
|
211
|
+
response.status,
|
|
212
|
+
responseBody
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
return response.json();
|
|
216
|
+
}
|
|
116
217
|
};
|
|
117
218
|
|
|
118
219
|
// src/index.ts
|
|
@@ -122,15 +223,27 @@ import {
|
|
|
122
223
|
NewLoginResponseSuccessSchema,
|
|
123
224
|
NewLoginResponseFailureSchema,
|
|
124
225
|
ValidatePasswordRequestSchema as ValidatePasswordRequestSchema2,
|
|
125
|
-
ValidatePasswordResponseSchema as ValidatePasswordResponseSchema2
|
|
226
|
+
ValidatePasswordResponseSchema as ValidatePasswordResponseSchema2,
|
|
227
|
+
DriverRankingsRequestSchema as DriverRankingsRequestSchema2,
|
|
228
|
+
DriverRankingsResponseSchema as DriverRankingsResponseSchema2,
|
|
229
|
+
DriverRankingSchema,
|
|
230
|
+
StateHeatmapRequestSchema as StateHeatmapRequestSchema2,
|
|
231
|
+
StateHeatmapResponseSchema as StateHeatmapResponseSchema2,
|
|
232
|
+
StateHeatmapEntrySchema
|
|
126
233
|
} from "@findatruck/shared-schemas";
|
|
127
234
|
export {
|
|
128
235
|
AggregatorClient,
|
|
129
236
|
AggregatorClientError,
|
|
237
|
+
DriverRankingSchema,
|
|
238
|
+
DriverRankingsRequestSchema2 as DriverRankingsRequestSchema,
|
|
239
|
+
DriverRankingsResponseSchema2 as DriverRankingsResponseSchema,
|
|
130
240
|
NewLoginRequestSchema2 as NewLoginRequestSchema,
|
|
131
241
|
NewLoginResponseFailureSchema,
|
|
132
242
|
NewLoginResponseSchema2 as NewLoginResponseSchema,
|
|
133
243
|
NewLoginResponseSuccessSchema,
|
|
244
|
+
StateHeatmapEntrySchema,
|
|
245
|
+
StateHeatmapRequestSchema2 as StateHeatmapRequestSchema,
|
|
246
|
+
StateHeatmapResponseSchema2 as StateHeatmapResponseSchema,
|
|
134
247
|
ValidatePasswordRequestSchema2 as ValidatePasswordRequestSchema,
|
|
135
248
|
ValidatePasswordResponseSchema2 as ValidatePasswordResponseSchema,
|
|
136
249
|
endpoints
|