UNPKG

@portone/server-sdk

Version:

PortOne JavaScript SDK for server-side usage

827 lines (826 loc) • 25 kB
import { TaxInvoiceError } from "./TaxInvoiceError.mjs"; import { USER_AGENT } from "../../../client.mjs"; export function TaxInvoiceClient(init) { const baseUrl = init.baseUrl ?? "https://api.portone.io"; const secret = init.secret; return { getB2bBulkTaxInvoice: async (options) => { const { bulkTaxInvoiceId, test } = options; const query = [ ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/bulk-tax-invoices/${encodeURIComponent(bulkTaxInvoiceId)}?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new GetB2bBulkTaxInvoiceError(await response.json()); } return response.json(); }, createB2bFileUploadUrl: async (options) => { const { test, fileName } = options; const requestBody = JSON.stringify({ fileName }); const query = [ ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/file-upload-url?${query}`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT }, body: requestBody } ); if (!response.ok) { throw new CreateB2bFileUploadUrlError(await response.json()); } return response.json(); }, downloadB2bTaxInvoicesSheet: async (options) => { const filter = options?.filter; const fields = options?.fields; const test = options?.test; const requestBody = JSON.stringify({ filter, fields, test }); const query = [ ["requestBody", requestBody] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices-sheet?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new DownloadB2bTaxInvoicesSheetError(await response.json()); } return response.text(); }, updateB2bTaxInvoiceDraft: async (options) => { const { test, brn, taxInvoiceKey, taxInvoiceKeyType, taxInvoice, memo } = options; const requestBody = JSON.stringify({ brn, taxInvoiceKey, taxInvoiceKeyType, taxInvoice, memo }); const query = [ ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/draft?${query}`, baseUrl), { method: "PUT", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT }, body: requestBody } ); if (!response.ok) { throw new UpdateB2bTaxInvoiceDraftError(await response.json()); } return response.json(); }, draftB2bTaxInvoice: async (options) => { const { test, taxInvoice, modification, memo } = options; const requestBody = JSON.stringify({ taxInvoice, modification, memo }); const query = [ ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/draft?${query}`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT }, body: requestBody } ); if (!response.ok) { throw new DraftB2bTaxInvoiceError(await response.json()); } return response.json(); }, issueB2bTaxInvoiceImmediately: async (options) => { const { test, taxInvoice, memo, modification } = options; const requestBody = JSON.stringify({ taxInvoice, memo, modification }); const query = [ ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/issue-immediately?${query}`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT }, body: requestBody } ); if (!response.ok) { throw new IssueB2bTaxInvoiceImmediatelyError(await response.json()); } return response.json(); }, requestB2bTaxInvoiceReverseIssuance: async (options) => { const { test, taxInvoice, memo, modification } = options; const requestBody = JSON.stringify({ taxInvoice, memo, modification }); const query = [ ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/request-reverse-issuance?${query}`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT }, body: requestBody } ); if (!response.ok) { throw new RequestB2bTaxInvoiceReverseIssuanceError(await response.json()); } return response.json(); }, attachB2bTaxInvoiceFile: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, test, fileId } = options; const requestBody = JSON.stringify({ fileId }); const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}/attach-file?${query}`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT }, body: requestBody } ); if (!response.ok) { throw new AttachB2bTaxInvoiceFileError(await response.json()); } }, deleteB2bTaxInvoiceAttachment: async (options) => { const { taxInvoiceKey, attachmentId, brn, taxInvoiceKeyType, test } = options; const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}/attachments/${encodeURIComponent(attachmentId)}?${query}`, baseUrl), { method: "DELETE", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new DeleteB2bTaxInvoiceAttachmentError(await response.json()); } }, getB2bTaxInvoiceAttachments: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, test } = options; const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}/attachments?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new GetB2bTaxInvoiceAttachmentsError(await response.json()); } return response.json(); }, cancelB2bTaxInvoiceIssuance: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, test, memo } = options; const requestBody = JSON.stringify({ memo }); const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}/cancel-issuance?${query}`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT }, body: requestBody } ); if (!response.ok) { throw new CancelB2bTaxInvoiceIssuanceError(await response.json()); } return response.json(); }, cancelB2bTaxInvoiceRequest: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, test, memo } = options; const requestBody = JSON.stringify({ memo }); const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}/cancel-request?${query}`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT }, body: requestBody } ); if (!response.ok) { throw new CancelB2bTaxInvoiceRequestError(await response.json()); } return response.json(); }, issueB2bTaxInvoice: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, test, memo, emailSubject } = options; const requestBody = JSON.stringify({ memo, emailSubject }); const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}/issue?${query}`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT }, body: requestBody } ); if (!response.ok) { throw new IssueB2bTaxInvoiceError(await response.json()); } return response.json(); }, getB2bTaxInvoicePdfDownloadUrl: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, test } = options; const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}/pdf-download-url?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new GetB2bTaxInvoicePdfDownloadUrlError(await response.json()); } return response.json(); }, getB2bTaxInvoicePopupUrl: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, includeMenu, test } = options; const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["includeMenu", includeMenu], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}/popup-url?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new GetB2bTaxInvoicePopupUrlError(await response.json()); } return response.json(); }, getB2bTaxInvoicePrintUrl: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, test } = options; const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}/print-url?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new GetB2bTaxInvoicePrintUrlError(await response.json()); } return response.json(); }, refuseB2bTaxInvoiceRequest: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, test, memo } = options; const requestBody = JSON.stringify({ memo }); const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}/refuse-request?${query}`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT }, body: requestBody } ); if (!response.ok) { throw new RefuseB2bTaxInvoiceRequestError(await response.json()); } return response.json(); }, requestB2bTaxInvoice: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, test } = options; const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}/request?${query}`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new requestB2bTaxInvoiceError(await response.json()); } return response.json(); }, sendToNtsB2bTaxInvoice: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, test } = options; const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}/send-to-nts?${query}`, baseUrl), { method: "POST", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new SendToNtsB2bTaxInvoiceError(await response.json()); } return response.json(); }, getB2bTaxInvoice: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, test } = options; const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new GetB2bTaxInvoiceError(await response.json()); } return response.json(); }, deleteB2bTaxInvoice: async (options) => { const { taxInvoiceKey, brn, taxInvoiceKeyType, test } = options; const query = [ ["brn", brn], ["taxInvoiceKeyType", taxInvoiceKeyType], ["test", test] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices/${encodeURIComponent(taxInvoiceKey)}?${query}`, baseUrl), { method: "DELETE", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new DeleteB2bTaxInvoiceError(await response.json()); } return response.json(); }, getB2bTaxInvoices: async (options) => { const test = options?.test; const pageNumber = options?.pageNumber; const pageSize = options?.pageSize; const filter = options?.filter; const sort = options?.sort; const requestBody = JSON.stringify({ test, pageNumber, pageSize, filter, sort }); const query = [ ["requestBody", requestBody] ].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&"); const response = await fetch( new URL(`/b2b/tax-invoices?${query}`, baseUrl), { method: "GET", headers: { Authorization: `PortOne ${secret}`, "User-Agent": USER_AGENT } } ); if (!response.ok) { throw new GetB2bTaxInvoicesError(await response.json()); } return response.json(); } }; } export class GetB2bBulkTaxInvoiceError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetB2bBulkTaxInvoiceError.prototype); this.name = "GetB2bBulkTaxInvoiceError"; } } export class CreateB2bFileUploadUrlError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, CreateB2bFileUploadUrlError.prototype); this.name = "CreateB2bFileUploadUrlError"; } } export class DownloadB2bTaxInvoicesSheetError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, DownloadB2bTaxInvoicesSheetError.prototype); this.name = "DownloadB2bTaxInvoicesSheetError"; } } export class UpdateB2bTaxInvoiceDraftError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, UpdateB2bTaxInvoiceDraftError.prototype); this.name = "UpdateB2bTaxInvoiceDraftError"; } } export class DraftB2bTaxInvoiceError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, DraftB2bTaxInvoiceError.prototype); this.name = "DraftB2bTaxInvoiceError"; } } export class IssueB2bTaxInvoiceImmediatelyError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, IssueB2bTaxInvoiceImmediatelyError.prototype); this.name = "IssueB2bTaxInvoiceImmediatelyError"; } } export class RequestB2bTaxInvoiceReverseIssuanceError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, RequestB2bTaxInvoiceReverseIssuanceError.prototype); this.name = "RequestB2bTaxInvoiceReverseIssuanceError"; } } export class AttachB2bTaxInvoiceFileError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, AttachB2bTaxInvoiceFileError.prototype); this.name = "AttachB2bTaxInvoiceFileError"; } } export class DeleteB2bTaxInvoiceAttachmentError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, DeleteB2bTaxInvoiceAttachmentError.prototype); this.name = "DeleteB2bTaxInvoiceAttachmentError"; } } export class GetB2bTaxInvoiceAttachmentsError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetB2bTaxInvoiceAttachmentsError.prototype); this.name = "GetB2bTaxInvoiceAttachmentsError"; } } export class CancelB2bTaxInvoiceIssuanceError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, CancelB2bTaxInvoiceIssuanceError.prototype); this.name = "CancelB2bTaxInvoiceIssuanceError"; } } export class CancelB2bTaxInvoiceRequestError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, CancelB2bTaxInvoiceRequestError.prototype); this.name = "CancelB2bTaxInvoiceRequestError"; } } export class IssueB2bTaxInvoiceError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, IssueB2bTaxInvoiceError.prototype); this.name = "IssueB2bTaxInvoiceError"; } } export class GetB2bTaxInvoicePdfDownloadUrlError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetB2bTaxInvoicePdfDownloadUrlError.prototype); this.name = "GetB2bTaxInvoicePdfDownloadUrlError"; } } export class GetB2bTaxInvoicePopupUrlError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetB2bTaxInvoicePopupUrlError.prototype); this.name = "GetB2bTaxInvoicePopupUrlError"; } } export class GetB2bTaxInvoicePrintUrlError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetB2bTaxInvoicePrintUrlError.prototype); this.name = "GetB2bTaxInvoicePrintUrlError"; } } export class RefuseB2bTaxInvoiceRequestError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, RefuseB2bTaxInvoiceRequestError.prototype); this.name = "RefuseB2bTaxInvoiceRequestError"; } } export class requestB2bTaxInvoiceError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, requestB2bTaxInvoiceError.prototype); this.name = "requestB2bTaxInvoiceError"; } } export class SendToNtsB2bTaxInvoiceError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, SendToNtsB2bTaxInvoiceError.prototype); this.name = "SendToNtsB2bTaxInvoiceError"; } } export class GetB2bTaxInvoiceError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetB2bTaxInvoiceError.prototype); this.name = "GetB2bTaxInvoiceError"; } } export class DeleteB2bTaxInvoiceError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, DeleteB2bTaxInvoiceError.prototype); this.name = "DeleteB2bTaxInvoiceError"; } } export class GetB2bTaxInvoicesError extends TaxInvoiceError { /** @ignore */ constructor(data) { super(data); Object.setPrototypeOf(this, GetB2bTaxInvoicesError.prototype); this.name = "GetB2bTaxInvoicesError"; } }