@vulog/aima-billing 1.2.33 → 1.2.35

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 CHANGED
@@ -82,6 +82,21 @@ const getInvoiceById = async (client, id) => {
82
82
  return client.get(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${id}`).then(({ data }) => data);
83
83
  };
84
84
  //#endregion
85
+ //#region src/getInvoicePdf.ts
86
+ const getInvoicePdf = async (client, invoiceId) => {
87
+ const result = zod.z.string().trim().min(1).uuid().safeParse(invoiceId);
88
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
89
+ const { data } = await client.get(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${invoiceId}/pdf`, { responseType: "arraybuffer" });
90
+ return data && data.byteLength > 0 ? data : null;
91
+ };
92
+ //#endregion
93
+ //#region src/getInvoicesByTripId.ts
94
+ const getInvoicesByTripId = async (client, tripId) => {
95
+ const result = zod.z.string().trim().min(1).safeParse(tripId);
96
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
97
+ return client.get(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/trips/${result.data}/invoices`).then(({ data }) => data);
98
+ };
99
+ //#endregion
85
100
  //#region src/getRefundableAmount.ts
86
101
  const schema$3 = zod.default.string().trim().min(1);
87
102
  const getRefundableAmount = async (client, invoiceId) => {
@@ -149,6 +164,8 @@ const payInvoice = async (client, invoiceId, manualPayment) => {
149
164
  exports.addCredits = addCredits;
150
165
  exports.chargeProduct = chargeProduct;
151
166
  exports.getInvoiceById = getInvoiceById;
167
+ exports.getInvoicePdf = getInvoicePdf;
168
+ exports.getInvoicesByTripId = getInvoicesByTripId;
152
169
  exports.getRefundableAmount = getRefundableAmount;
153
170
  exports.getUserCreditsByEntityId = getUserCreditsByEntityId;
154
171
  exports.getWalletsByEntity = getWalletsByEntity;
package/dist/index.d.cts CHANGED
@@ -153,6 +153,12 @@ declare const addCredits: (client: Client, payload: Payload$1) => Promise<Credit
153
153
  //#region src/getInvoiceById.d.ts
154
154
  declare const getInvoiceById: (client: Client, id: string) => Promise<Invoice>;
155
155
  //#endregion
156
+ //#region src/getInvoicePdf.d.ts
157
+ declare const getInvoicePdf: (client: Client, invoiceId: string) => Promise<ArrayBuffer | null>;
158
+ //#endregion
159
+ //#region src/getInvoicesByTripId.d.ts
160
+ declare const getInvoicesByTripId: (client: Client, tripId: string) => Promise<Invoice[]>;
161
+ //#endregion
156
162
  //#region src/getRefundableAmount.d.ts
157
163
  declare const getRefundableAmount: (client: Client, invoiceId: string) => Promise<RefundableAmount>;
158
164
  //#endregion
@@ -176,4 +182,4 @@ declare const updateWallet: (client: Client, walletId: string, actions: PatchAct
176
182
  //#region src/payInvoice.d.ts
177
183
  declare const payInvoice: (client: Client, invoiceId: string, manualPayment: ManualPayment) => Promise<Invoice>;
178
184
  //#endregion
179
- export { ChargeProductInfo, Credit, Invoice, ManualPayment, Paths, Receipt, RefundableAmount, Wallet, addCredits, chargeProduct, getInvoiceById, getRefundableAmount, getUserCreditsByEntityId, getWalletsByEntity, payInvoice, refund, updateWallet };
185
+ export { ChargeProductInfo, Credit, Invoice, ManualPayment, Paths, Receipt, RefundableAmount, Wallet, addCredits, chargeProduct, getInvoiceById, getInvoicePdf, getInvoicesByTripId, getRefundableAmount, getUserCreditsByEntityId, getWalletsByEntity, payInvoice, refund, updateWallet };
package/dist/index.d.mts CHANGED
@@ -153,6 +153,12 @@ declare const addCredits: (client: Client, payload: Payload$1) => Promise<Credit
153
153
  //#region src/getInvoiceById.d.ts
154
154
  declare const getInvoiceById: (client: Client, id: string) => Promise<Invoice>;
155
155
  //#endregion
156
+ //#region src/getInvoicePdf.d.ts
157
+ declare const getInvoicePdf: (client: Client, invoiceId: string) => Promise<ArrayBuffer | null>;
158
+ //#endregion
159
+ //#region src/getInvoicesByTripId.d.ts
160
+ declare const getInvoicesByTripId: (client: Client, tripId: string) => Promise<Invoice[]>;
161
+ //#endregion
156
162
  //#region src/getRefundableAmount.d.ts
157
163
  declare const getRefundableAmount: (client: Client, invoiceId: string) => Promise<RefundableAmount>;
158
164
  //#endregion
@@ -176,4 +182,4 @@ declare const updateWallet: (client: Client, walletId: string, actions: PatchAct
176
182
  //#region src/payInvoice.d.ts
177
183
  declare const payInvoice: (client: Client, invoiceId: string, manualPayment: ManualPayment) => Promise<Invoice>;
178
184
  //#endregion
179
- export { ChargeProductInfo, Credit, Invoice, ManualPayment, Paths, Receipt, RefundableAmount, Wallet, addCredits, chargeProduct, getInvoiceById, getRefundableAmount, getUserCreditsByEntityId, getWalletsByEntity, payInvoice, refund, updateWallet };
185
+ export { ChargeProductInfo, Credit, Invoice, ManualPayment, Paths, Receipt, RefundableAmount, Wallet, addCredits, chargeProduct, getInvoiceById, getInvoicePdf, getInvoicesByTripId, getRefundableAmount, getUserCreditsByEntityId, getWalletsByEntity, payInvoice, refund, updateWallet };
package/dist/index.mjs CHANGED
@@ -58,6 +58,21 @@ const getInvoiceById = async (client, id) => {
58
58
  return client.get(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${id}`).then(({ data }) => data);
59
59
  };
60
60
  //#endregion
61
+ //#region src/getInvoicePdf.ts
62
+ const getInvoicePdf = async (client, invoiceId) => {
63
+ const result = z.string().trim().min(1).uuid().safeParse(invoiceId);
64
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
65
+ const { data } = await client.get(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${invoiceId}/pdf`, { responseType: "arraybuffer" });
66
+ return data && data.byteLength > 0 ? data : null;
67
+ };
68
+ //#endregion
69
+ //#region src/getInvoicesByTripId.ts
70
+ const getInvoicesByTripId = async (client, tripId) => {
71
+ const result = z.string().trim().min(1).safeParse(tripId);
72
+ if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
73
+ return client.get(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/trips/${result.data}/invoices`).then(({ data }) => data);
74
+ };
75
+ //#endregion
61
76
  //#region src/getRefundableAmount.ts
62
77
  const schema$3 = z$1.string().trim().min(1);
63
78
  const getRefundableAmount = async (client, invoiceId) => {
@@ -122,4 +137,4 @@ const payInvoice = async (client, invoiceId, manualPayment) => {
122
137
  return client.post(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${result.data.invoiceId}/payment`, result.data.manualPayment).then(({ data }) => data);
123
138
  };
124
139
  //#endregion
125
- export { addCredits, chargeProduct, getInvoiceById, getRefundableAmount, getUserCreditsByEntityId, getWalletsByEntity, payInvoice, refund, updateWallet };
140
+ export { addCredits, chargeProduct, getInvoiceById, getInvoicePdf, getInvoicesByTripId, getRefundableAmount, getUserCreditsByEntityId, getWalletsByEntity, payInvoice, refund, updateWallet };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vulog/aima-billing",
3
3
  "type": "module",
4
- "version": "1.2.33",
4
+ "version": "1.2.35",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.cts",
@@ -32,8 +32,8 @@
32
32
  "author": "Vulog",
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
- "@vulog/aima-client": "1.2.33",
36
- "@vulog/aima-core": "1.2.33"
35
+ "@vulog/aima-client": "1.2.35",
36
+ "@vulog/aima-core": "1.2.35"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "zod": "^3.25.76"
@@ -0,0 +1,57 @@
1
+ import { describe, test, expect, vi, beforeEach } from 'vitest';
2
+ import { Client } from '@vulog/aima-client';
3
+ import { randomUUID } from 'crypto';
4
+ import { getInvoicePdf } from './getInvoicePdf';
5
+
6
+ describe('getInvoicePdf', () => {
7
+ const getMock = vi.fn();
8
+ const client = {
9
+ get: getMock,
10
+ clientOptions: {
11
+ fleetId: 'FLEET_ID',
12
+ },
13
+ } as unknown as Client;
14
+
15
+ beforeEach(() => {
16
+ getMock.mockReset();
17
+ });
18
+
19
+ test('throws Invalid args when invoiceId is not a valid UUID', async () => {
20
+ await expect(getInvoicePdf(client, 'not-a-uuid')).rejects.toThrow(TypeError);
21
+ await expect(getInvoicePdf(client, 'not-a-uuid')).rejects.toMatchObject({
22
+ message: 'Invalid args',
23
+ });
24
+ expect(getMock).not.toHaveBeenCalled();
25
+ });
26
+
27
+ test('throws Invalid args when invoiceId is empty', async () => {
28
+ await expect(getInvoicePdf(client, '')).rejects.toThrow(TypeError);
29
+ expect(getMock).not.toHaveBeenCalled();
30
+ });
31
+
32
+ test('calls GET with correct URL and responseType arraybuffer, returns ArrayBuffer when data has length', async () => {
33
+ const invoiceId = randomUUID();
34
+ const pdfBuffer = new ArrayBuffer(1024);
35
+ getMock.mockResolvedValueOnce({ data: pdfBuffer });
36
+
37
+ const result = await getInvoicePdf(client, invoiceId);
38
+
39
+ expect(getMock).toHaveBeenCalledTimes(1);
40
+ expect(getMock).toHaveBeenCalledWith(
41
+ `/boapi/proxy/billing/fleets/FLEET_ID/invoices/${invoiceId}/pdf`,
42
+ { responseType: 'arraybuffer' }
43
+ );
44
+ expect(result).toBe(pdfBuffer);
45
+ expect(result).toBeInstanceOf(ArrayBuffer);
46
+ expect((result as ArrayBuffer).byteLength).toBe(1024);
47
+ });
48
+
49
+ test('returns null when response data is empty or zero length', async () => {
50
+ const invoiceId = randomUUID();
51
+ getMock.mockResolvedValueOnce({ data: new ArrayBuffer(0) });
52
+
53
+ const result = await getInvoicePdf(client, invoiceId);
54
+
55
+ expect(result).toBeNull();
56
+ });
57
+ });
@@ -0,0 +1,18 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ export const getInvoicePdf = async (client: Client, invoiceId: string): Promise<ArrayBuffer | null> => {
5
+ const result = z.string().trim().min(1).uuid().safeParse(invoiceId);
6
+ if (!result.success) {
7
+ throw new TypeError('Invalid args', {
8
+ cause: result.error.issues,
9
+ });
10
+ }
11
+
12
+ const { data } = await client.get<ArrayBuffer>(
13
+ `/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/invoices/${invoiceId}/pdf`,
14
+ { responseType: 'arraybuffer' }
15
+ );
16
+
17
+ return data && data.byteLength > 0 ? data : null;
18
+ };
@@ -0,0 +1,73 @@
1
+ import { describe, test, expect, vi, beforeEach } from 'vitest';
2
+ import { Client } from '@vulog/aima-client';
3
+ import { getInvoicesByTripId } from './getInvoicesByTripId';
4
+ import type { Invoice } from './types';
5
+
6
+ describe('getInvoicesByTripId', () => {
7
+ const getMock = vi.fn();
8
+ const client = {
9
+ get: getMock,
10
+ clientOptions: {
11
+ fleetId: 'FLEET_ID',
12
+ },
13
+ } as unknown as Client;
14
+
15
+ beforeEach(() => {
16
+ getMock.mockReset();
17
+ });
18
+
19
+ test('throws Invalid args when tripId is empty', async () => {
20
+ await expect(getInvoicesByTripId(client, '')).rejects.toThrow(TypeError);
21
+ await expect(getInvoicesByTripId(client, '')).rejects.toMatchObject({
22
+ message: 'Invalid args',
23
+ });
24
+ expect(getMock).not.toHaveBeenCalled();
25
+ });
26
+
27
+ test('throws Invalid args when tripId is whitespace only', async () => {
28
+ await expect(getInvoicesByTripId(client, ' ')).rejects.toThrow(TypeError);
29
+ expect(getMock).not.toHaveBeenCalled();
30
+ });
31
+
32
+ test('calls GET with correct URL and returns invoices', async () => {
33
+ const tripId = 'BEBD00056A9A16103D418CC36D940E26';
34
+ const invoices: Invoice[] = [
35
+ {
36
+ id: '66bcbd77-37ef-47bd-b9af-877e5d213b8f',
37
+ sequence: 1,
38
+ userId: '20fb98a3-b60d-491a-9359-62e55f51fcb9',
39
+ invoiceDate: '2026-03-03',
40
+ updateDate: '2026-03-03T09:46:50Z',
41
+ fleetId: 'FLEET_ID',
42
+ invoiceYear: 2026,
43
+ invoicesStatus: 'PAID',
44
+ amount: 100,
45
+ currency: 'EUR',
46
+ entityId: 'entity-1',
47
+ attempts: 0,
48
+ pspReference: 'ref-1',
49
+ withTaxRefundAmount: 0,
50
+ },
51
+ ];
52
+ getMock.mockResolvedValueOnce({ data: invoices });
53
+
54
+ const result = await getInvoicesByTripId(client, tripId);
55
+
56
+ expect(getMock).toHaveBeenCalledTimes(1);
57
+ expect(getMock).toHaveBeenCalledWith(
58
+ `/boapi/proxy/billing/fleets/FLEET_ID/trips/${tripId}/invoices`
59
+ );
60
+ expect(result).toEqual(invoices);
61
+ expect(result).toHaveLength(1);
62
+ expect(result[0].id).toBe(invoices[0].id);
63
+ });
64
+
65
+ test('returns empty array when no invoices', async () => {
66
+ const tripId = 'some-trip-id';
67
+ getMock.mockResolvedValueOnce({ data: [] });
68
+
69
+ const result = await getInvoicesByTripId(client, tripId);
70
+
71
+ expect(result).toEqual([]);
72
+ });
73
+ });
@@ -0,0 +1,17 @@
1
+ import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
3
+
4
+ import { Invoice } from './types';
5
+
6
+ export const getInvoicesByTripId = async (client: Client, tripId: string): Promise<Invoice[]> => {
7
+ const result = z.string().trim().min(1).safeParse(tripId);
8
+ if (!result.success) {
9
+ throw new TypeError('Invalid args', {
10
+ cause: result.error.issues,
11
+ });
12
+ }
13
+
14
+ return client
15
+ .get<Invoice[]>(`/boapi/proxy/billing/fleets/${client.clientOptions.fleetId}/trips/${result.data}/invoices`)
16
+ .then(({ data }) => data);
17
+ };
package/src/index.ts CHANGED
@@ -3,6 +3,8 @@ export * from './types';
3
3
  export * from './getUserCreditsByEntityId';
4
4
  export * from './addCredits';
5
5
  export * from './getInvoiceById';
6
+ export * from './getInvoicePdf';
7
+ export * from './getInvoicesByTripId';
6
8
  export * from './getRefundableAmount';
7
9
  export * from './refund';
8
10
  export * from './getWalletsByEntity';