@vulog/aima-document
Version:
115 lines (108 loc) • 4.21 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
createOrUpdateDocument: () => createOrUpdateDocument,
getUserDocuments: () => getUserDocuments,
personalInformationDocumentTypeSchema: () => personalInformationDocumentTypeSchema,
personalInformationDocumentTypes: () => personalInformationDocumentTypes,
updateDocumentStatus: () => updateDocumentStatus
});
module.exports = __toCommonJS(index_exports);
// src/createOrUpdateDocument.ts
var import_zod = require("zod");
var schema = import_zod.z.object({
userId: import_zod.z.string().nonempty().uuid()
});
var createOrUpdateDocument = async (client, userId, document) => {
const result = schema.safeParse({ userId });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
return client.post(
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`,
document
).then(({ data }) => data);
};
// src/getUserDocuments.ts
var import_zod3 = require("zod");
// src/types.ts
var import_zod2 = require("zod");
var personalInformationDocumentTypes = ["documentNumber1"];
var personalInformationDocumentTypeSchema = import_zod2.z.enum(personalInformationDocumentTypes);
// src/getUserDocuments.ts
var schema2 = import_zod3.z.object({
userId: import_zod3.z.string().trim().nonempty().uuid(),
types: import_zod3.z.array(personalInformationDocumentTypeSchema).min(0).optional()
});
var getUserDocuments = async (client, userId, types) => {
const result = schema2.safeParse({ userId, types });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
const docSumary = await client.get(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents`).then(({ data }) => data);
if (docSumary && docSumary.documents?.length > 0 && result.data.types && result.data.types.length > 0) {
const piTypes = result.data.types.join(",");
docSumary.documents = await Promise.all(
docSumary.documents.map(async (doc) => {
const pi = await client.get(
`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/users/${userId}/documents/${doc.id}/pi?types=${piTypes}`
).then(({ data }) => data);
if (pi?.documentNumber1) {
return {
...doc,
// Copy the original
documentNumber: pi.documentNumber1
// update the documentNumber field
};
}
return doc;
})
);
}
return docSumary;
};
// src/updateDocumentStatus.ts
var import_zod4 = require("zod");
var schema3 = import_zod4.z.object({
userId: import_zod4.z.string().nonempty().uuid(),
documentId: import_zod4.z.number().nonnegative().int()
});
var updateDocumentStatus = async (client, userId, documentId, document) => {
const result = schema3.safeParse({ userId, documentId });
if (!result.success) {
throw new TypeError("Invalid args", {
cause: result.error.issues
});
}
return client.put(`/boapi/proxy/user/fleets/${client.clientOptions.fleetId}/documents/${documentId}`, document).then(({ data }) => data);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createOrUpdateDocument,
getUserDocuments,
personalInformationDocumentTypeSchema,
personalInformationDocumentTypes,
updateDocumentStatus
});