@vulog/aima-business 1.2.39 → 1.2.40
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 +248 -69
- package/dist/index.d.cts +254 -49
- package/dist/index.d.mts +254 -49
- package/dist/index.mjs +248 -69
- package/package.json +4 -4
- package/src/addBusinessCredit.ts +2 -0
- package/src/bulkAddBusinessUsers.ts +22 -17
- package/src/chargeBusinessProduct.ts +8 -0
- package/src/createBusiness.ts +45 -3
- package/src/createBusinessCostCenter.test.ts +15 -5
- package/src/createBusinessCostCenter.ts +3 -0
- package/src/getBusinessInviteLink.ts +30 -3
- package/src/getBusinessInvoices.test.ts +56 -0
- package/src/getBusinessInvoices.ts +21 -2
- package/src/getBusinessUsers.test.ts +54 -0
- package/src/getBusinessUsers.ts +16 -2
- package/src/getBusinessWallet.test.ts +44 -9
- package/src/getBusinessWallet.ts +32 -6
- package/src/getBusinesses.test.ts +71 -0
- package/src/getBusinesses.ts +24 -2
- package/src/getEntityProducts.ts +43 -6
- package/src/getEntityTrips.ts +47 -6
- package/src/getEntityTripsCost.ts +42 -9
- package/src/getInvoiceRefundNote.ts +18 -6
- package/src/getOngoingTrips.test.ts +72 -12
- package/src/getOngoingTrips.ts +37 -4
- package/src/inviteBusinessUser.ts +18 -7
- package/src/searchBusinessUsersByName.ts +1 -1
- package/src/searchBusinessUsersGlobal.ts +3 -3
- package/src/sendBusinessIban.ts +2 -0
- package/src/setInvoiceExternalPayment.ts +6 -4
- package/src/types.ts +167 -25
- package/src/updateBusiness.ts +45 -3
- package/src/updateBusinessCostCenter.ts +2 -0
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
let zod = require("zod");
|
|
3
3
|
let _vulog_aima_core = require("@vulog/aima-core");
|
|
4
4
|
//#region src/addBusinessCredit.ts
|
|
5
|
-
const bodySchema$5 = zod.z.object({
|
|
5
|
+
const bodySchema$5 = zod.z.object({
|
|
6
|
+
amount: zod.z.number().min(0),
|
|
7
|
+
expirationDate: zod.z.string().trim().min(1)
|
|
8
|
+
});
|
|
6
9
|
const addBusinessCredit = async (client, businessId, body) => {
|
|
7
10
|
const parsedId = zod.z.string().trim().min(1).uuid().safeParse(businessId);
|
|
8
11
|
if (!parsedId.success) throw new TypeError("Invalid args", { cause: parsedId.error.issues });
|
|
@@ -29,7 +32,7 @@ const addTripNote = async (client, tripId, body) => {
|
|
|
29
32
|
};
|
|
30
33
|
//#endregion
|
|
31
34
|
//#region src/addUserToBusiness.ts
|
|
32
|
-
const uuidSchema$
|
|
35
|
+
const uuidSchema$10 = zod.z.string().trim().min(1).uuid();
|
|
33
36
|
const bodySchema$4 = zod.z.object({
|
|
34
37
|
email: zod.z.string().trim().email().optional(),
|
|
35
38
|
emailConsent: zod.z.boolean().optional(),
|
|
@@ -37,8 +40,8 @@ const bodySchema$4 = zod.z.object({
|
|
|
37
40
|
costCenterId: zod.z.string().trim().min(1).uuid().optional()
|
|
38
41
|
}).optional();
|
|
39
42
|
const addUserToBusiness = async (client, businessId, userId, data) => {
|
|
40
|
-
const parsedBusinessId = uuidSchema$
|
|
41
|
-
const parsedUserId = uuidSchema$
|
|
43
|
+
const parsedBusinessId = uuidSchema$10.safeParse(businessId);
|
|
44
|
+
const parsedUserId = uuidSchema$10.safeParse(userId);
|
|
42
45
|
if (!parsedBusinessId.success || !parsedUserId.success) throw new TypeError("Invalid args", { cause: [...parsedBusinessId.error?.issues ?? [], ...parsedUserId.error?.issues ?? []] });
|
|
43
46
|
const result = bodySchema$4.safeParse(data);
|
|
44
47
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
@@ -46,11 +49,11 @@ const addUserToBusiness = async (client, businessId, userId, data) => {
|
|
|
46
49
|
};
|
|
47
50
|
//#endregion
|
|
48
51
|
//#region src/archiveBusinessProfile.ts
|
|
49
|
-
const uuidSchema$
|
|
52
|
+
const uuidSchema$9 = zod.z.string().trim().min(1).uuid();
|
|
50
53
|
const archiveBusinessProfile = async (client, businessId, userId, profileId) => {
|
|
51
|
-
const parsedBusinessId = uuidSchema$
|
|
52
|
-
const parsedUserId = uuidSchema$
|
|
53
|
-
const parsedProfileId = uuidSchema$
|
|
54
|
+
const parsedBusinessId = uuidSchema$9.safeParse(businessId);
|
|
55
|
+
const parsedUserId = uuidSchema$9.safeParse(userId);
|
|
56
|
+
const parsedProfileId = uuidSchema$9.safeParse(profileId);
|
|
54
57
|
if (!parsedBusinessId.success || !parsedUserId.success || !parsedProfileId.success) throw new TypeError("Invalid args", { cause: [
|
|
55
58
|
...parsedBusinessId.error?.issues ?? [],
|
|
56
59
|
...parsedUserId.error?.issues ?? [],
|
|
@@ -60,17 +63,17 @@ const archiveBusinessProfile = async (client, businessId, userId, profileId) =>
|
|
|
60
63
|
};
|
|
61
64
|
//#endregion
|
|
62
65
|
//#region src/bulkAddBusinessUsers.ts
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
const uuidSchema$8 = zod.z.string().trim().min(1).uuid();
|
|
67
|
+
const bulkAddBusinessUsers = async (client, businessId, file, locale) => {
|
|
68
|
+
const parsedId = uuidSchema$8.safeParse(businessId);
|
|
69
|
+
if (!parsedId.success) throw new TypeError("Invalid args", { cause: parsedId.error.issues });
|
|
70
|
+
const formData = new FormData();
|
|
71
|
+
formData.append("file", file);
|
|
72
|
+
const searchParams = new URLSearchParams();
|
|
73
|
+
if (locale) searchParams.append("locale", locale);
|
|
74
|
+
const queryString = searchParams.toString();
|
|
75
|
+
const url = `/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${parsedId.data}/user/bulk${queryString ? `?${queryString}` : ""}`;
|
|
76
|
+
return client.post(url, formData, { headers: { "Content-Type": "multipart/form-data" } }).then(({ data }) => data);
|
|
74
77
|
};
|
|
75
78
|
//#endregion
|
|
76
79
|
//#region src/businessDelegatedAdmin.ts
|
|
@@ -104,7 +107,13 @@ const removeBusinessOwner = async (client, businessId, userId) => {
|
|
|
104
107
|
};
|
|
105
108
|
//#endregion
|
|
106
109
|
//#region src/chargeBusinessProduct.ts
|
|
107
|
-
const bodySchema$3 = zod.z.object({
|
|
110
|
+
const bodySchema$3 = zod.z.object({
|
|
111
|
+
productId: zod.z.string().trim().min(1),
|
|
112
|
+
amount: zod.z.number().min(0),
|
|
113
|
+
userId: zod.z.string().trim().min(1).uuid().optional(),
|
|
114
|
+
productNotes: zod.z.string().trim().optional(),
|
|
115
|
+
serviceId: zod.z.string().trim().min(1).uuid().optional()
|
|
116
|
+
});
|
|
108
117
|
const chargeBusinessProduct = async (client, businessId, body) => {
|
|
109
118
|
const parsedId = zod.z.string().trim().min(1).uuid().safeParse(businessId);
|
|
110
119
|
if (!parsedId.success) throw new TypeError("Invalid args", { cause: parsedId.error.issues });
|
|
@@ -114,7 +123,7 @@ const chargeBusinessProduct = async (client, businessId, body) => {
|
|
|
114
123
|
};
|
|
115
124
|
//#endregion
|
|
116
125
|
//#region src/createBusiness.ts
|
|
117
|
-
const createBusinessBodySchema = zod.z.object({ name: zod.z.string().trim().min(1).max(255) });
|
|
126
|
+
const createBusinessBodySchema = zod.z.object({ name: zod.z.string().trim().min(1).max(255) }).passthrough();
|
|
118
127
|
const createBusiness = async (client, body) => {
|
|
119
128
|
const result = createBusinessBodySchema.safeParse(body);
|
|
120
129
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
@@ -122,17 +131,21 @@ const createBusiness = async (client, body) => {
|
|
|
122
131
|
};
|
|
123
132
|
//#endregion
|
|
124
133
|
//#region src/createBusinessCostCenter.ts
|
|
125
|
-
const schema$
|
|
134
|
+
const schema$10 = zod.z.object({
|
|
126
135
|
businessId: zod.z.string().trim().min(1).uuid(),
|
|
127
|
-
name: zod.z.string().trim().min(1).max(255)
|
|
136
|
+
name: zod.z.string().trim().min(1).max(255),
|
|
137
|
+
value: zod.z.string().trim().min(1)
|
|
128
138
|
});
|
|
129
139
|
const createBusinessCostCenter = async (client, businessId, body) => {
|
|
130
|
-
const result = schema$
|
|
140
|
+
const result = schema$10.safeParse({
|
|
131
141
|
businessId,
|
|
132
142
|
...body
|
|
133
143
|
});
|
|
134
144
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
135
|
-
return client.post(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${result.data.businessId}/costcenter`, {
|
|
145
|
+
return client.post(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${result.data.businessId}/costcenter`, {
|
|
146
|
+
name: result.data.name,
|
|
147
|
+
value: result.data.value
|
|
148
|
+
}).then(({ data }) => data);
|
|
136
149
|
};
|
|
137
150
|
//#endregion
|
|
138
151
|
//#region src/deactivateBusinessProfile.ts
|
|
@@ -145,12 +158,12 @@ const deactivateBusinessProfile = async (client, businessId, profileId) => {
|
|
|
145
158
|
};
|
|
146
159
|
//#endregion
|
|
147
160
|
//#region src/deleteBusinessCostCenter.ts
|
|
148
|
-
const schema$
|
|
161
|
+
const schema$9 = zod.z.object({
|
|
149
162
|
businessId: zod.z.string().trim().min(1).uuid(),
|
|
150
163
|
costCenterId: zod.z.string().trim().min(1).uuid()
|
|
151
164
|
});
|
|
152
165
|
const deleteBusinessCostCenter = async (client, businessId, costCenterId) => {
|
|
153
|
-
const result = schema$
|
|
166
|
+
const result = schema$9.safeParse({
|
|
154
167
|
businessId,
|
|
155
168
|
costCenterId
|
|
156
169
|
});
|
|
@@ -185,12 +198,12 @@ const getBusinessContacts = async (client, businessId) => {
|
|
|
185
198
|
};
|
|
186
199
|
//#endregion
|
|
187
200
|
//#region src/getBusinessCostCenterById.ts
|
|
188
|
-
const schema$
|
|
201
|
+
const schema$8 = zod.z.object({
|
|
189
202
|
businessId: zod.z.string().trim().min(1).uuid(),
|
|
190
203
|
costCenterId: zod.z.string().trim().min(1).uuid()
|
|
191
204
|
});
|
|
192
205
|
const getBusinessCostCenterById = async (client, businessId, costCenterId) => {
|
|
193
|
-
const result = schema$
|
|
206
|
+
const result = schema$8.safeParse({
|
|
194
207
|
businessId,
|
|
195
208
|
costCenterId
|
|
196
209
|
});
|
|
@@ -206,14 +219,28 @@ const getBusinessCostCenters = async (client, businessId) => {
|
|
|
206
219
|
};
|
|
207
220
|
//#endregion
|
|
208
221
|
//#region src/getBusinesses.ts
|
|
222
|
+
const businessFiltersSchema = zod.z.object({
|
|
223
|
+
name: zod.z.string().trim().min(1).optional(),
|
|
224
|
+
status: zod.z.string().trim().min(1).optional(),
|
|
225
|
+
updateSince: zod.z.string().trim().min(1).optional()
|
|
226
|
+
});
|
|
209
227
|
const getBusinesses = async (client, options) => {
|
|
210
|
-
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)().safeParse(options ?? {});
|
|
228
|
+
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)(businessFiltersSchema.default({})).safeParse(options ?? {});
|
|
211
229
|
if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
|
|
212
230
|
const finalOptions = resultOptions.data;
|
|
213
231
|
const searchParams = new URLSearchParams();
|
|
214
232
|
searchParams.append("page", finalOptions.page.toString());
|
|
215
233
|
searchParams.append("size", finalOptions.pageSize.toString());
|
|
216
234
|
if (finalOptions.sort) searchParams.append("sort", `${finalOptions.sort.toString()},${finalOptions.sortDirection.toString()}`);
|
|
235
|
+
const filterKeyMap = {
|
|
236
|
+
name: "name",
|
|
237
|
+
status: "status",
|
|
238
|
+
updateSince: "update_since"
|
|
239
|
+
};
|
|
240
|
+
Object.entries(finalOptions.filters).forEach(([key, value]) => {
|
|
241
|
+
if (value === void 0) return;
|
|
242
|
+
searchParams.append(filterKeyMap[key] ?? key, value);
|
|
243
|
+
});
|
|
217
244
|
const url = `/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business?${searchParams.toString()}`;
|
|
218
245
|
return client.get(url).then(({ data, headers }) => ({
|
|
219
246
|
data,
|
|
@@ -225,10 +252,25 @@ const getBusinesses = async (client, options) => {
|
|
|
225
252
|
};
|
|
226
253
|
//#endregion
|
|
227
254
|
//#region src/getBusinessInviteLink.ts
|
|
228
|
-
const
|
|
229
|
-
|
|
255
|
+
const schema$7 = zod.z.object({
|
|
256
|
+
businessId: zod.z.string().trim().min(1).uuid(),
|
|
257
|
+
email: zod.z.string().trim().email(),
|
|
258
|
+
firstName: zod.z.string().trim().min(1).optional(),
|
|
259
|
+
lastName: zod.z.string().trim().min(1).optional(),
|
|
260
|
+
costCenterId: zod.z.string().trim().min(1).uuid().optional()
|
|
261
|
+
});
|
|
262
|
+
const getBusinessInviteLink = async (client, businessId, params) => {
|
|
263
|
+
const result = schema$7.safeParse({
|
|
264
|
+
businessId,
|
|
265
|
+
...params
|
|
266
|
+
});
|
|
230
267
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
231
|
-
|
|
268
|
+
const { businessId: parsedId, ...queryFields } = result.data;
|
|
269
|
+
const searchParams = new URLSearchParams();
|
|
270
|
+
Object.entries(queryFields).forEach(([key, value]) => {
|
|
271
|
+
if (value !== void 0) searchParams.append(key, value);
|
|
272
|
+
});
|
|
273
|
+
return client.get(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${parsedId}/user/invite/link?${searchParams.toString()}`).then(({ data }) => data);
|
|
232
274
|
};
|
|
233
275
|
//#endregion
|
|
234
276
|
//#region src/getBusinessInvoiceProducts.ts
|
|
@@ -241,16 +283,28 @@ const getBusinessInvoiceProducts = async (client, entityId, invoiceId) => {
|
|
|
241
283
|
};
|
|
242
284
|
//#endregion
|
|
243
285
|
//#region src/getBusinessInvoices.ts
|
|
286
|
+
const invoiceFiltersSchema = zod.z.object({
|
|
287
|
+
fromDate: zod.z.string().trim().min(1).optional(),
|
|
288
|
+
toDate: zod.z.string().trim().min(1).optional()
|
|
289
|
+
});
|
|
244
290
|
const getBusinessInvoices = async (client, entityId, options) => {
|
|
245
291
|
const resultId = zod.z.string().trim().min(1).uuid().safeParse(entityId);
|
|
246
292
|
if (!resultId.success) throw new TypeError("Invalid args", { cause: resultId.error.issues });
|
|
247
|
-
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)().safeParse(options ?? {});
|
|
293
|
+
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)(invoiceFiltersSchema.default({})).safeParse(options ?? {});
|
|
248
294
|
if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
|
|
249
295
|
const finalOptions = resultOptions.data;
|
|
250
296
|
const searchParams = new URLSearchParams();
|
|
251
297
|
searchParams.append("page", finalOptions.page.toString());
|
|
252
298
|
searchParams.append("size", finalOptions.pageSize.toString());
|
|
253
299
|
if (finalOptions.sort) searchParams.append("sort", `${finalOptions.sort.toString()},${finalOptions.sortDirection.toString()}`);
|
|
300
|
+
const filterKeyMap = {
|
|
301
|
+
fromDate: "from_date",
|
|
302
|
+
toDate: "to_date"
|
|
303
|
+
};
|
|
304
|
+
Object.entries(finalOptions.filters).forEach(([key, value]) => {
|
|
305
|
+
if (value === void 0) return;
|
|
306
|
+
searchParams.append(filterKeyMap[key] ?? key, value);
|
|
307
|
+
});
|
|
254
308
|
const url = `/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/entities/${resultId.data}/businessInvoices?${searchParams.toString()}`;
|
|
255
309
|
return client.get(url).then(({ data, headers }) => ({
|
|
256
310
|
data,
|
|
@@ -306,16 +360,24 @@ const getBusinessUserGlobalById = async (client, userId) => {
|
|
|
306
360
|
};
|
|
307
361
|
//#endregion
|
|
308
362
|
//#region src/getBusinessUsers.ts
|
|
363
|
+
const businessUserFiltersSchema = zod.z.object({
|
|
364
|
+
role: zod.z.string().trim().min(1).optional(),
|
|
365
|
+
status: zod.z.string().trim().min(1).optional()
|
|
366
|
+
});
|
|
309
367
|
const getBusinessUsers = async (client, businessId, options) => {
|
|
310
368
|
const resultId = zod.z.string().trim().min(1).uuid().safeParse(businessId);
|
|
311
369
|
if (!resultId.success) throw new TypeError("Invalid args", { cause: resultId.error.issues });
|
|
312
|
-
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)().safeParse(options ?? {});
|
|
370
|
+
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)(businessUserFiltersSchema.default({})).safeParse(options ?? {});
|
|
313
371
|
if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
|
|
314
372
|
const finalOptions = resultOptions.data;
|
|
315
373
|
const searchParams = new URLSearchParams();
|
|
316
374
|
searchParams.append("page", finalOptions.page.toString());
|
|
317
375
|
searchParams.append("size", finalOptions.pageSize.toString());
|
|
318
376
|
if (finalOptions.sort) searchParams.append("sort", `${finalOptions.sort.toString()},${finalOptions.sortDirection.toString()}`);
|
|
377
|
+
Object.entries(finalOptions.filters).forEach(([key, value]) => {
|
|
378
|
+
if (value === void 0) return;
|
|
379
|
+
searchParams.append(key, value);
|
|
380
|
+
});
|
|
319
381
|
const url = `/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${resultId.data}/user?${searchParams.toString()}`;
|
|
320
382
|
return client.get(url).then(({ data, headers }) => ({
|
|
321
383
|
data,
|
|
@@ -327,10 +389,24 @@ const getBusinessUsers = async (client, businessId, options) => {
|
|
|
327
389
|
};
|
|
328
390
|
//#endregion
|
|
329
391
|
//#region src/getBusinessWallet.ts
|
|
330
|
-
const getBusinessWallet = async (client, businessId) => {
|
|
392
|
+
const getBusinessWallet = async (client, businessId, options) => {
|
|
331
393
|
const result = zod.z.string().trim().min(1).uuid().safeParse(businessId);
|
|
332
394
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
333
|
-
|
|
395
|
+
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)().safeParse(options ?? {});
|
|
396
|
+
if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
|
|
397
|
+
const finalOptions = resultOptions.data;
|
|
398
|
+
const searchParams = new URLSearchParams();
|
|
399
|
+
searchParams.append("page", finalOptions.page.toString());
|
|
400
|
+
searchParams.append("size", finalOptions.pageSize.toString());
|
|
401
|
+
if (finalOptions.sort) searchParams.append("sort", `${finalOptions.sort.toString()},${finalOptions.sortDirection.toString()}`);
|
|
402
|
+
const url = `/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${result.data}/wallet?${searchParams.toString()}`;
|
|
403
|
+
return client.get(url).then(({ data, headers }) => ({
|
|
404
|
+
data,
|
|
405
|
+
page: headers.number,
|
|
406
|
+
pageSize: headers.size,
|
|
407
|
+
total: headers.totalelements,
|
|
408
|
+
totalPages: headers.totalpages
|
|
409
|
+
}));
|
|
334
410
|
};
|
|
335
411
|
//#endregion
|
|
336
412
|
//#region src/getEntityBalance.ts
|
|
@@ -341,24 +417,90 @@ const getEntityBalance = async (client, entityId) => {
|
|
|
341
417
|
};
|
|
342
418
|
//#endregion
|
|
343
419
|
//#region src/getEntityProducts.ts
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
420
|
+
const entityProductFiltersSchema = zod.z.object({
|
|
421
|
+
period: zod.z.string().trim().min(1),
|
|
422
|
+
user: zod.z.string().trim().min(1).optional(),
|
|
423
|
+
productDetailsType: zod.z.enum([
|
|
424
|
+
"UNIT",
|
|
425
|
+
"ACCUMULATIVE",
|
|
426
|
+
"DEFAULT"
|
|
427
|
+
]).optional()
|
|
428
|
+
});
|
|
429
|
+
const getEntityProducts = async (client, entityId, options) => {
|
|
430
|
+
const parsedId = zod.z.string().trim().min(1).uuid().safeParse(entityId);
|
|
431
|
+
if (!parsedId.success) throw new TypeError("Invalid args", { cause: parsedId.error.issues });
|
|
432
|
+
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)(entityProductFiltersSchema).safeParse(options);
|
|
433
|
+
if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
|
|
434
|
+
const finalOptions = resultOptions.data;
|
|
435
|
+
const searchParams = new URLSearchParams();
|
|
436
|
+
searchParams.append("page", finalOptions.page.toString());
|
|
437
|
+
searchParams.append("size", finalOptions.pageSize.toString());
|
|
438
|
+
searchParams.append("period", finalOptions.filters.period);
|
|
439
|
+
if (finalOptions.filters.user) searchParams.append("user", finalOptions.filters.user);
|
|
440
|
+
if (finalOptions.filters.productDetailsType) searchParams.append("productDetailsType", finalOptions.filters.productDetailsType);
|
|
441
|
+
return client.get(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/billing/entity/${parsedId.data}/product?${searchParams.toString()}`).then(({ data, headers }) => ({
|
|
442
|
+
data,
|
|
443
|
+
page: headers.number,
|
|
444
|
+
pageSize: headers.size,
|
|
445
|
+
total: headers.totalelements,
|
|
446
|
+
totalPages: headers.totalpages
|
|
447
|
+
}));
|
|
348
448
|
};
|
|
349
449
|
//#endregion
|
|
350
450
|
//#region src/getEntityTrips.ts
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
451
|
+
const entityTripFiltersSchema = zod.z.object({
|
|
452
|
+
period: zod.z.string().trim().min(1),
|
|
453
|
+
costCenterIds: zod.z.array(zod.z.string().trim().min(1)).optional(),
|
|
454
|
+
user: zod.z.string().trim().min(1).optional()
|
|
455
|
+
});
|
|
456
|
+
const getEntityTrips = async (client, entityId, options) => {
|
|
457
|
+
const parsedId = zod.z.string().trim().min(1).uuid().safeParse(entityId);
|
|
458
|
+
if (!parsedId.success) throw new TypeError("Invalid args", { cause: parsedId.error.issues });
|
|
459
|
+
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)(entityTripFiltersSchema).safeParse(options);
|
|
460
|
+
if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
|
|
461
|
+
const finalOptions = resultOptions.data;
|
|
462
|
+
const searchParams = new URLSearchParams();
|
|
463
|
+
searchParams.append("page", finalOptions.page.toString());
|
|
464
|
+
searchParams.append("size", finalOptions.pageSize.toString());
|
|
465
|
+
searchParams.append("period", finalOptions.filters.period);
|
|
466
|
+
if (finalOptions.filters.user) searchParams.append("user", finalOptions.filters.user);
|
|
467
|
+
if (finalOptions.filters.costCenterIds) finalOptions.filters.costCenterIds.forEach((id) => {
|
|
468
|
+
searchParams.append("costCenterIds", id);
|
|
469
|
+
});
|
|
470
|
+
return client.get(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/billing/entity/${parsedId.data}/trip?${searchParams.toString()}`).then(({ data, headers }) => ({
|
|
471
|
+
data,
|
|
472
|
+
page: headers.number,
|
|
473
|
+
pageSize: headers.size,
|
|
474
|
+
total: headers.totalelements,
|
|
475
|
+
totalPages: headers.totalpages
|
|
476
|
+
}));
|
|
355
477
|
};
|
|
356
478
|
//#endregion
|
|
357
479
|
//#region src/getEntityTripsCost.ts
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
480
|
+
const tripsCostFiltersSchema = zod.z.object({
|
|
481
|
+
startDate: zod.z.string().trim().min(1),
|
|
482
|
+
endDate: zod.z.string().trim().min(1),
|
|
483
|
+
tripId: zod.z.string().trim().min(1).optional()
|
|
484
|
+
});
|
|
485
|
+
const getEntityTripsCost = async (client, entityId, options) => {
|
|
486
|
+
const parsedId = zod.z.string().trim().min(1).uuid().safeParse(entityId);
|
|
487
|
+
if (!parsedId.success) throw new TypeError("Invalid args", { cause: parsedId.error.issues });
|
|
488
|
+
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)(tripsCostFiltersSchema).safeParse(options);
|
|
489
|
+
if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
|
|
490
|
+
const finalOptions = resultOptions.data;
|
|
491
|
+
const searchParams = new URLSearchParams();
|
|
492
|
+
searchParams.append("page", finalOptions.page.toString());
|
|
493
|
+
searchParams.append("size", finalOptions.pageSize.toString());
|
|
494
|
+
searchParams.append("startDate", finalOptions.filters.startDate);
|
|
495
|
+
searchParams.append("endDate", finalOptions.filters.endDate);
|
|
496
|
+
if (finalOptions.filters.tripId) searchParams.append("tripId", finalOptions.filters.tripId);
|
|
497
|
+
return client.get(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/billing/entity/${parsedId.data}/trips/cost?${searchParams.toString()}`).then(({ data, headers }) => ({
|
|
498
|
+
data,
|
|
499
|
+
page: headers.number,
|
|
500
|
+
pageSize: headers.size,
|
|
501
|
+
total: headers.totalelements,
|
|
502
|
+
totalPages: headers.totalpages
|
|
503
|
+
}));
|
|
362
504
|
};
|
|
363
505
|
//#endregion
|
|
364
506
|
//#region src/getInvitationRequest.ts
|
|
@@ -384,10 +526,18 @@ const getInvoiceRefundableAmount = async (client, invoiceId) => {
|
|
|
384
526
|
};
|
|
385
527
|
//#endregion
|
|
386
528
|
//#region src/getInvoiceRefundNote.ts
|
|
387
|
-
const getInvoiceRefundNote = async (client, invoiceId) => {
|
|
529
|
+
const getInvoiceRefundNote = async (client, invoiceId, paymentRefundPspReference) => {
|
|
388
530
|
const result = zod.z.string().trim().min(1).uuid().safeParse(invoiceId);
|
|
389
531
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
390
|
-
|
|
532
|
+
const searchParams = new URLSearchParams();
|
|
533
|
+
if (paymentRefundPspReference) {
|
|
534
|
+
const refResult = zod.z.string().trim().min(1).safeParse(paymentRefundPspReference);
|
|
535
|
+
if (!refResult.success) throw new TypeError("Invalid args", { cause: refResult.error.issues });
|
|
536
|
+
searchParams.append("paymentRefundPspReference", refResult.data);
|
|
537
|
+
}
|
|
538
|
+
const query = searchParams.toString();
|
|
539
|
+
const url = `/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/invoices/${result.data}/refundNote${query ? `?${query}` : ""}`;
|
|
540
|
+
return client.get(url).then(({ data }) => data);
|
|
391
541
|
};
|
|
392
542
|
//#endregion
|
|
393
543
|
//#region src/getOngoingTripNotes.ts
|
|
@@ -398,8 +548,25 @@ const getOngoingTripNotes = async (client, tripId) => {
|
|
|
398
548
|
};
|
|
399
549
|
//#endregion
|
|
400
550
|
//#region src/getOngoingTrips.ts
|
|
401
|
-
const getOngoingTrips = async (client) => {
|
|
402
|
-
|
|
551
|
+
const getOngoingTrips = async (client, businessId, options) => {
|
|
552
|
+
const parsedId = zod.z.string().trim().min(1).uuid().safeParse(businessId);
|
|
553
|
+
if (!parsedId.success) throw new TypeError("Invalid args", { cause: parsedId.error.issues });
|
|
554
|
+
const resultOptions = (0, _vulog_aima_core.createPaginableOptionsSchema)().safeParse(options ?? {});
|
|
555
|
+
if (!resultOptions.success) throw new TypeError("Invalid options", { cause: resultOptions.error.issues });
|
|
556
|
+
const finalOptions = resultOptions.data;
|
|
557
|
+
const searchParams = new URLSearchParams();
|
|
558
|
+
searchParams.append("business", parsedId.data);
|
|
559
|
+
searchParams.append("page", finalOptions.page.toString());
|
|
560
|
+
searchParams.append("size", finalOptions.pageSize.toString());
|
|
561
|
+
if (finalOptions.sort) searchParams.append("sort", `${finalOptions.sort.toString()},${finalOptions.sortDirection.toString()}`);
|
|
562
|
+
const url = `/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/trip/ongoing?${searchParams.toString()}`;
|
|
563
|
+
return client.get(url).then(({ data, headers }) => ({
|
|
564
|
+
data,
|
|
565
|
+
page: headers.number,
|
|
566
|
+
pageSize: headers.size,
|
|
567
|
+
total: headers.totalelements,
|
|
568
|
+
totalPages: headers.totalpages
|
|
569
|
+
}));
|
|
403
570
|
};
|
|
404
571
|
//#endregion
|
|
405
572
|
//#region src/getStripePublishableKey.ts
|
|
@@ -415,19 +582,26 @@ const getStripeSetup = async (client, businessId) => {
|
|
|
415
582
|
};
|
|
416
583
|
//#endregion
|
|
417
584
|
//#region src/inviteBusinessUser.ts
|
|
418
|
-
const
|
|
585
|
+
const schema$6 = zod.z.object({
|
|
419
586
|
businessId: zod.z.string().trim().min(1).uuid(),
|
|
420
587
|
email: zod.z.string().trim().email(),
|
|
421
|
-
|
|
588
|
+
firstName: zod.z.string().trim().min(1).optional(),
|
|
589
|
+
lastName: zod.z.string().trim().min(1).optional(),
|
|
590
|
+
costCenterId: zod.z.string().trim().min(1).uuid().optional(),
|
|
591
|
+
locale: zod.z.string().trim().min(1).optional()
|
|
422
592
|
});
|
|
423
|
-
const inviteBusinessUser = async (client, businessId,
|
|
424
|
-
const result =
|
|
593
|
+
const inviteBusinessUser = async (client, businessId, params) => {
|
|
594
|
+
const result = schema$6.safeParse({
|
|
425
595
|
businessId,
|
|
426
|
-
...
|
|
596
|
+
...params
|
|
427
597
|
});
|
|
428
598
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
429
|
-
const { businessId: parsedId, ...
|
|
430
|
-
|
|
599
|
+
const { businessId: parsedId, ...queryFields } = result.data;
|
|
600
|
+
const searchParams = new URLSearchParams();
|
|
601
|
+
Object.entries(queryFields).forEach(([key, value]) => {
|
|
602
|
+
if (value !== void 0) searchParams.append(key, value);
|
|
603
|
+
});
|
|
604
|
+
await client.post(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${parsedId}/user/invite?${searchParams.toString()}`);
|
|
431
605
|
};
|
|
432
606
|
//#endregion
|
|
433
607
|
//#region src/listBusinessUsersGlobal.ts
|
|
@@ -493,17 +667,17 @@ const searchBusinessUsersByName = async (client, businessId, name) => {
|
|
|
493
667
|
});
|
|
494
668
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
495
669
|
const searchParams = new URLSearchParams();
|
|
496
|
-
searchParams.append("
|
|
670
|
+
searchParams.append("fullname", result.data.name);
|
|
497
671
|
const url = `/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${result.data.businessId}/users/name?${searchParams.toString()}`;
|
|
498
672
|
return client.get(url).then(({ data }) => data);
|
|
499
673
|
};
|
|
500
674
|
//#endregion
|
|
501
675
|
//#region src/searchBusinessUsersGlobal.ts
|
|
502
|
-
const searchBusinessUsersGlobal = async (client,
|
|
503
|
-
const result = zod.z.string().trim().min(1).safeParse(
|
|
676
|
+
const searchBusinessUsersGlobal = async (client, name) => {
|
|
677
|
+
const result = zod.z.string().trim().min(1).safeParse(name);
|
|
504
678
|
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
505
679
|
const searchParams = new URLSearchParams();
|
|
506
|
-
searchParams.append("
|
|
680
|
+
searchParams.append("name", result.data);
|
|
507
681
|
const url = `/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/users/search?${searchParams.toString()}`;
|
|
508
682
|
return client.get(url).then(({ data }) => data);
|
|
509
683
|
};
|
|
@@ -511,7 +685,8 @@ const searchBusinessUsersGlobal = async (client, query) => {
|
|
|
511
685
|
//#region src/sendBusinessIban.ts
|
|
512
686
|
const schema$2 = zod.z.object({
|
|
513
687
|
businessId: zod.z.string().trim().min(1).uuid(),
|
|
514
|
-
iban: zod.z.string().trim().min(1)
|
|
688
|
+
iban: zod.z.string().trim().min(1),
|
|
689
|
+
entityId: zod.z.string().trim().min(1).optional()
|
|
515
690
|
});
|
|
516
691
|
const sendBusinessIban = async (client, businessId, body) => {
|
|
517
692
|
const result = schema$2.safeParse({
|
|
@@ -525,8 +700,9 @@ const sendBusinessIban = async (client, businessId, body) => {
|
|
|
525
700
|
//#endregion
|
|
526
701
|
//#region src/setInvoiceExternalPayment.ts
|
|
527
702
|
const bodySchema$2 = zod.z.object({
|
|
528
|
-
|
|
529
|
-
|
|
703
|
+
requesterId: zod.z.string().trim().min(1),
|
|
704
|
+
notes: zod.z.string().trim().optional(),
|
|
705
|
+
paymentMethod: zod.z.string().trim().optional()
|
|
530
706
|
});
|
|
531
707
|
const setInvoiceExternalPayment = async (client, invoiceId, body) => {
|
|
532
708
|
const parsedId = zod.z.string().trim().min(1).uuid().safeParse(invoiceId);
|
|
@@ -537,7 +713,7 @@ const setInvoiceExternalPayment = async (client, invoiceId, body) => {
|
|
|
537
713
|
};
|
|
538
714
|
//#endregion
|
|
539
715
|
//#region src/updateBusiness.ts
|
|
540
|
-
const updateBusinessBodySchema = zod.z.object({ name: zod.z.string().trim().min(1).max(255).optional() });
|
|
716
|
+
const updateBusinessBodySchema = zod.z.object({ name: zod.z.string().trim().min(1).max(255).optional() }).passthrough();
|
|
541
717
|
const updateBusiness = async (client, businessId, body) => {
|
|
542
718
|
const parsedId = zod.z.string().trim().min(1).uuid().safeParse(businessId);
|
|
543
719
|
if (!parsedId.success) throw new TypeError("Invalid args", { cause: parsedId.error.issues });
|
|
@@ -548,7 +724,10 @@ const updateBusiness = async (client, businessId, body) => {
|
|
|
548
724
|
//#endregion
|
|
549
725
|
//#region src/updateBusinessCostCenter.ts
|
|
550
726
|
const uuidSchema$1 = zod.z.string().trim().min(1).uuid();
|
|
551
|
-
const bodySchema$1 = zod.z.object({
|
|
727
|
+
const bodySchema$1 = zod.z.object({
|
|
728
|
+
name: zod.z.string().trim().min(1).max(255).optional(),
|
|
729
|
+
value: zod.z.string().trim().min(1).optional()
|
|
730
|
+
});
|
|
552
731
|
const updateBusinessCostCenter = async (client, businessId, costCenterId, body) => {
|
|
553
732
|
const parsedBusinessId = uuidSchema$1.safeParse(businessId);
|
|
554
733
|
const parsedCostCenterId = uuidSchema$1.safeParse(costCenterId);
|