UNPKG

invoicing-sdk

Version:

Invoice SDK entry package for getting started quickly, including domain and application layers

1 lines 8.16 kB
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Invoicing SDK - Main Entry Point\n *\n * This package provides a convenient entry point for the invoicing system,\n * re-exporting key functionality from domain and application layers with\n * additional convenience functions for common use cases.\n */\n\n// Re-export key domain entities and value objects\nexport {\n Invoice,\n Money,\n type MoneyPlainObject,\n CustomerInfo,\n OrderItem,\n InvoiceFinancials,\n ShippingCost,\n} from \"@invoicing-sdk/domain\";\n\n// Re-export domain services and types\nexport {\n type InvoiceNumberValidator,\n type InvoiceNumberConfig,\n type InvoiceNumberRepository,\n InvoiceNumberValidatorImpl,\n DEFAULT_INVOICE_NUMBER_CONFIG,\n type PDFRenderer,\n type InvoiceData,\n type GermanLegalInfo,\n type PDFOptions,\n BasePDFRenderer,\n PDFGenerationError,\n InvalidLegalInfoError,\n DEFAULT_PDF_OPTIONS,\n type InvoiceNumberGenerator,\n type InvoiceNumberGeneratorConfig,\n InvoiceNumberGeneratorImpl,\n createInvoiceNumberGenerator,\n validateGeneratedNumber,\n DEFAULT_GENERATOR_CONFIG,\n GENERATOR_PRESETS,\n type ShippingRateProvider,\n type ShippingCostPolicy,\n type InvoiceIdGenerator,\n} from \"@invoicing-sdk/domain\";\n\n// Re-export application use cases\nexport {\n makeRequestInvoice,\n createRequestInvoiceUseCase,\n type RequestInvoiceDependencies,\n makeIssueInvoice,\n createIssueInvoiceUseCase,\n type IssueInvoiceDependencies,\n makeCreateInvoice,\n createCreateInvoiceUseCase,\n type CreateInvoiceDependencies,\n makeListInvoices,\n createListInvoicesUseCase,\n type ListInvoicesDependencies,\n makeGetInvoice,\n createGetInvoiceUseCase,\n type GetInvoiceDependencies,\n} from \"@invoicing-sdk/application\";\n\n// Re-export command and query interfaces\nexport {\n type RequestInvoiceCommand,\n type IssueInvoiceCommand,\n type CreateInvoiceCommand,\n type RequestInvoiceResult,\n type IssueInvoiceResult,\n type CreateInvoiceResult,\n type GetInvoiceQuery,\n type ListInvoicesQuery,\n type ListInvoicesResult,\n type GetInvoiceResult,\n} from \"@invoicing-sdk/application\";\n\n// Re-export port interfaces\nexport {\n type InvoiceRepository,\n type OrderRepository,\n} from \"@invoicing-sdk/application\";\n\n// Re-export event ports\nexport {\n type EventBus,\n type EventBusConfig,\n EventBusError,\n type EventHandler,\n EventPublishError,\n type EventSubscription,\n EventSubscriptionError,\n} from \"@invoicing-sdk/application\";\n\n// Convenience factory functions for common use cases\nimport {\n makeRequestInvoice,\n makeIssueInvoice,\n makeCreateInvoice,\n makeListInvoices,\n makeGetInvoice,\n type RequestInvoiceDependencies,\n type IssueInvoiceDependencies,\n type CreateInvoiceDependencies,\n type ListInvoicesDependencies,\n type GetInvoiceDependencies,\n} from \"@invoicing-sdk/application\";\n\n/**\n * All dependencies required for the complete invoicing SDK\n */\nexport interface InvoicingSDKDependencies\n extends RequestInvoiceDependencies,\n IssueInvoiceDependencies,\n CreateInvoiceDependencies,\n ListInvoicesDependencies,\n GetInvoiceDependencies {}\n\n/**\n * Complete invoicing SDK with all use cases\n */\nexport interface InvoicingSDK {\n requestInvoice: ReturnType<typeof makeRequestInvoice>;\n issueInvoice: ReturnType<typeof makeIssueInvoice>;\n /**\n * @deprecated Use {@link issueInvoice} instead.\n * Will be removed in the next major version.\n */\n createInvoice: ReturnType<typeof makeCreateInvoice>;\n listInvoices: ReturnType<typeof makeListInvoices>;\n getInvoice: ReturnType<typeof makeGetInvoice>;\n}\n\n/**\n * Factory function to create a complete invoicing SDK instance\n * with all use cases configured with the provided dependencies.\n *\n * @param dependencies - All required dependencies for the SDK\n * @returns Complete SDK instance with all use cases\n *\n * @example\n * ```typescript\n * const sdk = createInvoicingSDK({\n * invoiceRepository: myInvoiceRepo,\n * orderRepository: myOrderRepo,\n * invoiceNumberValidator: myValidator,\n * pdfRenderer: myPdfRenderer,\n * invoiceNumberGenerator: myGenerator,\n * });\n *\n * // Use the new issue invoice functionality (recommended)\n * const result = await sdk.issueInvoice({ orderId: '123', invoiceNumber: 'INV-001', issuedBy: 'user' });\n * \n * // Use the legacy create invoice functionality (deprecated)\n * const legacyResult = await sdk.createInvoice({ orderId: '123', invoiceNumber: 'INV-001', createdBy: 'user' });\n * ```\n */\nexport function createInvoicingSDK(\n dependencies: InvoicingSDKDependencies\n): InvoicingSDK {\n return {\n requestInvoice: makeRequestInvoice(dependencies),\n issueInvoice: makeIssueInvoice(dependencies),\n createInvoice: makeCreateInvoice(dependencies),\n listInvoices: makeListInvoices(dependencies),\n getInvoice: makeGetInvoice(dependencies),\n };\n}\n\n/**\n * Factory function to create individual use cases with their specific dependencies.\n * Useful when you only need specific functionality.\n *\n * @example\n * ```typescript\n * const { requestInvoice, issueInvoice } = createUseCases({\n * requestInvoice: makeRequestInvoice(requestDeps),\n * issueInvoice: makeIssueInvoice(issueDeps),\n * });\n * ```\n */\nexport function createUseCases<T extends Partial<InvoicingSDK>>(\n useCases: T\n): T {\n return useCases;\n}\n\n/**\n * Utility function to validate that all required dependencies are provided\n * for the complete SDK. Throws descriptive errors for missing dependencies.\n *\n * @param dependencies - Dependencies to validate\n * @throws Error if any required dependency is missing\n */\nexport function validateSDKDependencies(\n dependencies: Partial<InvoicingSDKDependencies>\n): asserts dependencies is InvoicingSDKDependencies {\n const required = [\n \"invoiceRepository\",\n \"orderRepository\",\n \"invoiceNumberValidator\",\n \"pdfRenderer\",\n \"invoiceNumberGenerator\",\n \"legalInfo\",\n \"shippingRateProvider\",\n \"shippingCostPolicy\",\n ] as const;\n\n const missing = required.filter(\n (dep) =>\n !(dep in dependencies) ||\n !dependencies[dep as keyof InvoicingSDKDependencies]\n );\n\n if (missing.length > 0) {\n throw new Error(\n `Missing required dependencies for InvoicingSDK: ${missing.join(\n \", \"\n )}. ` + \"Please provide all required dependencies to create the SDK.\"\n );\n }\n}\n\n/**\n * Safe factory function that validates dependencies before creating the SDK\n *\n * @param dependencies - Dependencies to validate and use\n * @returns Complete SDK instance\n * @throws Error if any required dependency is missing\n */\nexport function createInvoicingSDKSafe(\n dependencies: Partial<InvoicingSDKDependencies>\n): InvoicingSDK {\n validateSDKDependencies(dependencies);\n return createInvoicingSDK(dependencies);\n}\n"],"mappings":";AASA;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP;AAAA,EAIE;AAAA,EACA;AAAA,EAKA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OAEK;AAuBP;AAAA,EAGE;AAAA,EAEA;AAAA,EAEA;AAAA,OACK;AAGP;AAAA,EACE,sBAAAA;AAAA,EACA,oBAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,kBAAAC;AAAA,OAMK;AAmDA,SAAS,mBACd,cACc;AACd,SAAO;AAAA,IACL,gBAAgBJ,oBAAmB,YAAY;AAAA,IAC/C,cAAcC,kBAAiB,YAAY;AAAA,IAC3C,eAAeC,mBAAkB,YAAY;AAAA,IAC7C,cAAcC,kBAAiB,YAAY;AAAA,IAC3C,YAAYC,gBAAe,YAAY;AAAA,EACzC;AACF;AAcO,SAAS,eACd,UACG;AACH,SAAO;AACT;AASO,SAAS,wBACd,cACkD;AAClD,QAAM,WAAW;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,UAAU,SAAS;AAAA,IACvB,CAAC,QACC,EAAE,OAAO,iBACT,CAAC,aAAa,GAAqC;AAAA,EACvD;AAEA,MAAI,QAAQ,SAAS,GAAG;AACtB,UAAM,IAAI;AAAA,MACR,mDAAmD,QAAQ;AAAA,QACzD;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AASO,SAAS,uBACd,cACc;AACd,0BAAwB,YAAY;AACpC,SAAO,mBAAmB,YAAY;AACxC;","names":["makeRequestInvoice","makeIssueInvoice","makeCreateInvoice","makeListInvoices","makeGetInvoice"]}