@findatruck/aggregator-client 1.3.0 → 1.4.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 CHANGED
@@ -22,6 +22,9 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AggregatorClient: () => AggregatorClient,
24
24
  AggregatorClientError: () => AggregatorClientError,
25
+ AnonymousDriverErrorResponseSchema: () => import_shared_schemas2.AnonymousDriverErrorResponseSchema,
26
+ AnonymousDriverResponseSchema: () => import_shared_schemas2.AnonymousDriverResponseSchema,
27
+ CreateAnonymousDriverBodySchema: () => import_shared_schemas2.CreateAnonymousDriverBodySchema,
25
28
  DeleteProviderAccountRequestSchema: () => import_shared_schemas2.DeleteProviderAccountRequestSchema,
26
29
  DeleteProviderAccountResponseSchema: () => import_shared_schemas2.DeleteProviderAccountResponseSchema,
27
30
  DriverRankingSchema: () => import_shared_schemas2.DriverRankingSchema,
@@ -82,6 +85,12 @@ var endpoints = {
82
85
  method: "POST",
83
86
  requestSchema: import_shared_schemas.ManualBatchRequestSchema,
84
87
  responseSchema: import_shared_schemas.ManualBatchResponseSchema
88
+ },
89
+ anonymousDriver: {
90
+ path: "/anonymous-driver",
91
+ method: "POST",
92
+ requestSchema: import_shared_schemas.CreateAnonymousDriverBodySchema,
93
+ responseSchema: import_shared_schemas.AnonymousDriverResponseSchema
85
94
  }
86
95
  };
87
96
 
@@ -257,6 +266,30 @@ var AggregatorClient = class {
257
266
  }
258
267
  return responseParseResult.data;
259
268
  }
269
+ /**
270
+ * Creates an anonymous driver for GPS-only users without ELD login.
271
+ */
272
+ async anonymousDriver(request) {
273
+ const endpoint = endpoints.anonymousDriver;
274
+ const parseResult = endpoint.requestSchema.safeParse(request);
275
+ if (!parseResult.success) {
276
+ throw new AggregatorClientError(
277
+ `Invalid request: ${parseResult.error.message}`,
278
+ endpoint.path
279
+ );
280
+ }
281
+ const response = await this.makeRequest(endpoint.path, endpoint.method, request);
282
+ const responseParseResult = endpoint.responseSchema.safeParse(response);
283
+ if (!responseParseResult.success) {
284
+ throw new AggregatorClientError(
285
+ `Invalid response from aggregator: ${responseParseResult.error.message}`,
286
+ endpoint.path,
287
+ void 0,
288
+ response
289
+ );
290
+ }
291
+ return responseParseResult.data;
292
+ }
260
293
  async makeRequest(path, method, body) {
261
294
  const url = `${this.baseUrl}${path}`;
262
295
  const response = await fetch(url, {
@@ -268,11 +301,12 @@ var AggregatorClient = class {
268
301
  body: JSON.stringify(body)
269
302
  });
270
303
  if (!response.ok) {
304
+ const text = await response.text();
271
305
  let responseBody;
272
306
  try {
273
- responseBody = await response.json();
307
+ responseBody = JSON.parse(text);
274
308
  } catch {
275
- responseBody = await response.text();
309
+ responseBody = text;
276
310
  }
277
311
  throw new AggregatorClientError(
278
312
  `Request to ${path} failed with status ${response.status}`,
@@ -298,11 +332,12 @@ var AggregatorClient = class {
298
332
  }
299
333
  });
300
334
  if (!response.ok) {
335
+ const text = await response.text();
301
336
  let responseBody;
302
337
  try {
303
- responseBody = await response.json();
338
+ responseBody = JSON.parse(text);
304
339
  } catch {
305
- responseBody = await response.text();
340
+ responseBody = text;
306
341
  }
307
342
  throw new AggregatorClientError(
308
343
  `Request to ${path} failed with status ${response.status}`,
@@ -321,6 +356,9 @@ var import_shared_schemas2 = require("@findatruck/shared-schemas");
321
356
  0 && (module.exports = {
322
357
  AggregatorClient,
323
358
  AggregatorClientError,
359
+ AnonymousDriverErrorResponseSchema,
360
+ AnonymousDriverResponseSchema,
361
+ CreateAnonymousDriverBodySchema,
324
362
  DeleteProviderAccountRequestSchema,
325
363
  DeleteProviderAccountResponseSchema,
326
364
  DriverRankingSchema,
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { NewLoginRequest, NewLoginResponse, ValidatePasswordRequest, ValidatePasswordResponse, DeleteProviderAccountRequest, DeleteProviderAccountResponse, DriverRankingsRequest, DriverRankingsResponse, StateHeatmapRequest, StateHeatmapResponse, ManualBatchRequest, ManualBatchResponse } from '@findatruck/shared-schemas';
2
- export { DeleteProviderAccountRequest, DeleteProviderAccountRequestSchema, DeleteProviderAccountResponse, DeleteProviderAccountResponseSchema, DriverRanking, DriverRankingSchema, DriverRankingsRequest, DriverRankingsRequestSchema, DriverRankingsResponse, DriverRankingsResponseSchema, ManualBatchEntry, ManualBatchEntrySchema, ManualBatchRequest, ManualBatchRequestSchema, ManualBatchResponse, ManualBatchResponseSchema, ManualBatchTelemetry, ManualBatchTelemetrySchema, NewLoginRequest, NewLoginRequestSchema, NewLoginResponse, NewLoginResponseFailure, NewLoginResponseFailureSchema, NewLoginResponseSchema, NewLoginResponseSuccess, NewLoginResponseSuccessSchema, StateHeatmapEntry, StateHeatmapEntrySchema, StateHeatmapRequest, StateHeatmapRequestSchema, StateHeatmapResponse, StateHeatmapResponseSchema, ValidatePasswordRequest, ValidatePasswordRequestSchema, ValidatePasswordResponse, ValidatePasswordResponseSchema } from '@findatruck/shared-schemas';
1
+ import { NewLoginRequest, NewLoginResponse, ValidatePasswordRequest, ValidatePasswordResponse, DeleteProviderAccountRequest, DeleteProviderAccountResponse, DriverRankingsRequest, DriverRankingsResponse, StateHeatmapRequest, StateHeatmapResponse, ManualBatchRequest, ManualBatchResponse, CreateAnonymousDriverBody, AnonymousDriverResponse } from '@findatruck/shared-schemas';
2
+ export { AnonymousDriverErrorResponse, AnonymousDriverErrorResponseSchema, AnonymousDriverResponse, AnonymousDriverResponseSchema, CreateAnonymousDriverBody, CreateAnonymousDriverBodySchema, DeleteProviderAccountRequest, DeleteProviderAccountRequestSchema, DeleteProviderAccountResponse, DeleteProviderAccountResponseSchema, DriverRanking, DriverRankingSchema, DriverRankingsRequest, DriverRankingsRequestSchema, DriverRankingsResponse, DriverRankingsResponseSchema, ManualBatchEntry, ManualBatchEntrySchema, ManualBatchRequest, ManualBatchRequestSchema, ManualBatchResponse, ManualBatchResponseSchema, ManualBatchTelemetry, ManualBatchTelemetrySchema, 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
  /**
@@ -75,6 +75,10 @@ declare class AggregatorClient {
75
75
  * Used for non-ELD sources (external GPS trackers, etc.).
76
76
  */
77
77
  manualBatch(request: ManualBatchRequest): Promise<ManualBatchResponse>;
78
+ /**
79
+ * Creates an anonymous driver for GPS-only users without ELD login.
80
+ */
81
+ anonymousDriver(request: CreateAnonymousDriverBody): Promise<AnonymousDriverResponse>;
78
82
  private makeRequest;
79
83
  private makeGetRequest;
80
84
  }
@@ -213,6 +217,16 @@ declare const endpoints: {
213
217
  }, z.core.$strip>>;
214
218
  }, z.core.$strip>;
215
219
  };
220
+ readonly anonymousDriver: {
221
+ readonly path: "/anonymous-driver";
222
+ readonly method: "POST";
223
+ readonly requestSchema: z.ZodObject<{
224
+ convex_user_id: z.ZodString;
225
+ }, z.core.$strip>;
226
+ readonly responseSchema: z.ZodObject<{
227
+ driver_id: z.ZodString;
228
+ }, z.core.$strip>;
229
+ };
216
230
  };
217
231
  type EndpointName = keyof typeof endpoints;
218
232
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { NewLoginRequest, NewLoginResponse, ValidatePasswordRequest, ValidatePasswordResponse, DeleteProviderAccountRequest, DeleteProviderAccountResponse, DriverRankingsRequest, DriverRankingsResponse, StateHeatmapRequest, StateHeatmapResponse, ManualBatchRequest, ManualBatchResponse } from '@findatruck/shared-schemas';
2
- export { DeleteProviderAccountRequest, DeleteProviderAccountRequestSchema, DeleteProviderAccountResponse, DeleteProviderAccountResponseSchema, DriverRanking, DriverRankingSchema, DriverRankingsRequest, DriverRankingsRequestSchema, DriverRankingsResponse, DriverRankingsResponseSchema, ManualBatchEntry, ManualBatchEntrySchema, ManualBatchRequest, ManualBatchRequestSchema, ManualBatchResponse, ManualBatchResponseSchema, ManualBatchTelemetry, ManualBatchTelemetrySchema, NewLoginRequest, NewLoginRequestSchema, NewLoginResponse, NewLoginResponseFailure, NewLoginResponseFailureSchema, NewLoginResponseSchema, NewLoginResponseSuccess, NewLoginResponseSuccessSchema, StateHeatmapEntry, StateHeatmapEntrySchema, StateHeatmapRequest, StateHeatmapRequestSchema, StateHeatmapResponse, StateHeatmapResponseSchema, ValidatePasswordRequest, ValidatePasswordRequestSchema, ValidatePasswordResponse, ValidatePasswordResponseSchema } from '@findatruck/shared-schemas';
1
+ import { NewLoginRequest, NewLoginResponse, ValidatePasswordRequest, ValidatePasswordResponse, DeleteProviderAccountRequest, DeleteProviderAccountResponse, DriverRankingsRequest, DriverRankingsResponse, StateHeatmapRequest, StateHeatmapResponse, ManualBatchRequest, ManualBatchResponse, CreateAnonymousDriverBody, AnonymousDriverResponse } from '@findatruck/shared-schemas';
2
+ export { AnonymousDriverErrorResponse, AnonymousDriverErrorResponseSchema, AnonymousDriverResponse, AnonymousDriverResponseSchema, CreateAnonymousDriverBody, CreateAnonymousDriverBodySchema, DeleteProviderAccountRequest, DeleteProviderAccountRequestSchema, DeleteProviderAccountResponse, DeleteProviderAccountResponseSchema, DriverRanking, DriverRankingSchema, DriverRankingsRequest, DriverRankingsRequestSchema, DriverRankingsResponse, DriverRankingsResponseSchema, ManualBatchEntry, ManualBatchEntrySchema, ManualBatchRequest, ManualBatchRequestSchema, ManualBatchResponse, ManualBatchResponseSchema, ManualBatchTelemetry, ManualBatchTelemetrySchema, 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
  /**
@@ -75,6 +75,10 @@ declare class AggregatorClient {
75
75
  * Used for non-ELD sources (external GPS trackers, etc.).
76
76
  */
77
77
  manualBatch(request: ManualBatchRequest): Promise<ManualBatchResponse>;
78
+ /**
79
+ * Creates an anonymous driver for GPS-only users without ELD login.
80
+ */
81
+ anonymousDriver(request: CreateAnonymousDriverBody): Promise<AnonymousDriverResponse>;
78
82
  private makeRequest;
79
83
  private makeGetRequest;
80
84
  }
@@ -213,6 +217,16 @@ declare const endpoints: {
213
217
  }, z.core.$strip>>;
214
218
  }, z.core.$strip>;
215
219
  };
220
+ readonly anonymousDriver: {
221
+ readonly path: "/anonymous-driver";
222
+ readonly method: "POST";
223
+ readonly requestSchema: z.ZodObject<{
224
+ convex_user_id: z.ZodString;
225
+ }, z.core.$strip>;
226
+ readonly responseSchema: z.ZodObject<{
227
+ driver_id: z.ZodString;
228
+ }, z.core.$strip>;
229
+ };
216
230
  };
217
231
  type EndpointName = keyof typeof endpoints;
218
232
 
package/dist/index.js CHANGED
@@ -11,7 +11,9 @@ import {
11
11
  StateHeatmapRequestSchema,
12
12
  StateHeatmapResponseSchema,
13
13
  ManualBatchRequestSchema,
14
- ManualBatchResponseSchema
14
+ ManualBatchResponseSchema,
15
+ CreateAnonymousDriverBodySchema,
16
+ AnonymousDriverResponseSchema
15
17
  } from "@findatruck/shared-schemas";
16
18
  var endpoints = {
17
19
  newLogin: {
@@ -49,6 +51,12 @@ var endpoints = {
49
51
  method: "POST",
50
52
  requestSchema: ManualBatchRequestSchema,
51
53
  responseSchema: ManualBatchResponseSchema
54
+ },
55
+ anonymousDriver: {
56
+ path: "/anonymous-driver",
57
+ method: "POST",
58
+ requestSchema: CreateAnonymousDriverBodySchema,
59
+ responseSchema: AnonymousDriverResponseSchema
52
60
  }
53
61
  };
54
62
 
@@ -224,6 +232,30 @@ var AggregatorClient = class {
224
232
  }
225
233
  return responseParseResult.data;
226
234
  }
235
+ /**
236
+ * Creates an anonymous driver for GPS-only users without ELD login.
237
+ */
238
+ async anonymousDriver(request) {
239
+ const endpoint = endpoints.anonymousDriver;
240
+ const parseResult = endpoint.requestSchema.safeParse(request);
241
+ if (!parseResult.success) {
242
+ throw new AggregatorClientError(
243
+ `Invalid request: ${parseResult.error.message}`,
244
+ endpoint.path
245
+ );
246
+ }
247
+ const response = await this.makeRequest(endpoint.path, endpoint.method, request);
248
+ const responseParseResult = endpoint.responseSchema.safeParse(response);
249
+ if (!responseParseResult.success) {
250
+ throw new AggregatorClientError(
251
+ `Invalid response from aggregator: ${responseParseResult.error.message}`,
252
+ endpoint.path,
253
+ void 0,
254
+ response
255
+ );
256
+ }
257
+ return responseParseResult.data;
258
+ }
227
259
  async makeRequest(path, method, body) {
228
260
  const url = `${this.baseUrl}${path}`;
229
261
  const response = await fetch(url, {
@@ -235,11 +267,12 @@ var AggregatorClient = class {
235
267
  body: JSON.stringify(body)
236
268
  });
237
269
  if (!response.ok) {
270
+ const text = await response.text();
238
271
  let responseBody;
239
272
  try {
240
- responseBody = await response.json();
273
+ responseBody = JSON.parse(text);
241
274
  } catch {
242
- responseBody = await response.text();
275
+ responseBody = text;
243
276
  }
244
277
  throw new AggregatorClientError(
245
278
  `Request to ${path} failed with status ${response.status}`,
@@ -265,11 +298,12 @@ var AggregatorClient = class {
265
298
  }
266
299
  });
267
300
  if (!response.ok) {
301
+ const text = await response.text();
268
302
  let responseBody;
269
303
  try {
270
- responseBody = await response.json();
304
+ responseBody = JSON.parse(text);
271
305
  } catch {
272
- responseBody = await response.text();
306
+ responseBody = text;
273
307
  }
274
308
  throw new AggregatorClientError(
275
309
  `Request to ${path} failed with status ${response.status}`,
@@ -301,11 +335,17 @@ import {
301
335
  ManualBatchRequestSchema as ManualBatchRequestSchema2,
302
336
  ManualBatchResponseSchema as ManualBatchResponseSchema2,
303
337
  ManualBatchEntrySchema,
304
- ManualBatchTelemetrySchema
338
+ ManualBatchTelemetrySchema,
339
+ CreateAnonymousDriverBodySchema as CreateAnonymousDriverBodySchema2,
340
+ AnonymousDriverResponseSchema as AnonymousDriverResponseSchema2,
341
+ AnonymousDriverErrorResponseSchema
305
342
  } from "@findatruck/shared-schemas";
306
343
  export {
307
344
  AggregatorClient,
308
345
  AggregatorClientError,
346
+ AnonymousDriverErrorResponseSchema,
347
+ AnonymousDriverResponseSchema2 as AnonymousDriverResponseSchema,
348
+ CreateAnonymousDriverBodySchema2 as CreateAnonymousDriverBodySchema,
309
349
  DeleteProviderAccountRequestSchema2 as DeleteProviderAccountRequestSchema,
310
350
  DeleteProviderAccountResponseSchema2 as DeleteProviderAccountResponseSchema,
311
351
  DriverRankingSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@findatruck/aggregator-client",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "test:watch": "vitest"
24
24
  },
25
25
  "dependencies": {
26
- "@findatruck/shared-schemas": "^2.12.0"
26
+ "@findatruck/shared-schemas": "^2.14.0"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "zod": "^4.1.11"