@fast-white-cat/integration-ksef-direct 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/README.md +36 -0
  2. package/dist/index.js +2 -0
  3. package/dist/index.js.map +7 -0
  4. package/dist/modules/integration_ksef_direct/acl.js +13 -0
  5. package/dist/modules/integration_ksef_direct/acl.js.map +7 -0
  6. package/dist/modules/integration_ksef_direct/api/get/integration-ksef-direct/documents/[id].js +92 -0
  7. package/dist/modules/integration_ksef_direct/api/get/integration-ksef-direct/documents/[id].js.map +7 -0
  8. package/dist/modules/integration_ksef_direct/api/get/integration-ksef-direct/documents.js +105 -0
  9. package/dist/modules/integration_ksef_direct/api/get/integration-ksef-direct/documents.js.map +7 -0
  10. package/dist/modules/integration_ksef_direct/api/get/integration-ksef-direct/health.js +158 -0
  11. package/dist/modules/integration_ksef_direct/api/get/integration-ksef-direct/health.js.map +7 -0
  12. package/dist/modules/integration_ksef_direct/api/get/integration-ksef-direct/received-documents/[id].js +86 -0
  13. package/dist/modules/integration_ksef_direct/api/get/integration-ksef-direct/received-documents/[id].js.map +7 -0
  14. package/dist/modules/integration_ksef_direct/api/get/integration-ksef-direct/received-documents.js +112 -0
  15. package/dist/modules/integration_ksef_direct/api/get/integration-ksef-direct/received-documents.js.map +7 -0
  16. package/dist/modules/integration_ksef_direct/api/get/integration-ksef-direct/seller-info.js +54 -0
  17. package/dist/modules/integration_ksef_direct/api/get/integration-ksef-direct/seller-info.js.map +7 -0
  18. package/dist/modules/integration_ksef_direct/api/post/integration-ksef-direct/documents/[id]/send.js +64 -0
  19. package/dist/modules/integration_ksef_direct/api/post/integration-ksef-direct/documents/[id]/send.js.map +7 -0
  20. package/dist/modules/integration_ksef_direct/api/post/integration-ksef-direct/documents.js +104 -0
  21. package/dist/modules/integration_ksef_direct/api/post/integration-ksef-direct/documents.js.map +7 -0
  22. package/dist/modules/integration_ksef_direct/api/post/integration-ksef-direct/invoice-numbers.js +41 -0
  23. package/dist/modules/integration_ksef_direct/api/post/integration-ksef-direct/invoice-numbers.js.map +7 -0
  24. package/dist/modules/integration_ksef_direct/api/post/integration-ksef-direct/received-documents/fetch.js +172 -0
  25. package/dist/modules/integration_ksef_direct/api/post/integration-ksef-direct/received-documents/fetch.js.map +7 -0
  26. package/dist/modules/integration_ksef_direct/api/post/integration-ksef-direct/received-documents/sync.js +80 -0
  27. package/dist/modules/integration_ksef_direct/api/post/integration-ksef-direct/received-documents/sync.js.map +7 -0
  28. package/dist/modules/integration_ksef_direct/backend/integration-ksef-direct/documents/new/page.js +441 -0
  29. package/dist/modules/integration_ksef_direct/backend/integration-ksef-direct/documents/new/page.js.map +7 -0
  30. package/dist/modules/integration_ksef_direct/backend/integration-ksef-direct/documents/new/page.meta.js +8 -0
  31. package/dist/modules/integration_ksef_direct/backend/integration-ksef-direct/documents/new/page.meta.js.map +7 -0
  32. package/dist/modules/integration_ksef_direct/backend/integration-ksef-direct/documents/page.js +193 -0
  33. package/dist/modules/integration_ksef_direct/backend/integration-ksef-direct/documents/page.js.map +7 -0
  34. package/dist/modules/integration_ksef_direct/backend/integration-ksef-direct/received-documents/page.js +314 -0
  35. package/dist/modules/integration_ksef_direct/backend/integration-ksef-direct/received-documents/page.js.map +7 -0
  36. package/dist/modules/integration_ksef_direct/backend/page.js +154 -0
  37. package/dist/modules/integration_ksef_direct/backend/page.js.map +7 -0
  38. package/dist/modules/integration_ksef_direct/commands/create-ksef-direct-document.js +80 -0
  39. package/dist/modules/integration_ksef_direct/commands/create-ksef-direct-document.js.map +7 -0
  40. package/dist/modules/integration_ksef_direct/commands/enqueue-ksef-direct-document.js +43 -0
  41. package/dist/modules/integration_ksef_direct/commands/enqueue-ksef-direct-document.js.map +7 -0
  42. package/dist/modules/integration_ksef_direct/data/entities.js +224 -0
  43. package/dist/modules/integration_ksef_direct/data/entities.js.map +7 -0
  44. package/dist/modules/integration_ksef_direct/data/validators.js +103 -0
  45. package/dist/modules/integration_ksef_direct/data/validators.js.map +7 -0
  46. package/dist/modules/integration_ksef_direct/di.js +11 -0
  47. package/dist/modules/integration_ksef_direct/di.js.map +7 -0
  48. package/dist/modules/integration_ksef_direct/events.js +21 -0
  49. package/dist/modules/integration_ksef_direct/events.js.map +7 -0
  50. package/dist/modules/integration_ksef_direct/index.js +10 -0
  51. package/dist/modules/integration_ksef_direct/index.js.map +7 -0
  52. package/dist/modules/integration_ksef_direct/integration.js +56 -0
  53. package/dist/modules/integration_ksef_direct/integration.js.map +7 -0
  54. package/dist/modules/integration_ksef_direct/lib/health.js +32 -0
  55. package/dist/modules/integration_ksef_direct/lib/health.js.map +7 -0
  56. package/dist/modules/integration_ksef_direct/lib/invoiceNumberFormat.js +23 -0
  57. package/dist/modules/integration_ksef_direct/lib/invoiceNumberFormat.js.map +7 -0
  58. package/dist/modules/integration_ksef_direct/lib/ksefClient.js +523 -0
  59. package/dist/modules/integration_ksef_direct/lib/ksefClient.js.map +7 -0
  60. package/dist/modules/integration_ksef_direct/lib/ksefCrypto.js +103 -0
  61. package/dist/modules/integration_ksef_direct/lib/ksefCrypto.js.map +7 -0
  62. package/dist/modules/integration_ksef_direct/lib/ksefFa2Xml.js +123 -0
  63. package/dist/modules/integration_ksef_direct/lib/ksefFa2Xml.js.map +7 -0
  64. package/dist/modules/integration_ksef_direct/lib/ksefXmlParser.js +76 -0
  65. package/dist/modules/integration_ksef_direct/lib/ksefXmlParser.js.map +7 -0
  66. package/dist/modules/integration_ksef_direct/migrations/Migration20260519210000_integration_ksef_direct.js +15 -0
  67. package/dist/modules/integration_ksef_direct/migrations/Migration20260519210000_integration_ksef_direct.js.map +7 -0
  68. package/dist/modules/integration_ksef_direct/migrations/Migration20260520120000_ksef_direct_documents.js +17 -0
  69. package/dist/modules/integration_ksef_direct/migrations/Migration20260520120000_ksef_direct_documents.js.map +7 -0
  70. package/dist/modules/integration_ksef_direct/migrations/Migration20260520220000_ksef_direct_send_queue.js +15 -0
  71. package/dist/modules/integration_ksef_direct/migrations/Migration20260520220000_ksef_direct_send_queue.js.map +7 -0
  72. package/dist/modules/integration_ksef_direct/migrations/Migration20260520230000_ksef_direct_seller_per_document.js +17 -0
  73. package/dist/modules/integration_ksef_direct/migrations/Migration20260520230000_ksef_direct_seller_per_document.js.map +7 -0
  74. package/dist/modules/integration_ksef_direct/migrations/Migration20260521120000_ksef_direct_received_documents.js +16 -0
  75. package/dist/modules/integration_ksef_direct/migrations/Migration20260521120000_ksef_direct_received_documents.js.map +7 -0
  76. package/dist/modules/integration_ksef_direct/migrations/Migration20260521130000_ksef_received_download_urls.js +15 -0
  77. package/dist/modules/integration_ksef_direct/migrations/Migration20260521130000_ksef_received_download_urls.js.map +7 -0
  78. package/dist/modules/integration_ksef_direct/setup.js +11 -0
  79. package/dist/modules/integration_ksef_direct/setup.js.map +7 -0
  80. package/dist/modules/integration_ksef_direct/subscribers/auto-enqueue-ksef-document.js +19 -0
  81. package/dist/modules/integration_ksef_direct/subscribers/auto-enqueue-ksef-document.js.map +7 -0
  82. package/dist/modules/integration_ksef_direct/workers/check-ksef-document-status.js +103 -0
  83. package/dist/modules/integration_ksef_direct/workers/check-ksef-document-status.js.map +7 -0
  84. package/dist/modules/integration_ksef_direct/workers/send-ksef-document.js +104 -0
  85. package/dist/modules/integration_ksef_direct/workers/send-ksef-document.js.map +7 -0
  86. package/dist/modules/integration_ksef_direct/workers/sync-received-documents.js +137 -0
  87. package/dist/modules/integration_ksef_direct/workers/sync-received-documents.js.map +7 -0
  88. package/dist/types/declarations.d.js +1 -0
  89. package/dist/types/declarations.d.js.map +7 -0
  90. package/package.json +98 -0
  91. package/src/index.ts +1 -0
  92. package/src/modules/integration_ksef_direct/__tests__/invoiceNumberFormat.test.ts +42 -0
  93. package/src/modules/integration_ksef_direct/__tests__/ksefFa2Xml.test.ts +407 -0
  94. package/src/modules/integration_ksef_direct/__tests__/ksefXmlParser.test.ts +230 -0
  95. package/src/modules/integration_ksef_direct/acl.ts +9 -0
  96. package/src/modules/integration_ksef_direct/api/get/integration-ksef-direct/documents/[id].ts +94 -0
  97. package/src/modules/integration_ksef_direct/api/get/integration-ksef-direct/documents.ts +111 -0
  98. package/src/modules/integration_ksef_direct/api/get/integration-ksef-direct/health.ts +194 -0
  99. package/src/modules/integration_ksef_direct/api/get/integration-ksef-direct/received-documents/[id].ts +88 -0
  100. package/src/modules/integration_ksef_direct/api/get/integration-ksef-direct/received-documents.ts +119 -0
  101. package/src/modules/integration_ksef_direct/api/get/integration-ksef-direct/seller-info.ts +62 -0
  102. package/src/modules/integration_ksef_direct/api/post/integration-ksef-direct/documents/[id]/send.ts +64 -0
  103. package/src/modules/integration_ksef_direct/api/post/integration-ksef-direct/documents.ts +109 -0
  104. package/src/modules/integration_ksef_direct/api/post/integration-ksef-direct/invoice-numbers.ts +40 -0
  105. package/src/modules/integration_ksef_direct/api/post/integration-ksef-direct/received-documents/fetch.ts +185 -0
  106. package/src/modules/integration_ksef_direct/api/post/integration-ksef-direct/received-documents/sync.ts +86 -0
  107. package/src/modules/integration_ksef_direct/backend/integration-ksef-direct/documents/new/page.meta.ts +4 -0
  108. package/src/modules/integration_ksef_direct/backend/integration-ksef-direct/documents/new/page.tsx +470 -0
  109. package/src/modules/integration_ksef_direct/backend/integration-ksef-direct/documents/page.tsx +233 -0
  110. package/src/modules/integration_ksef_direct/backend/integration-ksef-direct/received-documents/page.tsx +415 -0
  111. package/src/modules/integration_ksef_direct/backend/page.tsx +183 -0
  112. package/src/modules/integration_ksef_direct/commands/create-ksef-direct-document.ts +93 -0
  113. package/src/modules/integration_ksef_direct/commands/enqueue-ksef-direct-document.ts +57 -0
  114. package/src/modules/integration_ksef_direct/data/entities.ts +195 -0
  115. package/src/modules/integration_ksef_direct/data/validators.ts +115 -0
  116. package/src/modules/integration_ksef_direct/di.ts +9 -0
  117. package/src/modules/integration_ksef_direct/events.ts +18 -0
  118. package/src/modules/integration_ksef_direct/i18n/en.json +115 -0
  119. package/src/modules/integration_ksef_direct/i18n/pl.json +115 -0
  120. package/src/modules/integration_ksef_direct/index.ts +6 -0
  121. package/src/modules/integration_ksef_direct/integration.ts +54 -0
  122. package/src/modules/integration_ksef_direct/lib/health.ts +43 -0
  123. package/src/modules/integration_ksef_direct/lib/invoiceNumberFormat.ts +23 -0
  124. package/src/modules/integration_ksef_direct/lib/ksefClient.ts +668 -0
  125. package/src/modules/integration_ksef_direct/lib/ksefCrypto.ts +138 -0
  126. package/src/modules/integration_ksef_direct/lib/ksefFa2Xml.ts +147 -0
  127. package/src/modules/integration_ksef_direct/lib/ksefXmlParser.ts +97 -0
  128. package/src/modules/integration_ksef_direct/migrations/.snapshot-open-mercato.json +1028 -0
  129. package/src/modules/integration_ksef_direct/migrations/Migration20260519210000_integration_ksef_direct.ts +15 -0
  130. package/src/modules/integration_ksef_direct/migrations/Migration20260520120000_ksef_direct_documents.ts +17 -0
  131. package/src/modules/integration_ksef_direct/migrations/Migration20260520220000_ksef_direct_send_queue.ts +15 -0
  132. package/src/modules/integration_ksef_direct/migrations/Migration20260520230000_ksef_direct_seller_per_document.ts +17 -0
  133. package/src/modules/integration_ksef_direct/migrations/Migration20260521120000_ksef_direct_received_documents.ts +16 -0
  134. package/src/modules/integration_ksef_direct/migrations/Migration20260521130000_ksef_received_download_urls.ts +15 -0
  135. package/src/modules/integration_ksef_direct/setup.ts +9 -0
  136. package/src/modules/integration_ksef_direct/subscribers/auto-enqueue-ksef-document.ts +21 -0
  137. package/src/modules/integration_ksef_direct/workers/check-ksef-document-status.ts +129 -0
  138. package/src/modules/integration_ksef_direct/workers/send-ksef-document.ts +137 -0
  139. package/src/modules/integration_ksef_direct/workers/sync-received-documents.ts +171 -0
  140. package/src/types/declarations.d.ts +1 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/integration_ksef_direct/data/entities.ts"],
4
+ "sourcesContent": ["import { Entity, PrimaryKey, Property, Index, Unique } from '@mikro-orm/decorators/legacy'\n\nexport interface KsefDirectStoredLineItem {\n description: string\n quantity: number\n unit: string\n unitNetPrice: number\n vatRate: string\n netAmount: number\n vatAmount: number\n grossAmount: number\n}\n\n@Entity({ tableName: 'ksef_direct_documents' })\n@Index({ properties: ['organizationId', 'tenantId'] })\n@Index({ properties: ['organizationId', 'tenantId', 'status'] })\n@Index({ properties: ['organizationId', 'tenantId', 'source'] })\n@Index({ properties: ['ksefReferenceNumber'] })\nexport class KsefDirectDocument {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'source', type: 'text', default: 'manual' })\n source: 'manual' | 'ksef_sync' | 'sales_invoice' = 'manual'\n\n @Property({ name: 'status', type: 'text', default: 'draft' })\n status: 'draft' | 'queued' | 'sending' | 'sent' | 'failed' = 'draft'\n\n @Property({ name: 'ksef_reference_number', type: 'text', nullable: true })\n ksefReferenceNumber?: string | null\n\n @Property({ name: 'seller_nip', type: 'text' })\n sellerNip!: string\n\n @Property({ name: 'buyer_nip', type: 'text' })\n buyerNip!: string\n\n @Property({ name: 'buyer_name', type: 'text', nullable: true })\n buyerName?: string | null\n\n @Property({ name: 'invoice_number', type: 'text' })\n invoiceNumber!: string\n\n @Property({ name: 'issue_date', type: Date })\n issueDate!: Date\n\n @Property({ name: 'sale_date', type: Date, nullable: true })\n saleDate?: Date | null\n\n @Property({ name: 'net_amount', type: 'string', columnType: 'numeric(15,2)' })\n netAmount!: string\n\n @Property({ name: 'vat_amount', type: 'string', columnType: 'numeric(15,2)' })\n vatAmount!: string\n\n @Property({ name: 'gross_amount', type: 'string', columnType: 'numeric(15,2)' })\n grossAmount!: string\n\n @Property({ name: 'currency', type: 'text', default: 'PLN' })\n currency: string = 'PLN'\n\n @Property({ name: 'line_items', type: 'json', columnType: 'jsonb' })\n lineItems: KsefDirectStoredLineItem[] = []\n\n @Property({ name: 'notes', type: 'text', nullable: true })\n notes?: string | null\n\n @Property({ name: 'ksef_processing_reference_number', type: 'text', nullable: true })\n ksefProcessingReferenceNumber?: string | null\n\n @Property({ name: 'seller_name', type: 'text', nullable: true })\n sellerName?: string | null\n\n @Property({ name: 'seller_address_l1', type: 'text', nullable: true })\n sellerAddressL1?: string | null\n\n @Property({ name: 'seller_city', type: 'text', nullable: true })\n sellerCity?: string | null\n\n @Property({ name: 'seller_country', type: 'text', nullable: true })\n sellerCountry?: string | null\n\n @Property({ name: 'error_message', type: 'text', nullable: true })\n errorMessage?: string | null\n\n @Property({ name: 'created_at', type: Date })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n\n@Entity({ tableName: 'ksef_direct_received_documents' })\n@Index({ properties: ['organizationId', 'tenantId'] })\n@Index({ properties: ['organizationId', 'tenantId', 'status'] })\n@Unique({ properties: ['organizationId', 'ksefReferenceNumber'] })\nexport class KsefDirectReceivedDocument {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'ksef_reference_number', type: 'text' })\n ksefReferenceNumber!: string\n\n @Property({ name: 'raw_xml', type: 'text', nullable: true })\n rawXml?: string | null\n\n @Property({ name: 'invoice_number', type: 'text', nullable: true })\n invoiceNumber?: string | null\n\n @Property({ name: 'seller_nip', type: 'text', nullable: true })\n sellerNip?: string | null\n\n @Property({ name: 'seller_name', type: 'text', nullable: true })\n sellerName?: string | null\n\n @Property({ name: 'issue_date', type: 'string', columnType: 'date', nullable: true })\n issueDate?: string | null\n\n @Property({ name: 'currency', type: 'text', nullable: true })\n currency?: string | null\n\n @Property({ name: 'net_amount', type: 'string', columnType: 'numeric(15,2)', nullable: true })\n netAmount?: string | null\n\n @Property({ name: 'vat_amount', type: 'string', columnType: 'numeric(15,2)', nullable: true })\n vatAmount?: string | null\n\n @Property({ name: 'gross_amount', type: 'string', columnType: 'numeric(15,2)', nullable: true })\n grossAmount?: string | null\n\n @Property({ name: 'status', type: 'text', default: 'pending_download' })\n status: 'pending_download' | 'downloaded' | 'failed' = 'pending_download'\n\n @Property({ name: 'error_message', type: 'text', nullable: true })\n errorMessage?: string | null\n\n @Property({ name: 'upo_download_url', type: 'text', nullable: true })\n upoDownloadUrl?: string | null\n\n @Property({ name: 'invoice_download_url', type: 'text', nullable: true })\n invoiceDownloadUrl?: string | null\n\n @Property({ name: 'synced_at', type: Date, nullable: true })\n syncedAt?: Date | null\n\n @Property({ name: 'created_at', type: Date })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n\n@Entity({ tableName: 'ksef_direct_connections' })\n@Index({ properties: ['status', 'updatedAt'] })\n@Unique({ properties: ['organizationId', 'tenantId'] })\nexport class KsefDirectConnection {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'status', type: 'text', default: 'unconfigured' })\n status: 'unconfigured' | 'checking' | 'connected' | 'error' = 'unconfigured'\n\n @Property({ name: 'last_checked_at', type: Date, nullable: true })\n lastCheckedAt?: Date | null\n\n @Property({ name: 'error_message', type: 'text', nullable: true })\n errorMessage?: string | null\n\n @Property({ name: 'error_code', type: 'text', nullable: true })\n errorCode?: string | null\n\n @Property({ name: 'created_at', type: Date })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n"],
5
+ "mappings": ";;;;;;;;;;AAAA,SAAS,QAAQ,YAAY,UAAU,OAAO,cAAc;AAkBrD,IAAM,qBAAN,MAAyB;AAAA,EAAzB;AAW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AA0B,CAAC;AAAA,EAC/C,MAAM,EAAE,YAAY,CAAC,UAAU,WAAW,EAAE,CAAC;AAAA,EAC7C,OAAO,EAAE,YAAY,CAAC,kBAAkB,UAAU,EAAE,CAAC;AAAA,GACzC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,103 @@
1
+ import { z } from "zod";
2
+ const dateString = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Must be YYYY-MM-DD");
3
+ const vatRates = ["0", "5", "8", "23", "ZW", "NP"];
4
+ const KsefDirectLineItemSchema = z.object({
5
+ description: z.string().min(1),
6
+ quantity: z.number().positive(),
7
+ unit: z.string().min(1).default("szt"),
8
+ unitNetPrice: z.number().min(0),
9
+ vatRate: z.enum(vatRates)
10
+ });
11
+ const CreateKsefDirectDocumentSchema = z.object({
12
+ buyerNip: z.string().regex(/^\d{10}$/, "NIP must be 10 digits"),
13
+ buyerName: z.string().max(256).optional(),
14
+ invoiceNumber: z.string().min(1).max(256),
15
+ issueDate: dateString,
16
+ saleDate: dateString.optional(),
17
+ currency: z.string().length(3).default("PLN"),
18
+ lineItems: z.array(KsefDirectLineItemSchema).min(1),
19
+ notes: z.string().optional(),
20
+ sellerName: z.string().min(1).max(512).optional(),
21
+ sellerAddressL1: z.string().min(1).max(512),
22
+ sellerCity: z.string().min(1).max(256),
23
+ sellerCountry: z.string().length(2).optional()
24
+ });
25
+ const KsefDirectConnectionStatusSchema = z.enum(["unconfigured", "checking", "connected", "error"]);
26
+ const KsefDirectCredentialsSchema = z.object({
27
+ ksef_token: z.string().min(1),
28
+ nip: z.string().min(1),
29
+ environment: z.enum(["test", "production"])
30
+ });
31
+ const KsefDirectRateLimitsSchema = z.object({
32
+ otherPerSecond: z.number().optional(),
33
+ otherPerMinute: z.number().optional()
34
+ });
35
+ const KsefDirectHealthResponseSchema = z.discriminatedUnion("status", [
36
+ z.object({
37
+ status: z.literal("connected"),
38
+ lastCheckedAt: z.string(),
39
+ environment: z.enum(["test", "production"]),
40
+ rateLimits: KsefDirectRateLimitsSchema.optional()
41
+ }),
42
+ z.object({
43
+ status: z.literal("error"),
44
+ lastCheckedAt: z.string(),
45
+ error: z.string(),
46
+ errorCode: z.string()
47
+ }),
48
+ z.object({
49
+ status: z.literal("unconfigured"),
50
+ lastCheckedAt: z.null()
51
+ }),
52
+ z.object({
53
+ status: z.literal("checking"),
54
+ lastCheckedAt: z.string().nullable()
55
+ })
56
+ ]);
57
+ const KsefSendInvoiceResponseSchema = z.object({
58
+ referenceNumber: z.string(),
59
+ processingCode: z.number().optional(),
60
+ processingDescription: z.string().optional(),
61
+ timestamp: z.string().optional()
62
+ }).passthrough();
63
+ const KsefInvoiceStatusResponseSchema = z.object({
64
+ referenceNumber: z.string(),
65
+ processingCode: z.number(),
66
+ processingDescription: z.string().optional(),
67
+ invoiceStatus: z.object({
68
+ ksefReferenceNumber: z.string().optional(),
69
+ invoiceNumber: z.string().optional()
70
+ }).optional()
71
+ }).passthrough();
72
+ const isoDate = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Must be YYYY-MM-DD");
73
+ const ReceivedDocumentSyncSchema = z.object({
74
+ dateFrom: isoDate,
75
+ dateTo: isoDate
76
+ }).refine(
77
+ (data) => data.dateTo >= data.dateFrom,
78
+ { message: "dateTo must be >= dateFrom", path: ["dateTo"] }
79
+ ).refine(
80
+ (data) => {
81
+ const from = new Date(data.dateFrom);
82
+ const to = new Date(data.dateTo);
83
+ const diffDays = (to.getTime() - from.getTime()) / (1e3 * 60 * 60 * 24);
84
+ return diffDays <= 366;
85
+ },
86
+ { message: "Date range must not exceed 366 days", path: ["dateTo"] }
87
+ );
88
+ const ReceivedDocumentFetchSchema = z.object({
89
+ ksefReferenceNumber: z.string().min(1)
90
+ });
91
+ export {
92
+ CreateKsefDirectDocumentSchema,
93
+ KsefDirectConnectionStatusSchema,
94
+ KsefDirectCredentialsSchema,
95
+ KsefDirectHealthResponseSchema,
96
+ KsefDirectLineItemSchema,
97
+ KsefDirectRateLimitsSchema,
98
+ KsefInvoiceStatusResponseSchema,
99
+ KsefSendInvoiceResponseSchema,
100
+ ReceivedDocumentFetchSchema,
101
+ ReceivedDocumentSyncSchema
102
+ };
103
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/integration_ksef_direct/data/validators.ts"],
4
+ "sourcesContent": ["import { z } from 'zod'\n\nconst dateString = z.string().regex(/^\\d{4}-\\d{2}-\\d{2}$/, 'Must be YYYY-MM-DD')\nconst vatRates = ['0', '5', '8', '23', 'ZW', 'NP'] as const\n\nexport const KsefDirectLineItemSchema = z.object({\n description: z.string().min(1),\n quantity: z.number().positive(),\n unit: z.string().min(1).default('szt'),\n unitNetPrice: z.number().min(0),\n vatRate: z.enum(vatRates),\n})\n\nexport const CreateKsefDirectDocumentSchema = z.object({\n buyerNip: z.string().regex(/^\\d{10}$/, 'NIP must be 10 digits'),\n buyerName: z.string().max(256).optional(),\n invoiceNumber: z.string().min(1).max(256),\n issueDate: dateString,\n saleDate: dateString.optional(),\n currency: z.string().length(3).default('PLN'),\n lineItems: z.array(KsefDirectLineItemSchema).min(1),\n notes: z.string().optional(),\n sellerName: z.string().min(1).max(512).optional(),\n sellerAddressL1: z.string().min(1).max(512),\n sellerCity: z.string().min(1).max(256),\n sellerCountry: z.string().length(2).optional(),\n})\n\nexport type CreateKsefDirectDocumentInput = z.infer<typeof CreateKsefDirectDocumentSchema>\nexport type KsefDirectLineItemInput = z.infer<typeof KsefDirectLineItemSchema>\n\nexport const KsefDirectConnectionStatusSchema = z.enum(['unconfigured', 'checking', 'connected', 'error'])\n\nexport const KsefDirectCredentialsSchema = z.object({\n ksef_token: z.string().min(1),\n nip: z.string().min(1),\n environment: z.enum(['test', 'production']),\n})\n\nexport const KsefDirectRateLimitsSchema = z.object({\n otherPerSecond: z.number().optional(),\n otherPerMinute: z.number().optional(),\n})\n\nexport const KsefDirectHealthResponseSchema = z.discriminatedUnion('status', [\n z.object({\n status: z.literal('connected'),\n lastCheckedAt: z.string(),\n environment: z.enum(['test', 'production']),\n rateLimits: KsefDirectRateLimitsSchema.optional(),\n }),\n z.object({\n status: z.literal('error'),\n lastCheckedAt: z.string(),\n error: z.string(),\n errorCode: z.string(),\n }),\n z.object({\n status: z.literal('unconfigured'),\n lastCheckedAt: z.null(),\n }),\n z.object({\n status: z.literal('checking'),\n lastCheckedAt: z.string().nullable(),\n }),\n])\n\nexport type KsefDirectCredentials = z.infer<typeof KsefDirectCredentialsSchema>\nexport type KsefDirectHealthResponse = z.infer<typeof KsefDirectHealthResponseSchema>\nexport type KsefDirectRateLimits = z.infer<typeof KsefDirectRateLimitsSchema>\n\nexport const KsefSendInvoiceResponseSchema = z.object({\n referenceNumber: z.string(),\n processingCode: z.number().optional(),\n processingDescription: z.string().optional(),\n timestamp: z.string().optional(),\n}).passthrough()\n\nexport const KsefInvoiceStatusResponseSchema = z.object({\n referenceNumber: z.string(),\n processingCode: z.number(),\n processingDescription: z.string().optional(),\n invoiceStatus: z.object({\n ksefReferenceNumber: z.string().optional(),\n invoiceNumber: z.string().optional(),\n }).optional(),\n}).passthrough()\n\nexport type KsefSendInvoiceResponse = z.infer<typeof KsefSendInvoiceResponseSchema>\nexport type KsefInvoiceStatusResponse = z.infer<typeof KsefInvoiceStatusResponseSchema>\n\nconst isoDate = z.string().regex(/^\\d{4}-\\d{2}-\\d{2}$/, 'Must be YYYY-MM-DD')\n\nexport const ReceivedDocumentSyncSchema = z.object({\n dateFrom: isoDate,\n dateTo: isoDate,\n}).refine(\n (data) => data.dateTo >= data.dateFrom,\n { message: 'dateTo must be >= dateFrom', path: ['dateTo'] },\n).refine(\n (data) => {\n const from = new Date(data.dateFrom)\n const to = new Date(data.dateTo)\n const diffDays = (to.getTime() - from.getTime()) / (1000 * 60 * 60 * 24)\n return diffDays <= 366\n },\n { message: 'Date range must not exceed 366 days', path: ['dateTo'] },\n)\n\nexport const ReceivedDocumentFetchSchema = z.object({\n ksefReferenceNumber: z.string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C,uBAAuB,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3C,WAAW,EAAE,OAAO,EAAE,SAAS;AACjC,CAAC,EAAE,YAAY;AAER,MAAM,kCAAkC,EAAE,OAAO;AAAA,EACtD,iBAAiB,EAAE,OAAO;AAAA,EAC1B,gBAAgB,EAAE,OAAO;AAAA,EACzB,uBAAuB,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3C,eAAe,EAAE,OAAO;AAAA,IACtB,qBAAqB,EAAE,OAAO,EAAE,SAAS;AAAA,IACzC,eAAe,EAAE,OAAO,EAAE,SAAS;AAAA,EACrC,CAAC,EAAE,SAAS;AACd,CAAC,EAAE,YAAY;AAKf,MAAM,UAAU,EAAE,OAAO,EAAE,MAAM,uBAAuB,oBAAoB;AAErE,MAAM,6BAA6B,EAAE,OAAO;AAAA,EACjD,UAAU;AAAA,EACV,QAAQ;AACV,CAAC,EAAE;AAAA,EACD,CAAC,SAAS,KAAK,UAAU,KAAK;AAAA,EAC9B,EAAE,SAAS,8BAA8B,MAAM,CAAC,QAAQ,EAAE;AAC5D,EAAE;AAAA,EACA,CAAC,SAAS;AACR,UAAM,OAAO,IAAI,KAAK,KAAK,QAAQ;AACnC,UAAM,KAAK,IAAI,KAAK,KAAK,MAAM;AAC/B,UAAM,YAAY,GAAG,QAAQ,IAAI,KAAK,QAAQ,MAAM,MAAO,KAAK,KAAK;AACrE,WAAO,YAAY;AAAA,EACrB;AAAA,EACA,EAAE,SAAS,uCAAuC,MAAM,CAAC,QAAQ,EAAE;AACrE;AAEO,MAAM,8BAA8B,EAAE,OAAO;AAAA,EAClD,qBAAqB,EAAE,OAAO,EAAE,IAAI,CAAC;AACvC,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,11 @@
1
+ import { asValue } from "awilix";
2
+ import { ksefDirectHealthChecker } from "./lib/health.js";
3
+ function register(container) {
4
+ container.register({
5
+ ksefDirectHealthChecker: asValue(ksefDirectHealthChecker)
6
+ });
7
+ }
8
+ export {
9
+ register
10
+ };
11
+ //# sourceMappingURL=di.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/modules/integration_ksef_direct/di.ts"],
4
+ "sourcesContent": ["import { asValue } from 'awilix'\nimport type { AppContainer } from '@open-mercato/shared/lib/di/container'\nimport { ksefDirectHealthChecker } from './lib/health'\n\nexport function register(container: AppContainer) {\n container.register({\n ksefDirectHealthChecker: asValue(ksefDirectHealthChecker),\n })\n}\n"],
5
+ "mappings": "AAAA,SAAS,eAAe;AAExB,SAAS,+BAA+B;AAEjC,SAAS,SAAS,WAAyB;AAChD,YAAU,SAAS;AAAA,IACjB,yBAAyB,QAAQ,uBAAuB;AAAA,EAC1D,CAAC;AACH;",
6
+ "names": []
7
+ }
@@ -0,0 +1,21 @@
1
+ import { createModuleEvents } from "@open-mercato/shared/modules/events";
2
+ const events = [
3
+ { id: "ksef_direct.connection.connected", label: "KSeF Direct Connection Established", entity: "ksef_direct_connection", category: "lifecycle" },
4
+ { id: "ksef_direct.connection.failed", label: "KSeF Direct Connection Failed", entity: "ksef_direct_connection", category: "lifecycle" },
5
+ { id: "ksef_direct.connection.checked", label: "KSeF Direct Connection Checked", entity: "ksef_direct_connection", category: "lifecycle" },
6
+ { id: "ksef_direct.document.created", label: "KSeF Direct Document Created", entity: "ksef_direct_document", category: "lifecycle" },
7
+ { id: "ksef_direct.document.queued", label: "KSeF Direct Document Queued", entity: "ksef_direct_document", category: "lifecycle", clientBroadcast: true },
8
+ { id: "ksef_direct.document.sent", label: "KSeF Direct Document Sent", entity: "ksef_direct_document", category: "lifecycle", clientBroadcast: true },
9
+ { id: "ksef_direct.document.failed", label: "KSeF Direct Document Failed", entity: "ksef_direct_document", category: "lifecycle", clientBroadcast: true },
10
+ { id: "ksef_direct.received_document.synced", label: "KSeF Direct Received Documents Synced", entity: "ksef_direct_received_document", category: "lifecycle" },
11
+ { id: "ksef_direct.received_document.failed", label: "KSeF Direct Received Document Failed", entity: "ksef_direct_received_document", category: "lifecycle" }
12
+ ];
13
+ const eventsConfig = createModuleEvents({ moduleId: "integration_ksef_direct", events });
14
+ const emitKsefDirectEvent = eventsConfig.emit;
15
+ var events_default = eventsConfig;
16
+ export {
17
+ events_default as default,
18
+ emitKsefDirectEvent,
19
+ eventsConfig
20
+ };
21
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/modules/integration_ksef_direct/events.ts"],
4
+ "sourcesContent": ["import { createModuleEvents } from '@open-mercato/shared/modules/events'\n\nconst events = [\n { id: 'ksef_direct.connection.connected', label: 'KSeF Direct Connection Established', entity: 'ksef_direct_connection', category: 'lifecycle' },\n { id: 'ksef_direct.connection.failed', label: 'KSeF Direct Connection Failed', entity: 'ksef_direct_connection', category: 'lifecycle' },\n { id: 'ksef_direct.connection.checked', label: 'KSeF Direct Connection Checked', entity: 'ksef_direct_connection', category: 'lifecycle' },\n { id: 'ksef_direct.document.created', label: 'KSeF Direct Document Created', entity: 'ksef_direct_document', category: 'lifecycle' },\n { id: 'ksef_direct.document.queued', label: 'KSeF Direct Document Queued', entity: 'ksef_direct_document', category: 'lifecycle', clientBroadcast: true },\n { id: 'ksef_direct.document.sent', label: 'KSeF Direct Document Sent', entity: 'ksef_direct_document', category: 'lifecycle', clientBroadcast: true },\n { id: 'ksef_direct.document.failed', label: 'KSeF Direct Document Failed', entity: 'ksef_direct_document', category: 'lifecycle', clientBroadcast: true },\n { id: 'ksef_direct.received_document.synced', label: 'KSeF Direct Received Documents Synced', entity: 'ksef_direct_received_document', category: 'lifecycle' },\n { id: 'ksef_direct.received_document.failed', label: 'KSeF Direct Received Document Failed', entity: 'ksef_direct_received_document', category: 'lifecycle' },\n] as const\n\nexport const eventsConfig = createModuleEvents({ moduleId: 'integration_ksef_direct', events })\nexport const emitKsefDirectEvent = eventsConfig.emit\nexport type KsefDirectEventId = typeof events[number]['id']\nexport default eventsConfig\n"],
5
+ "mappings": "AAAA,SAAS,0BAA0B;AAEnC,MAAM,SAAS;AAAA,EACb,EAAE,IAAI,oCAAoC,OAAO,sCAAsC,QAAQ,0BAA0B,UAAU,YAAY;AAAA,EAC/I,EAAE,IAAI,iCAAiC,OAAO,iCAAiC,QAAQ,0BAA0B,UAAU,YAAY;AAAA,EACvI,EAAE,IAAI,kCAAkC,OAAO,kCAAkC,QAAQ,0BAA0B,UAAU,YAAY;AAAA,EACzI,EAAE,IAAI,gCAAgC,OAAO,gCAAgC,QAAQ,wBAAwB,UAAU,YAAY;AAAA,EACnI,EAAE,IAAI,+BAA+B,OAAO,+BAA+B,QAAQ,wBAAwB,UAAU,aAAa,iBAAiB,KAAK;AAAA,EACxJ,EAAE,IAAI,6BAA6B,OAAO,6BAA6B,QAAQ,wBAAwB,UAAU,aAAa,iBAAiB,KAAK;AAAA,EACpJ,EAAE,IAAI,+BAA+B,OAAO,+BAA+B,QAAQ,wBAAwB,UAAU,aAAa,iBAAiB,KAAK;AAAA,EACxJ,EAAE,IAAI,wCAAwC,OAAO,yCAAyC,QAAQ,iCAAiC,UAAU,YAAY;AAAA,EAC7J,EAAE,IAAI,wCAAwC,OAAO,wCAAwC,QAAQ,iCAAiC,UAAU,YAAY;AAC9J;AAEO,MAAM,eAAe,mBAAmB,EAAE,UAAU,2BAA2B,OAAO,CAAC;AACvF,MAAM,sBAAsB,aAAa;AAEhD,IAAO,iBAAQ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,10 @@
1
+ const metadata = {
2
+ id: "integration_ksef_direct",
3
+ title: "KSeF Integration",
4
+ description: "Direct integration with the Polish KSeF system via official MF API v2",
5
+ requires: ["integrations"]
6
+ };
7
+ export {
8
+ metadata
9
+ };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/modules/integration_ksef_direct/index.ts"],
4
+ "sourcesContent": ["export const metadata = {\n id: 'integration_ksef_direct',\n title: 'KSeF Integration',\n description: 'Direct integration with the Polish KSeF system via official MF API v2',\n requires: ['integrations'],\n}\n"],
5
+ "mappings": "AAAO,MAAM,WAAW;AAAA,EACtB,IAAI;AAAA,EACJ,OAAO;AAAA,EACP,aAAa;AAAA,EACb,UAAU,CAAC,cAAc;AAC3B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,56 @@
1
+ const integration = {
2
+ id: "integration_ksef_direct",
3
+ title: "KSeF Direct",
4
+ description: "Direct integration with the Polish National e-Invoice System (KSeF) via official MF REST API v2 \u2014 no Exorigo/SmartKSeF middleware required.",
5
+ category: "fiscal",
6
+ providerKey: "ksef_direct",
7
+ icon: "file-text",
8
+ package: "@fast-white-cat/integration-ksef-direct",
9
+ version: "0.1.0",
10
+ author: "FastWhiteCat",
11
+ company: "FastWhiteCat",
12
+ license: "PROPRIETARY",
13
+ tags: ["ksef", "e-invoicing", "poland", "fiscal", "tax-compliance", "direct"],
14
+ credentials: {
15
+ fields: [
16
+ {
17
+ key: "ksef_token",
18
+ label: "KSeF Token",
19
+ type: "secret",
20
+ required: true
21
+ },
22
+ {
23
+ key: "nip",
24
+ label: "NIP (Tax Identification Number)",
25
+ type: "text",
26
+ required: true
27
+ },
28
+ {
29
+ key: "environment",
30
+ label: "Environment",
31
+ type: "select",
32
+ required: true,
33
+ options: [
34
+ { value: "test", label: "Test (api-test.ksef.mf.gov.pl)" },
35
+ { value: "production", label: "Production (api.ksef.mf.gov.pl)" }
36
+ ]
37
+ }
38
+ ]
39
+ },
40
+ healthCheck: {
41
+ service: "ksefDirectHealthChecker"
42
+ },
43
+ apiVersions: [
44
+ {
45
+ id: "ksef-api-v2",
46
+ label: "KSeF MF API v2",
47
+ status: "stable",
48
+ default: true,
49
+ changelog: "Direct MF KSeF API v2 \u2014 challenge/token auth flow"
50
+ }
51
+ ]
52
+ };
53
+ export {
54
+ integration
55
+ };
56
+ //# sourceMappingURL=integration.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/modules/integration_ksef_direct/integration.ts"],
4
+ "sourcesContent": ["import type { IntegrationDefinition } from '@open-mercato/shared/modules/integrations/types'\n\nexport const integration: IntegrationDefinition = {\n id: 'integration_ksef_direct',\n title: 'KSeF Direct',\n description: 'Direct integration with the Polish National e-Invoice System (KSeF) via official MF REST API v2 \u2014 no Exorigo/SmartKSeF middleware required.',\n category: 'fiscal',\n providerKey: 'ksef_direct',\n icon: 'file-text',\n package: '@fast-white-cat/integration-ksef-direct',\n version: '0.1.0',\n author: 'FastWhiteCat',\n company: 'FastWhiteCat',\n license: 'PROPRIETARY',\n tags: ['ksef', 'e-invoicing', 'poland', 'fiscal', 'tax-compliance', 'direct'],\n credentials: {\n fields: [\n {\n key: 'ksef_token',\n label: 'KSeF Token',\n type: 'secret',\n required: true,\n },\n {\n key: 'nip',\n label: 'NIP (Tax Identification Number)',\n type: 'text',\n required: true,\n },\n {\n key: 'environment',\n label: 'Environment',\n type: 'select',\n required: true,\n options: [\n { value: 'test', label: 'Test (api-test.ksef.mf.gov.pl)' },\n { value: 'production', label: 'Production (api.ksef.mf.gov.pl)' },\n ],\n },\n ],\n },\n healthCheck: {\n service: 'ksefDirectHealthChecker',\n },\n apiVersions: [\n {\n id: 'ksef-api-v2',\n label: 'KSeF MF API v2',\n status: 'stable',\n default: true,\n changelog: 'Direct MF KSeF API v2 \u2014 challenge/token auth flow',\n },\n ],\n}\n"],
5
+ "mappings": "AAEO,MAAM,cAAqC;AAAA,EAChD,IAAI;AAAA,EACJ,OAAO;AAAA,EACP,aAAa;AAAA,EACb,UAAU;AAAA,EACV,aAAa;AAAA,EACb,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,MAAM,CAAC,QAAQ,eAAe,UAAU,UAAU,kBAAkB,QAAQ;AAAA,EAC5E,aAAa;AAAA,IACX,QAAQ;AAAA,MACN;AAAA,QACE,KAAK;AAAA,QACL,OAAO;AAAA,QACP,MAAM;AAAA,QACN,UAAU;AAAA,MACZ;AAAA,MACA;AAAA,QACE,KAAK;AAAA,QACL,OAAO;AAAA,QACP,MAAM;AAAA,QACN,UAAU;AAAA,MACZ;AAAA,MACA;AAAA,QACE,KAAK;AAAA,QACL,OAAO;AAAA,QACP,MAAM;AAAA,QACN,UAAU;AAAA,QACV,SAAS;AAAA,UACP,EAAE,OAAO,QAAQ,OAAO,iCAAiC;AAAA,UACzD,EAAE,OAAO,cAAc,OAAO,kCAAkC;AAAA,QAClE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EACA,aAAa;AAAA,IACX,SAAS;AAAA,EACX;AAAA,EACA,aAAa;AAAA,IACX;AAAA,MACE,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,WAAW;AAAA,IACb;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,32 @@
1
+ import { verifyAccess, KsefAuthError, KsefNetworkError } from "./ksefClient.js";
2
+ const ksefDirectHealthChecker = {
3
+ async check(credentials) {
4
+ const typed = {
5
+ ksefToken: credentials.ksef_token,
6
+ nip: credentials.nip,
7
+ environment: credentials.environment
8
+ };
9
+ try {
10
+ const rateLimits = await verifyAccess(typed);
11
+ return {
12
+ status: "healthy",
13
+ message: `Connected to KSeF ${typed.environment} (NIP: ${typed.nip})`,
14
+ details: { environment: typed.environment, nip: typed.nip, rateLimits },
15
+ checkedAt: /* @__PURE__ */ new Date()
16
+ };
17
+ } catch (err) {
18
+ const message = err instanceof Error ? err.message : "Unknown error";
19
+ const errorCode = err instanceof KsefAuthError ? err.errorCode : err instanceof KsefNetworkError ? err.errorCode : "UNKNOWN_ERROR";
20
+ return {
21
+ status: "unhealthy",
22
+ message: `KSeF connection failed: ${message}`,
23
+ details: { error: message, errorCode },
24
+ checkedAt: /* @__PURE__ */ new Date()
25
+ };
26
+ }
27
+ }
28
+ };
29
+ export {
30
+ ksefDirectHealthChecker
31
+ };
32
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/integration_ksef_direct/lib/health.ts"],
4
+ "sourcesContent": ["import { verifyAccess, KsefAuthError, KsefNetworkError } from './ksefClient'\nimport type { KsefCredentials } from './ksefClient'\n\nexport interface HealthCheckResult {\n status: 'healthy' | 'unhealthy'\n message: string\n details: Record<string, unknown>\n checkedAt: Date\n}\n\nexport const ksefDirectHealthChecker = {\n async check(credentials: Record<string, unknown>): Promise<HealthCheckResult> {\n const typed: KsefCredentials = {\n ksefToken: credentials.ksef_token as string,\n nip: credentials.nip as string,\n environment: credentials.environment as 'test' | 'production',\n }\n\n try {\n const rateLimits = await verifyAccess(typed)\n return {\n status: 'healthy',\n message: `Connected to KSeF ${typed.environment} (NIP: ${typed.nip})`,\n details: { environment: typed.environment, nip: typed.nip, rateLimits },\n checkedAt: new Date(),\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Unknown error'\n const errorCode =\n err instanceof KsefAuthError\n ? err.errorCode\n : err instanceof KsefNetworkError\n ? err.errorCode\n : 'UNKNOWN_ERROR'\n return {\n status: 'unhealthy',\n message: `KSeF connection failed: ${message}`,\n details: { error: message, errorCode },\n checkedAt: new Date(),\n }\n }\n },\n}\n"],
5
+ "mappings": "AAAA,SAAS,cAAc,eAAe,wBAAwB;AAUvD,MAAM,0BAA0B;AAAA,EACrC,MAAM,MAAM,aAAkE;AAC5E,UAAM,QAAyB;AAAA,MAC7B,WAAW,YAAY;AAAA,MACvB,KAAK,YAAY;AAAA,MACjB,aAAa,YAAY;AAAA,IAC3B;AAEA,QAAI;AACF,YAAM,aAAa,MAAM,aAAa,KAAK;AAC3C,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,SAAS,qBAAqB,MAAM,WAAW,UAAU,MAAM,GAAG;AAAA,QAClE,SAAS,EAAE,aAAa,MAAM,aAAa,KAAK,MAAM,KAAK,WAAW;AAAA,QACtE,WAAW,oBAAI,KAAK;AAAA,MACtB;AAAA,IACF,SAAS,KAAc;AACrB,YAAM,UAAU,eAAe,QAAQ,IAAI,UAAU;AACrD,YAAM,YACJ,eAAe,gBACX,IAAI,YACJ,eAAe,mBACb,IAAI,YACJ;AACR,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,SAAS,2BAA2B,OAAO;AAAA,QAC3C,SAAS,EAAE,OAAO,SAAS,UAAU;AAAA,QACrC,WAAW,oBAAI,KAAK;AAAA,MACtB;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,23 @@
1
+ import { randomBytes } from "crypto";
2
+ const ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
3
+ const MAX_VALID = 256 - 256 % ALPHABET.length;
4
+ function createAlphanumericId(size) {
5
+ let id = "";
6
+ while (id.length < size) {
7
+ const byte = randomBytes(1)[0];
8
+ if (byte >= MAX_VALID) continue;
9
+ id += ALPHABET[byte % ALPHABET.length];
10
+ }
11
+ return id;
12
+ }
13
+ function generateKsefInvoiceNumber() {
14
+ const now = /* @__PURE__ */ new Date();
15
+ const yyyy = String(now.getFullYear());
16
+ const mm = String(now.getMonth() + 1).padStart(2, "0");
17
+ const unique = createAlphanumericId(8);
18
+ return `FV/${yyyy}/${mm}/${unique}`;
19
+ }
20
+ export {
21
+ generateKsefInvoiceNumber
22
+ };
23
+ //# sourceMappingURL=invoiceNumberFormat.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/integration_ksef_direct/lib/invoiceNumberFormat.ts"],
4
+ "sourcesContent": ["import { randomBytes } from 'crypto'\n\n// Format: FV/{yyyy}/{mm}/{nanoid:8} \u2014 extensible to per-tenant configurable format in the future\nconst ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'\nconst MAX_VALID = 256 - (256 % ALPHABET.length)\n\nfunction createAlphanumericId(size: number): string {\n let id = ''\n while (id.length < size) {\n const byte = randomBytes(1)[0]\n if (byte >= MAX_VALID) continue\n id += ALPHABET[byte % ALPHABET.length]\n }\n return id\n}\n\nexport function generateKsefInvoiceNumber(): string {\n const now = new Date()\n const yyyy = String(now.getFullYear())\n const mm = String(now.getMonth() + 1).padStart(2, '0')\n const unique = createAlphanumericId(8)\n return `FV/${yyyy}/${mm}/${unique}`\n}\n"],
5
+ "mappings": "AAAA,SAAS,mBAAmB;AAG5B,MAAM,WAAW;AACjB,MAAM,YAAY,MAAO,MAAM,SAAS;AAExC,SAAS,qBAAqB,MAAsB;AAClD,MAAI,KAAK;AACT,SAAO,GAAG,SAAS,MAAM;AACvB,UAAM,OAAO,YAAY,CAAC,EAAE,CAAC;AAC7B,QAAI,QAAQ,UAAW;AACvB,UAAM,SAAS,OAAO,SAAS,MAAM;AAAA,EACvC;AACA,SAAO;AACT;AAEO,SAAS,4BAAoC;AAClD,QAAM,MAAM,oBAAI,KAAK;AACrB,QAAM,OAAO,OAAO,IAAI,YAAY,CAAC;AACrC,QAAM,KAAK,OAAO,IAAI,SAAS,IAAI,CAAC,EAAE,SAAS,GAAG,GAAG;AACrD,QAAM,SAAS,qBAAqB,CAAC;AACrC,SAAO,MAAM,IAAI,IAAI,EAAE,IAAI,MAAM;AACnC;",
6
+ "names": []
7
+ }