@ksefnik/simulator 0.0.1

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 (42) hide show
  1. package/LICENSE +21 -0
  2. package/dist/adapter.d.ts +16 -0
  3. package/dist/adapter.d.ts.map +1 -0
  4. package/dist/adapter.js +35 -0
  5. package/dist/adapter.js.map +1 -0
  6. package/dist/index.d.ts +12 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +14 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/invoice-store.d.ts +10 -0
  11. package/dist/invoice-store.d.ts.map +1 -0
  12. package/dist/invoice-store.js +21 -0
  13. package/dist/invoice-store.js.map +1 -0
  14. package/dist/scenarios/happy-path.d.ts +3 -0
  15. package/dist/scenarios/happy-path.d.ts.map +1 -0
  16. package/dist/scenarios/happy-path.js +4 -0
  17. package/dist/scenarios/happy-path.js.map +1 -0
  18. package/dist/scenarios/index.d.ts +10 -0
  19. package/dist/scenarios/index.d.ts.map +1 -0
  20. package/dist/scenarios/index.js +16 -0
  21. package/dist/scenarios/index.js.map +1 -0
  22. package/dist/scenarios/invalid-nip.d.ts +3 -0
  23. package/dist/scenarios/invalid-nip.d.ts.map +1 -0
  24. package/dist/scenarios/invalid-nip.js +9 -0
  25. package/dist/scenarios/invalid-nip.js.map +1 -0
  26. package/dist/scenarios/session-expired.d.ts +3 -0
  27. package/dist/scenarios/session-expired.d.ts.map +1 -0
  28. package/dist/scenarios/session-expired.js +19 -0
  29. package/dist/scenarios/session-expired.js.map +1 -0
  30. package/dist/scenarios/timeout.d.ts +3 -0
  31. package/dist/scenarios/timeout.d.ts.map +1 -0
  32. package/dist/scenarios/timeout.js +14 -0
  33. package/dist/scenarios/timeout.js.map +1 -0
  34. package/dist/scenarios/upo-delay.d.ts +3 -0
  35. package/dist/scenarios/upo-delay.d.ts.map +1 -0
  36. package/dist/scenarios/upo-delay.js +18 -0
  37. package/dist/scenarios/upo-delay.js.map +1 -0
  38. package/dist/types.d.ts +7 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +2 -0
  41. package/dist/types.js.map +1 -0
  42. package/package.json +39 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CodeFormers-it
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ import type { KsefAdapter, FetchInvoicesOpts, SendInvoiceInput, SendInvoiceResult, UpoResult, Invoice } from '@ksefnik/shared';
2
+ import { InvoiceStore } from './invoice-store.js';
3
+ export interface ScenarioHooks {
4
+ beforeFetch?(opts: FetchInvoicesOpts): Promise<void>;
5
+ beforeSend?(input: SendInvoiceInput): Promise<void>;
6
+ beforeGetUpo?(ref: string): Promise<UpoResult | null>;
7
+ }
8
+ export declare class MockKsefAdapter implements KsefAdapter {
9
+ private store;
10
+ private hooks;
11
+ constructor(store: InvoiceStore, hooks?: ScenarioHooks);
12
+ fetchInvoices(opts: FetchInvoicesOpts): Promise<Invoice[]>;
13
+ sendInvoice(input: SendInvoiceInput): Promise<SendInvoiceResult>;
14
+ getUpo(ksefReference: string): Promise<UpoResult>;
15
+ }
16
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,OAAO,EACR,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACpD,UAAU,CAAC,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACnD,YAAY,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAA;CACtD;AAED,qBAAa,eAAgB,YAAW,WAAW;IAE/C,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,KAAK;gBADL,KAAK,EAAE,YAAY,EACnB,KAAK,GAAE,aAAkB;IAG7B,aAAa,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAK1D,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAShE,MAAM,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;CAWxD"}
@@ -0,0 +1,35 @@
1
+ export class MockKsefAdapter {
2
+ store;
3
+ hooks;
4
+ constructor(store, hooks = {}) {
5
+ this.store = store;
6
+ this.hooks = hooks;
7
+ }
8
+ async fetchInvoices(opts) {
9
+ if (this.hooks.beforeFetch)
10
+ await this.hooks.beforeFetch(opts);
11
+ return this.store.getByDateRange(opts.from, opts.to);
12
+ }
13
+ async sendInvoice(input) {
14
+ if (this.hooks.beforeSend)
15
+ await this.hooks.beforeSend(input);
16
+ const ref = `KSEF-SIM-${Date.now()}-${Math.random().toString(36).slice(2, 8).toUpperCase()}`;
17
+ return {
18
+ ksefReference: ref,
19
+ timestamp: new Date().toISOString(),
20
+ };
21
+ }
22
+ async getUpo(ksefReference) {
23
+ if (this.hooks.beforeGetUpo) {
24
+ const override = await this.hooks.beforeGetUpo(ksefReference);
25
+ if (override)
26
+ return override;
27
+ }
28
+ return {
29
+ ksefReference,
30
+ upoXml: `<UPO ref="${ksefReference}"/>`,
31
+ status: 'confirmed',
32
+ };
33
+ }
34
+ }
35
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAgBA,MAAM,OAAO,eAAe;IAEhB;IACA;IAFV,YACU,KAAmB,EACnB,QAAuB,EAAE;QADzB,UAAK,GAAL,KAAK,CAAc;QACnB,UAAK,GAAL,KAAK,CAAoB;IAChC,CAAC;IAEJ,KAAK,CAAC,aAAa,CAAC,IAAuB;QACzC,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW;YAAE,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QAC9D,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;IACtD,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAAuB;QACvC,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU;YAAE,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QAC7D,MAAM,GAAG,GAAG,YAAY,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAA;QAC5F,OAAO;YACL,aAAa,EAAE,GAAG;YAClB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAA;IACH,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,aAAqB;QAChC,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;YAC5B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,aAAa,CAAC,CAAA;YAC7D,IAAI,QAAQ;gBAAE,OAAO,QAAQ,CAAA;QAC/B,CAAC;QACD,OAAO;YACL,aAAa;YACb,MAAM,EAAE,aAAa,aAAa,KAAK;YACvC,MAAM,EAAE,WAAW;SACpB,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import type { SimulatorConfig } from './types.js';
2
+ import { MockKsefAdapter } from './adapter.js';
3
+ import { InvoiceStore } from './invoice-store.js';
4
+ export { MockKsefAdapter } from './adapter.js';
5
+ export { InvoiceStore } from './invoice-store.js';
6
+ export type { SimulatorConfig, ScenarioName } from './types.js';
7
+ export type { ScenarioHooks } from './adapter.js';
8
+ export declare function createKsefSimulator(config: SimulatorConfig): {
9
+ adapter: MockKsefAdapter;
10
+ store: InvoiceStore;
11
+ };
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGjD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC/D,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEjD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe;;;EAQ1D"}
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ import { MockKsefAdapter } from './adapter.js';
2
+ import { InvoiceStore } from './invoice-store.js';
3
+ import { getScenarioHooks } from './scenarios/index.js';
4
+ export { MockKsefAdapter } from './adapter.js';
5
+ export { InvoiceStore } from './invoice-store.js';
6
+ export function createKsefSimulator(config) {
7
+ const store = new InvoiceStore();
8
+ if (config.invoices)
9
+ store.seed(config.invoices);
10
+ const hooks = getScenarioHooks(config.scenario);
11
+ const adapter = new MockKsefAdapter(store, hooks);
12
+ return { adapter, store };
13
+ }
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAIjD,MAAM,UAAU,mBAAmB,CAAC,MAAuB;IACzD,MAAM,KAAK,GAAG,IAAI,YAAY,EAAE,CAAA;IAChC,IAAI,MAAM,CAAC,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAEhD,MAAM,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAC/C,MAAM,OAAO,GAAG,IAAI,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAEjD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;AAC3B,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Invoice } from '@ksefnik/shared';
2
+ export declare class InvoiceStore {
3
+ private invoices;
4
+ seed(invoices: Invoice[]): void;
5
+ add(invoice: Invoice): void;
6
+ getAll(): Invoice[];
7
+ getByDateRange(from: string, to: string): Invoice[];
8
+ clear(): void;
9
+ }
10
+ //# sourceMappingURL=invoice-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoice-store.d.ts","sourceRoot":"","sources":["../src/invoice-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAE9C,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAA6B;IAE7C,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAM/B,GAAG,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAI3B,MAAM,IAAI,OAAO,EAAE;IAInB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,EAAE;IAInD,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,21 @@
1
+ export class InvoiceStore {
2
+ invoices = new Map();
3
+ seed(invoices) {
4
+ for (const inv of invoices) {
5
+ this.invoices.set(inv.id, inv);
6
+ }
7
+ }
8
+ add(invoice) {
9
+ this.invoices.set(invoice.id, invoice);
10
+ }
11
+ getAll() {
12
+ return [...this.invoices.values()];
13
+ }
14
+ getByDateRange(from, to) {
15
+ return this.getAll().filter((i) => i.issueDate >= from && i.issueDate <= to);
16
+ }
17
+ clear() {
18
+ this.invoices.clear();
19
+ }
20
+ }
21
+ //# sourceMappingURL=invoice-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoice-store.js","sourceRoot":"","sources":["../src/invoice-store.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,YAAY;IACf,QAAQ,GAAG,IAAI,GAAG,EAAmB,CAAA;IAE7C,IAAI,CAAC,QAAmB;QACtB,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YAC3B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;QAChC,CAAC;IACH,CAAC;IAED,GAAG,CAAC,OAAgB;QAClB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IACxC,CAAC;IAED,MAAM;QACJ,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;IACpC,CAAC;IAED,cAAc,CAAC,IAAY,EAAE,EAAU;QACrC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,IAAI,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,CAAA;IAC9E,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IACvB,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ import type { ScenarioHooks } from '../adapter.js';
2
+ export declare function happyPath(): ScenarioHooks;
3
+ //# sourceMappingURL=happy-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"happy-path.d.ts","sourceRoot":"","sources":["../../src/scenarios/happy-path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,wBAAgB,SAAS,IAAI,aAAa,CAEzC"}
@@ -0,0 +1,4 @@
1
+ export function happyPath() {
2
+ return {};
3
+ }
4
+ //# sourceMappingURL=happy-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"happy-path.js","sourceRoot":"","sources":["../../src/scenarios/happy-path.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,SAAS;IACvB,OAAO,EAAE,CAAA;AACX,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ScenarioHooks } from '../adapter.js';
2
+ import type { ScenarioName } from '../types.js';
3
+ import { happyPath } from './happy-path.js';
4
+ import { timeout } from './timeout.js';
5
+ import { invalidNip } from './invalid-nip.js';
6
+ import { sessionExpired } from './session-expired.js';
7
+ import { upoDelay } from './upo-delay.js';
8
+ export declare function getScenarioHooks(name: ScenarioName): ScenarioHooks;
9
+ export { happyPath, timeout, invalidNip, sessionExpired, upoDelay };
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scenarios/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,YAAY,GAAG,aAAa,CAQlE;AAED,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { happyPath } from './happy-path.js';
2
+ import { timeout } from './timeout.js';
3
+ import { invalidNip } from './invalid-nip.js';
4
+ import { sessionExpired } from './session-expired.js';
5
+ import { upoDelay } from './upo-delay.js';
6
+ export function getScenarioHooks(name) {
7
+ switch (name) {
8
+ case 'happy-path': return happyPath();
9
+ case 'timeout': return timeout(100); // short for tests
10
+ case 'invalid-nip': return invalidNip();
11
+ case 'session-expired': return sessionExpired();
12
+ case 'upo-delay': return upoDelay();
13
+ }
14
+ }
15
+ export { happyPath, timeout, invalidNip, sessionExpired, upoDelay };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scenarios/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,MAAM,UAAU,gBAAgB,CAAC,IAAkB;IACjD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,YAAY,CAAC,CAAC,OAAO,SAAS,EAAE,CAAA;QACrC,KAAK,SAAS,CAAC,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAA,CAAC,kBAAkB;QACtD,KAAK,aAAa,CAAC,CAAC,OAAO,UAAU,EAAE,CAAA;QACvC,KAAK,iBAAiB,CAAC,CAAC,OAAO,cAAc,EAAE,CAAA;QAC/C,KAAK,WAAW,CAAC,CAAC,OAAO,QAAQ,EAAE,CAAA;IACrC,CAAC;AACH,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { ScenarioHooks } from '../adapter.js';
2
+ export declare function invalidNip(): ScenarioHooks;
3
+ //# sourceMappingURL=invalid-nip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invalid-nip.d.ts","sourceRoot":"","sources":["../../src/scenarios/invalid-nip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,wBAAgB,UAAU,IAAI,aAAa,CAM1C"}
@@ -0,0 +1,9 @@
1
+ import { KsefApiError } from '@ksefnik/shared';
2
+ export function invalidNip() {
3
+ return {
4
+ async beforeSend(input) {
5
+ throw new KsefApiError(`NIP validation failed for: ${input.nip}`, 400, { nip: input.nip });
6
+ },
7
+ };
8
+ }
9
+ //# sourceMappingURL=invalid-nip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invalid-nip.js","sourceRoot":"","sources":["../../src/scenarios/invalid-nip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG9C,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,KAAK,CAAC,UAAU,CAAC,KAAK;YACpB,MAAM,IAAI,YAAY,CAAC,8BAA8B,KAAK,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAA;QAC5F,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ScenarioHooks } from '../adapter.js';
2
+ export declare function sessionExpired(): ScenarioHooks;
3
+ //# sourceMappingURL=session-expired.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-expired.d.ts","sourceRoot":"","sources":["../../src/scenarios/session-expired.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,wBAAgB,cAAc,IAAI,aAAa,CAgB9C"}
@@ -0,0 +1,19 @@
1
+ import { KsefSessionError } from '@ksefnik/shared';
2
+ export function sessionExpired() {
3
+ let requestCount = 0;
4
+ return {
5
+ async beforeFetch() {
6
+ requestCount++;
7
+ if (requestCount > 1) {
8
+ throw new KsefSessionError('Session expired after first request');
9
+ }
10
+ },
11
+ async beforeSend() {
12
+ requestCount++;
13
+ if (requestCount > 1) {
14
+ throw new KsefSessionError('Session expired after first request');
15
+ }
16
+ },
17
+ };
18
+ }
19
+ //# sourceMappingURL=session-expired.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-expired.js","sourceRoot":"","sources":["../../src/scenarios/session-expired.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGlD,MAAM,UAAU,cAAc;IAC5B,IAAI,YAAY,GAAG,CAAC,CAAA;IACpB,OAAO;QACL,KAAK,CAAC,WAAW;YACf,YAAY,EAAE,CAAA;YACd,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;gBACrB,MAAM,IAAI,gBAAgB,CAAC,qCAAqC,CAAC,CAAA;YACnE,CAAC;QACH,CAAC;QACD,KAAK,CAAC,UAAU;YACd,YAAY,EAAE,CAAA;YACd,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;gBACrB,MAAM,IAAI,gBAAgB,CAAC,qCAAqC,CAAC,CAAA;YACnE,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ScenarioHooks } from '../adapter.js';
2
+ export declare function timeout(delayMs?: number): ScenarioHooks;
3
+ //# sourceMappingURL=timeout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/scenarios/timeout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,wBAAgB,OAAO,CAAC,OAAO,GAAE,MAAc,GAAG,aAAa,CAW9D"}
@@ -0,0 +1,14 @@
1
+ import { KsefTimeoutError } from '@ksefnik/shared';
2
+ export function timeout(delayMs = 10000) {
3
+ return {
4
+ async beforeFetch() {
5
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
6
+ throw new KsefTimeoutError('Simulated KSeF timeout');
7
+ },
8
+ async beforeSend() {
9
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
10
+ throw new KsefTimeoutError('Simulated KSeF timeout');
11
+ },
12
+ };
13
+ }
14
+ //# sourceMappingURL=timeout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/scenarios/timeout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGlD,MAAM,UAAU,OAAO,CAAC,UAAkB,KAAK;IAC7C,OAAO;QACL,KAAK,CAAC,WAAW;YACf,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;YAC5D,MAAM,IAAI,gBAAgB,CAAC,wBAAwB,CAAC,CAAA;QACtD,CAAC;QACD,KAAK,CAAC,UAAU;YACd,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;YAC5D,MAAM,IAAI,gBAAgB,CAAC,wBAAwB,CAAC,CAAA;QACtD,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ScenarioHooks } from '../adapter.js';
2
+ export declare function upoDelay(): ScenarioHooks;
3
+ //# sourceMappingURL=upo-delay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upo-delay.d.ts","sourceRoot":"","sources":["../../src/scenarios/upo-delay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,wBAAgB,QAAQ,IAAI,aAAa,CAgBxC"}
@@ -0,0 +1,18 @@
1
+ export function upoDelay() {
2
+ const callCounts = new Map();
3
+ return {
4
+ async beforeGetUpo(ref) {
5
+ const count = (callCounts.get(ref) ?? 0) + 1;
6
+ callCounts.set(ref, count);
7
+ if (count === 1) {
8
+ return {
9
+ ksefReference: ref,
10
+ upoXml: '',
11
+ status: 'pending',
12
+ };
13
+ }
14
+ return null; // fall through to default (confirmed)
15
+ },
16
+ };
17
+ }
18
+ //# sourceMappingURL=upo-delay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upo-delay.js","sourceRoot":"","sources":["../../src/scenarios/upo-delay.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ;IACtB,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC5C,OAAO;QACL,KAAK,CAAC,YAAY,CAAC,GAAG;YACpB,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;YAC5C,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YAC1B,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;gBAChB,OAAO;oBACL,aAAa,EAAE,GAAG;oBAClB,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE,SAAkB;iBAC3B,CAAA;YACH,CAAC;YACD,OAAO,IAAI,CAAA,CAAC,sCAAsC;QACpD,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Invoice } from '@ksefnik/shared';
2
+ export type ScenarioName = 'happy-path' | 'timeout' | 'invalid-nip' | 'session-expired' | 'upo-delay';
3
+ export interface SimulatorConfig {
4
+ scenario: ScenarioName;
5
+ invoices?: Invoice[];
6
+ }
7
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAE9C,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,SAAS,GAAG,aAAa,GAAG,iBAAiB,GAAG,WAAW,CAAA;AAErG,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,YAAY,CAAA;IACtB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;CACrB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@ksefnik/simulator",
3
+ "version": "0.0.1",
4
+ "description": "Offline KSeF mock server for testing and development without hitting the real Ministry of Finance API",
5
+ "license": "MIT",
6
+ "author": "CodeFormers",
7
+ "homepage": "https://ksefnik.pl",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/CodeFormers-it/ksefnik.git",
11
+ "directory": "packages/simulator"
12
+ },
13
+ "keywords": ["ksef", "ksefnik", "simulator", "mock", "testing", "einvoice"],
14
+ "type": "module",
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "files": ["dist", "!dist/**/__tests__", "!dist/**/*.test.*", "README.md", "LICENSE"],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ }
26
+ },
27
+ "scripts": {
28
+ "build": "tsc --build",
29
+ "dev": "tsc --build --watch",
30
+ "typecheck": "tsc --noEmit"
31
+ },
32
+ "dependencies": {
33
+ "@ksefnik/shared": "workspace:^",
34
+ "@ksefnik/core": "workspace:^"
35
+ },
36
+ "devDependencies": {
37
+ "typescript": "^5.7"
38
+ }
39
+ }