@vulog/aima-business 1.2.39
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 +668 -0
- package/dist/index.d.cts +346 -0
- package/dist/index.d.mts +346 -0
- package/dist/index.mjs +609 -0
- package/package.json +42 -0
- package/src/addBusinessCredit.ts +31 -0
- package/src/addStripePayment.ts +18 -0
- package/src/addTripNote.test.ts +67 -0
- package/src/addTripNote.ts +30 -0
- package/src/addUserToBusiness.test.ts +74 -0
- package/src/addUserToBusiness.ts +49 -0
- package/src/archiveBusinessProfile.ts +28 -0
- package/src/bulkAddBusinessUsers.ts +27 -0
- package/src/businessDelegatedAdmin.test.ts +68 -0
- package/src/businessDelegatedAdmin.ts +32 -0
- package/src/businessOwner.test.ts +68 -0
- package/src/businessOwner.ts +32 -0
- package/src/chargeBusinessProduct.ts +31 -0
- package/src/createBusiness.test.ts +54 -0
- package/src/createBusiness.ts +23 -0
- package/src/createBusinessCostCenter.test.ts +61 -0
- package/src/createBusinessCostCenter.ts +34 -0
- package/src/deactivateBusinessProfile.ts +22 -0
- package/src/deleteBusinessCostCenter.test.ts +45 -0
- package/src/deleteBusinessCostCenter.ts +23 -0
- package/src/deleteInvitationRequest.test.ts +45 -0
- package/src/deleteInvitationRequest.ts +13 -0
- package/src/getBillingGroups.ts +9 -0
- package/src/getBusinessById.test.ts +47 -0
- package/src/getBusinessById.ts +15 -0
- package/src/getBusinessContacts.ts +17 -0
- package/src/getBusinessCostCenterById.ts +27 -0
- package/src/getBusinessCostCenters.ts +18 -0
- package/src/getBusinessInviteLink.ts +17 -0
- package/src/getBusinessInvoiceProducts.ts +24 -0
- package/src/getBusinessInvoiceTrips.ts +20 -0
- package/src/getBusinessInvoices.test.ts +92 -0
- package/src/getBusinessInvoices.ts +43 -0
- package/src/getBusinessPaymentDetails.ts +20 -0
- package/src/getBusinessProducts.ts +9 -0
- package/src/getBusinessTripById.ts +15 -0
- package/src/getBusinessUserById.ts +26 -0
- package/src/getBusinessUserGlobalById.ts +15 -0
- package/src/getBusinessUsers.test.ts +70 -0
- package/src/getBusinessUsers.ts +43 -0
- package/src/getBusinessWallet.test.ts +46 -0
- package/src/getBusinessWallet.ts +17 -0
- package/src/getBusinesses.test.ts +133 -0
- package/src/getBusinesses.ts +36 -0
- package/src/getEntityBalance.ts +17 -0
- package/src/getEntityProducts.ts +15 -0
- package/src/getEntityTrips.ts +13 -0
- package/src/getEntityTripsCost.ts +17 -0
- package/src/getInvitationRequest.test.ts +46 -0
- package/src/getInvitationRequest.ts +17 -0
- package/src/getInvoicePdf.test.ts +62 -0
- package/src/getInvoicePdf.ts +16 -0
- package/src/getInvoiceRefundNote.ts +17 -0
- package/src/getInvoiceRefundableAmount.ts +20 -0
- package/src/getOngoingTripNotes.ts +17 -0
- package/src/getOngoingTrips.test.ts +43 -0
- package/src/getOngoingTrips.ts +9 -0
- package/src/getStripePublishableKey.ts +9 -0
- package/src/getStripeSetup.ts +17 -0
- package/src/index.ts +58 -0
- package/src/inviteBusinessUser.ts +31 -0
- package/src/listBusinessUsersGlobal.test.ts +65 -0
- package/src/listBusinessUsersGlobal.ts +26 -0
- package/src/redeemBusinessPromoCode.ts +18 -0
- package/src/refundInvoice.test.ts +72 -0
- package/src/refundInvoice.ts +33 -0
- package/src/refundInvoiceAmount.ts +20 -0
- package/src/searchBusinessUsersByName.ts +27 -0
- package/src/searchBusinessUsersGlobal.ts +18 -0
- package/src/sendBusinessIban.ts +29 -0
- package/src/setInvoiceExternalPayment.ts +33 -0
- package/src/types.ts +163 -0
- package/src/updateBusiness.test.ts +65 -0
- package/src/updateBusiness.ts +35 -0
- package/src/updateBusinessCostCenter.ts +41 -0
- package/src/updateBusinessProfileStatus.ts +22 -0
- package/src/updateBusinessUserProfile.ts +51 -0
- package/src/updateInvoiceStatus.test.ts +54 -0
- package/src/updateInvoiceStatus.ts +19 -0
- package/tsconfig.json +9 -0
- package/tsdown.config.ts +8 -0
- package/vitest.config.ts +1 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, test, vi, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { Client } from '@vulog/aima-client';
|
|
3
|
+
import { getOngoingTrips } from './getOngoingTrips';
|
|
4
|
+
|
|
5
|
+
describe('getOngoingTrips', () => {
|
|
6
|
+
const getMock = vi.fn();
|
|
7
|
+
const client = {
|
|
8
|
+
get: getMock,
|
|
9
|
+
clientOptions: {
|
|
10
|
+
fleetId: 'FLEET_ID',
|
|
11
|
+
},
|
|
12
|
+
} as unknown as Client;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
vi.clearAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('should return an array of ongoing trips', async () => {
|
|
19
|
+
const mockResponse = [
|
|
20
|
+
{ tripId: '018ab2b6-71b2-4c76-90bd-6e8d3f268618' },
|
|
21
|
+
{ tripId: '129bc3c7-82c3-5d87-a1ce-7f9e4g379729' },
|
|
22
|
+
];
|
|
23
|
+
getMock.mockResolvedValueOnce({ data: mockResponse });
|
|
24
|
+
|
|
25
|
+
const result = await getOngoingTrips(client);
|
|
26
|
+
|
|
27
|
+
expect(result).toEqual(mockResponse);
|
|
28
|
+
expect(getMock).toHaveBeenCalledWith(
|
|
29
|
+
'/boapi/proxy/business/fleets/FLEET_ID/trip/ongoing'
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('should return an empty array when no ongoing trips', async () => {
|
|
34
|
+
getMock.mockResolvedValueOnce({ data: [] });
|
|
35
|
+
|
|
36
|
+
const result = await getOngoingTrips(client);
|
|
37
|
+
|
|
38
|
+
expect(result).toEqual([]);
|
|
39
|
+
expect(getMock).toHaveBeenCalledWith(
|
|
40
|
+
'/boapi/proxy/business/fleets/FLEET_ID/trip/ongoing'
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
|
|
3
|
+
import { BusinessTrip } from './types';
|
|
4
|
+
|
|
5
|
+
export const getOngoingTrips = async (client: Client): Promise<BusinessTrip[]> => {
|
|
6
|
+
return client
|
|
7
|
+
.get<BusinessTrip[]>(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/trip/ongoing`)
|
|
8
|
+
.then(({ data }) => data);
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
|
|
3
|
+
import { StripeConfig } from './types';
|
|
4
|
+
|
|
5
|
+
export const getStripePublishableKey = async (client: Client): Promise<StripeConfig> => {
|
|
6
|
+
return client
|
|
7
|
+
.get<StripeConfig>(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/stripe/config/key`)
|
|
8
|
+
.then(({ data }) => data);
|
|
9
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { StripeSetup } from './types';
|
|
5
|
+
|
|
6
|
+
export const getStripeSetup = async (client: Client, businessId: string): Promise<StripeSetup> => {
|
|
7
|
+
const result = z.string().trim().min(1).uuid().safeParse(businessId);
|
|
8
|
+
if (!result.success) {
|
|
9
|
+
throw new TypeError('Invalid args', { cause: result.error.issues });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return client
|
|
13
|
+
.get<StripeSetup>(
|
|
14
|
+
`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/stripe/businesses/${result.data}/add`
|
|
15
|
+
)
|
|
16
|
+
.then(({ data }) => data);
|
|
17
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export * from './addBusinessCredit';
|
|
2
|
+
export * from './addStripePayment';
|
|
3
|
+
export * from './addTripNote';
|
|
4
|
+
export * from './addUserToBusiness';
|
|
5
|
+
export * from './archiveBusinessProfile';
|
|
6
|
+
export * from './bulkAddBusinessUsers';
|
|
7
|
+
export * from './businessDelegatedAdmin';
|
|
8
|
+
export * from './businessOwner';
|
|
9
|
+
export * from './chargeBusinessProduct';
|
|
10
|
+
export * from './createBusiness';
|
|
11
|
+
export * from './createBusinessCostCenter';
|
|
12
|
+
export * from './deactivateBusinessProfile';
|
|
13
|
+
export * from './deleteBusinessCostCenter';
|
|
14
|
+
export * from './deleteInvitationRequest';
|
|
15
|
+
export * from './getBillingGroups';
|
|
16
|
+
export * from './getBusinessById';
|
|
17
|
+
export * from './getBusinessContacts';
|
|
18
|
+
export * from './getBusinessCostCenterById';
|
|
19
|
+
export * from './getBusinessCostCenters';
|
|
20
|
+
export * from './getBusinesses';
|
|
21
|
+
export * from './getBusinessInviteLink';
|
|
22
|
+
export * from './getBusinessInvoiceProducts';
|
|
23
|
+
export * from './getBusinessInvoices';
|
|
24
|
+
export * from './getBusinessInvoiceTrips';
|
|
25
|
+
export * from './getBusinessPaymentDetails';
|
|
26
|
+
export * from './getBusinessProducts';
|
|
27
|
+
export * from './getBusinessTripById';
|
|
28
|
+
export * from './getBusinessUserById';
|
|
29
|
+
export * from './getBusinessUserGlobalById';
|
|
30
|
+
export * from './getBusinessUsers';
|
|
31
|
+
export * from './getBusinessWallet';
|
|
32
|
+
export * from './getEntityBalance';
|
|
33
|
+
export * from './getEntityProducts';
|
|
34
|
+
export * from './getEntityTrips';
|
|
35
|
+
export * from './getEntityTripsCost';
|
|
36
|
+
export * from './getInvitationRequest';
|
|
37
|
+
export * from './getInvoicePdf';
|
|
38
|
+
export * from './getInvoiceRefundableAmount';
|
|
39
|
+
export * from './getInvoiceRefundNote';
|
|
40
|
+
export * from './getOngoingTripNotes';
|
|
41
|
+
export * from './getOngoingTrips';
|
|
42
|
+
export * from './getStripePublishableKey';
|
|
43
|
+
export * from './getStripeSetup';
|
|
44
|
+
export * from './inviteBusinessUser';
|
|
45
|
+
export * from './listBusinessUsersGlobal';
|
|
46
|
+
export * from './redeemBusinessPromoCode';
|
|
47
|
+
export * from './refundInvoice';
|
|
48
|
+
export * from './refundInvoiceAmount';
|
|
49
|
+
export * from './searchBusinessUsersByName';
|
|
50
|
+
export * from './searchBusinessUsersGlobal';
|
|
51
|
+
export * from './sendBusinessIban';
|
|
52
|
+
export * from './setInvoiceExternalPayment';
|
|
53
|
+
export * from './types';
|
|
54
|
+
export * from './updateBusiness';
|
|
55
|
+
export * from './updateBusinessCostCenter';
|
|
56
|
+
export * from './updateBusinessProfileStatus';
|
|
57
|
+
export * from './updateBusinessUserProfile';
|
|
58
|
+
export * from './updateInvoiceStatus';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export type InviteBusinessUserBody = {
|
|
5
|
+
email: string;
|
|
6
|
+
costCenterId?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const inviteSchema = z.object({
|
|
10
|
+
businessId: z.string().trim().min(1).uuid(),
|
|
11
|
+
email: z.string().trim().email(),
|
|
12
|
+
costCenterId: z.string().trim().min(1).uuid().optional(),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const inviteBusinessUser = async (
|
|
16
|
+
client: Client,
|
|
17
|
+
businessId: string,
|
|
18
|
+
body: InviteBusinessUserBody
|
|
19
|
+
): Promise<void> => {
|
|
20
|
+
const result = inviteSchema.safeParse({ businessId, ...body });
|
|
21
|
+
if (!result.success) {
|
|
22
|
+
throw new TypeError('Invalid args', { cause: result.error.issues });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { businessId: parsedId, ...parsedBody } = result.data;
|
|
26
|
+
|
|
27
|
+
await client.post<void>(
|
|
28
|
+
`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${parsedId}/user/invite`,
|
|
29
|
+
parsedBody
|
|
30
|
+
);
|
|
31
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, test, vi, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { Client } from '@vulog/aima-client';
|
|
3
|
+
import { listBusinessUsersGlobal } from './listBusinessUsersGlobal';
|
|
4
|
+
|
|
5
|
+
describe('listBusinessUsersGlobal', () => {
|
|
6
|
+
const postMock = vi.fn();
|
|
7
|
+
const client = {
|
|
8
|
+
post: postMock,
|
|
9
|
+
clientOptions: {
|
|
10
|
+
fleetId: 'FLEET_ID',
|
|
11
|
+
},
|
|
12
|
+
} as unknown as Client;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
vi.clearAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const USER_ID_1 = '018ab2b6-71b2-4c76-90bd-6e8d3f268618';
|
|
19
|
+
const USER_ID_2 = '550e8400-e29b-41d4-a716-446655440000';
|
|
20
|
+
|
|
21
|
+
test('should return business users for valid userIds', async () => {
|
|
22
|
+
const mockResponse = [
|
|
23
|
+
{ userId: USER_ID_1, businessId: 'b1', role: 'ADMIN' },
|
|
24
|
+
{ userId: USER_ID_2, businessId: 'b2', role: 'USER' },
|
|
25
|
+
];
|
|
26
|
+
postMock.mockResolvedValueOnce({ data: mockResponse });
|
|
27
|
+
|
|
28
|
+
const result = await listBusinessUsersGlobal(client, { userIds: [USER_ID_1, USER_ID_2] });
|
|
29
|
+
|
|
30
|
+
expect(result).toEqual(mockResponse);
|
|
31
|
+
expect(postMock).toHaveBeenCalledWith(
|
|
32
|
+
'/boapi/proxy/business/fleets/FLEET_ID/users/list',
|
|
33
|
+
{ userIds: [USER_ID_1, USER_ID_2] }
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('should throw for empty userIds array', async () => {
|
|
38
|
+
await expect(listBusinessUsersGlobal(client, { userIds: [] })).rejects.toThrow(TypeError);
|
|
39
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('should throw for invalid UUIDs in array', async () => {
|
|
43
|
+
await expect(
|
|
44
|
+
listBusinessUsersGlobal(client, { userIds: ['not-a-uuid', 'also-bad'] })
|
|
45
|
+
).rejects.toThrow(TypeError);
|
|
46
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('should throw when array contains mix of valid and invalid UUIDs', async () => {
|
|
50
|
+
await expect(
|
|
51
|
+
listBusinessUsersGlobal(client, { userIds: [USER_ID_1, 'not-a-uuid'] })
|
|
52
|
+
).rejects.toThrow(TypeError);
|
|
53
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('error cause includes Zod issues', async () => {
|
|
57
|
+
try {
|
|
58
|
+
await listBusinessUsersGlobal(client, { userIds: [] });
|
|
59
|
+
} catch (err) {
|
|
60
|
+
expect(err).toBeInstanceOf(TypeError);
|
|
61
|
+
expect((err as Error).cause).toBeDefined();
|
|
62
|
+
expect(Array.isArray((err as Error).cause)).toBe(true);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { BusinessUser } from './types';
|
|
5
|
+
|
|
6
|
+
export type ListBusinessUsersGlobalBody = {
|
|
7
|
+
userIds: string[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const schema = z.object({
|
|
11
|
+
userIds: z.array(z.string().trim().min(1).uuid()).min(1),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const listBusinessUsersGlobal = async (
|
|
15
|
+
client: Client,
|
|
16
|
+
body: ListBusinessUsersGlobalBody
|
|
17
|
+
): Promise<BusinessUser[]> => {
|
|
18
|
+
const result = schema.safeParse(body);
|
|
19
|
+
if (!result.success) {
|
|
20
|
+
throw new TypeError('Invalid args', { cause: result.error.issues });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return client
|
|
24
|
+
.post<BusinessUser[]>(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/users/list`, result.data)
|
|
25
|
+
.then(({ data }) => data);
|
|
26
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const schema = z.object({
|
|
5
|
+
businessId: z.string().trim().min(1).uuid(),
|
|
6
|
+
reference: z.string().trim().min(1),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const redeemBusinessPromoCode = async (client: Client, businessId: string, reference: string): Promise<void> => {
|
|
10
|
+
const result = schema.safeParse({ businessId, reference });
|
|
11
|
+
if (!result.success) {
|
|
12
|
+
throw new TypeError('Invalid args', { cause: result.error.issues });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
await client.post<void>(
|
|
16
|
+
`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${result.data.businessId}/promoCodes/redeem/${result.data.reference}`
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { describe, test, vi, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { Client } from '@vulog/aima-client';
|
|
3
|
+
import { refundInvoice } from './refundInvoice';
|
|
4
|
+
|
|
5
|
+
describe('refundInvoice', () => {
|
|
6
|
+
const postMock = vi.fn();
|
|
7
|
+
const client = {
|
|
8
|
+
post: postMock,
|
|
9
|
+
clientOptions: { fleetId: 'FLEET_ID' },
|
|
10
|
+
} as unknown as Client;
|
|
11
|
+
|
|
12
|
+
const INVOICE_ID = '018ab2b6-71b2-4c76-90bd-6e8d3f268618';
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
vi.clearAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('should process refund with amount and note', async () => {
|
|
19
|
+
postMock.mockResolvedValueOnce({ data: undefined });
|
|
20
|
+
|
|
21
|
+
const result = await refundInvoice(client, INVOICE_ID, {
|
|
22
|
+
amount: 50,
|
|
23
|
+
note: 'Customer requested refund',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(result).toBeUndefined();
|
|
27
|
+
expect(postMock).toHaveBeenCalledWith(
|
|
28
|
+
`/boapi/proxy/business/fleets/FLEET_ID/invoices/${INVOICE_ID}/refund`,
|
|
29
|
+
{ amount: 50, note: 'Customer requested refund' }
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('should process refund without body', async () => {
|
|
34
|
+
postMock.mockResolvedValueOnce({ data: undefined });
|
|
35
|
+
|
|
36
|
+
const result = await refundInvoice(client, INVOICE_ID);
|
|
37
|
+
|
|
38
|
+
expect(result).toBeUndefined();
|
|
39
|
+
expect(postMock).toHaveBeenCalledWith(
|
|
40
|
+
`/boapi/proxy/business/fleets/FLEET_ID/invoices/${INVOICE_ID}/refund`,
|
|
41
|
+
{}
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('should filter out undefined and null values', async () => {
|
|
46
|
+
postMock.mockResolvedValueOnce({ data: undefined });
|
|
47
|
+
|
|
48
|
+
await refundInvoice(client, INVOICE_ID, {
|
|
49
|
+
amount: 100,
|
|
50
|
+
note: null,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(postMock).toHaveBeenCalledWith(
|
|
54
|
+
`/boapi/proxy/business/fleets/FLEET_ID/invoices/${INVOICE_ID}/refund`,
|
|
55
|
+
{ amount: 100 }
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('should throw for invalid invoiceId', async () => {
|
|
60
|
+
await expect(refundInvoice(client, 'not-a-uuid', { amount: 10 })).rejects.toThrow(TypeError);
|
|
61
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('should throw for empty invoiceId', async () => {
|
|
65
|
+
await expect(refundInvoice(client, '', { amount: 10 })).rejects.toThrow(TypeError);
|
|
66
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('should throw for negative amount', async () => {
|
|
70
|
+
await expect(refundInvoice(client, INVOICE_ID, { amount: -10 })).rejects.toThrow('Invalid args');
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export type RefundInvoiceBody = {
|
|
5
|
+
amount?: number;
|
|
6
|
+
note?: string | null;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const refundInvoiceBodySchema = z.object({
|
|
10
|
+
amount: z.number().min(0).optional(),
|
|
11
|
+
note: z.string().trim().nullable().optional(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const refundInvoice = async (client: Client, invoiceId: string, body?: RefundInvoiceBody): Promise<void> => {
|
|
15
|
+
const parsedId = z.string().trim().min(1).uuid().safeParse(invoiceId);
|
|
16
|
+
if (!parsedId.success) {
|
|
17
|
+
throw new TypeError('Invalid args', { cause: parsedId.error.issues });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const result = refundInvoiceBodySchema.safeParse(body ?? {});
|
|
21
|
+
if (!result.success) {
|
|
22
|
+
throw new TypeError('Invalid args', { cause: result.error.issues });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const filteredData = Object.fromEntries(
|
|
26
|
+
Object.entries(result.data).filter(([_, value]) => value !== undefined && value !== null)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
await client.post<void>(
|
|
30
|
+
`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/invoices/${parsedId.data}/refund`,
|
|
31
|
+
filteredData
|
|
32
|
+
);
|
|
33
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const schema = z.object({
|
|
5
|
+
invoiceId: z.string().trim().min(1).uuid(),
|
|
6
|
+
amount: z.number().min(0),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
/** @deprecated Use refundInvoice instead */
|
|
10
|
+
export const refundInvoiceAmount = async (client: Client, invoiceId: string, amount: number): Promise<void> => {
|
|
11
|
+
const result = schema.safeParse({ invoiceId, amount });
|
|
12
|
+
if (!result.success) {
|
|
13
|
+
throw new TypeError('Invalid args', { cause: result.error.issues });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
await client.post<void>(
|
|
17
|
+
`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/invoices/${result.data.invoiceId}/refund/${result.data.amount}`,
|
|
18
|
+
{}
|
|
19
|
+
);
|
|
20
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { BusinessUser } from './types';
|
|
5
|
+
|
|
6
|
+
const searchSchema = z.object({
|
|
7
|
+
businessId: z.string().trim().min(1).uuid(),
|
|
8
|
+
name: z.string().trim().min(1),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const searchBusinessUsersByName = async (
|
|
12
|
+
client: Client,
|
|
13
|
+
businessId: string,
|
|
14
|
+
name: string
|
|
15
|
+
): Promise<BusinessUser[]> => {
|
|
16
|
+
const result = searchSchema.safeParse({ businessId, name });
|
|
17
|
+
if (!result.success) {
|
|
18
|
+
throw new TypeError('Invalid args', { cause: result.error.issues });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const searchParams = new URLSearchParams();
|
|
22
|
+
searchParams.append('name', result.data.name);
|
|
23
|
+
|
|
24
|
+
const url = `/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${result.data.businessId}/users/name?${searchParams.toString()}`;
|
|
25
|
+
|
|
26
|
+
return client.get<BusinessUser[]>(url).then(({ data }) => data);
|
|
27
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { BusinessUser } from './types';
|
|
5
|
+
|
|
6
|
+
export const searchBusinessUsersGlobal = async (client: Client, query: string): Promise<BusinessUser[]> => {
|
|
7
|
+
const result = z.string().trim().min(1).safeParse(query);
|
|
8
|
+
if (!result.success) {
|
|
9
|
+
throw new TypeError('Invalid args', { cause: result.error.issues });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const searchParams = new URLSearchParams();
|
|
13
|
+
searchParams.append('query', result.data);
|
|
14
|
+
|
|
15
|
+
const url = `/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/users/search?${searchParams.toString()}`;
|
|
16
|
+
|
|
17
|
+
return client.get<BusinessUser[]>(url).then(({ data }) => data);
|
|
18
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export type SendBusinessIbanBody = {
|
|
5
|
+
iban: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const schema = z.object({
|
|
9
|
+
businessId: z.string().trim().min(1).uuid(),
|
|
10
|
+
iban: z.string().trim().min(1),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const sendBusinessIban = async (
|
|
14
|
+
client: Client,
|
|
15
|
+
businessId: string,
|
|
16
|
+
body: SendBusinessIbanBody
|
|
17
|
+
): Promise<void> => {
|
|
18
|
+
const result = schema.safeParse({ businessId, ...body });
|
|
19
|
+
if (!result.success) {
|
|
20
|
+
throw new TypeError('Invalid args', { cause: result.error.issues });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const { businessId: parsedId, ...parsedBody } = result.data;
|
|
24
|
+
|
|
25
|
+
await client.post<void>(
|
|
26
|
+
`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${parsedId}/paymentDetails/wireTransfer`,
|
|
27
|
+
parsedBody
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Client } from '@vulog/aima-client';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export type SetInvoiceExternalPaymentBody = {
|
|
5
|
+
paymentReference?: string;
|
|
6
|
+
paymentDate?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const bodySchema = z.object({
|
|
10
|
+
paymentReference: z.string().trim().min(1).optional(),
|
|
11
|
+
paymentDate: z.string().trim().min(1).optional(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const setInvoiceExternalPayment = async (
|
|
15
|
+
client: Client,
|
|
16
|
+
invoiceId: string,
|
|
17
|
+
body: SetInvoiceExternalPaymentBody
|
|
18
|
+
): Promise<void> => {
|
|
19
|
+
const parsedId = z.string().trim().min(1).uuid().safeParse(invoiceId);
|
|
20
|
+
if (!parsedId.success) {
|
|
21
|
+
throw new TypeError('Invalid args', { cause: parsedId.error.issues });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const result = bodySchema.safeParse(body);
|
|
25
|
+
if (!result.success) {
|
|
26
|
+
throw new TypeError('Invalid args', { cause: result.error.issues });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await client.put<void>(
|
|
30
|
+
`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/invoices/${parsedId.data}/externalPayment`,
|
|
31
|
+
result.data
|
|
32
|
+
);
|
|
33
|
+
};
|