@vulog/aima-booking 1.1.91 → 1.1.92
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.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +51 -0
- package/dist/index.mjs +39 -0
- package/package.json +3 -3
- package/src/allocateVehicle.test.ts +49 -0
- package/src/allocateVehicle.ts +32 -0
- package/src/deallocateVehicle.test.ts +47 -0
- package/src/deallocateVehicle.ts +32 -0
- package/src/index.ts +2 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Client } from '@vulog/aima-client';
|
|
2
2
|
import { PaginableOptions, PaginableResponse } from '@vulog/aima-core';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { UUID } from 'crypto';
|
|
4
5
|
|
|
5
6
|
type PaymentReceipts = {
|
|
6
7
|
id: string;
|
|
@@ -195,4 +196,8 @@ declare const IncludeSchema: z.ZodEnum<["INFO", "SERVICES"]>;
|
|
|
195
196
|
type IncludeStation = z.infer<typeof IncludeSchema>;
|
|
196
197
|
declare const getStationById: (client: Client, id: string, includes?: IncludeStation[]) => Promise<Station | null>;
|
|
197
198
|
|
|
198
|
-
|
|
199
|
+
declare const allocateVehicle: (client: Client, bookingRequestId: UUID, vehicleId: UUID, serviceId: UUID) => Promise<SATBookingRequest>;
|
|
200
|
+
|
|
201
|
+
declare const deallocateVehicle: (client: Client, bookingRequestId: UUID, vehicleId: UUID) => Promise<SATBookingRequest>;
|
|
202
|
+
|
|
203
|
+
export { type BaseBookingRequest, type BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type CustomPrice, type DayOpeningHours, type Days, type GeoInfo, type Include, type IncludeStation, type OpeningHours, type PaymentReceipts, type SATBookingRequest, type SATBookingRequestStatus, type Service, type ServiceInfo, type ServiceType, type Station, type Timetable, allocateVehicle, deallocateVehicle, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Client } from '@vulog/aima-client';
|
|
2
2
|
import { PaginableOptions, PaginableResponse } from '@vulog/aima-core';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { UUID } from 'crypto';
|
|
4
5
|
|
|
5
6
|
type PaymentReceipts = {
|
|
6
7
|
id: string;
|
|
@@ -195,4 +196,8 @@ declare const IncludeSchema: z.ZodEnum<["INFO", "SERVICES"]>;
|
|
|
195
196
|
type IncludeStation = z.infer<typeof IncludeSchema>;
|
|
196
197
|
declare const getStationById: (client: Client, id: string, includes?: IncludeStation[]) => Promise<Station | null>;
|
|
197
198
|
|
|
198
|
-
|
|
199
|
+
declare const allocateVehicle: (client: Client, bookingRequestId: UUID, vehicleId: UUID, serviceId: UUID) => Promise<SATBookingRequest>;
|
|
200
|
+
|
|
201
|
+
declare const deallocateVehicle: (client: Client, bookingRequestId: UUID, vehicleId: UUID) => Promise<SATBookingRequest>;
|
|
202
|
+
|
|
203
|
+
export { type BaseBookingRequest, type BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type CustomPrice, type DayOpeningHours, type Days, type GeoInfo, type Include, type IncludeStation, type OpeningHours, type PaymentReceipts, type SATBookingRequest, type SATBookingRequestStatus, type Service, type ServiceInfo, type ServiceType, type Station, type Timetable, allocateVehicle, deallocateVehicle, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,11 +17,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
21
31
|
var index_exports = {};
|
|
22
32
|
__export(index_exports, {
|
|
33
|
+
allocateVehicle: () => allocateVehicle,
|
|
34
|
+
deallocateVehicle: () => deallocateVehicle,
|
|
23
35
|
getBookingRequestById: () => getBookingRequestById,
|
|
24
36
|
getBookingRequestByTrip: () => getBookingRequestByTrip,
|
|
25
37
|
getBookingRequests: () => getBookingRequests,
|
|
@@ -409,8 +421,47 @@ var getStationById = async (client, id, includes = []) => {
|
|
|
409
421
|
}
|
|
410
422
|
return station;
|
|
411
423
|
};
|
|
424
|
+
|
|
425
|
+
// src/allocateVehicle.ts
|
|
426
|
+
var import_zod6 = __toESM(require("zod"));
|
|
427
|
+
var allocateVehicleSchema = import_zod6.default.object({
|
|
428
|
+
bookingRequestId: import_zod6.default.string().uuid(),
|
|
429
|
+
vehicleId: import_zod6.default.string().uuid(),
|
|
430
|
+
serviceId: import_zod6.default.string().uuid()
|
|
431
|
+
});
|
|
432
|
+
var allocateVehicle = async (client, bookingRequestId, vehicleId, serviceId) => {
|
|
433
|
+
const resultPayload = allocateVehicleSchema.safeParse({ bookingRequestId, vehicleId, serviceId });
|
|
434
|
+
if (!resultPayload.success) {
|
|
435
|
+
throw new TypeError("Invalid args", {
|
|
436
|
+
cause: resultPayload.error.issues
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
return client.post(
|
|
440
|
+
`boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/allocate/${vehicleId}?serviceId=${serviceId}`
|
|
441
|
+
).then(({ data }) => data);
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
// src/deallocateVehicle.ts
|
|
445
|
+
var import_zod7 = __toESM(require("zod"));
|
|
446
|
+
var deallocateVehicleSchema = import_zod7.default.object({
|
|
447
|
+
bookingRequestId: import_zod7.default.string().uuid(),
|
|
448
|
+
vehicleId: import_zod7.default.string().uuid()
|
|
449
|
+
});
|
|
450
|
+
var deallocateVehicle = async (client, bookingRequestId, vehicleId) => {
|
|
451
|
+
const resultPayload = deallocateVehicleSchema.safeParse({ bookingRequestId, vehicleId });
|
|
452
|
+
if (!resultPayload.success) {
|
|
453
|
+
throw new TypeError("Invalid args", {
|
|
454
|
+
cause: resultPayload.error.issues
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
return client.delete(
|
|
458
|
+
`boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/vehicles/${vehicleId}`
|
|
459
|
+
).then(({ data }) => data);
|
|
460
|
+
};
|
|
412
461
|
// Annotate the CommonJS export names for ESM import in node:
|
|
413
462
|
0 && (module.exports = {
|
|
463
|
+
allocateVehicle,
|
|
464
|
+
deallocateVehicle,
|
|
414
465
|
getBookingRequestById,
|
|
415
466
|
getBookingRequestByTrip,
|
|
416
467
|
getBookingRequests,
|
package/dist/index.mjs
CHANGED
|
@@ -375,7 +375,46 @@ var getStationById = async (client, id, includes = []) => {
|
|
|
375
375
|
}
|
|
376
376
|
return station;
|
|
377
377
|
};
|
|
378
|
+
|
|
379
|
+
// src/allocateVehicle.ts
|
|
380
|
+
import z6 from "zod";
|
|
381
|
+
var allocateVehicleSchema = z6.object({
|
|
382
|
+
bookingRequestId: z6.string().uuid(),
|
|
383
|
+
vehicleId: z6.string().uuid(),
|
|
384
|
+
serviceId: z6.string().uuid()
|
|
385
|
+
});
|
|
386
|
+
var allocateVehicle = async (client, bookingRequestId, vehicleId, serviceId) => {
|
|
387
|
+
const resultPayload = allocateVehicleSchema.safeParse({ bookingRequestId, vehicleId, serviceId });
|
|
388
|
+
if (!resultPayload.success) {
|
|
389
|
+
throw new TypeError("Invalid args", {
|
|
390
|
+
cause: resultPayload.error.issues
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
return client.post(
|
|
394
|
+
`boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/allocate/${vehicleId}?serviceId=${serviceId}`
|
|
395
|
+
).then(({ data }) => data);
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
// src/deallocateVehicle.ts
|
|
399
|
+
import z7 from "zod";
|
|
400
|
+
var deallocateVehicleSchema = z7.object({
|
|
401
|
+
bookingRequestId: z7.string().uuid(),
|
|
402
|
+
vehicleId: z7.string().uuid()
|
|
403
|
+
});
|
|
404
|
+
var deallocateVehicle = async (client, bookingRequestId, vehicleId) => {
|
|
405
|
+
const resultPayload = deallocateVehicleSchema.safeParse({ bookingRequestId, vehicleId });
|
|
406
|
+
if (!resultPayload.success) {
|
|
407
|
+
throw new TypeError("Invalid args", {
|
|
408
|
+
cause: resultPayload.error.issues
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
return client.delete(
|
|
412
|
+
`boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/vehicles/${vehicleId}`
|
|
413
|
+
).then(({ data }) => data);
|
|
414
|
+
};
|
|
378
415
|
export {
|
|
416
|
+
allocateVehicle,
|
|
417
|
+
deallocateVehicle,
|
|
379
418
|
getBookingRequestById,
|
|
380
419
|
getBookingRequestByTrip,
|
|
381
420
|
getBookingRequests,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-booking",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.92",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"author": "Vulog",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@vulog/aima-client": "1.1.
|
|
23
|
-
"@vulog/aima-core": "1.1.
|
|
22
|
+
"@vulog/aima-client": "1.1.92",
|
|
23
|
+
"@vulog/aima-core": "1.1.92"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"es-toolkit": "^1.39.9",
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, test, vi, expect, beforeEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { Client } from '@vulog/aima-client';
|
|
4
|
+
import { allocateVehicle } from './allocateVehicle';
|
|
5
|
+
import { UUID } from 'crypto';
|
|
6
|
+
|
|
7
|
+
describe('allocateVehicle', () => {
|
|
8
|
+
const postMock = vi.fn();
|
|
9
|
+
const client = {
|
|
10
|
+
post: postMock,
|
|
11
|
+
clientOptions: {
|
|
12
|
+
fleetId: 'FLEET_ID',
|
|
13
|
+
},
|
|
14
|
+
} as unknown as Client;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
vi.clearAllMocks();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('should return invalid args', async () => {
|
|
21
|
+
const bookingRequestId = 'BOOKING_REQUEST_ID';
|
|
22
|
+
const vehicleId = 'VEHICLE_ID';
|
|
23
|
+
const serviceId = 'SERVICE_ID';
|
|
24
|
+
|
|
25
|
+
// expect to throw error if invalid UUIDs are provided
|
|
26
|
+
await expect(
|
|
27
|
+
allocateVehicle(client, bookingRequestId as UUID, vehicleId as UUID, serviceId as UUID)
|
|
28
|
+
).rejects.toThrow('Invalid args');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('should allocate vehicle successfully', async () => {
|
|
32
|
+
const bookingRequestId = '550e8400-e29b-41d4-a716-446655440000';
|
|
33
|
+
const vehicleId = '550e8400-e29b-41d4-a716-446655440001';
|
|
34
|
+
const serviceId = '550e8400-e29b-41d4-a716-446655440002';
|
|
35
|
+
|
|
36
|
+
const mockResponse = {
|
|
37
|
+
id: 'some-id',
|
|
38
|
+
status: 'ALLOCATED',
|
|
39
|
+
// other properties of SATBookingRequest
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
postMock.mockResolvedValueOnce({
|
|
43
|
+
data: mockResponse,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const result = await allocateVehicle(client, bookingRequestId, vehicleId, serviceId);
|
|
47
|
+
expect(result).toEqual(mockResponse);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { UUID } from 'crypto';
|
|
2
|
+
|
|
3
|
+
import { Client } from '@vulog/aima-client';
|
|
4
|
+
|
|
5
|
+
import z from 'zod';
|
|
6
|
+
|
|
7
|
+
import { SATBookingRequest } from './types';
|
|
8
|
+
|
|
9
|
+
const allocateVehicleSchema = z.object({
|
|
10
|
+
bookingRequestId: z.string().uuid(),
|
|
11
|
+
vehicleId: z.string().uuid(),
|
|
12
|
+
serviceId: z.string().uuid(),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const allocateVehicle = async (
|
|
16
|
+
client: Client,
|
|
17
|
+
bookingRequestId: UUID,
|
|
18
|
+
vehicleId: UUID,
|
|
19
|
+
serviceId: UUID
|
|
20
|
+
): Promise<SATBookingRequest> => {
|
|
21
|
+
const resultPayload = allocateVehicleSchema.safeParse({ bookingRequestId, vehicleId, serviceId });
|
|
22
|
+
if (!resultPayload.success) {
|
|
23
|
+
throw new TypeError('Invalid args', {
|
|
24
|
+
cause: resultPayload.error.issues,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return client
|
|
28
|
+
.post<SATBookingRequest>(
|
|
29
|
+
`boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/allocate/${vehicleId}?serviceId=${serviceId}`
|
|
30
|
+
)
|
|
31
|
+
.then(({ data }) => data);
|
|
32
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { describe, test, vi, expect, beforeEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { Client } from '@vulog/aima-client';
|
|
4
|
+
import { deallocateVehicle } from './deallocateVehicle';
|
|
5
|
+
import { UUID } from 'crypto';
|
|
6
|
+
|
|
7
|
+
describe('deallocateVehicle', () => {
|
|
8
|
+
const deleteMock = vi.fn();
|
|
9
|
+
const client = {
|
|
10
|
+
delete: deleteMock,
|
|
11
|
+
clientOptions: {
|
|
12
|
+
fleetId: 'FLEET_ID',
|
|
13
|
+
},
|
|
14
|
+
} as unknown as Client;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
vi.clearAllMocks();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('should return invalid args', async () => {
|
|
21
|
+
const bookingRequestId = 'BOOKING_REQUEST_ID';
|
|
22
|
+
const vehicleId = 'VEHICLE_ID';
|
|
23
|
+
|
|
24
|
+
// expect to throw error if invalid UUIDs are provided
|
|
25
|
+
await expect(deallocateVehicle(client, bookingRequestId as UUID, vehicleId as UUID)).rejects.toThrow(
|
|
26
|
+
'Invalid args'
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('should deallocate vehicle successfully', async () => {
|
|
31
|
+
const bookingRequestId = '550e8400-e29b-41d4-a716-446655440000';
|
|
32
|
+
const vehicleId = '550e8400-e29b-41d4-a716-446655440001';
|
|
33
|
+
|
|
34
|
+
const mockResponse = {
|
|
35
|
+
id: 'some-id',
|
|
36
|
+
vehicleId: null,
|
|
37
|
+
// other properties of SATBookingRequest
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
deleteMock.mockResolvedValueOnce({
|
|
41
|
+
data: mockResponse,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const result = await deallocateVehicle(client, bookingRequestId, vehicleId);
|
|
45
|
+
expect(result).toEqual(mockResponse);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// https://java-sta.vulog.com/boapi/proxy/user/scheduledBooking/fleets/LEO-CAMTR/bookingrequests/2e603670-9684-4df1-9ff5-7f380ce6b8dc/vehicles/2e15c6f2-0b75-47ca-b885-b60f6ac35b12
|
|
2
|
+
|
|
3
|
+
import { UUID } from 'crypto';
|
|
4
|
+
|
|
5
|
+
import { Client } from '@vulog/aima-client';
|
|
6
|
+
|
|
7
|
+
import z from 'zod';
|
|
8
|
+
|
|
9
|
+
import { SATBookingRequest } from './types';
|
|
10
|
+
|
|
11
|
+
const deallocateVehicleSchema = z.object({
|
|
12
|
+
bookingRequestId: z.string().uuid(),
|
|
13
|
+
vehicleId: z.string().uuid(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const deallocateVehicle = async (
|
|
17
|
+
client: Client,
|
|
18
|
+
bookingRequestId: UUID,
|
|
19
|
+
vehicleId: UUID
|
|
20
|
+
): Promise<SATBookingRequest> => {
|
|
21
|
+
const resultPayload = deallocateVehicleSchema.safeParse({ bookingRequestId, vehicleId });
|
|
22
|
+
if (!resultPayload.success) {
|
|
23
|
+
throw new TypeError('Invalid args', {
|
|
24
|
+
cause: resultPayload.error.issues,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return client
|
|
28
|
+
.delete<SATBookingRequest>(
|
|
29
|
+
`boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/vehicles/${vehicleId}`
|
|
30
|
+
)
|
|
31
|
+
.then(({ data }) => data);
|
|
32
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -8,3 +8,5 @@ export { getStations } from './getStations';
|
|
|
8
8
|
export type { Include } from './getStations';
|
|
9
9
|
export { getStationById } from './getStation';
|
|
10
10
|
export type { IncludeStation } from './getStation';
|
|
11
|
+
export { allocateVehicle } from './allocateVehicle';
|
|
12
|
+
export { deallocateVehicle } from './deallocateVehicle';
|