37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
|
|
import { token } from "@conusai-kit/core"
|
|
import type { InvoiceTerms, InvoiceView, SeriesView } from "../contract/index.js"
|
|
export interface Page<T> {
|
|
rows: T[]
|
|
after?: string
|
|
}
|
|
export interface InvoicingReads {
|
|
list(after?: string): Promise<Page<InvoiceView>>
|
|
get(id: string): Promise<InvoiceView>
|
|
series(after?: string): Promise<Page<SeriesView>>
|
|
ubl(id: string): Promise<{ filename: string; xml: string }>
|
|
}
|
|
export interface InvoicingService extends InvoicingReads {
|
|
draft(data: InvoiceTerms, key: string): Promise<InvoiceView>
|
|
update(id: string, data: InvoiceTerms, revision: string, key: string): Promise<InvoiceView>
|
|
transition(
|
|
operation: "issue" | "credit" | "void",
|
|
input: { invoiceId: string; expectedVersion: string; key: string; seriesId?: string; reason?: string },
|
|
): Promise<InvoiceView>
|
|
createSeries(input: {
|
|
code: string
|
|
prefix: string
|
|
kind: "invoice" | "credit_note"
|
|
key: string
|
|
}): Promise<SeriesView>
|
|
}
|
|
export const readsOf = (service: InvoicingReads): InvoicingReads => ({
|
|
list: (after) => service.list(after),
|
|
get: (id) => service.get(id),
|
|
series: (after) => service.series(after),
|
|
ubl: (id) => service.ubl(id),
|
|
})
|
|
export const INVOICING_SERVICE = token<InvoicingService>("invoicing.service", {
|
|
views: { read: readsOf, write: readsOf },
|
|
})
|