UNPKG

@montarist/nilvera-api

Version:

An unofficial SDK for integrating with Nilvera e-Invoice, e-Archive services

159 lines (158 loc) 7.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EInvoiceService = void 0; const einvoice_endpoints_1 = require("../constants/endpoints/einvoice.endpoints"); const base_service_1 = require("./base.service"); /** * EInvoiceService * Service for managing draft e-invoice operations. */ class EInvoiceService extends base_service_1.BaseService { /** * Lists draft invoices by sending a request to the API. * @param {DraftRequest} params - Query parameters * @returns {Promise<ApiResponse<DraftResponse>>} - Draft invoice response with curl command */ async listDrafts(params) { return await this.apiClient.get(einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.LIST, params); } /** * Sends a request to the API to delete draft invoices. * @param {string[]} uuids - List of UUIDs of draft invoices to be deleted * @returns {Promise<ApiResponse<boolean>>} - Operation result with curl command */ async deleteDrafts(uuids) { return await this.apiClient.delete(einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.DELETE, { data: uuids, }); } /** * Downloads the HTML format of the draft. * @param {string} uuid - UUID of the draft invoice to get HTML format * @returns {Promise<ApiResponse<string>>} - HTML content of the draft invoice with curl command */ async getDraftHtml(uuid) { const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.HTML(uuid); return await this.apiClient.get(url); } /** * Downloads the PDF format of the draft. * @param {string} uuid - UUID of the draft invoice to get PDF format * @returns {Promise<ApiResponse<Blob>>} - PDF content of the draft invoice with curl command */ async getDraftPdf(uuid) { const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.PDF(uuid); return await this.apiClient.get(url, undefined, { responseType: 'blob' }); } /** * Downloads the XML format of the draft. * @param {string} uuid - UUID of the draft invoice to get XML format * @returns {Promise<ApiResponse<string>>} - XML content of the draft invoice with curl command */ async getDraftXml(uuid) { const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.XML(uuid); return await this.apiClient.get(url); } /** * Gets the model information of the draft. * @param {string} uuid - UUID of the draft invoice to get model information * @returns {Promise<ApiResponse<DraftModelResponse>>} - Model of the draft invoice with curl command */ async getDraftModel(uuid) { const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.MODEL(uuid); return await this.apiClient.get(url); } /** * Assigns tags to a draft invoice. * @param {string} documentUUID - UUID of the draft invoice to assign tags * @param {string[]} tagUUIDs - List of tag UUIDs to be assigned * @returns {Promise<ApiResponse<boolean>>} - Operation result with curl command */ async assignTagToDraft(documentUUID, tagUUIDs) { const data = { DocumentUUID: documentUUID, Tags: tagUUIDs, }; const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.ASSIGN_TAGS; return await this.apiClient.put(url, data); } /** * Gets the tag information of a draft invoice. * @param {string} documentUUID - UUID of the draft invoice to get tag information * @returns {Promise<ApiResponse<TagInfo[]>>} - List of tag information with curl command */ async getDraftTags(documentUUID) { const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.GET_TAGS(documentUUID); return await this.apiClient.get(url); } /** * Exports draft invoices in bulk. * @param {string[]} uuids - List of UUIDs of draft invoices to be exported * @param {ExportType} fileType - Requested file type * @returns {Promise<ApiResponse<string>>} - Exported file URL with curl command */ async exportDrafts(uuids, fileType) { const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.EXPORT(fileType); return await this.apiClient.post(url, uuids); } /** * Assigns new status to draft invoices. * @param {string[]} uuids - List of UUIDs of draft invoices to assign status * @param {OperationType} operationType - New operation type * @returns {Promise<ApiResponse<boolean>>} - Operation result with curl command */ async assignNewStatusToDrafts(uuids, operationType) { const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.OPERATION(operationType); return await this.apiClient.put(url, uuids); } /** * Confirms and sends draft invoices. * @param {DraftConfirmRequest[]} drafts - Information of draft invoices to be sent * @returns {Promise<ApiResponse<string[]>>} - Response in case of success with curl command */ async confirmAndSendDrafts(drafts) { const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.CONFIRM_AND_SEND; return await this.apiClient.post(url, drafts); } /** * Edits and sends a draft. * @param {EditAndSendDraftRequest} editAndSendRequest - Request containing draft information to be edited * @returns {Promise<ApiResponse<EditAndSendDraftResponse>>} - Response in case of success with curl command */ async editAndSendDraft(editAndSendRequest) { const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.EDIT_AND_SEND; return await this.apiClient.post(url, editAndSendRequest); } /** * Creates a new draft invoice. * @param {CreateDraftRequest} createDraftRequest - Draft invoice creation request * @returns {Promise<ApiResponse<CreateDraftResponse>>} - Information of the created draft invoice with curl command */ async createDraft(createDraftRequest) { const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.CREATE; return await this.apiClient.post(url, createDraftRequest, { headers: { Accept: 'text/plain', }, }); } /** * Creates a new invoice model. * @param {CreateDraftEArchiveInvoiceRequest} createDraftRequest - Details of the draft invoice to be created * @returns {Promise<ApiResponse<string>>} - UUID and invoice number of created draft invoice with curl command */ async createEInvoiceModel(createEInvoiceModelRequest) { const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.SEND.MODEL; return await this.apiClient.post(url, createEInvoiceModelRequest); } /** * Creates draft invoices in bulk. * @param {CreateBulkDraftRequest} createBulkDraftRequest - Request containing details of bulk draft invoices * @returns {Promise<ApiResponse<string[]>>} - List of UUIDs of successfully created draft invoices with curl command */ async createBulkDraft(createBulkDraftRequest) { const url = einvoice_endpoints_1.EINVOICE_ENDPOINTS.DRAFT.CREATE_BULK; return await this.apiClient.post(url, createBulkDraftRequest); } } exports.EInvoiceService = EInvoiceService;