@vulog/aima-document 1.2.30 → 1.2.31
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 +74 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.mts +61 -56
- package/dist/index.mjs +60 -94
- package/package.json +20 -7
- package/src/getUserDocuments.test.ts +56 -55
- package/{tsup.config.ts → tsdown.config.ts} +1 -1
- package/dist/index.d.ts +0 -83
- package/dist/index.js +0 -134
- /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let zod = require("zod");
|
|
3
|
+
//#region src/createOrUpdateDocument.ts
|
|
4
|
+
const schema$3 = zod.z.object({ userId: zod.z.string().nonempty().uuid() });
|
|
5
|
+
const createOrUpdateDocument = async (client, userId, document) => {
|
|
6
|
+
const result = schema$3.safeParse({ userId });
|
|
7
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
8
|
+
return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`, document).then(({ data }) => data);
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/types.ts
|
|
12
|
+
const personalInformationDocumentTypes = ["DOCUMENT_NUMBER_1"];
|
|
13
|
+
const personalInformationDocumentTypeSchema = zod.z.enum(personalInformationDocumentTypes);
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/getUserDocuments.ts
|
|
16
|
+
const schema$2 = zod.z.object({
|
|
17
|
+
userId: zod.z.string().trim().nonempty().uuid(),
|
|
18
|
+
types: zod.z.array(personalInformationDocumentTypeSchema).min(0).optional()
|
|
19
|
+
});
|
|
20
|
+
const getUserDocuments = async (client, userId, types) => {
|
|
21
|
+
const result = schema$2.safeParse({
|
|
22
|
+
userId,
|
|
23
|
+
types
|
|
24
|
+
});
|
|
25
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
26
|
+
const docSumary = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`).then(({ data }) => data);
|
|
27
|
+
if (docSumary && docSumary.documents?.length > 0 && result.data.types && result.data.types.length > 0) {
|
|
28
|
+
const piTypes = result.data.types.join(",");
|
|
29
|
+
docSumary.documents = await Promise.all(docSumary.documents.map(async (doc) => {
|
|
30
|
+
const pi = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${doc.id}/pi?types=${piTypes}`).then(({ data }) => data);
|
|
31
|
+
if (pi?.documentNumber1) return {
|
|
32
|
+
...doc,
|
|
33
|
+
documentNumber: pi.documentNumber1
|
|
34
|
+
};
|
|
35
|
+
return doc;
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
return docSumary;
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/updateDocumentStatus.ts
|
|
42
|
+
const schema$1 = zod.z.object({
|
|
43
|
+
userId: zod.z.string().nonempty().uuid(),
|
|
44
|
+
documentId: zod.z.number().nonnegative().int()
|
|
45
|
+
});
|
|
46
|
+
const updateDocumentStatus = async (client, userId, documentId, document) => {
|
|
47
|
+
const result = schema$1.safeParse({
|
|
48
|
+
userId,
|
|
49
|
+
documentId
|
|
50
|
+
});
|
|
51
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
52
|
+
return client.put(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/documents/${documentId}`, document).then(({ data }) => data);
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/deleteDocument.ts
|
|
56
|
+
const schema = zod.z.object({
|
|
57
|
+
userId: zod.z.string().nonempty().uuid(),
|
|
58
|
+
documentId: zod.z.number().positive().int()
|
|
59
|
+
});
|
|
60
|
+
const deleteDocument = async (client, userId, documentId) => {
|
|
61
|
+
const result = schema.safeParse({
|
|
62
|
+
userId,
|
|
63
|
+
documentId
|
|
64
|
+
});
|
|
65
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
66
|
+
await client.delete(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${documentId}`);
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
exports.createOrUpdateDocument = createOrUpdateDocument;
|
|
70
|
+
exports.deleteDocument = deleteDocument;
|
|
71
|
+
exports.getUserDocuments = getUserDocuments;
|
|
72
|
+
exports.personalInformationDocumentTypeSchema = personalInformationDocumentTypeSchema;
|
|
73
|
+
exports.personalInformationDocumentTypes = personalInformationDocumentTypes;
|
|
74
|
+
exports.updateDocumentStatus = updateDocumentStatus;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Client } from "@vulog/aima-client";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type DocumentType = {
|
|
6
|
+
id: number;
|
|
7
|
+
fleetId: string;
|
|
8
|
+
type: string;
|
|
9
|
+
name: string;
|
|
10
|
+
mandatory: boolean;
|
|
11
|
+
hasNumber: boolean;
|
|
12
|
+
hasExpirationDate: boolean;
|
|
13
|
+
numberUploadUrl: number;
|
|
14
|
+
hasIssuingCountry: boolean;
|
|
15
|
+
hasIssuingOffice: boolean;
|
|
16
|
+
hasIssuingDate: boolean;
|
|
17
|
+
hasDlClass: boolean;
|
|
18
|
+
};
|
|
19
|
+
type FileUrl = {
|
|
20
|
+
id: number;
|
|
21
|
+
url: string;
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
24
|
+
type DocumentStatus = 'MISSING' | 'VALID' | 'INVALID' | 'EXPIRED' | 'PENDING_REVIEW';
|
|
25
|
+
type DocumentFull = {
|
|
26
|
+
id: number;
|
|
27
|
+
fleetId: string;
|
|
28
|
+
userId: string;
|
|
29
|
+
documentType: DocumentType;
|
|
30
|
+
documentNumber?: string;
|
|
31
|
+
expirationDate?: string;
|
|
32
|
+
files: FileUrl[];
|
|
33
|
+
uploadUrls: FileUrl[];
|
|
34
|
+
status: DocumentStatus;
|
|
35
|
+
reviewer?: string;
|
|
36
|
+
issuingCountry?: 'AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' | 'AN' | 'AO' | 'AQ' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BV' | 'BW' | 'BY' | 'BZ' | 'CA' | 'CC' | 'CD' | 'CF' | 'CG' | 'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CN' | 'CO' | 'CR' | 'CU' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'DZ' | 'EC' | 'EE' | 'EG' | 'EH' | 'ER' | 'ES' | 'ET' | 'FI' | 'FJ' | 'FK' | 'FM' | 'FO' | 'FR' | 'GA' | 'GB' | 'GD' | 'GE' | 'GF' | 'GG' | 'GH' | 'GI' | 'GL' | 'GM' | 'GN' | 'GP' | 'GQ' | 'GR' | 'GS' | 'GT' | 'GU' | 'GW' | 'GY' | 'HK' | 'HM' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' | 'IO' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JE' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KN' | 'KP' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' | 'LB' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'LY' | 'MA' | 'MC' | 'MD' | 'ME' | 'MF' | 'MG' | 'MH' | 'MK' | 'ML' | 'MM' | 'MN' | 'MO' | 'MP' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' | 'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' | 'NE' | 'NF' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' | 'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' | 'PG' | 'PH' | 'PK' | 'PL' | 'PM' | 'PN' | 'PR' | 'PS' | 'PT' | 'PW' | 'PY' | 'QA' | 'RE' | 'RO' | 'RS' | 'RU' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' | 'SE' | 'SG' | 'SH' | 'SI' | 'SJ' | 'SK' | 'SL' | 'SM' | 'SN' | 'SO' | 'SR' | 'SS' | 'ST' | 'SV' | 'SX' | 'SY' | 'SZ' | 'TC' | 'TD' | 'TF' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' | 'UM' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' | 'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'YE' | 'YT' | 'ZA' | 'ZM' | 'ZW';
|
|
37
|
+
issuingOffice?: string;
|
|
38
|
+
issuingDate?: string;
|
|
39
|
+
dlClass?: string;
|
|
40
|
+
issuingSubdivision?: string;
|
|
41
|
+
};
|
|
42
|
+
type DocumentBody = Partial<Omit<DocumentFull, 'id' | 'fleetId' | 'documentType' | 'files' | 'uploadUrls'> | 'status' | 'reviewer'> & {
|
|
43
|
+
documentType: string;
|
|
44
|
+
};
|
|
45
|
+
type DocumentStatusReview = {
|
|
46
|
+
status: DocumentStatus;
|
|
47
|
+
reviewer: string;
|
|
48
|
+
};
|
|
49
|
+
type DocumentByService = {
|
|
50
|
+
serviceId: string;
|
|
51
|
+
areMandatoryPresent: boolean;
|
|
52
|
+
mandatoryDocumentTypeId: number[];
|
|
53
|
+
};
|
|
54
|
+
type DocumentByFranchise = {
|
|
55
|
+
fleetId: string;
|
|
56
|
+
serviceId: string;
|
|
57
|
+
mandatoryDocumentTypeId: number[];
|
|
58
|
+
};
|
|
59
|
+
type DocumentSummary = {
|
|
60
|
+
documentTypes: DocumentType[];
|
|
61
|
+
documents: DocumentFull[];
|
|
62
|
+
documentByService: DocumentByService[];
|
|
63
|
+
documentByFranchise: DocumentByFranchise[] | null;
|
|
64
|
+
};
|
|
65
|
+
declare const personalInformationDocumentTypes: readonly ["DOCUMENT_NUMBER_1"];
|
|
66
|
+
type PersonalInformationDocumentType = (typeof personalInformationDocumentTypes)[number];
|
|
67
|
+
declare const personalInformationDocumentTypeSchema: z.ZodEnum<["DOCUMENT_NUMBER_1"]>;
|
|
68
|
+
type PersonalInformationDocument = {
|
|
69
|
+
fleetId: string;
|
|
70
|
+
userId: string;
|
|
71
|
+
documentId: string;
|
|
72
|
+
documentNumber1?: string;
|
|
73
|
+
updateDate: string;
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/createOrUpdateDocument.d.ts
|
|
77
|
+
declare const createOrUpdateDocument: (client: Client, userId: string, document: DocumentBody) => Promise<DocumentFull>;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/getUserDocuments.d.ts
|
|
80
|
+
declare const getUserDocuments: (client: Client, userId: string, types?: PersonalInformationDocumentType[]) => Promise<DocumentSummary>;
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/updateDocumentStatus.d.ts
|
|
83
|
+
declare const updateDocumentStatus: (client: Client, userId: string, documentId: number, document: DocumentStatusReview) => Promise<DocumentFull>;
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/deleteDocument.d.ts
|
|
86
|
+
declare const deleteDocument: (client: Client, userId: string, documentId: number) => Promise<void>;
|
|
87
|
+
//#endregion
|
|
88
|
+
export { DocumentBody, DocumentByFranchise, DocumentByService, DocumentFull, DocumentStatus, DocumentStatusReview, DocumentSummary, DocumentType, FileUrl, PersonalInformationDocument, PersonalInformationDocumentType, createOrUpdateDocument, deleteDocument, getUserDocuments, personalInformationDocumentTypeSchema, personalInformationDocumentTypes, updateDocumentStatus };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,83 +1,88 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Client } from "@vulog/aima-client";
|
|
3
3
|
|
|
4
|
+
//#region src/types.d.ts
|
|
4
5
|
type DocumentType = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
id: number;
|
|
7
|
+
fleetId: string;
|
|
8
|
+
type: string;
|
|
9
|
+
name: string;
|
|
10
|
+
mandatory: boolean;
|
|
11
|
+
hasNumber: boolean;
|
|
12
|
+
hasExpirationDate: boolean;
|
|
13
|
+
numberUploadUrl: number;
|
|
14
|
+
hasIssuingCountry: boolean;
|
|
15
|
+
hasIssuingOffice: boolean;
|
|
16
|
+
hasIssuingDate: boolean;
|
|
17
|
+
hasDlClass: boolean;
|
|
17
18
|
};
|
|
18
19
|
type FileUrl = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
id: number;
|
|
21
|
+
url: string;
|
|
22
|
+
name: string;
|
|
22
23
|
};
|
|
23
24
|
type DocumentStatus = 'MISSING' | 'VALID' | 'INVALID' | 'EXPIRED' | 'PENDING_REVIEW';
|
|
24
25
|
type DocumentFull = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
id: number;
|
|
27
|
+
fleetId: string;
|
|
28
|
+
userId: string;
|
|
29
|
+
documentType: DocumentType;
|
|
30
|
+
documentNumber?: string;
|
|
31
|
+
expirationDate?: string;
|
|
32
|
+
files: FileUrl[];
|
|
33
|
+
uploadUrls: FileUrl[];
|
|
34
|
+
status: DocumentStatus;
|
|
35
|
+
reviewer?: string;
|
|
36
|
+
issuingCountry?: 'AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' | 'AN' | 'AO' | 'AQ' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BV' | 'BW' | 'BY' | 'BZ' | 'CA' | 'CC' | 'CD' | 'CF' | 'CG' | 'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CN' | 'CO' | 'CR' | 'CU' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'DZ' | 'EC' | 'EE' | 'EG' | 'EH' | 'ER' | 'ES' | 'ET' | 'FI' | 'FJ' | 'FK' | 'FM' | 'FO' | 'FR' | 'GA' | 'GB' | 'GD' | 'GE' | 'GF' | 'GG' | 'GH' | 'GI' | 'GL' | 'GM' | 'GN' | 'GP' | 'GQ' | 'GR' | 'GS' | 'GT' | 'GU' | 'GW' | 'GY' | 'HK' | 'HM' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' | 'IO' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JE' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KN' | 'KP' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' | 'LB' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'LY' | 'MA' | 'MC' | 'MD' | 'ME' | 'MF' | 'MG' | 'MH' | 'MK' | 'ML' | 'MM' | 'MN' | 'MO' | 'MP' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' | 'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' | 'NE' | 'NF' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' | 'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' | 'PG' | 'PH' | 'PK' | 'PL' | 'PM' | 'PN' | 'PR' | 'PS' | 'PT' | 'PW' | 'PY' | 'QA' | 'RE' | 'RO' | 'RS' | 'RU' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' | 'SE' | 'SG' | 'SH' | 'SI' | 'SJ' | 'SK' | 'SL' | 'SM' | 'SN' | 'SO' | 'SR' | 'SS' | 'ST' | 'SV' | 'SX' | 'SY' | 'SZ' | 'TC' | 'TD' | 'TF' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' | 'UM' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' | 'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'YE' | 'YT' | 'ZA' | 'ZM' | 'ZW';
|
|
37
|
+
issuingOffice?: string;
|
|
38
|
+
issuingDate?: string;
|
|
39
|
+
dlClass?: string;
|
|
40
|
+
issuingSubdivision?: string;
|
|
40
41
|
};
|
|
41
42
|
type DocumentBody = Partial<Omit<DocumentFull, 'id' | 'fleetId' | 'documentType' | 'files' | 'uploadUrls'> | 'status' | 'reviewer'> & {
|
|
42
|
-
|
|
43
|
+
documentType: string;
|
|
43
44
|
};
|
|
44
45
|
type DocumentStatusReview = {
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
status: DocumentStatus;
|
|
47
|
+
reviewer: string;
|
|
47
48
|
};
|
|
48
49
|
type DocumentByService = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
serviceId: string;
|
|
51
|
+
areMandatoryPresent: boolean;
|
|
52
|
+
mandatoryDocumentTypeId: number[];
|
|
52
53
|
};
|
|
53
54
|
type DocumentByFranchise = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
fleetId: string;
|
|
56
|
+
serviceId: string;
|
|
57
|
+
mandatoryDocumentTypeId: number[];
|
|
57
58
|
};
|
|
58
59
|
type DocumentSummary = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
documentTypes: DocumentType[];
|
|
61
|
+
documents: DocumentFull[];
|
|
62
|
+
documentByService: DocumentByService[];
|
|
63
|
+
documentByFranchise: DocumentByFranchise[] | null;
|
|
63
64
|
};
|
|
64
65
|
declare const personalInformationDocumentTypes: readonly ["DOCUMENT_NUMBER_1"];
|
|
65
66
|
type PersonalInformationDocumentType = (typeof personalInformationDocumentTypes)[number];
|
|
66
67
|
declare const personalInformationDocumentTypeSchema: z.ZodEnum<["DOCUMENT_NUMBER_1"]>;
|
|
67
68
|
type PersonalInformationDocument = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
fleetId: string;
|
|
70
|
+
userId: string;
|
|
71
|
+
documentId: string;
|
|
72
|
+
documentNumber1?: string;
|
|
73
|
+
updateDate: string;
|
|
73
74
|
};
|
|
74
|
-
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/createOrUpdateDocument.d.ts
|
|
75
77
|
declare const createOrUpdateDocument: (client: Client, userId: string, document: DocumentBody) => Promise<DocumentFull>;
|
|
76
|
-
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/getUserDocuments.d.ts
|
|
77
80
|
declare const getUserDocuments: (client: Client, userId: string, types?: PersonalInformationDocumentType[]) => Promise<DocumentSummary>;
|
|
78
|
-
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/updateDocumentStatus.d.ts
|
|
79
83
|
declare const updateDocumentStatus: (client: Client, userId: string, documentId: number, document: DocumentStatusReview) => Promise<DocumentFull>;
|
|
80
|
-
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/deleteDocument.d.ts
|
|
81
86
|
declare const deleteDocument: (client: Client, userId: string, documentId: number) => Promise<void>;
|
|
82
|
-
|
|
83
|
-
export {
|
|
87
|
+
//#endregion
|
|
88
|
+
export { DocumentBody, DocumentByFranchise, DocumentByService, DocumentFull, DocumentStatus, DocumentStatusReview, DocumentSummary, DocumentType, FileUrl, PersonalInformationDocument, PersonalInformationDocumentType, createOrUpdateDocument, deleteDocument, getUserDocuments, personalInformationDocumentTypeSchema, personalInformationDocumentTypes, updateDocumentStatus };
|
package/dist/index.mjs
CHANGED
|
@@ -1,102 +1,68 @@
|
|
|
1
|
-
// src/createOrUpdateDocument.ts
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
throw new TypeError("Invalid args", {
|
|
10
|
-
cause: result.error.issues
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
return client.post(
|
|
14
|
-
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`,
|
|
15
|
-
document
|
|
16
|
-
).then(({ data }) => data);
|
|
2
|
+
//#region src/createOrUpdateDocument.ts
|
|
3
|
+
const schema$3 = z.object({ userId: z.string().nonempty().uuid() });
|
|
4
|
+
const createOrUpdateDocument = async (client, userId, document) => {
|
|
5
|
+
const result = schema$3.safeParse({ userId });
|
|
6
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
7
|
+
return client.post(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`, document).then(({ data }) => data);
|
|
17
8
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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()
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/types.ts
|
|
11
|
+
const personalInformationDocumentTypes = ["DOCUMENT_NUMBER_1"];
|
|
12
|
+
const personalInformationDocumentTypeSchema = z.enum(personalInformationDocumentTypes);
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/getUserDocuments.ts
|
|
15
|
+
const schema$2 = z.object({
|
|
16
|
+
userId: z.string().trim().nonempty().uuid(),
|
|
17
|
+
types: z.array(personalInformationDocumentTypeSchema).min(0).optional()
|
|
31
18
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
documentNumber: pi.documentNumber1
|
|
52
|
-
// update the documentNumber field
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
return doc;
|
|
56
|
-
})
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
return docSumary;
|
|
19
|
+
const getUserDocuments = async (client, userId, types) => {
|
|
20
|
+
const result = schema$2.safeParse({
|
|
21
|
+
userId,
|
|
22
|
+
types
|
|
23
|
+
});
|
|
24
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
25
|
+
const docSumary = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`).then(({ data }) => data);
|
|
26
|
+
if (docSumary && docSumary.documents?.length > 0 && result.data.types && result.data.types.length > 0) {
|
|
27
|
+
const piTypes = result.data.types.join(",");
|
|
28
|
+
docSumary.documents = await Promise.all(docSumary.documents.map(async (doc) => {
|
|
29
|
+
const pi = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${doc.id}/pi?types=${piTypes}`).then(({ data }) => data);
|
|
30
|
+
if (pi?.documentNumber1) return {
|
|
31
|
+
...doc,
|
|
32
|
+
documentNumber: pi.documentNumber1
|
|
33
|
+
};
|
|
34
|
+
return doc;
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return docSumary;
|
|
60
38
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
documentId: z4.number().nonnegative().int()
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/updateDocumentStatus.ts
|
|
41
|
+
const schema$1 = z.object({
|
|
42
|
+
userId: z.string().nonempty().uuid(),
|
|
43
|
+
documentId: z.number().nonnegative().int()
|
|
67
44
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return client.put(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/documents/${documentId}`, document).then(({ data }) => data);
|
|
45
|
+
const updateDocumentStatus = async (client, userId, documentId, document) => {
|
|
46
|
+
const result = schema$1.safeParse({
|
|
47
|
+
userId,
|
|
48
|
+
documentId
|
|
49
|
+
});
|
|
50
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
51
|
+
return client.put(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/documents/${documentId}`, document).then(({ data }) => data);
|
|
76
52
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
documentId: z5.number().positive().int()
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/deleteDocument.ts
|
|
55
|
+
const schema = z.object({
|
|
56
|
+
userId: z.string().nonempty().uuid(),
|
|
57
|
+
documentId: z.number().positive().int()
|
|
83
58
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
await client.delete(
|
|
92
|
-
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${documentId}`
|
|
93
|
-
);
|
|
94
|
-
};
|
|
95
|
-
export {
|
|
96
|
-
createOrUpdateDocument,
|
|
97
|
-
deleteDocument,
|
|
98
|
-
getUserDocuments,
|
|
99
|
-
personalInformationDocumentTypeSchema,
|
|
100
|
-
personalInformationDocumentTypes,
|
|
101
|
-
updateDocumentStatus
|
|
59
|
+
const deleteDocument = async (client, userId, documentId) => {
|
|
60
|
+
const result = schema.safeParse({
|
|
61
|
+
userId,
|
|
62
|
+
documentId
|
|
63
|
+
});
|
|
64
|
+
if (!result.success) throw new TypeError("Invalid args", { cause: result.error.issues });
|
|
65
|
+
await client.delete(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${documentId}`);
|
|
102
66
|
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { createOrUpdateDocument, deleteDocument, getUserDocuments, personalInformationDocumentTypeSchema, personalInformationDocumentTypes, updateDocumentStatus };
|
package/package.json
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-document",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.2.31",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
5
6
|
"module": "dist/index.mjs",
|
|
6
|
-
"types": "dist/index.d.
|
|
7
|
+
"types": "dist/index.d.cts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"default": "./dist/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.cts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
7
20
|
"scripts": {
|
|
8
|
-
"build": "
|
|
9
|
-
"dev": "
|
|
21
|
+
"build": "tsdown",
|
|
22
|
+
"dev": "tsdown --watch",
|
|
10
23
|
"test": "vitest run",
|
|
11
24
|
"test:watch": "vitest",
|
|
12
25
|
"lint": "eslint src/**/* --ext .ts"
|
|
@@ -19,8 +32,8 @@
|
|
|
19
32
|
"author": "Vulog",
|
|
20
33
|
"license": "MIT",
|
|
21
34
|
"dependencies": {
|
|
22
|
-
"@vulog/aima-client": "1.2.
|
|
23
|
-
"@vulog/aima-core": "1.2.
|
|
35
|
+
"@vulog/aima-client": "1.2.31",
|
|
36
|
+
"@vulog/aima-core": "1.2.31"
|
|
24
37
|
},
|
|
25
38
|
"peerDependencies": {
|
|
26
39
|
"zod": "^3.25.76"
|
|
@@ -19,7 +19,7 @@ describe('getUserDocument', () => {
|
|
|
19
19
|
hasIssuingCountry: false,
|
|
20
20
|
hasIssuingOffice: true,
|
|
21
21
|
hasIssuingDate: true,
|
|
22
|
-
hasDlClass: false
|
|
22
|
+
hasDlClass: false,
|
|
23
23
|
};
|
|
24
24
|
const docTypeDl = {
|
|
25
25
|
id: 691,
|
|
@@ -35,7 +35,7 @@ describe('getUserDocument', () => {
|
|
|
35
35
|
hasIssuingDate: true,
|
|
36
36
|
hasDlClass: true,
|
|
37
37
|
hasIssuingSubdivision: true,
|
|
38
|
-
}
|
|
38
|
+
};
|
|
39
39
|
const docTypeSelfie = {
|
|
40
40
|
id: 460,
|
|
41
41
|
fleetId: FLEET_ID,
|
|
@@ -49,17 +49,13 @@ describe('getUserDocument', () => {
|
|
|
49
49
|
hasIssuingOffice: false,
|
|
50
50
|
hasIssuingDate: false,
|
|
51
51
|
hasDlClass: false,
|
|
52
|
-
hasIssuingSubdivision: false
|
|
52
|
+
hasIssuingSubdivision: false,
|
|
53
53
|
};
|
|
54
54
|
const idDocId = 10892065;
|
|
55
55
|
const dlDocId = 10892077;
|
|
56
56
|
const selfieDocId = 10931811;
|
|
57
57
|
const documents = {
|
|
58
|
-
documentTypes: [
|
|
59
|
-
{ ...docTypeId },
|
|
60
|
-
{ ...docTypeDl },
|
|
61
|
-
{ ...docTypeSelfie },
|
|
62
|
-
],
|
|
58
|
+
documentTypes: [{ ...docTypeId }, { ...docTypeDl }, { ...docTypeSelfie }],
|
|
63
59
|
documents: [
|
|
64
60
|
{
|
|
65
61
|
id: idDocId,
|
|
@@ -72,15 +68,15 @@ describe('getUserDocument', () => {
|
|
|
72
68
|
{
|
|
73
69
|
id: null,
|
|
74
70
|
url: `https://java-test.vulog.com/boapi/proxy/upload/fleets/${FLEET_ID}/users/${USER_ID}/documents/${idDocId}/${docTypeId.type}_0`,
|
|
75
|
-
name: `${docTypeId.type}_0
|
|
76
|
-
}
|
|
71
|
+
name: `${docTypeId.type}_0`,
|
|
72
|
+
},
|
|
77
73
|
],
|
|
78
74
|
uploadUrls: [
|
|
79
75
|
{
|
|
80
76
|
id: null,
|
|
81
77
|
url: `https://java-test.vulog.com/upload/fleets/${FLEET_ID}/documents/${idDocId}/${docTypeId.type}_0?tk=s2TzoXn%2BhEUKnCbEEFZfhRqOvStMSdS14ow3QHFhgRA3ttoqIrcNxpP4JhMvyIYkyGLo%2Bnwttnz3zt1NkOX3Lf8PBVPiXXyxB9%2BtW1FkBISvOOjA0FTyMLquFoe2cSNn`,
|
|
82
|
-
name: `${docTypeId.type}_0
|
|
83
|
-
}
|
|
78
|
+
name: `${docTypeId.type}_0`,
|
|
79
|
+
},
|
|
84
80
|
],
|
|
85
81
|
status: 'VALID',
|
|
86
82
|
reviewer: '493a4d98-7437-42db-8d4e-bd722ac62caa',
|
|
@@ -89,7 +85,7 @@ describe('getUserDocument', () => {
|
|
|
89
85
|
issuingDate: '2023-01-16',
|
|
90
86
|
dlClass: null,
|
|
91
87
|
issuingSubdivision: null,
|
|
92
|
-
documentNumber: null
|
|
88
|
+
documentNumber: null,
|
|
93
89
|
},
|
|
94
90
|
{
|
|
95
91
|
id: dlDocId,
|
|
@@ -102,25 +98,25 @@ describe('getUserDocument', () => {
|
|
|
102
98
|
{
|
|
103
99
|
id: null,
|
|
104
100
|
url: `https://java-test.vulog.com/boapi/proxy/upload/fleets/${FLEET_ID}/users/${USER_ID}/documents/${dlDocId}/${docTypeDl.type}_0`,
|
|
105
|
-
name: `${docTypeDl.type}_0
|
|
101
|
+
name: `${docTypeDl.type}_0`,
|
|
106
102
|
},
|
|
107
103
|
{
|
|
108
104
|
id: null,
|
|
109
105
|
url: `https://java-test.vulog.com/boapi/proxy/upload/fleets/${FLEET_ID}/users/${USER_ID}/documents/${dlDocId}/${docTypeDl.type}_1`,
|
|
110
|
-
name: `${docTypeDl.type}_1
|
|
111
|
-
}
|
|
106
|
+
name: `${docTypeDl.type}_1`,
|
|
107
|
+
},
|
|
112
108
|
],
|
|
113
109
|
uploadUrls: [
|
|
114
110
|
{
|
|
115
111
|
id: null,
|
|
116
112
|
url: `https://java-test.vulog.com/upload/fleets/${FLEET_ID}/documents/${dlDocId}/${docTypeDl.type}_0?tk=3Xs08XSnb2ZatHY%2Blic5G88IMPGKs0LOy8hlM47eaER1nPDxgYeewOMYySGQfbPMKz3Opy5T3RPULV9O3IBCm4iOIApdah4Q22rCi4hH5rZ%2BOyGuLwmffBuoYA16rLuO`,
|
|
117
|
-
name: `${docTypeDl.type}_0
|
|
113
|
+
name: `${docTypeDl.type}_0`,
|
|
118
114
|
},
|
|
119
115
|
{
|
|
120
116
|
id: null,
|
|
121
117
|
url: `https://java-test.vulog.com/upload/fleets/${FLEET_ID}/documents/${dlDocId}/${docTypeDl.type}_1?tk=fg8Y3duKmYM3olsMaC6mipzB5AsjCf5h8mRHwNb4iGzpy8MqMXigaBce5PxdFKcgiuQjoWYvcbBZx2W985Mqt8CGpxoGIzqbYOmsS9kvPjp6UZERqnfan73y5vk3MPUy`,
|
|
122
|
-
name: `${docTypeDl.type}_1
|
|
123
|
-
}
|
|
118
|
+
name: `${docTypeDl.type}_1`,
|
|
119
|
+
},
|
|
124
120
|
],
|
|
125
121
|
status: 'VALID',
|
|
126
122
|
reviewer: '493a4d98-7437-42db-8d4e-bd722ac62caf',
|
|
@@ -129,7 +125,7 @@ describe('getUserDocument', () => {
|
|
|
129
125
|
issuingDate: '1994-02-18',
|
|
130
126
|
dlClass: 'B',
|
|
131
127
|
issuingSubdivision: '06',
|
|
132
|
-
documentNumber: '123456'
|
|
128
|
+
documentNumber: '123456',
|
|
133
129
|
},
|
|
134
130
|
{
|
|
135
131
|
id: selfieDocId,
|
|
@@ -143,14 +139,14 @@ describe('getUserDocument', () => {
|
|
|
143
139
|
id: null,
|
|
144
140
|
url: 'https://java-eu01.vulog.com/upload/fleets/${FLEET_ID}/file?tk=sbSfJzSpv8xJ4FN7ETn5Zq5ykKoAmYKIpFjvVPzVpsCcAGmrMWNJ3h4NunQu***',
|
|
145
141
|
name: `${docTypeSelfie.type}_0`,
|
|
146
|
-
}
|
|
142
|
+
},
|
|
147
143
|
],
|
|
148
144
|
uploadUrls: [
|
|
149
145
|
{
|
|
150
146
|
id: null,
|
|
151
147
|
url: 'https://java-eu01.vulog.com/upload/fleets/${FLEET_ID}/documents/10931800/SELFIE_0?tk=sbSfJzSpv8xJ4FN7ETn5Zn1MGPxqzzDIvE1WJ***',
|
|
152
148
|
name: `${docTypeSelfie.type}_0`,
|
|
153
|
-
}
|
|
149
|
+
},
|
|
154
150
|
],
|
|
155
151
|
status: 'VALID',
|
|
156
152
|
reviewer: 'Registration',
|
|
@@ -159,38 +155,38 @@ describe('getUserDocument', () => {
|
|
|
159
155
|
issuingDate: null,
|
|
160
156
|
dlClass: null,
|
|
161
157
|
issuingSubdivision: null,
|
|
162
|
-
documentNumber: null
|
|
158
|
+
documentNumber: null,
|
|
163
159
|
},
|
|
164
160
|
],
|
|
165
161
|
documentByService: [
|
|
166
162
|
{
|
|
167
163
|
serviceId: '0166e9a0-ac01-46d1-8211-f5ac24145953',
|
|
168
164
|
areMandatoryPresent: false,
|
|
169
|
-
mandatoryDocumentTypeId: []
|
|
165
|
+
mandatoryDocumentTypeId: [],
|
|
170
166
|
},
|
|
171
167
|
{
|
|
172
168
|
serviceId: '0a6db44e-8a83-4f74-a6f8-5b21bd693289',
|
|
173
169
|
areMandatoryPresent: false,
|
|
174
|
-
mandatoryDocumentTypeId: []
|
|
175
|
-
}
|
|
170
|
+
mandatoryDocumentTypeId: [],
|
|
171
|
+
},
|
|
176
172
|
],
|
|
177
|
-
documentByFranchise: null
|
|
173
|
+
documentByFranchise: null,
|
|
178
174
|
};
|
|
179
175
|
const piId = {
|
|
180
176
|
fleetId: FLEET_ID,
|
|
181
177
|
userId: USER_ID,
|
|
182
178
|
documentId: idDocId,
|
|
183
179
|
documentNumber1: '741',
|
|
184
|
-
updateDate: '2025-04-29T10:40:42.000Z'
|
|
185
|
-
}
|
|
180
|
+
updateDate: '2025-04-29T10:40:42.000Z',
|
|
181
|
+
};
|
|
186
182
|
const piDl = {
|
|
187
183
|
fleetId: FLEET_ID,
|
|
188
184
|
userId: USER_ID,
|
|
189
185
|
documentId: dlDocId,
|
|
190
186
|
documentNumber1: '159',
|
|
191
|
-
updateDate: '2025-04-29T10:40:42.000Z'
|
|
192
|
-
}
|
|
193
|
-
|
|
187
|
+
updateDate: '2025-04-29T10:40:42.000Z',
|
|
188
|
+
};
|
|
189
|
+
|
|
194
190
|
const getMock = vi.fn();
|
|
195
191
|
const client = {
|
|
196
192
|
get: getMock,
|
|
@@ -202,7 +198,7 @@ describe('getUserDocument', () => {
|
|
|
202
198
|
beforeEach(() => {
|
|
203
199
|
getMock.mockReset();
|
|
204
200
|
vi.useFakeTimers({ now: new Date('2025-01-12T13:35:50.123Z') });
|
|
205
|
-
|
|
201
|
+
|
|
206
202
|
getMock.mockImplementation((url: string): Promise<any> => {
|
|
207
203
|
if (url === `/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents`) {
|
|
208
204
|
return Promise.resolve({
|
|
@@ -210,39 +206,42 @@ describe('getUserDocument', () => {
|
|
|
210
206
|
status: 200,
|
|
211
207
|
statusText: 'OK',
|
|
212
208
|
headers: {},
|
|
213
|
-
config: {}
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
209
|
+
config: {},
|
|
210
|
+
});
|
|
211
|
+
} else if (
|
|
212
|
+
url.startsWith(`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents/${idDocId}/pi`)
|
|
213
|
+
) {
|
|
217
214
|
return Promise.resolve({
|
|
218
215
|
data: piId,
|
|
219
216
|
status: 200,
|
|
220
217
|
statusText: 'OK',
|
|
221
218
|
headers: {},
|
|
222
|
-
config: {}
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
219
|
+
config: {},
|
|
220
|
+
});
|
|
221
|
+
} else if (
|
|
222
|
+
url.startsWith(`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents/${dlDocId}/pi`)
|
|
223
|
+
) {
|
|
226
224
|
return Promise.resolve({
|
|
227
225
|
data: piDl,
|
|
228
226
|
status: 200,
|
|
229
227
|
statusText: 'OK',
|
|
230
228
|
headers: {},
|
|
231
|
-
config: {}
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
229
|
+
config: {},
|
|
230
|
+
});
|
|
231
|
+
} else if (
|
|
232
|
+
url.startsWith(`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents/${selfieDocId}/pi`)
|
|
233
|
+
) {
|
|
235
234
|
return Promise.resolve({
|
|
236
235
|
data: {
|
|
237
236
|
fleetId: FLEET_ID,
|
|
238
237
|
userId: USER_ID,
|
|
239
|
-
documentId: selfieDocId
|
|
238
|
+
documentId: selfieDocId,
|
|
240
239
|
},
|
|
241
240
|
status: 200,
|
|
242
241
|
statusText: 'OK',
|
|
243
242
|
headers: {},
|
|
244
|
-
config: {}
|
|
245
|
-
|
|
243
|
+
config: {},
|
|
244
|
+
});
|
|
246
245
|
}
|
|
247
246
|
// Pour les autres URLs, rejetez la promesse
|
|
248
247
|
return Promise.reject(new Error('404 Not Found'));
|
|
@@ -254,7 +253,6 @@ describe('getUserDocument', () => {
|
|
|
254
253
|
});
|
|
255
254
|
|
|
256
255
|
test('call without PI', async () => {
|
|
257
|
-
|
|
258
256
|
const docs = await getUserDocuments(client, USER_ID);
|
|
259
257
|
expect(getMock).toHaveBeenCalledOnce();
|
|
260
258
|
expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents`);
|
|
@@ -299,7 +297,7 @@ describe('getUserDocument', () => {
|
|
|
299
297
|
expect(docs.documents[1].issuingDate).toEqual(documents.documents[1].issuingDate);
|
|
300
298
|
expect(docs.documents[1].dlClass).toEqual(documents.documents[1].dlClass);
|
|
301
299
|
expect(docs.documents[1].issuingSubdivision).toEqual(documents.documents[1].issuingSubdivision);
|
|
302
|
-
|
|
300
|
+
|
|
303
301
|
expect(docs.documents[2].fleetId).toEqual(documents.documents[2].fleetId);
|
|
304
302
|
expect(docs.documents[2].userId).toEqual(documents.documents[2].userId);
|
|
305
303
|
expect(docs.documents[2].documentType).not.toBeNull();
|
|
@@ -317,12 +315,15 @@ describe('getUserDocument', () => {
|
|
|
317
315
|
});
|
|
318
316
|
|
|
319
317
|
test('call with PI', async () => {
|
|
320
|
-
|
|
321
318
|
const docs = await getUserDocuments(client, USER_ID, ['DOCUMENT_NUMBER_1']);
|
|
322
319
|
expect(getMock).toHaveBeenCalledTimes(4);
|
|
323
320
|
expect(getMock).toBeCalledWith(`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents`);
|
|
324
|
-
expect(getMock).toBeCalledWith(
|
|
325
|
-
|
|
321
|
+
expect(getMock).toBeCalledWith(
|
|
322
|
+
`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents/${idDocId}/pi?types=DOCUMENT_NUMBER_1`
|
|
323
|
+
);
|
|
324
|
+
expect(getMock).toBeCalledWith(
|
|
325
|
+
`/boapi/proxy/user/fleets/${FLEET_ID}/users/${USER_ID}/documents/${dlDocId}/pi?types=DOCUMENT_NUMBER_1`
|
|
326
|
+
);
|
|
326
327
|
|
|
327
328
|
expect(docs).toBeTruthy();
|
|
328
329
|
expect(docs.documents).toBeTruthy();
|
|
@@ -335,11 +336,11 @@ describe('getUserDocument', () => {
|
|
|
335
336
|
expect(docs.documents[2].id).toEqual(documents.documents[2].id);
|
|
336
337
|
expect(docs.documents[2].documentNumber).toBeFalsy();
|
|
337
338
|
|
|
338
|
-
if(docs.documents[0].id === idDocId) {
|
|
339
|
+
if (docs.documents[0].id === idDocId) {
|
|
339
340
|
expect(docs.documents[0].documentNumber).toEqual(piId.documentNumber1);
|
|
340
341
|
expect(docs.documents[1].documentNumber).toEqual(piDl.documentNumber1);
|
|
341
342
|
}
|
|
342
|
-
if(docs.documents[0].id === dlDocId) {
|
|
343
|
+
if (docs.documents[0].id === dlDocId) {
|
|
343
344
|
expect(docs.documents[0].documentNumber).toEqual(piDl.documentNumber1);
|
|
344
345
|
expect(docs.documents[1].documentNumber).toEqual(piId.documentNumber1);
|
|
345
346
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Client } from '@vulog/aima-client';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
type DocumentType = {
|
|
5
|
-
id: number;
|
|
6
|
-
fleetId: string;
|
|
7
|
-
type: string;
|
|
8
|
-
name: string;
|
|
9
|
-
mandatory: boolean;
|
|
10
|
-
hasNumber: boolean;
|
|
11
|
-
hasExpirationDate: boolean;
|
|
12
|
-
numberUploadUrl: number;
|
|
13
|
-
hasIssuingCountry: boolean;
|
|
14
|
-
hasIssuingOffice: boolean;
|
|
15
|
-
hasIssuingDate: boolean;
|
|
16
|
-
hasDlClass: boolean;
|
|
17
|
-
};
|
|
18
|
-
type FileUrl = {
|
|
19
|
-
id: number;
|
|
20
|
-
url: string;
|
|
21
|
-
name: string;
|
|
22
|
-
};
|
|
23
|
-
type DocumentStatus = 'MISSING' | 'VALID' | 'INVALID' | 'EXPIRED' | 'PENDING_REVIEW';
|
|
24
|
-
type DocumentFull = {
|
|
25
|
-
id: number;
|
|
26
|
-
fleetId: string;
|
|
27
|
-
userId: string;
|
|
28
|
-
documentType: DocumentType;
|
|
29
|
-
documentNumber?: string;
|
|
30
|
-
expirationDate?: string;
|
|
31
|
-
files: FileUrl[];
|
|
32
|
-
uploadUrls: FileUrl[];
|
|
33
|
-
status: DocumentStatus;
|
|
34
|
-
reviewer?: string;
|
|
35
|
-
issuingCountry?: 'AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' | 'AN' | 'AO' | 'AQ' | 'AR' | 'AS' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BV' | 'BW' | 'BY' | 'BZ' | 'CA' | 'CC' | 'CD' | 'CF' | 'CG' | 'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CN' | 'CO' | 'CR' | 'CU' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'DZ' | 'EC' | 'EE' | 'EG' | 'EH' | 'ER' | 'ES' | 'ET' | 'FI' | 'FJ' | 'FK' | 'FM' | 'FO' | 'FR' | 'GA' | 'GB' | 'GD' | 'GE' | 'GF' | 'GG' | 'GH' | 'GI' | 'GL' | 'GM' | 'GN' | 'GP' | 'GQ' | 'GR' | 'GS' | 'GT' | 'GU' | 'GW' | 'GY' | 'HK' | 'HM' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' | 'IO' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JE' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KN' | 'KP' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' | 'LB' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'LY' | 'MA' | 'MC' | 'MD' | 'ME' | 'MF' | 'MG' | 'MH' | 'MK' | 'ML' | 'MM' | 'MN' | 'MO' | 'MP' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' | 'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' | 'NE' | 'NF' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' | 'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' | 'PG' | 'PH' | 'PK' | 'PL' | 'PM' | 'PN' | 'PR' | 'PS' | 'PT' | 'PW' | 'PY' | 'QA' | 'RE' | 'RO' | 'RS' | 'RU' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' | 'SE' | 'SG' | 'SH' | 'SI' | 'SJ' | 'SK' | 'SL' | 'SM' | 'SN' | 'SO' | 'SR' | 'SS' | 'ST' | 'SV' | 'SX' | 'SY' | 'SZ' | 'TC' | 'TD' | 'TF' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' | 'UM' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' | 'VG' | 'VI' | 'VN' | 'VU' | 'WF' | 'WS' | 'YE' | 'YT' | 'ZA' | 'ZM' | 'ZW';
|
|
36
|
-
issuingOffice?: string;
|
|
37
|
-
issuingDate?: string;
|
|
38
|
-
dlClass?: string;
|
|
39
|
-
issuingSubdivision?: string;
|
|
40
|
-
};
|
|
41
|
-
type DocumentBody = Partial<Omit<DocumentFull, 'id' | 'fleetId' | 'documentType' | 'files' | 'uploadUrls'> | 'status' | 'reviewer'> & {
|
|
42
|
-
documentType: string;
|
|
43
|
-
};
|
|
44
|
-
type DocumentStatusReview = {
|
|
45
|
-
status: DocumentStatus;
|
|
46
|
-
reviewer: string;
|
|
47
|
-
};
|
|
48
|
-
type DocumentByService = {
|
|
49
|
-
serviceId: string;
|
|
50
|
-
areMandatoryPresent: boolean;
|
|
51
|
-
mandatoryDocumentTypeId: number[];
|
|
52
|
-
};
|
|
53
|
-
type DocumentByFranchise = {
|
|
54
|
-
fleetId: string;
|
|
55
|
-
serviceId: string;
|
|
56
|
-
mandatoryDocumentTypeId: number[];
|
|
57
|
-
};
|
|
58
|
-
type DocumentSummary = {
|
|
59
|
-
documentTypes: DocumentType[];
|
|
60
|
-
documents: DocumentFull[];
|
|
61
|
-
documentByService: DocumentByService[];
|
|
62
|
-
documentByFranchise: DocumentByFranchise[] | null;
|
|
63
|
-
};
|
|
64
|
-
declare const personalInformationDocumentTypes: readonly ["DOCUMENT_NUMBER_1"];
|
|
65
|
-
type PersonalInformationDocumentType = (typeof personalInformationDocumentTypes)[number];
|
|
66
|
-
declare const personalInformationDocumentTypeSchema: z.ZodEnum<["DOCUMENT_NUMBER_1"]>;
|
|
67
|
-
type PersonalInformationDocument = {
|
|
68
|
-
fleetId: string;
|
|
69
|
-
userId: string;
|
|
70
|
-
documentId: string;
|
|
71
|
-
documentNumber1?: string;
|
|
72
|
-
updateDate: string;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
declare const createOrUpdateDocument: (client: Client, userId: string, document: DocumentBody) => Promise<DocumentFull>;
|
|
76
|
-
|
|
77
|
-
declare const getUserDocuments: (client: Client, userId: string, types?: PersonalInformationDocumentType[]) => Promise<DocumentSummary>;
|
|
78
|
-
|
|
79
|
-
declare const updateDocumentStatus: (client: Client, userId: string, documentId: number, document: DocumentStatusReview) => Promise<DocumentFull>;
|
|
80
|
-
|
|
81
|
-
declare const deleteDocument: (client: Client, userId: string, documentId: number) => Promise<void>;
|
|
82
|
-
|
|
83
|
-
export { type DocumentBody, type DocumentByFranchise, type DocumentByService, type DocumentFull, type DocumentStatus, type DocumentStatusReview, type DocumentSummary, type DocumentType, type FileUrl, type PersonalInformationDocument, type PersonalInformationDocumentType, createOrUpdateDocument, deleteDocument, getUserDocuments, personalInformationDocumentTypeSchema, personalInformationDocumentTypes, updateDocumentStatus };
|
package/dist/index.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
createOrUpdateDocument: () => createOrUpdateDocument,
|
|
24
|
-
deleteDocument: () => deleteDocument,
|
|
25
|
-
getUserDocuments: () => getUserDocuments,
|
|
26
|
-
personalInformationDocumentTypeSchema: () => personalInformationDocumentTypeSchema,
|
|
27
|
-
personalInformationDocumentTypes: () => personalInformationDocumentTypes,
|
|
28
|
-
updateDocumentStatus: () => updateDocumentStatus
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(index_exports);
|
|
31
|
-
|
|
32
|
-
// src/createOrUpdateDocument.ts
|
|
33
|
-
var import_zod = require("zod");
|
|
34
|
-
var schema = import_zod.z.object({
|
|
35
|
-
userId: import_zod.z.string().nonempty().uuid()
|
|
36
|
-
});
|
|
37
|
-
var createOrUpdateDocument = async (client, userId, document) => {
|
|
38
|
-
const result = schema.safeParse({ userId });
|
|
39
|
-
if (!result.success) {
|
|
40
|
-
throw new TypeError("Invalid args", {
|
|
41
|
-
cause: result.error.issues
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
return client.post(
|
|
45
|
-
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`,
|
|
46
|
-
document
|
|
47
|
-
).then(({ data }) => data);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// src/getUserDocuments.ts
|
|
51
|
-
var import_zod3 = require("zod");
|
|
52
|
-
|
|
53
|
-
// src/types.ts
|
|
54
|
-
var import_zod2 = require("zod");
|
|
55
|
-
var personalInformationDocumentTypes = ["DOCUMENT_NUMBER_1"];
|
|
56
|
-
var personalInformationDocumentTypeSchema = import_zod2.z.enum(personalInformationDocumentTypes);
|
|
57
|
-
|
|
58
|
-
// src/getUserDocuments.ts
|
|
59
|
-
var schema2 = import_zod3.z.object({
|
|
60
|
-
userId: import_zod3.z.string().trim().nonempty().uuid(),
|
|
61
|
-
types: import_zod3.z.array(personalInformationDocumentTypeSchema).min(0).optional()
|
|
62
|
-
});
|
|
63
|
-
var getUserDocuments = async (client, userId, types) => {
|
|
64
|
-
const result = schema2.safeParse({ userId, types });
|
|
65
|
-
if (!result.success) {
|
|
66
|
-
throw new TypeError("Invalid args", {
|
|
67
|
-
cause: result.error.issues
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
const docSumary = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`).then(({ data }) => data);
|
|
71
|
-
if (docSumary && docSumary.documents?.length > 0 && result.data.types && result.data.types.length > 0) {
|
|
72
|
-
const piTypes = result.data.types.join(",");
|
|
73
|
-
docSumary.documents = await Promise.all(
|
|
74
|
-
docSumary.documents.map(async (doc) => {
|
|
75
|
-
const pi = await client.get(
|
|
76
|
-
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${doc.id}/pi?types=${piTypes}`
|
|
77
|
-
).then(({ data }) => data);
|
|
78
|
-
if (pi?.documentNumber1) {
|
|
79
|
-
return {
|
|
80
|
-
...doc,
|
|
81
|
-
// Copy the original
|
|
82
|
-
documentNumber: pi.documentNumber1
|
|
83
|
-
// update the documentNumber field
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
return doc;
|
|
87
|
-
})
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
return docSumary;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// src/updateDocumentStatus.ts
|
|
94
|
-
var import_zod4 = require("zod");
|
|
95
|
-
var schema3 = import_zod4.z.object({
|
|
96
|
-
userId: import_zod4.z.string().nonempty().uuid(),
|
|
97
|
-
documentId: import_zod4.z.number().nonnegative().int()
|
|
98
|
-
});
|
|
99
|
-
var updateDocumentStatus = async (client, userId, documentId, document) => {
|
|
100
|
-
const result = schema3.safeParse({ userId, documentId });
|
|
101
|
-
if (!result.success) {
|
|
102
|
-
throw new TypeError("Invalid args", {
|
|
103
|
-
cause: result.error.issues
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return client.put(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/documents/${documentId}`, document).then(({ data }) => data);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// src/deleteDocument.ts
|
|
110
|
-
var import_zod5 = require("zod");
|
|
111
|
-
var schema4 = import_zod5.z.object({
|
|
112
|
-
userId: import_zod5.z.string().nonempty().uuid(),
|
|
113
|
-
documentId: import_zod5.z.number().positive().int()
|
|
114
|
-
});
|
|
115
|
-
var deleteDocument = async (client, userId, documentId) => {
|
|
116
|
-
const result = schema4.safeParse({ userId, documentId });
|
|
117
|
-
if (!result.success) {
|
|
118
|
-
throw new TypeError("Invalid args", {
|
|
119
|
-
cause: result.error.issues
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
await client.delete(
|
|
123
|
-
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${documentId}`
|
|
124
|
-
);
|
|
125
|
-
};
|
|
126
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
127
|
-
0 && (module.exports = {
|
|
128
|
-
createOrUpdateDocument,
|
|
129
|
-
deleteDocument,
|
|
130
|
-
getUserDocuments,
|
|
131
|
-
personalInformationDocumentTypeSchema,
|
|
132
|
-
personalInformationDocumentTypes,
|
|
133
|
-
updateDocumentStatus
|
|
134
|
-
});
|
|
File without changes
|