@vulog/aima-unavailability 1.2.29 → 1.2.31

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 ADDED
@@ -0,0 +1,166 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let zod = require("zod");
3
+ //#region src/getUnavailabilitiesByVehicle.ts
4
+ const schema$5 = zod.z.object({ vehicleId: zod.z.string().trim().min(1).uuid() });
5
+ const getUnavailabilitiesByVehicle = async (client, vehicleId) => {
6
+ const result = schema$5.safeParse({ vehicleId });
7
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
8
+ return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/vehicles/${result.data.vehicleId}`).then(({ data }) => data).catch((error) => {
9
+ if (error.formattedError?.status === 404) return [];
10
+ throw error;
11
+ });
12
+ };
13
+ //#endregion
14
+ //#region src/getUnavailabilities.ts
15
+ const schema$4 = zod.z.object({
16
+ from: zod.z.string().datetime({
17
+ offset: false,
18
+ precision: 0
19
+ }),
20
+ to: zod.z.string().datetime({
21
+ offset: false,
22
+ precision: 0
23
+ }),
24
+ page: zod.z.number().int().nonnegative().default(0)
25
+ });
26
+ const getUnavailabilities = async (client, options) => {
27
+ const result = schema$4.safeParse({
28
+ from: options.from,
29
+ to: options.to,
30
+ page: options.page ?? 0
31
+ });
32
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
33
+ const allUnavailabilities = [];
34
+ let currentPage = result.data.page;
35
+ let hasMorePages = true;
36
+ const MAX_PAGES = 50;
37
+ while (hasMorePages) {
38
+ if (currentPage >= MAX_PAGES) throw new Error(`Maximum page limit (${MAX_PAGES}) reached. This might indicate an issue with the pagination or a very large dataset.`);
39
+ const queryParams = new URLSearchParams({
40
+ from: result.data.from,
41
+ to: result.data.to,
42
+ page: currentPage.toString()
43
+ });
44
+ const unavailabilities = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/vehicles?${queryParams.toString()}`).then(({ data }) => data).catch((error) => {
45
+ if (error.formattedError?.status === 404) return [];
46
+ throw error;
47
+ });
48
+ allUnavailabilities.push(...unavailabilities);
49
+ hasMorePages = unavailabilities.length > 0;
50
+ currentPage += 1;
51
+ }
52
+ return allUnavailabilities;
53
+ };
54
+ //#endregion
55
+ //#region src/createUnavailability.ts
56
+ const schema$3 = zod.z.object({
57
+ cronExpression: zod.z.string().min(1),
58
+ duration: zod.z.number().int().positive(),
59
+ maintenanceTitle: zod.z.string().min(1),
60
+ vehicleId: zod.z.string().uuid()
61
+ });
62
+ const createUnavailability = async (client, body) => {
63
+ const result = schema$3.safeParse(body);
64
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
65
+ return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability`, {
66
+ cronExpression: result.data.cronExpression,
67
+ duration: result.data.duration,
68
+ maintenanceTitle: result.data.maintenanceTitle,
69
+ vehicleId: result.data.vehicleId
70
+ }).then(({ data }) => data);
71
+ };
72
+ //#endregion
73
+ //#region src/updateUnavailability.ts
74
+ const schema$2 = zod.z.object({
75
+ id: zod.z.number().int().positive(),
76
+ cronExpression: zod.z.string().min(1),
77
+ duration: zod.z.number().int().positive(),
78
+ maintenanceTitle: zod.z.string().min(1),
79
+ vehicleId: zod.z.string().uuid()
80
+ });
81
+ const updateUnavailability = async (client, id, body) => {
82
+ const result = schema$2.safeParse({
83
+ id,
84
+ ...body
85
+ });
86
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
87
+ return client.put(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/${result.data.id}`, {
88
+ cronExpression: result.data.cronExpression,
89
+ duration: result.data.duration,
90
+ maintenanceTitle: result.data.maintenanceTitle,
91
+ vehicleId: result.data.vehicleId
92
+ }).then(({ data }) => data);
93
+ };
94
+ //#endregion
95
+ //#region src/deleteUnavailability.ts
96
+ const schema$1 = zod.z.object({ id: zod.z.number().int().positive() });
97
+ const deleteUnavailability = async (client, id) => {
98
+ const result = schema$1.safeParse({ id });
99
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
100
+ return client.delete(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/${result.data.id}`).then(() => void 0).catch((error) => {
101
+ if (error.formattedError?.status === 404) return;
102
+ throw error;
103
+ });
104
+ };
105
+ //#endregion
106
+ //#region src/deleteUnavailabilitiesByVehicle.ts
107
+ const schema = zod.z.object({ vehicleId: zod.z.string().trim().min(1).uuid() });
108
+ const deleteUnavailabilitiesByVehicle = async (client, vehicleId) => {
109
+ const result = schema.safeParse({ vehicleId });
110
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
111
+ return client.delete(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/vehicles/${result.data.vehicleId}`).then(() => void 0).catch((error) => {
112
+ if (error.formattedError?.status === 404) return;
113
+ throw error;
114
+ });
115
+ };
116
+ //#endregion
117
+ //#region src/generateCronExpression.ts
118
+ /**
119
+ * Generates a Quartz cron expression from a date.
120
+ * Format: second minute hour day month dayOfWeek year
121
+ * Example: "0 0 23 14 8 ? 2018"
122
+ *
123
+ * @param date - The date to convert to cron expression (Date object or ISO string)
124
+ * @param timezone - Optional timezone string (e.g., "Europe/Paris", "America/New_York")
125
+ * If provided, the date will be converted to the specified timezone.
126
+ * If not provided, the date will be used as-is.
127
+ * @returns A cron expression string in Quartz format
128
+ */
129
+ const generateCronExpression = (date, timezone) => {
130
+ let dateObj;
131
+ if (typeof date === "string") dateObj = new Date(date);
132
+ else dateObj = new Date(date);
133
+ if (Number.isNaN(dateObj.getTime())) throw new TypeError("Invalid date provided");
134
+ if (timezone) {
135
+ const parts = new Intl.DateTimeFormat("en-US", {
136
+ timeZone: timezone,
137
+ year: "numeric",
138
+ month: "2-digit",
139
+ day: "2-digit",
140
+ hour: "2-digit",
141
+ minute: "2-digit",
142
+ second: "2-digit",
143
+ hour12: false
144
+ }).formatToParts(dateObj);
145
+ const year = parseInt(parts.find((p) => p.type === "year")?.value || "0", 10);
146
+ const month = parseInt(parts.find((p) => p.type === "month")?.value || "0", 10);
147
+ const day = parseInt(parts.find((p) => p.type === "day")?.value || "0", 10);
148
+ const hour = parseInt(parts.find((p) => p.type === "hour")?.value || "0", 10);
149
+ const minute = parseInt(parts.find((p) => p.type === "minute")?.value || "0", 10);
150
+ return `${parseInt(parts.find((p) => p.type === "second")?.value || "0", 10)} ${minute} ${hour} ${day} ${month} ? ${year}`;
151
+ }
152
+ const year = dateObj.getFullYear();
153
+ const month = dateObj.getMonth() + 1;
154
+ const day = dateObj.getDate();
155
+ const hour = dateObj.getHours();
156
+ const minute = dateObj.getMinutes();
157
+ return `${dateObj.getSeconds()} ${minute} ${hour} ${day} ${month} ? ${year}`;
158
+ };
159
+ //#endregion
160
+ exports.createUnavailability = createUnavailability;
161
+ exports.deleteUnavailabilitiesByVehicle = deleteUnavailabilitiesByVehicle;
162
+ exports.deleteUnavailability = deleteUnavailability;
163
+ exports.generateCronExpression = generateCronExpression;
164
+ exports.getUnavailabilities = getUnavailabilities;
165
+ exports.getUnavailabilitiesByVehicle = getUnavailabilitiesByVehicle;
166
+ exports.updateUnavailability = updateUnavailability;
@@ -1,37 +1,45 @@
1
- import { Client } from '@vulog/aima-client';
1
+ import { Client } from "@vulog/aima-client";
2
2
 
3
+ //#region src/types.d.ts
3
4
  type Unavailability = {
4
- id: number;
5
- cronExpression: string;
6
- duration: number;
7
- maintenanceTitle: string;
8
- vehicleId: string;
5
+ id: number;
6
+ cronExpression: string;
7
+ duration: number;
8
+ maintenanceTitle: string;
9
+ vehicleId: string;
9
10
  };
10
11
  type CreateUnavailabilityBody = {
11
- cronExpression: string;
12
- duration: number;
13
- maintenanceTitle: string;
14
- vehicleId: string;
12
+ cronExpression: string;
13
+ duration: number;
14
+ maintenanceTitle: string;
15
+ vehicleId: string;
15
16
  };
16
17
  type UpdateUnavailabilityBody = CreateUnavailabilityBody;
17
18
  type UnavailabilityOptions = {
18
- from: string;
19
- to: string;
20
- page?: number;
19
+ from: string;
20
+ to: string;
21
+ page?: number;
21
22
  };
22
-
23
+ //#endregion
24
+ //#region src/getUnavailabilitiesByVehicle.d.ts
23
25
  declare const getUnavailabilitiesByVehicle: (client: Client, vehicleId: string) => Promise<Unavailability[]>;
24
-
26
+ //#endregion
27
+ //#region src/getUnavailabilities.d.ts
25
28
  declare const getUnavailabilities: (client: Client, options: UnavailabilityOptions) => Promise<Unavailability[]>;
26
-
29
+ //#endregion
30
+ //#region src/createUnavailability.d.ts
27
31
  declare const createUnavailability: (client: Client, body: CreateUnavailabilityBody) => Promise<Unavailability>;
28
-
32
+ //#endregion
33
+ //#region src/updateUnavailability.d.ts
29
34
  declare const updateUnavailability: (client: Client, id: number, body: UpdateUnavailabilityBody) => Promise<Unavailability>;
30
-
35
+ //#endregion
36
+ //#region src/deleteUnavailability.d.ts
31
37
  declare const deleteUnavailability: (client: Client, id: number) => Promise<void>;
32
-
38
+ //#endregion
39
+ //#region src/deleteUnavailabilitiesByVehicle.d.ts
33
40
  declare const deleteUnavailabilitiesByVehicle: (client: Client, vehicleId: string) => Promise<void>;
34
-
41
+ //#endregion
42
+ //#region src/generateCronExpression.d.ts
35
43
  /**
36
44
  * Generates a Quartz cron expression from a date.
37
45
  * Format: second minute hour day month dayOfWeek year
@@ -44,5 +52,5 @@ declare const deleteUnavailabilitiesByVehicle: (client: Client, vehicleId: strin
44
52
  * @returns A cron expression string in Quartz format
45
53
  */
46
54
  declare const generateCronExpression: (date: Date | string, timezone?: string) => string;
47
-
48
- export { type CreateUnavailabilityBody, type Unavailability, type UnavailabilityOptions, type UpdateUnavailabilityBody, createUnavailability, deleteUnavailabilitiesByVehicle, deleteUnavailability, generateCronExpression, getUnavailabilities, getUnavailabilitiesByVehicle, updateUnavailability };
55
+ //#endregion
56
+ export { CreateUnavailabilityBody, Unavailability, UnavailabilityOptions, UpdateUnavailabilityBody, createUnavailability, deleteUnavailabilitiesByVehicle, deleteUnavailability, generateCronExpression, getUnavailabilities, getUnavailabilitiesByVehicle, updateUnavailability };
package/dist/index.d.mts CHANGED
@@ -1,37 +1,45 @@
1
- import { Client } from '@vulog/aima-client';
1
+ import { Client } from "@vulog/aima-client";
2
2
 
3
+ //#region src/types.d.ts
3
4
  type Unavailability = {
4
- id: number;
5
- cronExpression: string;
6
- duration: number;
7
- maintenanceTitle: string;
8
- vehicleId: string;
5
+ id: number;
6
+ cronExpression: string;
7
+ duration: number;
8
+ maintenanceTitle: string;
9
+ vehicleId: string;
9
10
  };
10
11
  type CreateUnavailabilityBody = {
11
- cronExpression: string;
12
- duration: number;
13
- maintenanceTitle: string;
14
- vehicleId: string;
12
+ cronExpression: string;
13
+ duration: number;
14
+ maintenanceTitle: string;
15
+ vehicleId: string;
15
16
  };
16
17
  type UpdateUnavailabilityBody = CreateUnavailabilityBody;
17
18
  type UnavailabilityOptions = {
18
- from: string;
19
- to: string;
20
- page?: number;
19
+ from: string;
20
+ to: string;
21
+ page?: number;
21
22
  };
22
-
23
+ //#endregion
24
+ //#region src/getUnavailabilitiesByVehicle.d.ts
23
25
  declare const getUnavailabilitiesByVehicle: (client: Client, vehicleId: string) => Promise<Unavailability[]>;
24
-
26
+ //#endregion
27
+ //#region src/getUnavailabilities.d.ts
25
28
  declare const getUnavailabilities: (client: Client, options: UnavailabilityOptions) => Promise<Unavailability[]>;
26
-
29
+ //#endregion
30
+ //#region src/createUnavailability.d.ts
27
31
  declare const createUnavailability: (client: Client, body: CreateUnavailabilityBody) => Promise<Unavailability>;
28
-
32
+ //#endregion
33
+ //#region src/updateUnavailability.d.ts
29
34
  declare const updateUnavailability: (client: Client, id: number, body: UpdateUnavailabilityBody) => Promise<Unavailability>;
30
-
35
+ //#endregion
36
+ //#region src/deleteUnavailability.d.ts
31
37
  declare const deleteUnavailability: (client: Client, id: number) => Promise<void>;
32
-
38
+ //#endregion
39
+ //#region src/deleteUnavailabilitiesByVehicle.d.ts
33
40
  declare const deleteUnavailabilitiesByVehicle: (client: Client, vehicleId: string) => Promise<void>;
34
-
41
+ //#endregion
42
+ //#region src/generateCronExpression.d.ts
35
43
  /**
36
44
  * Generates a Quartz cron expression from a date.
37
45
  * Format: second minute hour day month dayOfWeek year
@@ -44,5 +52,5 @@ declare const deleteUnavailabilitiesByVehicle: (client: Client, vehicleId: strin
44
52
  * @returns A cron expression string in Quartz format
45
53
  */
46
54
  declare const generateCronExpression: (date: Date | string, timezone?: string) => string;
47
-
48
- export { type CreateUnavailabilityBody, type Unavailability, type UnavailabilityOptions, type UpdateUnavailabilityBody, createUnavailability, deleteUnavailabilitiesByVehicle, deleteUnavailability, generateCronExpression, getUnavailabilities, getUnavailabilitiesByVehicle, updateUnavailability };
55
+ //#endregion
56
+ export { CreateUnavailabilityBody, Unavailability, UnavailabilityOptions, UpdateUnavailabilityBody, createUnavailability, deleteUnavailabilitiesByVehicle, deleteUnavailability, generateCronExpression, getUnavailabilities, getUnavailabilitiesByVehicle, updateUnavailability };
package/dist/index.mjs CHANGED
@@ -1,218 +1,159 @@
1
- // src/getUnavailabilitiesByVehicle.ts
2
1
  import { z } from "zod";
3
- var schema = z.object({
4
- vehicleId: z.string().trim().min(1).uuid()
5
- });
6
- var getUnavailabilitiesByVehicle = async (client, vehicleId) => {
7
- const result = schema.safeParse({ vehicleId });
8
- if (!result.success) {
9
- throw new TypeError("Invalid args", {
10
- cause: result.error.issues
11
- });
12
- }
13
- return client.get(
14
- `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/vehicles/${result.data.vehicleId}`
15
- ).then(({ data }) => data).catch((error) => {
16
- if (error.formattedError?.status === 404) {
17
- return [];
18
- }
19
- throw error;
20
- });
21
- };
22
-
23
- // src/getUnavailabilities.ts
24
- import { z as z2 } from "zod";
25
- var schema2 = z2.object({
26
- from: z2.string().datetime({ offset: false, precision: 0 }),
27
- to: z2.string().datetime({ offset: false, precision: 0 }),
28
- page: z2.number().int().nonnegative().default(0)
29
- });
30
- var getUnavailabilities = async (client, options) => {
31
- const result = schema2.safeParse({
32
- from: options.from,
33
- to: options.to,
34
- page: options.page ?? 0
35
- });
36
- if (!result.success) {
37
- throw new TypeError("Invalid args", {
38
- cause: result.error.issues
39
- });
40
- }
41
- const allUnavailabilities = [];
42
- let currentPage = result.data.page;
43
- let hasMorePages = true;
44
- const MAX_PAGES = 50;
45
- while (hasMorePages) {
46
- if (currentPage >= MAX_PAGES) {
47
- throw new Error(
48
- `Maximum page limit (${MAX_PAGES}) reached. This might indicate an issue with the pagination or a very large dataset.`
49
- );
50
- }
51
- const queryParams = new URLSearchParams({
52
- from: result.data.from,
53
- to: result.data.to,
54
- page: currentPage.toString()
55
- });
56
- const unavailabilities = await client.get(
57
- `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/vehicles?${queryParams.toString()}`
58
- ).then(({ data }) => data).catch((error) => {
59
- if (error.formattedError?.status === 404) {
60
- return [];
61
- }
62
- throw error;
63
- });
64
- allUnavailabilities.push(...unavailabilities);
65
- hasMorePages = unavailabilities.length > 0;
66
- currentPage += 1;
67
- }
68
- return allUnavailabilities;
2
+ //#region src/getUnavailabilitiesByVehicle.ts
3
+ const schema$5 = z.object({ vehicleId: z.string().trim().min(1).uuid() });
4
+ const getUnavailabilitiesByVehicle = async (client, vehicleId) => {
5
+ const result = schema$5.safeParse({ vehicleId });
6
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
7
+ return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/vehicles/${result.data.vehicleId}`).then(({ data }) => data).catch((error) => {
8
+ if (error.formattedError?.status === 404) return [];
9
+ throw error;
10
+ });
69
11
  };
70
-
71
- // src/createUnavailability.ts
72
- import { z as z3 } from "zod";
73
- var schema3 = z3.object({
74
- cronExpression: z3.string().min(1),
75
- duration: z3.number().int().positive(),
76
- maintenanceTitle: z3.string().min(1),
77
- vehicleId: z3.string().uuid()
12
+ //#endregion
13
+ //#region src/getUnavailabilities.ts
14
+ const schema$4 = z.object({
15
+ from: z.string().datetime({
16
+ offset: false,
17
+ precision: 0
18
+ }),
19
+ to: z.string().datetime({
20
+ offset: false,
21
+ precision: 0
22
+ }),
23
+ page: z.number().int().nonnegative().default(0)
78
24
  });
79
- var createUnavailability = async (client, body) => {
80
- const result = schema3.safeParse(body);
81
- if (!result.success) {
82
- throw new TypeError("Invalid args", {
83
- cause: result.error.issues
84
- });
85
- }
86
- return client.post(
87
- `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability`,
88
- {
89
- cronExpression: result.data.cronExpression,
90
- duration: result.data.duration,
91
- maintenanceTitle: result.data.maintenanceTitle,
92
- vehicleId: result.data.vehicleId
93
- }
94
- ).then(({ data }) => data);
25
+ const getUnavailabilities = async (client, options) => {
26
+ const result = schema$4.safeParse({
27
+ from: options.from,
28
+ to: options.to,
29
+ page: options.page ?? 0
30
+ });
31
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
32
+ const allUnavailabilities = [];
33
+ let currentPage = result.data.page;
34
+ let hasMorePages = true;
35
+ const MAX_PAGES = 50;
36
+ while (hasMorePages) {
37
+ if (currentPage >= MAX_PAGES) throw new Error(`Maximum page limit (${MAX_PAGES}) reached. This might indicate an issue with the pagination or a very large dataset.`);
38
+ const queryParams = new URLSearchParams({
39
+ from: result.data.from,
40
+ to: result.data.to,
41
+ page: currentPage.toString()
42
+ });
43
+ const unavailabilities = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/vehicles?${queryParams.toString()}`).then(({ data }) => data).catch((error) => {
44
+ if (error.formattedError?.status === 404) return [];
45
+ throw error;
46
+ });
47
+ allUnavailabilities.push(...unavailabilities);
48
+ hasMorePages = unavailabilities.length > 0;
49
+ currentPage += 1;
50
+ }
51
+ return allUnavailabilities;
95
52
  };
96
-
97
- // src/updateUnavailability.ts
98
- import { z as z4 } from "zod";
99
- var schema4 = z4.object({
100
- id: z4.number().int().positive(),
101
- cronExpression: z4.string().min(1),
102
- duration: z4.number().int().positive(),
103
- maintenanceTitle: z4.string().min(1),
104
- vehicleId: z4.string().uuid()
53
+ //#endregion
54
+ //#region src/createUnavailability.ts
55
+ const schema$3 = z.object({
56
+ cronExpression: z.string().min(1),
57
+ duration: z.number().int().positive(),
58
+ maintenanceTitle: z.string().min(1),
59
+ vehicleId: z.string().uuid()
105
60
  });
106
- var updateUnavailability = async (client, id, body) => {
107
- const result = schema4.safeParse({
108
- id,
109
- ...body
110
- });
111
- if (!result.success) {
112
- throw new TypeError("Invalid args", {
113
- cause: result.error.issues
114
- });
115
- }
116
- return client.put(
117
- `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/${result.data.id}`,
118
- {
119
- cronExpression: result.data.cronExpression,
120
- duration: result.data.duration,
121
- maintenanceTitle: result.data.maintenanceTitle,
122
- vehicleId: result.data.vehicleId
123
- }
124
- ).then(({ data }) => data);
61
+ const createUnavailability = async (client, body) => {
62
+ const result = schema$3.safeParse(body);
63
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
64
+ return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability`, {
65
+ cronExpression: result.data.cronExpression,
66
+ duration: result.data.duration,
67
+ maintenanceTitle: result.data.maintenanceTitle,
68
+ vehicleId: result.data.vehicleId
69
+ }).then(({ data }) => data);
125
70
  };
126
-
127
- // src/deleteUnavailability.ts
128
- import { z as z5 } from "zod";
129
- var schema5 = z5.object({
130
- id: z5.number().int().positive()
71
+ //#endregion
72
+ //#region src/updateUnavailability.ts
73
+ const schema$2 = z.object({
74
+ id: z.number().int().positive(),
75
+ cronExpression: z.string().min(1),
76
+ duration: z.number().int().positive(),
77
+ maintenanceTitle: z.string().min(1),
78
+ vehicleId: z.string().uuid()
131
79
  });
132
- var deleteUnavailability = async (client, id) => {
133
- const result = schema5.safeParse({ id });
134
- if (!result.success) {
135
- throw new TypeError("Invalid args", {
136
- cause: result.error.issues
137
- });
138
- }
139
- return client.delete(
140
- `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/${result.data.id}`
141
- ).then(() => void 0).catch((error) => {
142
- if (error.formattedError?.status === 404) {
143
- return void 0;
144
- }
145
- throw error;
146
- });
80
+ const updateUnavailability = async (client, id, body) => {
81
+ const result = schema$2.safeParse({
82
+ id,
83
+ ...body
84
+ });
85
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
86
+ return client.put(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/${result.data.id}`, {
87
+ cronExpression: result.data.cronExpression,
88
+ duration: result.data.duration,
89
+ maintenanceTitle: result.data.maintenanceTitle,
90
+ vehicleId: result.data.vehicleId
91
+ }).then(({ data }) => data);
147
92
  };
148
-
149
- // src/deleteUnavailabilitiesByVehicle.ts
150
- import { z as z6 } from "zod";
151
- var schema6 = z6.object({
152
- vehicleId: z6.string().trim().min(1).uuid()
153
- });
154
- var deleteUnavailabilitiesByVehicle = async (client, vehicleId) => {
155
- const result = schema6.safeParse({ vehicleId });
156
- if (!result.success) {
157
- throw new TypeError("Invalid args", {
158
- cause: result.error.issues
159
- });
160
- }
161
- return client.delete(
162
- `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/vehicles/${result.data.vehicleId}`
163
- ).then(() => void 0).catch((error) => {
164
- if (error.formattedError?.status === 404) {
165
- return void 0;
166
- }
167
- throw error;
168
- });
93
+ //#endregion
94
+ //#region src/deleteUnavailability.ts
95
+ const schema$1 = z.object({ id: z.number().int().positive() });
96
+ const deleteUnavailability = async (client, id) => {
97
+ const result = schema$1.safeParse({ id });
98
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
99
+ return client.delete(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/${result.data.id}`).then(() => void 0).catch((error) => {
100
+ if (error.formattedError?.status === 404) return;
101
+ throw error;
102
+ });
169
103
  };
170
-
171
- // src/generateCronExpression.ts
172
- var generateCronExpression = (date, timezone) => {
173
- let dateObj;
174
- if (typeof date === "string") {
175
- dateObj = new Date(date);
176
- } else {
177
- dateObj = new Date(date);
178
- }
179
- if (Number.isNaN(dateObj.getTime())) {
180
- throw new TypeError("Invalid date provided");
181
- }
182
- if (timezone) {
183
- const formatter = new Intl.DateTimeFormat("en-US", {
184
- timeZone: timezone,
185
- year: "numeric",
186
- month: "2-digit",
187
- day: "2-digit",
188
- hour: "2-digit",
189
- minute: "2-digit",
190
- second: "2-digit",
191
- hour12: false
192
- });
193
- const parts = formatter.formatToParts(dateObj);
194
- const year2 = parseInt(parts.find((p) => p.type === "year")?.value || "0", 10);
195
- const month2 = parseInt(parts.find((p) => p.type === "month")?.value || "0", 10);
196
- const day2 = parseInt(parts.find((p) => p.type === "day")?.value || "0", 10);
197
- const hour2 = parseInt(parts.find((p) => p.type === "hour")?.value || "0", 10);
198
- const minute2 = parseInt(parts.find((p) => p.type === "minute")?.value || "0", 10);
199
- const second2 = parseInt(parts.find((p) => p.type === "second")?.value || "0", 10);
200
- return `${second2} ${minute2} ${hour2} ${day2} ${month2} ? ${year2}`;
201
- }
202
- const year = dateObj.getFullYear();
203
- const month = dateObj.getMonth() + 1;
204
- const day = dateObj.getDate();
205
- const hour = dateObj.getHours();
206
- const minute = dateObj.getMinutes();
207
- const second = dateObj.getSeconds();
208
- return `${second} ${minute} ${hour} ${day} ${month} ? ${year}`;
104
+ //#endregion
105
+ //#region src/deleteUnavailabilitiesByVehicle.ts
106
+ const schema = z.object({ vehicleId: z.string().trim().min(1).uuid() });
107
+ const deleteUnavailabilitiesByVehicle = async (client, vehicleId) => {
108
+ const result = schema.safeParse({ vehicleId });
109
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
110
+ return client.delete(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/vehicles/${result.data.vehicleId}`).then(() => void 0).catch((error) => {
111
+ if (error.formattedError?.status === 404) return;
112
+ throw error;
113
+ });
209
114
  };
210
- export {
211
- createUnavailability,
212
- deleteUnavailabilitiesByVehicle,
213
- deleteUnavailability,
214
- generateCronExpression,
215
- getUnavailabilities,
216
- getUnavailabilitiesByVehicle,
217
- updateUnavailability
115
+ //#endregion
116
+ //#region src/generateCronExpression.ts
117
+ /**
118
+ * Generates a Quartz cron expression from a date.
119
+ * Format: second minute hour day month dayOfWeek year
120
+ * Example: "0 0 23 14 8 ? 2018"
121
+ *
122
+ * @param date - The date to convert to cron expression (Date object or ISO string)
123
+ * @param timezone - Optional timezone string (e.g., "Europe/Paris", "America/New_York")
124
+ * If provided, the date will be converted to the specified timezone.
125
+ * If not provided, the date will be used as-is.
126
+ * @returns A cron expression string in Quartz format
127
+ */
128
+ const generateCronExpression = (date, timezone) => {
129
+ let dateObj;
130
+ if (typeof date === "string") dateObj = new Date(date);
131
+ else dateObj = new Date(date);
132
+ if (Number.isNaN(dateObj.getTime())) throw new TypeError("Invalid date provided");
133
+ if (timezone) {
134
+ const parts = new Intl.DateTimeFormat("en-US", {
135
+ timeZone: timezone,
136
+ year: "numeric",
137
+ month: "2-digit",
138
+ day: "2-digit",
139
+ hour: "2-digit",
140
+ minute: "2-digit",
141
+ second: "2-digit",
142
+ hour12: false
143
+ }).formatToParts(dateObj);
144
+ const year = parseInt(parts.find((p) => p.type === "year")?.value || "0", 10);
145
+ const month = parseInt(parts.find((p) => p.type === "month")?.value || "0", 10);
146
+ const day = parseInt(parts.find((p) => p.type === "day")?.value || "0", 10);
147
+ const hour = parseInt(parts.find((p) => p.type === "hour")?.value || "0", 10);
148
+ const minute = parseInt(parts.find((p) => p.type === "minute")?.value || "0", 10);
149
+ return `${parseInt(parts.find((p) => p.type === "second")?.value || "0", 10)} ${minute} ${hour} ${day} ${month} ? ${year}`;
150
+ }
151
+ const year = dateObj.getFullYear();
152
+ const month = dateObj.getMonth() + 1;
153
+ const day = dateObj.getDate();
154
+ const hour = dateObj.getHours();
155
+ const minute = dateObj.getMinutes();
156
+ return `${dateObj.getSeconds()} ${minute} ${hour} ${day} ${month} ? ${year}`;
218
157
  };
158
+ //#endregion
159
+ export { createUnavailability, deleteUnavailabilitiesByVehicle, deleteUnavailability, generateCronExpression, getUnavailabilities, getUnavailabilitiesByVehicle, updateUnavailability };
package/package.json CHANGED
@@ -1,12 +1,25 @@
1
1
  {
2
2
  "name": "@vulog/aima-unavailability",
3
- "version": "1.2.29",
4
- "main": "dist/index.js",
3
+ "type": "module",
4
+ "version": "1.2.31",
5
+ "main": "dist/index.cjs",
5
6
  "module": "dist/index.mjs",
6
- "types": "dist/index.d.ts",
7
+ "types": "dist/index.d.cts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.mts",
12
+ "default": "./dist/index.mjs"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.cts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ }
19
+ },
7
20
  "scripts": {
8
- "build": "tsup",
9
- "dev": "tsup --watch",
21
+ "build": "tsdown",
22
+ "dev": "tsdown --watch",
10
23
  "test": "vitest run",
11
24
  "test:watch": "vitest",
12
25
  "lint": "eslint src/**/* --ext .ts"
@@ -19,8 +32,8 @@
19
32
  "author": "Vulog",
20
33
  "license": "MIT",
21
34
  "dependencies": {
22
- "@vulog/aima-client": "1.2.29",
23
- "@vulog/aima-core": "1.2.29"
35
+ "@vulog/aima-client": "1.2.31",
36
+ "@vulog/aima-core": "1.2.31"
24
37
  },
25
38
  "peerDependencies": {
26
39
  "zod": "^3.25.76"
@@ -50,15 +50,11 @@ describe('createUnavailability', () => {
50
50
 
51
51
  const result = await createUnavailability(client, body);
52
52
  expect(result).toEqual(mockResponse);
53
- expect(postMock).toBeCalledWith(
54
- `/boapi/proxy/user/fleets/FLEET_ID/scheduledRules/unavailability`,
55
- {
56
- cronExpression: body.cronExpression,
57
- duration: body.duration,
58
- maintenanceTitle: body.maintenanceTitle,
59
- vehicleId: body.vehicleId,
60
- }
61
- );
53
+ expect(postMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/scheduledRules/unavailability`, {
54
+ cronExpression: body.cronExpression,
55
+ duration: body.duration,
56
+ maintenanceTitle: body.maintenanceTitle,
57
+ vehicleId: body.vehicleId,
58
+ });
62
59
  });
63
60
  });
64
-
@@ -68,4 +68,3 @@ describe('deleteUnavailabilitiesByVehicle', () => {
68
68
  });
69
69
  });
70
70
  });
71
-
@@ -33,9 +33,7 @@ describe('deleteUnavailability', () => {
33
33
 
34
34
  const result = await deleteUnavailability(client, id);
35
35
  expect(result).toBeUndefined();
36
- expect(deleteMock).toBeCalledWith(
37
- `/boapi/proxy/user/fleets/FLEET_ID/scheduledRules/unavailability/${id}`
38
- );
36
+ expect(deleteMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/scheduledRules/unavailability/${id}`);
39
37
  });
40
38
 
41
39
  test('should delete unavailability successfully', async () => {
@@ -47,9 +45,7 @@ describe('deleteUnavailability', () => {
47
45
 
48
46
  const result = await deleteUnavailability(client, id);
49
47
  expect(result).toBeUndefined();
50
- expect(deleteMock).toBeCalledWith(
51
- `/boapi/proxy/user/fleets/FLEET_ID/scheduledRules/unavailability/${id}`
52
- );
48
+ expect(deleteMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/scheduledRules/unavailability/${id}`);
53
49
  });
54
50
 
55
51
  test('should throw error on non-404 errors', async () => {
@@ -68,4 +64,3 @@ describe('deleteUnavailability', () => {
68
64
  });
69
65
  });
70
66
  });
71
-
@@ -109,4 +109,3 @@ describe('generateCronExpression', () => {
109
109
  expect(cron).toBe('0 0 12 29 2 ? 2020');
110
110
  });
111
111
  });
112
-
@@ -120,4 +120,3 @@ describe('getUnavailabilities', () => {
120
120
  });
121
121
  });
122
122
  });
123
-
@@ -76,4 +76,3 @@ describe('getUnavailabilitiesByVehicle', () => {
76
76
  });
77
77
  });
78
78
  });
79
-
@@ -64,15 +64,11 @@ describe('updateUnavailability', () => {
64
64
 
65
65
  const result = await updateUnavailability(client, id, body);
66
66
  expect(result).toEqual(mockResponse);
67
- expect(putMock).toBeCalledWith(
68
- `/boapi/proxy/user/fleets/FLEET_ID/scheduledRules/unavailability/${id}`,
69
- {
70
- cronExpression: body.cronExpression,
71
- duration: body.duration,
72
- maintenanceTitle: body.maintenanceTitle,
73
- vehicleId: body.vehicleId,
74
- }
75
- );
67
+ expect(putMock).toBeCalledWith(`/boapi/proxy/user/fleets/FLEET_ID/scheduledRules/unavailability/${id}`, {
68
+ cronExpression: body.cronExpression,
69
+ duration: body.duration,
70
+ maintenanceTitle: body.maintenanceTitle,
71
+ vehicleId: body.vehicleId,
72
+ });
76
73
  });
77
74
  });
78
-
@@ -1,4 +1,4 @@
1
- import { defineConfig } from 'tsup';
1
+ import { defineConfig } from 'tsdown';
2
2
 
3
3
  export default defineConfig({
4
4
  entry: ['src/index.ts'],
package/dist/index.js DELETED
@@ -1,251 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- createUnavailability: () => createUnavailability,
24
- deleteUnavailabilitiesByVehicle: () => deleteUnavailabilitiesByVehicle,
25
- deleteUnavailability: () => deleteUnavailability,
26
- generateCronExpression: () => generateCronExpression,
27
- getUnavailabilities: () => getUnavailabilities,
28
- getUnavailabilitiesByVehicle: () => getUnavailabilitiesByVehicle,
29
- updateUnavailability: () => updateUnavailability
30
- });
31
- module.exports = __toCommonJS(index_exports);
32
-
33
- // src/getUnavailabilitiesByVehicle.ts
34
- var import_zod = require("zod");
35
- var schema = import_zod.z.object({
36
- vehicleId: import_zod.z.string().trim().min(1).uuid()
37
- });
38
- var getUnavailabilitiesByVehicle = async (client, vehicleId) => {
39
- const result = schema.safeParse({ vehicleId });
40
- if (!result.success) {
41
- throw new TypeError("Invalid args", {
42
- cause: result.error.issues
43
- });
44
- }
45
- return client.get(
46
- `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/vehicles/${result.data.vehicleId}`
47
- ).then(({ data }) => data).catch((error) => {
48
- if (error.formattedError?.status === 404) {
49
- return [];
50
- }
51
- throw error;
52
- });
53
- };
54
-
55
- // src/getUnavailabilities.ts
56
- var import_zod2 = require("zod");
57
- var schema2 = import_zod2.z.object({
58
- from: import_zod2.z.string().datetime({ offset: false, precision: 0 }),
59
- to: import_zod2.z.string().datetime({ offset: false, precision: 0 }),
60
- page: import_zod2.z.number().int().nonnegative().default(0)
61
- });
62
- var getUnavailabilities = async (client, options) => {
63
- const result = schema2.safeParse({
64
- from: options.from,
65
- to: options.to,
66
- page: options.page ?? 0
67
- });
68
- if (!result.success) {
69
- throw new TypeError("Invalid args", {
70
- cause: result.error.issues
71
- });
72
- }
73
- const allUnavailabilities = [];
74
- let currentPage = result.data.page;
75
- let hasMorePages = true;
76
- const MAX_PAGES = 50;
77
- while (hasMorePages) {
78
- if (currentPage >= MAX_PAGES) {
79
- throw new Error(
80
- `Maximum page limit (${MAX_PAGES}) reached. This might indicate an issue with the pagination or a very large dataset.`
81
- );
82
- }
83
- const queryParams = new URLSearchParams({
84
- from: result.data.from,
85
- to: result.data.to,
86
- page: currentPage.toString()
87
- });
88
- const unavailabilities = await client.get(
89
- `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/vehicles?${queryParams.toString()}`
90
- ).then(({ data }) => data).catch((error) => {
91
- if (error.formattedError?.status === 404) {
92
- return [];
93
- }
94
- throw error;
95
- });
96
- allUnavailabilities.push(...unavailabilities);
97
- hasMorePages = unavailabilities.length > 0;
98
- currentPage += 1;
99
- }
100
- return allUnavailabilities;
101
- };
102
-
103
- // src/createUnavailability.ts
104
- var import_zod3 = require("zod");
105
- var schema3 = import_zod3.z.object({
106
- cronExpression: import_zod3.z.string().min(1),
107
- duration: import_zod3.z.number().int().positive(),
108
- maintenanceTitle: import_zod3.z.string().min(1),
109
- vehicleId: import_zod3.z.string().uuid()
110
- });
111
- var createUnavailability = async (client, body) => {
112
- const result = schema3.safeParse(body);
113
- if (!result.success) {
114
- throw new TypeError("Invalid args", {
115
- cause: result.error.issues
116
- });
117
- }
118
- return client.post(
119
- `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability`,
120
- {
121
- cronExpression: result.data.cronExpression,
122
- duration: result.data.duration,
123
- maintenanceTitle: result.data.maintenanceTitle,
124
- vehicleId: result.data.vehicleId
125
- }
126
- ).then(({ data }) => data);
127
- };
128
-
129
- // src/updateUnavailability.ts
130
- var import_zod4 = require("zod");
131
- var schema4 = import_zod4.z.object({
132
- id: import_zod4.z.number().int().positive(),
133
- cronExpression: import_zod4.z.string().min(1),
134
- duration: import_zod4.z.number().int().positive(),
135
- maintenanceTitle: import_zod4.z.string().min(1),
136
- vehicleId: import_zod4.z.string().uuid()
137
- });
138
- var updateUnavailability = async (client, id, body) => {
139
- const result = schema4.safeParse({
140
- id,
141
- ...body
142
- });
143
- if (!result.success) {
144
- throw new TypeError("Invalid args", {
145
- cause: result.error.issues
146
- });
147
- }
148
- return client.put(
149
- `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/${result.data.id}`,
150
- {
151
- cronExpression: result.data.cronExpression,
152
- duration: result.data.duration,
153
- maintenanceTitle: result.data.maintenanceTitle,
154
- vehicleId: result.data.vehicleId
155
- }
156
- ).then(({ data }) => data);
157
- };
158
-
159
- // src/deleteUnavailability.ts
160
- var import_zod5 = require("zod");
161
- var schema5 = import_zod5.z.object({
162
- id: import_zod5.z.number().int().positive()
163
- });
164
- var deleteUnavailability = async (client, id) => {
165
- const result = schema5.safeParse({ id });
166
- if (!result.success) {
167
- throw new TypeError("Invalid args", {
168
- cause: result.error.issues
169
- });
170
- }
171
- return client.delete(
172
- `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/${result.data.id}`
173
- ).then(() => void 0).catch((error) => {
174
- if (error.formattedError?.status === 404) {
175
- return void 0;
176
- }
177
- throw error;
178
- });
179
- };
180
-
181
- // src/deleteUnavailabilitiesByVehicle.ts
182
- var import_zod6 = require("zod");
183
- var schema6 = import_zod6.z.object({
184
- vehicleId: import_zod6.z.string().trim().min(1).uuid()
185
- });
186
- var deleteUnavailabilitiesByVehicle = async (client, vehicleId) => {
187
- const result = schema6.safeParse({ vehicleId });
188
- if (!result.success) {
189
- throw new TypeError("Invalid args", {
190
- cause: result.error.issues
191
- });
192
- }
193
- return client.delete(
194
- `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/scheduledRules/unavailability/vehicles/${result.data.vehicleId}`
195
- ).then(() => void 0).catch((error) => {
196
- if (error.formattedError?.status === 404) {
197
- return void 0;
198
- }
199
- throw error;
200
- });
201
- };
202
-
203
- // src/generateCronExpression.ts
204
- var generateCronExpression = (date, timezone) => {
205
- let dateObj;
206
- if (typeof date === "string") {
207
- dateObj = new Date(date);
208
- } else {
209
- dateObj = new Date(date);
210
- }
211
- if (Number.isNaN(dateObj.getTime())) {
212
- throw new TypeError("Invalid date provided");
213
- }
214
- if (timezone) {
215
- const formatter = new Intl.DateTimeFormat("en-US", {
216
- timeZone: timezone,
217
- year: "numeric",
218
- month: "2-digit",
219
- day: "2-digit",
220
- hour: "2-digit",
221
- minute: "2-digit",
222
- second: "2-digit",
223
- hour12: false
224
- });
225
- const parts = formatter.formatToParts(dateObj);
226
- const year2 = parseInt(parts.find((p) => p.type === "year")?.value || "0", 10);
227
- const month2 = parseInt(parts.find((p) => p.type === "month")?.value || "0", 10);
228
- const day2 = parseInt(parts.find((p) => p.type === "day")?.value || "0", 10);
229
- const hour2 = parseInt(parts.find((p) => p.type === "hour")?.value || "0", 10);
230
- const minute2 = parseInt(parts.find((p) => p.type === "minute")?.value || "0", 10);
231
- const second2 = parseInt(parts.find((p) => p.type === "second")?.value || "0", 10);
232
- return `${second2} ${minute2} ${hour2} ${day2} ${month2} ? ${year2}`;
233
- }
234
- const year = dateObj.getFullYear();
235
- const month = dateObj.getMonth() + 1;
236
- const day = dateObj.getDate();
237
- const hour = dateObj.getHours();
238
- const minute = dateObj.getMinutes();
239
- const second = dateObj.getSeconds();
240
- return `${second} ${minute} ${hour} ${day} ${month} ? ${year}`;
241
- };
242
- // Annotate the CommonJS export names for ESM import in node:
243
- 0 && (module.exports = {
244
- createUnavailability,
245
- deleteUnavailabilitiesByVehicle,
246
- deleteUnavailability,
247
- generateCronExpression,
248
- getUnavailabilities,
249
- getUnavailabilitiesByVehicle,
250
- updateUnavailability
251
- });
File without changes