@vulog/aima-document 1.1.79 → 1.1.81

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
@@ -1,4 +1,5 @@
1
1
  import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
2
3
 
3
4
  type DocumentType = {
4
5
  id: number;
@@ -59,11 +60,21 @@ type DocumentSummary = {
59
60
  documentByService: DocumentByService[];
60
61
  documentByFranchise: DocumentByFranchise[] | null;
61
62
  };
63
+ declare const personalInformationDocumentTypes: readonly ["documentNumber1"];
64
+ type PersonalInformationDocumentType = (typeof personalInformationDocumentTypes)[number];
65
+ declare const personalInformationDocumentTypeSchema: z.ZodEnum<["documentNumber1"]>;
66
+ type PersonalInformationDocument = {
67
+ fleetId: string;
68
+ userId: string;
69
+ documentId: string;
70
+ documentNumber1?: string;
71
+ updateDate: string;
72
+ };
62
73
 
63
74
  declare const createOrUpdateDocument: (client: Client, userId: string, document: DocumentBody) => Promise<DocumentFull>;
64
75
 
65
- declare const getUserDocuments: (client: Client, userId: string) => Promise<DocumentSummary>;
76
+ declare const getUserDocuments: (client: Client, userId: string, types?: PersonalInformationDocumentType[]) => Promise<DocumentSummary>;
66
77
 
67
78
  declare const updateDocumentStatus: (client: Client, userId: string, documentId: number, document: DocumentStatusReview) => Promise<DocumentFull>;
68
79
 
69
- export { type DocumentBody, type DocumentByFranchise, type DocumentByService, type DocumentFull, type DocumentStatus, type DocumentStatusReview, type DocumentSummary, type DocumentType, type FileUrl, createOrUpdateDocument, getUserDocuments, updateDocumentStatus };
80
+ export { type DocumentBody, type DocumentByFranchise, type DocumentByService, type DocumentFull, type DocumentStatus, type DocumentStatusReview, type DocumentSummary, type DocumentType, type FileUrl, type PersonalInformationDocument, type PersonalInformationDocumentType, createOrUpdateDocument, getUserDocuments, personalInformationDocumentTypeSchema, personalInformationDocumentTypes, updateDocumentStatus };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Client } from '@vulog/aima-client';
2
+ import { z } from 'zod';
2
3
 
3
4
  type DocumentType = {
4
5
  id: number;
@@ -59,11 +60,21 @@ type DocumentSummary = {
59
60
  documentByService: DocumentByService[];
60
61
  documentByFranchise: DocumentByFranchise[] | null;
61
62
  };
63
+ declare const personalInformationDocumentTypes: readonly ["documentNumber1"];
64
+ type PersonalInformationDocumentType = (typeof personalInformationDocumentTypes)[number];
65
+ declare const personalInformationDocumentTypeSchema: z.ZodEnum<["documentNumber1"]>;
66
+ type PersonalInformationDocument = {
67
+ fleetId: string;
68
+ userId: string;
69
+ documentId: string;
70
+ documentNumber1?: string;
71
+ updateDate: string;
72
+ };
62
73
 
63
74
  declare const createOrUpdateDocument: (client: Client, userId: string, document: DocumentBody) => Promise<DocumentFull>;
64
75
 
65
- declare const getUserDocuments: (client: Client, userId: string) => Promise<DocumentSummary>;
76
+ declare const getUserDocuments: (client: Client, userId: string, types?: PersonalInformationDocumentType[]) => Promise<DocumentSummary>;
66
77
 
67
78
  declare const updateDocumentStatus: (client: Client, userId: string, documentId: number, document: DocumentStatusReview) => Promise<DocumentFull>;
68
79
 
69
- export { type DocumentBody, type DocumentByFranchise, type DocumentByService, type DocumentFull, type DocumentStatus, type DocumentStatusReview, type DocumentSummary, type DocumentType, type FileUrl, createOrUpdateDocument, getUserDocuments, updateDocumentStatus };
80
+ export { type DocumentBody, type DocumentByFranchise, type DocumentByService, type DocumentFull, type DocumentStatus, type DocumentStatusReview, type DocumentSummary, type DocumentType, type FileUrl, type PersonalInformationDocument, type PersonalInformationDocumentType, createOrUpdateDocument, getUserDocuments, personalInformationDocumentTypeSchema, personalInformationDocumentTypes, updateDocumentStatus };
package/dist/index.js CHANGED
@@ -22,6 +22,8 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  createOrUpdateDocument: () => createOrUpdateDocument,
24
24
  getUserDocuments: () => getUserDocuments,
25
+ personalInformationDocumentTypeSchema: () => personalInformationDocumentTypeSchema,
26
+ personalInformationDocumentTypes: () => personalInformationDocumentTypes,
25
27
  updateDocumentStatus: () => updateDocumentStatus
26
28
  });
27
29
  module.exports = __toCommonJS(index_exports);
@@ -45,25 +47,53 @@ var createOrUpdateDocument = async (client, userId, document) => {
45
47
  };
46
48
 
47
49
  // src/getUserDocuments.ts
50
+ var import_zod3 = require("zod");
51
+
52
+ // src/types.ts
48
53
  var import_zod2 = require("zod");
49
- var schema2 = import_zod2.z.object({
50
- userId: import_zod2.z.string().trim().nonempty().uuid()
54
+ var personalInformationDocumentTypes = ["documentNumber1"];
55
+ var personalInformationDocumentTypeSchema = import_zod2.z.enum(personalInformationDocumentTypes);
56
+
57
+ // src/getUserDocuments.ts
58
+ var schema2 = import_zod3.z.object({
59
+ userId: import_zod3.z.string().trim().nonempty().uuid(),
60
+ types: import_zod3.z.array(personalInformationDocumentTypeSchema).min(0).optional()
51
61
  });
52
- var getUserDocuments = async (client, userId) => {
53
- const result = schema2.safeParse({ userId });
62
+ var getUserDocuments = async (client, userId, types) => {
63
+ const result = schema2.safeParse({ userId, types });
54
64
  if (!result.success) {
55
65
  throw new TypeError("Invalid args", {
56
66
  cause: result.error.issues
57
67
  });
58
68
  }
59
- return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`).then(({ data }) => data);
69
+ const docSumary = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`).then(({ data }) => data);
70
+ if (docSumary && docSumary.documents?.length > 0 && result.data.types && result.data.types.length > 0) {
71
+ const piTypes = result.data.types.join(",");
72
+ docSumary.documents = await Promise.all(
73
+ docSumary.documents.map(async (doc) => {
74
+ const pi = await client.get(
75
+ `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${doc.id}/pi?types=${piTypes}`
76
+ ).then(({ data }) => data);
77
+ if (pi?.documentNumber1) {
78
+ return {
79
+ ...doc,
80
+ // Copy the original
81
+ documentNumber: pi.documentNumber1
82
+ // update the documentNumber field
83
+ };
84
+ }
85
+ return doc;
86
+ })
87
+ );
88
+ }
89
+ return docSumary;
60
90
  };
61
91
 
62
92
  // src/updateDocumentStatus.ts
63
- var import_zod3 = require("zod");
64
- var schema3 = import_zod3.z.object({
65
- userId: import_zod3.z.string().nonempty().uuid(),
66
- documentId: import_zod3.z.number().nonnegative().int()
93
+ var import_zod4 = require("zod");
94
+ var schema3 = import_zod4.z.object({
95
+ userId: import_zod4.z.string().nonempty().uuid(),
96
+ documentId: import_zod4.z.number().nonnegative().int()
67
97
  });
68
98
  var updateDocumentStatus = async (client, userId, documentId, document) => {
69
99
  const result = schema3.safeParse({ userId, documentId });
@@ -78,5 +108,7 @@ var updateDocumentStatus = async (client, userId, documentId, document) => {
78
108
  0 && (module.exports = {
79
109
  createOrUpdateDocument,
80
110
  getUserDocuments,
111
+ personalInformationDocumentTypeSchema,
112
+ personalInformationDocumentTypes,
81
113
  updateDocumentStatus
82
114
  });
package/dist/index.mjs CHANGED
@@ -17,25 +17,53 @@ var createOrUpdateDocument = async (client, userId, document) => {
17
17
  };
18
18
 
19
19
  // src/getUserDocuments.ts
20
+ import { z as z3 } from "zod";
21
+
22
+ // src/types.ts
20
23
  import { z as z2 } from "zod";
21
- var schema2 = z2.object({
22
- userId: z2.string().trim().nonempty().uuid()
24
+ var personalInformationDocumentTypes = ["documentNumber1"];
25
+ var personalInformationDocumentTypeSchema = z2.enum(personalInformationDocumentTypes);
26
+
27
+ // src/getUserDocuments.ts
28
+ var schema2 = z3.object({
29
+ userId: z3.string().trim().nonempty().uuid(),
30
+ types: z3.array(personalInformationDocumentTypeSchema).min(0).optional()
23
31
  });
24
- var getUserDocuments = async (client, userId) => {
25
- const result = schema2.safeParse({ userId });
32
+ var getUserDocuments = async (client, userId, types) => {
33
+ const result = schema2.safeParse({ userId, types });
26
34
  if (!result.success) {
27
35
  throw new TypeError("Invalid args", {
28
36
  cause: result.error.issues
29
37
  });
30
38
  }
31
- return client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`).then(({ data }) => data);
39
+ const docSumary = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`).then(({ data }) => data);
40
+ if (docSumary && docSumary.documents?.length > 0 && result.data.types && result.data.types.length > 0) {
41
+ const piTypes = result.data.types.join(",");
42
+ docSumary.documents = await Promise.all(
43
+ docSumary.documents.map(async (doc) => {
44
+ const pi = await client.get(
45
+ `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${doc.id}/pi?types=${piTypes}`
46
+ ).then(({ data }) => data);
47
+ if (pi?.documentNumber1) {
48
+ return {
49
+ ...doc,
50
+ // Copy the original
51
+ documentNumber: pi.documentNumber1
52
+ // update the documentNumber field
53
+ };
54
+ }
55
+ return doc;
56
+ })
57
+ );
58
+ }
59
+ return docSumary;
32
60
  };
33
61
 
34
62
  // src/updateDocumentStatus.ts
35
- import { z as z3 } from "zod";
36
- var schema3 = z3.object({
37
- userId: z3.string().nonempty().uuid(),
38
- documentId: z3.number().nonnegative().int()
63
+ import { z as z4 } from "zod";
64
+ var schema3 = z4.object({
65
+ userId: z4.string().nonempty().uuid(),
66
+ documentId: z4.number().nonnegative().int()
39
67
  });
40
68
  var updateDocumentStatus = async (client, userId, documentId, document) => {
41
69
  const result = schema3.safeParse({ userId, documentId });
@@ -49,5 +77,7 @@ var updateDocumentStatus = async (client, userId, documentId, document) => {
49
77
  export {
50
78
  createOrUpdateDocument,
51
79
  getUserDocuments,
80
+ personalInformationDocumentTypeSchema,
81
+ personalInformationDocumentTypes,
52
82
  updateDocumentStatus
53
83
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-document",
3
- "version": "1.1.79",
3
+ "version": "1.1.81",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "author": "Vulog",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@vulog/aima-client": "1.1.79",
23
- "@vulog/aima-core": "1.1.79"
22
+ "@vulog/aima-client": "1.1.81",
23
+ "@vulog/aima-core": "1.1.81"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "zod": "^3.24.2"
@@ -0,0 +1,232 @@
1
+ import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { Client } from '@vulog/aima-client';
3
+ import { getUserDocuments } from './getUserDocuments';
4
+ import { personalInformationUserTypes } from '../../user/src/types';
5
+ import { personalInformationDocumentTypes } from './types';
6
+
7
+ describe('getUserDocument', () => {
8
+ const FLEET_ID = 'FLEET_ID';
9
+ const USER_ID = '018ab2b6-71b2-4c76-90bd-6e8d3f268618';
10
+ const docTypeId = {
11
+ id: 690,
12
+ fleetId: FLEET_ID,
13
+ type: 'IDENTITY_CARD',
14
+ name: 'ID',
15
+ mandatory: false,
16
+ hasNumber: true,
17
+ hasExpirationDate: false,
18
+ numberUploadUrl: 1,
19
+ hasIssuingCountry: false,
20
+ hasIssuingOffice: true,
21
+ hasIssuingDate: true,
22
+ hasDlClass: false
23
+ };
24
+ const docTypeDl = {
25
+ id: 691,
26
+ fleetId: FLEET_ID,
27
+ type: 'DRIVING_LICENSE',
28
+ name: 'Driving license',
29
+ mandatory: false,
30
+ hasNumber: true,
31
+ hasExpirationDate: false,
32
+ numberUploadUrl: 2,
33
+ hasIssuingCountry: false,
34
+ hasIssuingOffice: true,
35
+ hasIssuingDate: true,
36
+ hasDlClass: false
37
+ }
38
+ const idDocId = 10892065;
39
+ const dlDocId = 10892077;
40
+ const documents = {
41
+ documentTypes: [
42
+ { ...docTypeId },
43
+ { ...docTypeDl}
44
+ ],
45
+ documents: [
46
+ {
47
+ id: idDocId,
48
+ fleetId: FLEET_ID,
49
+ userId: USER_ID,
50
+ documentType: { ...docTypeId },
51
+ expirationDate: '1970-01-01',
52
+ files: [
53
+ {
54
+ id: null,
55
+ url: `https://java-test.vulog.com/boapi/proxy/upload/fleets/${FLEET_ID}/users/${USER_ID}/documents/${idDocId}/${docTypeId.type}_0`,
56
+ name: `${docTypeId.type}_0`
57
+ }
58
+ ],
59
+ uploadUrls: [
60
+ {
61
+ id: null,
62
+ url: `https://java-test.vulog.com/upload/fleets/${FLEET_ID}/documents/${idDocId}/${docTypeId.type}_0?tk=s2TzoXn%2BhEUKnCbEEFZfhRqOvStMSdS14ow3QHFhgRA3ttoqIrcNxpP4JhMvyIYkyGLo%2Bnwttnz3zt1NkOX3Lf8PBVPiXXyxB9%2BtW1FkBISvOOjA0FTyMLquFoe2cSNn`,
63
+ name: `${docTypeId.type}_0`
64
+ }
65
+ ],
66
+ status: 'VALID',
67
+ reviewer: '493a4d98-7437-42db-8d4e-bd722ac62caa',
68
+ issuingCountry: null,
69
+ issuingOffice: 'Nice, 06',
70
+ issuingDate: '2023-01-16',
71
+ dlClass: null,
72
+ documentNumber: null
73
+ },
74
+ {
75
+ id: dlDocId,
76
+ fleetId: FLEET_ID,
77
+ userId: USER_ID,
78
+ documentType: { ...docTypeDl },
79
+ expirationDate: '1970-01-01',
80
+ files: [
81
+ {
82
+ id: null,
83
+ url: `https://java-test.vulog.com/boapi/proxy/upload/fleets/${FLEET_ID}/users/${USER_ID}/documents/${dlDocId}/${docTypeDl.type}_0`,
84
+ name: `${docTypeDl.type}_0`
85
+ },
86
+ {
87
+ id: null,
88
+ url: `https://java-test.vulog.com/boapi/proxy/upload/fleets/${FLEET_ID}/users/${USER_ID}/documents/${dlDocId}/${docTypeDl.type}_1`,
89
+ name: `${docTypeDl.type}_1`
90
+ }
91
+ ],
92
+ uploadUrls: [
93
+ {
94
+ id: null,
95
+ url: `https://java-test.vulog.com/upload/fleets/${FLEET_ID}/documents/${dlDocId}/${docTypeDl.type}_0?tk=3Xs08XSnb2ZatHY%2Blic5G88IMPGKs0LOy8hlM47eaER1nPDxgYeewOMYySGQfbPMKz3Opy5T3RPULV9O3IBCm4iOIApdah4Q22rCi4hH5rZ%2BOyGuLwmffBuoYA16rLuO`,
96
+ name: `${docTypeDl.type}_0`
97
+ },
98
+ {
99
+ id: null,
100
+ url: `https://java-test.vulog.com/upload/fleets/${FLEET_ID}/documents/${dlDocId}/${docTypeDl.type}_1?tk=fg8Y3duKmYM3olsMaC6mipzB5AsjCf5h8mRHwNb4iGzpy8MqMXigaBce5PxdFKcgiuQjoWYvcbBZx2W985Mqt8CGpxoGIzqbYOmsS9kvPjp6UZERqnfan73y5vk3MPUy`,
101
+ name: `${docTypeDl.type}_1`
102
+ }
103
+ ],
104
+ status: 'VALID',
105
+ reviewer: '493a4d98-7437-42db-8d4e-bd722ac62caf',
106
+ issuingCountry: null,
107
+ issuingOffice: 'Nice',
108
+ issuingDate: '1994-02-18',
109
+ dlClass: null,
110
+ documentNumber: null
111
+ }
112
+ ],
113
+ documentByService: [
114
+ {
115
+ serviceId: '0166e9a0-ac01-46d1-8211-f5ac24145953',
116
+ areMandatoryPresent: false,
117
+ mandatoryDocumentTypeId: []
118
+ },
119
+ {
120
+ serviceId: '0a6db44e-8a83-4f74-a6f8-5b21bd693289',
121
+ areMandatoryPresent: false,
122
+ mandatoryDocumentTypeId: []
123
+ }
124
+ ],
125
+ documentByFranchise: null
126
+ };
127
+ const piId = {
128
+ fleetId: FLEET_ID,
129
+ userId: USER_ID,
130
+ documentId: idDocId,
131
+ documentNumber1: '741',
132
+ updateDate: '2025-04-29T10:40:42.000Z'
133
+ }
134
+ const piDl = {
135
+ fleetId: FLEET_ID,
136
+ userId: USER_ID,
137
+ documentId: dlDocId,
138
+ documentNumber1: '159',
139
+ updateDate: '2025-04-29T10:40:42.000Z'
140
+ }
141
+
142
+ const getMock = vi.fn();
143
+ const client = {
144
+ get: getMock,
145
+ clientOptions: {
146
+ fleetId: FLEET_ID,
147
+ },
148
+ } as unknown as Client;
149
+
150
+ beforeEach(() => {
151
+ getMock.mockReset();
152
+ vi.useFakeTimers({ now: new Date('2025-01-12T13:35:50.123Z') });
153
+
154
+ getMock.mockImplementation((url: string): Promise<any> => {
155
+ if (url === `/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents`) {
156
+ return Promise.resolve({
157
+ data: documents,
158
+ status: 200,
159
+ statusText: 'OK',
160
+ headers: {},
161
+ config: {}
162
+ });
163
+ }
164
+ else if (url.startsWith(`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents/${idDocId}/pi`)) {
165
+ return Promise.resolve({
166
+ data: piId,
167
+ status: 200,
168
+ statusText: 'OK',
169
+ headers: {},
170
+ config: {}
171
+ });
172
+ }
173
+ else if (url.startsWith(`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents/${dlDocId}/pi`)) {
174
+ return Promise.resolve({
175
+ data: piDl,
176
+ status: 200,
177
+ statusText: 'OK',
178
+ headers: {},
179
+ config: {}
180
+ });
181
+ }
182
+ // Pour les autres URLs, rejetez la promesse
183
+ return Promise.reject(new Error('404 Not Found'));
184
+ });
185
+ });
186
+
187
+ afterEach(() => {
188
+ vi.useRealTimers();
189
+ });
190
+
191
+ test('call without PI', async () => {
192
+
193
+ const docs = await getUserDocuments(client, USER_ID);
194
+ expect(getMock).toHaveBeenCalledOnce();
195
+ expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents`);
196
+
197
+ expect(docs).toBeTruthy();
198
+ expect(docs.documents).toBeTruthy();
199
+ expect(docs.documents.length).toEqual(documents.documents.length);
200
+ expect(docs.documents.length).toEqual(2);
201
+ expect(docs.documents[0].id).toEqual(documents.documents[0].id);
202
+ expect(docs.documents[0].documentNumber).toBeNull();
203
+ expect(docs.documents[1].id).toEqual(documents.documents[1].id);
204
+ expect(docs.documents[1].documentNumber).toBeNull();
205
+ });
206
+
207
+ test('call with PI', async () => {
208
+
209
+ const docs = await getUserDocuments(client, USER_ID, ['documentNumber1']);
210
+ expect(getMock).toHaveBeenCalledTimes(3);
211
+ expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents`);
212
+ expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents/${idDocId}/pi?types=documentNumber1`);
213
+ expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents/${dlDocId}/pi?types=documentNumber1`);
214
+
215
+ expect(docs).toBeTruthy();
216
+ expect(docs.documents).toBeTruthy();
217
+ expect(docs.documents.length).toEqual(documents.documents.length);
218
+ expect(docs.documents.length).toEqual(2);
219
+ expect(docs.documents[0].id).toEqual(documents.documents[0].id);
220
+ expect(docs.documents[0].documentNumber).toBeTruthy();
221
+ expect(docs.documents[1].id).toEqual(documents.documents[1].id);
222
+ expect(docs.documents[1].documentNumber).toBeTruthy();
223
+ if(docs.documents[0].id === idDocId) {
224
+ expect(docs.documents[0].documentNumber).toEqual(piId.documentNumber1);
225
+ expect(docs.documents[1].documentNumber).toEqual(piDl.documentNumber1);
226
+ }
227
+ if(docs.documents[0].id === dlDocId) {
228
+ expect(docs.documents[0].documentNumber).toEqual(piDl.documentNumber1);
229
+ expect(docs.documents[1].documentNumber).toEqual(piId.documentNumber1);
230
+ }
231
+ });
232
+ });
@@ -1,21 +1,54 @@
1
1
  import { Client } from '@vulog/aima-client';
2
2
  import { z } from 'zod';
3
3
 
4
- import { DocumentSummary } from './types';
4
+ import {
5
+ DocumentSummary,
6
+ PersonalInformationDocument,
7
+ PersonalInformationDocumentType,
8
+ personalInformationDocumentTypeSchema,
9
+ } from './types';
5
10
 
6
11
  const schema = z.object({
7
12
  userId: z.string().trim().nonempty().uuid(),
13
+ types: z.array(personalInformationDocumentTypeSchema).min(0).optional(),
8
14
  });
9
15
 
10
- export const getUserDocuments = async (client: Client, userId: string): Promise<DocumentSummary> => {
11
- const result = schema.safeParse({ userId });
16
+ export const getUserDocuments = async (
17
+ client: Client,
18
+ userId: string,
19
+ types?: PersonalInformationDocumentType[] // optional parameter
20
+ ): Promise<DocumentSummary> => {
21
+ const result = schema.safeParse({ userId, types });
12
22
  if (!result.success) {
13
23
  throw new TypeError('Invalid args', {
14
24
  cause: result.error.issues,
15
25
  });
16
26
  }
17
27
 
18
- return client
28
+ const docSumary: DocumentSummary = await client
19
29
  .get<DocumentSummary>(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`)
20
30
  .then(({ data }) => data);
31
+
32
+ if (docSumary && docSumary.documents?.length > 0 && result.data.types && result.data.types.length > 0) {
33
+ const piTypes = result.data.types.join(',');
34
+ docSumary.documents = await Promise.all(
35
+ docSumary.documents.map(async (doc) => {
36
+ const pi: PersonalInformationDocument = await client
37
+ .get<PersonalInformationDocument>(
38
+ `/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${doc.id}/pi?types=${piTypes}`
39
+ )
40
+ .then(({ data }) => data);
41
+
42
+ if (pi?.documentNumber1) {
43
+ return {
44
+ ...doc, // Copy the original
45
+ documentNumber: pi.documentNumber1, // update the documentNumber field
46
+ };
47
+ }
48
+ return doc;
49
+ })
50
+ );
51
+ }
52
+
53
+ return docSumary;
21
54
  };
package/src/types.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { z } from 'zod';
2
+
1
3
  export type DocumentType = {
2
4
  id: number;
3
5
  fleetId: string;
@@ -317,3 +319,15 @@ export type DocumentSummary = {
317
319
  documentByService: DocumentByService[];
318
320
  documentByFranchise: DocumentByFranchise[] | null;
319
321
  };
322
+
323
+ export const personalInformationDocumentTypes = ['documentNumber1'] as const;
324
+ export type PersonalInformationDocumentType = (typeof personalInformationDocumentTypes)[number];
325
+ export const personalInformationDocumentTypeSchema = z.enum(personalInformationDocumentTypes);
326
+
327
+ export type PersonalInformationDocument = {
328
+ fleetId: string;
329
+ userId: string;
330
+ documentId: string;
331
+ documentNumber1?: string;
332
+ updateDate: string;
333
+ };