@voyantjs/plugin-smartbill 0.5.0 → 0.6.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.
package/README.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # @voyantjs/plugin-smartbill
2
2
 
3
- SmartBill e-invoicing plugin for Voyant. Subscribes to invoice events and creates/cancels/syncs invoices via the SmartBill REST API for Romanian tax compliance.
3
+ SmartBill e-invoicing sync adapter bundle for Voyant.
4
+
5
+ Architecturally, this package is primarily:
6
+
7
+ - a SmartBill e-invoicing adapter
8
+ - a subscriber bundle for finance invoice events
9
+ - an optional plugin bundle for distribution
10
+
11
+ It subscribes to invoice events and creates, cancels, or syncs invoices via the
12
+ SmartBill REST API for Romanian tax compliance.
4
13
 
5
14
  ## Install
6
15
 
@@ -14,20 +23,25 @@ pnpm add @voyantjs/plugin-smartbill
14
23
  import { smartbillPlugin } from "@voyantjs/plugin-smartbill"
15
24
  import { createApp } from "@voyantjs/hono"
16
25
 
26
+ const smartbillSync = smartbillPlugin({
27
+ username: env.SMARTBILL_USERNAME,
28
+ apiToken: env.SMARTBILL_API_TOKEN,
29
+ companyVatCode: "RO12345678",
30
+ seriesName: "A",
31
+ // optional: language, art311SpecialRegime, events, mapEvent, logger
32
+ })
33
+
17
34
  const app = createApp({
18
- plugins: [
19
- smartbillPlugin({
20
- username: env.SMARTBILL_USERNAME,
21
- apiToken: env.SMARTBILL_API_TOKEN,
22
- companyVatCode: "RO12345678",
23
- seriesName: "A",
24
- // optional: language, art311SpecialRegime, events, mapEvent, logger
25
- }),
26
- ],
35
+ plugins: [smartbillSync],
27
36
  })
28
37
  ```
29
38
 
30
- By default the plugin wires up 3 subscribers (`invoice.issued`, `invoice.voided`, `invoice.external.sync.requested`) that create, cancel, and check payment status on SmartBill. All error handling is fire-and-forget per the EventBus contract.
39
+ The exported value is an optional distribution bundle. At runtime, the package
40
+ behaves primarily as a subscriber-driven SmartBill sync adapter. By default it
41
+ wires up 3 subscribers (`invoice.issued`, `invoice.voided`,
42
+ `invoice.external.sync.requested`) that create, cancel, and check payment
43
+ status on SmartBill. All error handling is fire-and-forget per the EventBus
44
+ contract.
31
45
 
32
46
  ## Exports
33
47
 
package/dist/index.d.ts CHANGED
@@ -4,6 +4,8 @@ export type { SmartbillMappingOptions } from "./mapping.js";
4
4
  export { mapClient, mapLineItems, mapVoyantInvoiceToSmartbill } from "./mapping.js";
5
5
  export type { SmartbillLogger, SmartbillMapFn, SmartbillPluginOptions, SmartbillSyncEventNames, } from "./plugin.js";
6
6
  export { smartbillPlugin } from "./plugin.js";
7
+ export type { ResolvedSmartbillSyncEventNames, SmartbillSyncRuntime } from "./runtime.js";
8
+ export { createSmartbillSyncRuntime } from "./runtime.js";
7
9
  export type { SmartbillInvoiceSettlementPoller, SmartbillInvoiceSettlementPollerOptions, SmartbillSettlementExternalRef, SmartbillSettlementInvoice, SmartbillSettlementPollerContext, SmartbillSettlementPollerResult, } from "./settlement.js";
8
10
  export { createSmartbillInvoiceSettlementPoller } from "./settlement.js";
9
11
  export type { SmartbillClient, SmartbillFetch, SmartbillInvoiceBody, SmartbillInvoiceResponse, SmartbillPdfResponse, SmartbillProduct, SmartbillStatusResponse, VoyantInvoiceEvent, } from "./types.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAA;AACnF,YAAY,EACV,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,YAAY,EACV,gCAAgC,EAChC,uCAAuC,EACvC,8BAA8B,EAC9B,0BAA0B,EAC1B,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,sCAAsC,EAAE,MAAM,iBAAiB,CAAA;AACxE,YAAY,EACV,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAA;AACnF,YAAY,EACV,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,YAAY,EAAE,+BAA+B,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACzF,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AACzD,YAAY,EACV,gCAAgC,EAChC,uCAAuC,EACvC,8BAA8B,EAC9B,0BAA0B,EAC1B,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,sCAAsC,EAAE,MAAM,iBAAiB,CAAA;AACxE,YAAY,EACV,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { createSmartbillClient } from "./client.js";
2
2
  export { mapClient, mapLineItems, mapVoyantInvoiceToSmartbill } from "./mapping.js";
3
3
  export { smartbillPlugin } from "./plugin.js";
4
+ export { createSmartbillSyncRuntime } from "./runtime.js";
4
5
  export { createSmartbillInvoiceSettlementPoller } from "./settlement.js";
package/dist/plugin.d.ts CHANGED
@@ -1,55 +1,21 @@
1
1
  import type { Plugin } from "@voyantjs/core";
2
- import { type SmartbillClientOptions } from "./client.js";
3
- import { mapVoyantInvoiceToSmartbill, type SmartbillMappingOptions } from "./mapping.js";
2
+ import type { SmartbillClientOptions } from "./client.js";
3
+ import type { mapVoyantInvoiceToSmartbill, SmartbillMappingOptions } from "./mapping.js";
4
4
  import type { VoyantInvoiceEvent } from "./types.js";
5
- /**
6
- * Event names the plugin subscribes to. Defaults match the
7
- * `invoice.<action>` naming convention from the EventBus.
8
- */
9
5
  export interface SmartbillSyncEventNames {
10
6
  issued?: string;
11
7
  voided?: string;
12
8
  syncRequested?: string;
13
9
  }
14
- /**
15
- * Logger shape used to surface plugin errors without coupling to any specific
16
- * runtime. Defaults to `console`.
17
- */
18
10
  export interface SmartbillLogger {
19
11
  error: (message: string, meta?: unknown) => void;
20
12
  info?: (message: string, meta?: unknown) => void;
21
13
  }
22
- /**
23
- * Custom mapper from a Voyant invoice event to a SmartBill invoice body.
24
- * When provided, replaces the default {@link mapVoyantInvoiceToSmartbill}.
25
- */
26
14
  export type SmartbillMapFn = (event: VoyantInvoiceEvent) => ReturnType<typeof mapVoyantInvoiceToSmartbill>;
27
15
  export interface SmartbillPluginOptions extends SmartbillClientOptions, SmartbillMappingOptions {
28
- /**
29
- * Event names this plugin subscribes to.
30
- * Defaults to `invoice.issued` / `invoice.voided` / `invoice.external.sync.requested`.
31
- */
32
16
  events?: SmartbillSyncEventNames;
33
- /**
34
- * Map a Voyant invoice event into a SmartBill invoice body.
35
- * Defaults to the built-in {@link mapVoyantInvoiceToSmartbill}.
36
- */
37
17
  mapEvent?: SmartbillMapFn;
38
- /** Override logger. Defaults to `console`. */
39
18
  logger?: SmartbillLogger;
40
19
  }
41
- /**
42
- * Build a Voyant {@link Plugin} that pushes invoice events to SmartBill
43
- * for Romanian e-invoicing.
44
- *
45
- * The plugin subscribes to three events (configurable via
46
- * {@link SmartbillPluginOptions.events}):
47
- * - `invoice.issued` → create invoice in SmartBill
48
- * - `invoice.voided` → cancel invoice in SmartBill
49
- * - `invoice.external.sync.requested` → re-fetch payment status
50
- *
51
- * Errors are caught and logged — subscribers are fire-and-forget per the
52
- * EventBus contract, so a SmartBill outage never blocks the emitter.
53
- */
54
20
  export declare function smartbillPlugin(options: SmartbillPluginOptions): Plugin;
55
21
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,gBAAgB,CAAA;AAExD,OAAO,EAAyB,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAChF,OAAO,EAAE,2BAA2B,EAAE,KAAK,uBAAuB,EAAE,MAAM,cAAc,CAAA;AACxF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpD;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IAChD,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;CACjD;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,KAAK,EAAE,kBAAkB,KACtB,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAA;AAEnD,MAAM,WAAW,sBAAuB,SAAQ,sBAAsB,EAAE,uBAAuB;IAC7F;;;OAGG;IACH,MAAM,CAAC,EAAE,uBAAuB,CAAA;IAChC;;;OAGG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB,8CAA8C;IAC9C,MAAM,CAAC,EAAE,eAAe,CAAA;CACzB;AASD;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,CA8GvE"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,gBAAgB,CAAA;AAGxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,KAAK,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAExF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAGpD,MAAM,WAAW,uBAAuB;IACtC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IAChD,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;CACjD;AAED,MAAM,MAAM,cAAc,GAAG,CAC3B,KAAK,EAAE,kBAAkB,KACtB,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAA;AAEnD,MAAM,WAAW,sBAAuB,SAAQ,sBAAsB,EAAE,uBAAuB;IAC7F,MAAM,CAAC,EAAE,uBAAuB,CAAA;IAChC,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB,MAAM,CAAC,EAAE,eAAe,CAAA;CACzB;AASD,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,CAmGvE"}
package/dist/plugin.js CHANGED
@@ -1,5 +1,6 @@
1
- import { createSmartbillClient } from "./client.js";
2
- import { mapVoyantInvoiceToSmartbill } from "./mapping.js";
1
+ import { ZodError } from "zod";
2
+ import { createSmartbillSyncRuntime } from "./runtime.js";
3
+ import { smartbillPluginOptionsSchema } from "./validation.js";
3
4
  function coerceEvent(data) {
4
5
  if (data == null || typeof data !== "object")
5
6
  return null;
@@ -8,41 +9,14 @@ function coerceEvent(data) {
8
9
  return null;
9
10
  return maybe;
10
11
  }
11
- /**
12
- * Build a Voyant {@link Plugin} that pushes invoice events to SmartBill
13
- * for Romanian e-invoicing.
14
- *
15
- * The plugin subscribes to three events (configurable via
16
- * {@link SmartbillPluginOptions.events}):
17
- * - `invoice.issued` → create invoice in SmartBill
18
- * - `invoice.voided` → cancel invoice in SmartBill
19
- * - `invoice.external.sync.requested` → re-fetch payment status
20
- *
21
- * Errors are caught and logged — subscribers are fire-and-forget per the
22
- * EventBus contract, so a SmartBill outage never blocks the emitter.
23
- */
24
12
  export function smartbillPlugin(options) {
25
- const client = createSmartbillClient(options);
26
- const logger = options.logger ?? console;
27
- const mappingOptions = {
28
- companyVatCode: options.companyVatCode,
29
- seriesName: options.seriesName,
30
- language: options.language,
31
- isTaxIncluded: options.isTaxIncluded,
32
- art311SpecialRegime: options.art311SpecialRegime,
33
- };
34
- const mapEvent = options.mapEvent ??
35
- ((ev) => mapVoyantInvoiceToSmartbill(ev, mappingOptions));
36
- const eventNames = {
37
- issued: options.events?.issued ?? "invoice.issued",
38
- voided: options.events?.voided ?? "invoice.voided",
39
- syncRequested: options.events?.syncRequested ?? "invoice.external.sync.requested",
40
- };
13
+ const validatedOptions = parseSmartbillPluginOptions(options);
14
+ const { client, logger, mapEvent, eventNames } = createSmartbillSyncRuntime(validatedOptions);
41
15
  const subscribers = [
42
16
  {
43
17
  event: eventNames.issued,
44
- handler: async (data) => {
45
- const event = coerceEvent(data);
18
+ handler: async (envelope) => {
19
+ const event = coerceEvent(envelope.data);
46
20
  if (!event)
47
21
  return;
48
22
  try {
@@ -57,14 +31,14 @@ export function smartbillPlugin(options) {
57
31
  },
58
32
  {
59
33
  event: eventNames.voided,
60
- handler: async (data) => {
61
- const event = coerceEvent(data);
34
+ handler: async (envelope) => {
35
+ const event = coerceEvent(envelope.data);
62
36
  if (!event)
63
37
  return;
64
38
  try {
65
39
  const seriesName = typeof event.externalSeriesName === "string"
66
40
  ? event.externalSeriesName
67
- : options.seriesName;
41
+ : validatedOptions.seriesName;
68
42
  const number = typeof event.externalNumber === "string"
69
43
  ? event.externalNumber
70
44
  : typeof event.invoiceNumber === "string"
@@ -74,7 +48,7 @@ export function smartbillPlugin(options) {
74
48
  logger.error(`[smartbill] cannot cancel invoice ${event.id}: missing external number`);
75
49
  return;
76
50
  }
77
- await client.cancelInvoice(options.companyVatCode, seriesName, number);
51
+ await client.cancelInvoice(validatedOptions.companyVatCode, seriesName, number);
78
52
  logger.info?.(`[smartbill] invoice cancelled: ${seriesName}-${number} for ${event.id}`);
79
53
  }
80
54
  catch (err) {
@@ -84,14 +58,14 @@ export function smartbillPlugin(options) {
84
58
  },
85
59
  {
86
60
  event: eventNames.syncRequested,
87
- handler: async (data) => {
88
- const event = coerceEvent(data);
61
+ handler: async (envelope) => {
62
+ const event = coerceEvent(envelope.data);
89
63
  if (!event)
90
64
  return;
91
65
  try {
92
66
  const seriesName = typeof event.externalSeriesName === "string"
93
67
  ? event.externalSeriesName
94
- : options.seriesName;
68
+ : validatedOptions.seriesName;
95
69
  const number = typeof event.externalNumber === "string"
96
70
  ? event.externalNumber
97
71
  : typeof event.invoiceNumber === "string"
@@ -101,7 +75,7 @@ export function smartbillPlugin(options) {
101
75
  logger.error(`[smartbill] cannot sync invoice ${event.id}: missing external number`);
102
76
  return;
103
77
  }
104
- const status = await client.getPaymentStatus(options.companyVatCode, seriesName, number);
78
+ const status = await client.getPaymentStatus(validatedOptions.companyVatCode, seriesName, number);
105
79
  logger.info?.(`[smartbill] payment status for ${seriesName}-${number}: ${status.status}`, status);
106
80
  }
107
81
  catch (err) {
@@ -116,3 +90,20 @@ export function smartbillPlugin(options) {
116
90
  subscribers,
117
91
  };
118
92
  }
93
+ function parseSmartbillPluginOptions(options) {
94
+ try {
95
+ return smartbillPluginOptionsSchema.parse(options);
96
+ }
97
+ catch (error) {
98
+ if (error instanceof ZodError) {
99
+ const detail = error.issues
100
+ .map((issue) => {
101
+ const path = issue.path.join(".") || "options";
102
+ return `${path}: ${issue.message}`;
103
+ })
104
+ .join("; ");
105
+ throw new Error(`Invalid SmartBill plugin options: ${detail}`);
106
+ }
107
+ throw error;
108
+ }
109
+ }
@@ -0,0 +1,15 @@
1
+ import { createSmartbillClient } from "./client.js";
2
+ import type { SmartbillLogger, SmartbillMapFn, SmartbillPluginOptions } from "./plugin.js";
3
+ export interface ResolvedSmartbillSyncEventNames {
4
+ issued: string;
5
+ voided: string;
6
+ syncRequested: string;
7
+ }
8
+ export interface SmartbillSyncRuntime {
9
+ client: ReturnType<typeof createSmartbillClient>;
10
+ logger: SmartbillLogger;
11
+ mapEvent: SmartbillMapFn;
12
+ eventNames: ResolvedSmartbillSyncEventNames;
13
+ }
14
+ export declare function createSmartbillSyncRuntime(options: SmartbillPluginOptions): SmartbillSyncRuntime;
15
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEnD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAG1F,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAA;IAChD,MAAM,EAAE,eAAe,CAAA;IACvB,QAAQ,EAAE,cAAc,CAAA;IACxB,UAAU,EAAE,+BAA+B,CAAA;CAC5C;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,sBAAsB,GAAG,oBAAoB,CAyBhG"}
@@ -0,0 +1,26 @@
1
+ import { createSmartbillClient } from "./client.js";
2
+ import { mapVoyantInvoiceToSmartbill } from "./mapping.js";
3
+ export function createSmartbillSyncRuntime(options) {
4
+ const client = createSmartbillClient(options);
5
+ const logger = options.logger ?? console;
6
+ const mappingOptions = {
7
+ companyVatCode: options.companyVatCode,
8
+ seriesName: options.seriesName,
9
+ language: options.language,
10
+ isTaxIncluded: options.isTaxIncluded,
11
+ art311SpecialRegime: options.art311SpecialRegime,
12
+ };
13
+ const mapEvent = options.mapEvent ??
14
+ ((event) => mapVoyantInvoiceToSmartbill(event, mappingOptions));
15
+ const eventNames = {
16
+ issued: options.events?.issued ?? "invoice.issued",
17
+ voided: options.events?.voided ?? "invoice.voided",
18
+ syncRequested: options.events?.syncRequested ?? "invoice.external.sync.requested",
19
+ };
20
+ return {
21
+ client,
22
+ logger,
23
+ mapEvent,
24
+ eventNames,
25
+ };
26
+ }
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ import type { SmartbillLogger, SmartbillMapFn, SmartbillSyncEventNames } from "./plugin.js";
3
+ import type { SmartbillFetch } from "./types.js";
4
+ export declare const smartbillPluginOptionsSchema: z.ZodObject<{
5
+ username: z.ZodString;
6
+ apiToken: z.ZodString;
7
+ companyVatCode: z.ZodString;
8
+ seriesName: z.ZodString;
9
+ apiUrl: z.ZodOptional<z.ZodString>;
10
+ fetch: z.ZodOptional<z.ZodCustom<SmartbillFetch | undefined, SmartbillFetch | undefined>>;
11
+ language: z.ZodOptional<z.ZodString>;
12
+ isTaxIncluded: z.ZodOptional<z.ZodBoolean>;
13
+ art311SpecialRegime: z.ZodOptional<z.ZodBoolean>;
14
+ events: z.ZodOptional<z.ZodCustom<SmartbillSyncEventNames | undefined, SmartbillSyncEventNames | undefined>>;
15
+ mapEvent: z.ZodOptional<z.ZodCustom<SmartbillMapFn | undefined, SmartbillMapFn | undefined>>;
16
+ logger: z.ZodOptional<z.ZodCustom<SmartbillLogger | undefined, SmartbillLogger | undefined>>;
17
+ }, z.core.$strip>;
18
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EAEd,uBAAuB,EACxB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAmChD,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;iBAaK,CAAA"}
@@ -0,0 +1,33 @@
1
+ import { z } from "zod";
2
+ const optionalString = z.string().trim().min(1).optional();
3
+ const optionalUrl = z.string().trim().url().optional();
4
+ const optionalFetch = z.custom((value) => value === undefined || typeof value === "function", "Expected a fetch implementation function");
5
+ const optionalLogger = z.custom((value) => value === undefined ||
6
+ (typeof value === "object" &&
7
+ value !== null &&
8
+ typeof value.error === "function" &&
9
+ ((value.info ?? undefined) === undefined ||
10
+ typeof value.info === "function")), "Expected a logger with an error function");
11
+ const optionalMapEvent = z.custom((value) => value === undefined || typeof value === "function", "Expected a mapEvent function");
12
+ const optionalEvents = z.custom((value) => {
13
+ if (value === undefined)
14
+ return true;
15
+ if (typeof value !== "object" || value === null)
16
+ return false;
17
+ const events = value;
18
+ return [events.issued, events.voided, events.syncRequested].every((entry) => entry === undefined || (typeof entry === "string" && entry.trim().length > 0));
19
+ }, "Expected event names to be non-empty strings");
20
+ export const smartbillPluginOptionsSchema = z.object({
21
+ username: z.string().trim().min(1),
22
+ apiToken: z.string().trim().min(1),
23
+ companyVatCode: z.string().trim().min(1),
24
+ seriesName: z.string().trim().min(1),
25
+ apiUrl: optionalUrl,
26
+ fetch: optionalFetch.optional(),
27
+ language: optionalString,
28
+ isTaxIncluded: z.boolean().optional(),
29
+ art311SpecialRegime: z.boolean().optional(),
30
+ events: optionalEvents.optional(),
31
+ mapEvent: optionalMapEvent.optional(),
32
+ logger: optionalLogger.optional(),
33
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voyantjs/plugin-smartbill",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "license": "FSL-1.1-Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -26,7 +26,8 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@voyantjs/core": "0.5.0"
29
+ "zod": "^4.3.6",
30
+ "@voyantjs/core": "0.6.0"
30
31
  },
31
32
  "devDependencies": {
32
33
  "typescript": "^6.0.2",