@inbridge/oif-ts
Version:
TypeScript integration for the Open Invoice Format (OIF) schema. Easily create OIF-compliant PDFs and parse/validate JSON.
126 lines (118 loc) • 3.42 kB
TypeScript
import { InvoiceType } from './lib/enums/invoice-type.enum.js';
import { InvoiceItem } from './lib/types/invoice-item.js';
import { CorrectingInvoiceData } from './lib/types/correcting-invoice-data.js';
import { PaymentInformation } from './lib/types/payment-information.js';
import { CashPayment } from './lib/classes/payment-information/cash-payment.js';
import { CancellationInvoice } from './lib/classes/invoice-types/cancellation-invoice.js';
declare const SchemaVersions: readonly ["latest", "2025.01"];
type SchemaVersion = typeof SchemaVersions[number];
declare class SchemaProvider {
private static _instance;
private _validateFn;
private readonly ajv;
private _version;
private readonly _invoiceTypeMap;
get isHeated(): boolean;
private constructor();
private static _getInstance;
private _load;
private _validate;
/**
* Set the schema version to use
* @param version
*/
static setVersion(version: SchemaVersion): Promise<void>;
/**
* Stringify an OIF object
* @param invoice
*/
static stringify(invoice: Invoice): Promise<string>;
/**
* Parse an JSON to an OIF object
* @param json
*/
static parse<T extends Invoice>(json: string): Promise<T>;
}
declare class BaseInvoice {
version: Exclude<SchemaVersion, 'latest'>;
/**
* The id of the invoice
*/
id: string;
/**
* The date when the invoice was created
*/
createdAt: Date;
/**
* The date when the invoice was last updated
*/
servicePeriod: {
start: Date;
end: Date;
};
/**
* Type of the invoice
*/
type: InvoiceType;
/**
* The payment information of the invoice
*/
paymentInformation: PaymentInformation;
/**
* The items of the invoice
* @param InvoiceItem[] items
*/
items: InvoiceItem[];
/**
* The net price sum of the invoice
*/
get netPriceSum(): number;
/**
* The tax sum of the invoice
*/
get taxSum(): number;
/**
* The gross price sum of the invoice
*/
get grossPriceSum(): number;
/**
* When this is a correcting invoice, this field contains the data of the invoice that will be corrected
*/
correction?: CorrectingInvoiceData;
constructor(id: string, servicePeriod: {
start: Date;
end: Date;
});
}
declare class DefaultInvoice extends BaseInvoice {
/**
* @inheritDoc
*/
readonly type = InvoiceType.INVOICE;
}
declare class RecurringInvoice extends BaseInvoice {
/**
* @inheritDoc
*/
readonly type: InvoiceType.RECURRING_INVOICE;
/**
* @inheritDoc
*/
paymentInformation: Exclude<PaymentInformation, CashPayment>;
/**
* Reference to the subscription that this invoice is for
*/
subscriptionId?: string;
}
declare class PartialInvoice extends BaseInvoice {
/**
* @inheritDoc
*/
readonly type: InvoiceType.PARTIAL_INVOICE;
/**
* The ID of the invoice that this invoice is a partial payment of
*/
previousInvoiceId: string;
}
type Invoice = DefaultInvoice | RecurringInvoice | PartialInvoice | CancellationInvoice;
export { BaseInvoice as B, DefaultInvoice as D, type Invoice as I, PartialInvoice as P, RecurringInvoice as R, SchemaVersions as S, type SchemaVersion as a, SchemaProvider as b };