@vulog/aima-ticket 1.1.82 → 1.1.84

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 CHANGED
@@ -43,4 +43,16 @@ declare const getTickets: (client: Client, options?: PaginableOptions<TicketFilt
43
43
 
44
44
  declare const getUserGroups: (client: Client, id: string) => Promise<UserGroup[]>;
45
45
 
46
- export { type Priority, PriorityList, type Status, StatusList, type Ticket, type TicketFilters, type UserGroup, getTickets, getUserGroups };
46
+ type CreateTicketParam = {
47
+ subject: string;
48
+ description: string;
49
+ status: 'NEW' | 'PENDING' | 'CLOSED' | 'RESOLVED' | 'ONGOING' | 'REJECTED';
50
+ priority: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
51
+ categoryId: number;
52
+ vehicleIds?: string[];
53
+ userIds?: string[];
54
+ tripId?: string;
55
+ };
56
+ declare const createTicket: (client: Client, data: CreateTicketParam) => Promise<Ticket>;
57
+
58
+ export { type CreateTicketParam, type Priority, PriorityList, type Status, StatusList, type Ticket, type TicketFilters, type UserGroup, createTicket, getTickets, getUserGroups };
package/dist/index.d.ts CHANGED
@@ -43,4 +43,16 @@ declare const getTickets: (client: Client, options?: PaginableOptions<TicketFilt
43
43
 
44
44
  declare const getUserGroups: (client: Client, id: string) => Promise<UserGroup[]>;
45
45
 
46
- export { type Priority, PriorityList, type Status, StatusList, type Ticket, type TicketFilters, type UserGroup, getTickets, getUserGroups };
46
+ type CreateTicketParam = {
47
+ subject: string;
48
+ description: string;
49
+ status: 'NEW' | 'PENDING' | 'CLOSED' | 'RESOLVED' | 'ONGOING' | 'REJECTED';
50
+ priority: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
51
+ categoryId: number;
52
+ vehicleIds?: string[];
53
+ userIds?: string[];
54
+ tripId?: string;
55
+ };
56
+ declare const createTicket: (client: Client, data: CreateTicketParam) => Promise<Ticket>;
57
+
58
+ export { type CreateTicketParam, type Priority, PriorityList, type Status, StatusList, type Ticket, type TicketFilters, type UserGroup, createTicket, getTickets, getUserGroups };
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ createTicket: () => createTicket,
23
24
  getTickets: () => getTickets,
24
25
  getUserGroups: () => getUserGroups
25
26
  });
@@ -89,8 +90,38 @@ var getUserGroups = async (client, id) => {
89
90
  throw error;
90
91
  });
91
92
  };
93
+
94
+ // src/createTicket.ts
95
+ var import_zod4 = require("zod");
96
+ var createTicketParamSchema = import_zod4.z.object({
97
+ subject: import_zod4.z.string().min(1),
98
+ description: import_zod4.z.string().optional(),
99
+ status: import_zod4.z.enum(["NEW", "PENDING", "CLOSED", "RESOLVED", "ONGOING", "REJECTED"]).default("NEW"),
100
+ priority: import_zod4.z.enum(["LOW", "MEDIUM", "HIGH", "CRITICAL"]).default("MEDIUM"),
101
+ categoryId: import_zod4.z.number().min(0),
102
+ vehicleIds: import_zod4.z.array(import_zod4.z.string().uuid()).optional(),
103
+ userIds: import_zod4.z.array(import_zod4.z.string().uuid()).optional(),
104
+ tripId: import_zod4.z.string().optional()
105
+ });
106
+ var createTicket = async (client, data) => {
107
+ const resultData = createTicketParamSchema.safeParse(data);
108
+ if (!resultData.success) {
109
+ throw new TypeError("Invalid data", {
110
+ cause: resultData.error.issues
111
+ });
112
+ }
113
+ const ticket = await client.post(
114
+ `/boapi/proxy/desk/fleets/${client.clientOptions.fleetId}/tickets`,
115
+ resultData.data
116
+ );
117
+ if (!ticket) {
118
+ throw new Error("Failed to create ticket");
119
+ }
120
+ return ticket.data;
121
+ };
92
122
  // Annotate the CommonJS export names for ESM import in node:
93
123
  0 && (module.exports = {
124
+ createTicket,
94
125
  getTickets,
95
126
  getUserGroups
96
127
  });
package/dist/index.mjs CHANGED
@@ -62,7 +62,37 @@ var getUserGroups = async (client, id) => {
62
62
  throw error;
63
63
  });
64
64
  };
65
+
66
+ // src/createTicket.ts
67
+ import { z as z4 } from "zod";
68
+ var createTicketParamSchema = z4.object({
69
+ subject: z4.string().min(1),
70
+ description: z4.string().optional(),
71
+ status: z4.enum(["NEW", "PENDING", "CLOSED", "RESOLVED", "ONGOING", "REJECTED"]).default("NEW"),
72
+ priority: z4.enum(["LOW", "MEDIUM", "HIGH", "CRITICAL"]).default("MEDIUM"),
73
+ categoryId: z4.number().min(0),
74
+ vehicleIds: z4.array(z4.string().uuid()).optional(),
75
+ userIds: z4.array(z4.string().uuid()).optional(),
76
+ tripId: z4.string().optional()
77
+ });
78
+ var createTicket = async (client, data) => {
79
+ const resultData = createTicketParamSchema.safeParse(data);
80
+ if (!resultData.success) {
81
+ throw new TypeError("Invalid data", {
82
+ cause: resultData.error.issues
83
+ });
84
+ }
85
+ const ticket = await client.post(
86
+ `/boapi/proxy/desk/fleets/${client.clientOptions.fleetId}/tickets`,
87
+ resultData.data
88
+ );
89
+ if (!ticket) {
90
+ throw new Error("Failed to create ticket");
91
+ }
92
+ return ticket.data;
93
+ };
65
94
  export {
95
+ createTicket,
66
96
  getTickets,
67
97
  getUserGroups
68
98
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-ticket",
3
- "version": "1.1.82",
3
+ "version": "1.1.84",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -19,11 +19,11 @@
19
19
  "author": "Vulog",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@vulog/aima-client": "1.1.82",
23
- "@vulog/aima-core": "1.1.82"
22
+ "@vulog/aima-client": "1.1.84",
23
+ "@vulog/aima-core": "1.1.84"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "zod": "^3.25.76"
27
27
  },
28
28
  "description": ""
29
- }
29
+ }
@@ -0,0 +1,103 @@
1
+ import { describe, test, vi, expect } from 'vitest';
2
+
3
+ import { createTicket } from './createTicket';
4
+ import { Client } from '@vulog/aima-client';
5
+
6
+ describe('create ticket', () => {
7
+ const postMock = vi.fn();
8
+ const client = {
9
+ post: postMock,
10
+ clientOptions: {
11
+ fleetId: 'FLEET_ID',
12
+ },
13
+ } as unknown as Client;
14
+
15
+ const mock = {
16
+ subject: 'Failed pre-billing payment',
17
+ description: `Description`,
18
+ status: 'NEW' as const,
19
+ priority: 'HIGH' as const,
20
+ categoryId: 32025,
21
+ vehicleIds: ['c9b57828-f011-4ea2-9c6f-c0b2b01383b0'],
22
+ userIds: ['5c4369cd-e826-493c-a20c-e60b62253e68'],
23
+ tripId: 'zeknezpf68',
24
+ };
25
+
26
+ const create = {
27
+ createTicket,
28
+ };
29
+
30
+ const ticket = {
31
+ id: '3ec3dab8-9e7e-4b8d-be95-19bb3401227a',
32
+ fleetId: 'LEO-CAMTR',
33
+ tripId: '723752C7F3ADC56C13D4E7AFE04A9B57',
34
+ creatorId: null,
35
+ assignedTo: null,
36
+ subject: 'Failed pre-billing payment',
37
+ description: 'Description',
38
+ status: 'NEW',
39
+ priority: 'HIGH',
40
+ categoryId: '32025',
41
+ eventType: null,
42
+ modelId: null,
43
+ isManuallyCreated: false,
44
+ vehicleIds: ['c9b57828-f011-4ea2-9c6f-c0b2b01383b0'],
45
+ userIds: ['5c4369cd-e826-493c-a20c-e60b62253e68'],
46
+ vehicleCount: 1,
47
+ userCount: 1,
48
+ creationDate: '2025-08-19 06:52:17',
49
+ updateDate: '2025-08-19 06:52:17',
50
+ workedHours: null,
51
+ customerFault: false,
52
+ groupId: null,
53
+ userId: '5c4369cd-e826-493c-a20c-e60b62253e68',
54
+ vehicleId: 'c9b57828-f011-4ea2-9c6f-c0b2b01383b0',
55
+ };
56
+
57
+ const createTicketSpy = vi.spyOn(create, 'createTicket');
58
+
59
+ test('call ok', async () => {
60
+ const mockData = mock;
61
+ postMock.mockResolvedValue({ data: ticket });
62
+ await create.createTicket(client, mockData);
63
+ expect(createTicketSpy).toHaveBeenCalledWith(client, mockData);
64
+ expect(createTicketSpy).toHaveBeenCalledTimes(1);
65
+ expect(postMock).toHaveBeenCalledWith(
66
+ `/boapi/proxy/desk/fleets/${client.clientOptions.fleetId}/tickets`,
67
+ mockData
68
+ );
69
+ expect(postMock).toHaveBeenCalledTimes(1);
70
+ });
71
+
72
+ test('call with invalid data', async () => {
73
+ const invalidData = {
74
+ ...mock,
75
+ subject: '',
76
+ };
77
+ await expect(create.createTicket(client, invalidData)).rejects.toThrow(TypeError);
78
+ });
79
+
80
+ test('call with invalid vehicleIds', async () => {
81
+ const invalidData = {
82
+ ...mock,
83
+ vehicleIds: ['invalid-uuid'],
84
+ };
85
+ await expect(create.createTicket(client, invalidData)).rejects.toThrow(TypeError);
86
+ });
87
+
88
+ test('call with invalid userIds', async () => {
89
+ const invalidData = {
90
+ ...mock,
91
+ userIds: ['invalid-uuid'],
92
+ };
93
+ await expect(create.createTicket(client, invalidData)).rejects.toThrow(TypeError);
94
+ });
95
+
96
+ test('call with invalid categoryId', async () => {
97
+ const invalidData = {
98
+ ...mock,
99
+ categoryId: '12345',
100
+ };
101
+ await expect(create.createTicket(client, invalidData)).rejects.toThrow(TypeError);
102
+ });
103
+ });
@@ -0,0 +1,44 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ import { Ticket } from './types';
5
+
6
+ export type CreateTicketParam = {
7
+ subject: string;
8
+ description: string;
9
+ status: 'NEW' | 'PENDING' | 'CLOSED' | 'RESOLVED' | 'ONGOING' | 'REJECTED';
10
+ priority: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
11
+ categoryId: number;
12
+ vehicleIds?: string[];
13
+ userIds?: string[];
14
+ tripId?: string;
15
+ };
16
+
17
+ const createTicketParamSchema = z.object({
18
+ subject: z.string().min(1),
19
+ description: z.string().optional(),
20
+ status: z.enum(['NEW', 'PENDING', 'CLOSED', 'RESOLVED', 'ONGOING', 'REJECTED']).default('NEW'),
21
+ priority: z.enum(['LOW', 'MEDIUM', 'HIGH', 'CRITICAL']).default('MEDIUM'),
22
+ categoryId: z.number().min(0),
23
+ vehicleIds: z.array(z.string().uuid()).optional(),
24
+ userIds: z.array(z.string().uuid()).optional(),
25
+ tripId: z.string().optional(),
26
+ });
27
+
28
+ export const createTicket = async (client: Client, data: CreateTicketParam): Promise<Ticket> => {
29
+ const resultData = createTicketParamSchema.safeParse(data);
30
+ if (!resultData.success) {
31
+ throw new TypeError('Invalid data', {
32
+ cause: resultData.error.issues,
33
+ });
34
+ }
35
+
36
+ const ticket = await client.post(
37
+ `/boapi/proxy/desk/fleets/${client.clientOptions.fleetId}/tickets`,
38
+ resultData.data
39
+ );
40
+ if (!ticket) {
41
+ throw new Error('Failed to create ticket');
42
+ }
43
+ return ticket.data;
44
+ };
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './getTickets';
2
2
  export * from './getUserGroupById';
3
+ export * from './createTicket';
3
4
  export type * from './types';