@accounter/shaam-uniform-format-generator 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.
- package/README.md +123 -0
- package/cjs/api/generate-report.js +53 -0
- package/cjs/api/parse-files.js +32 -0
- package/cjs/format/index.js +8 -0
- package/cjs/format/newline.js +10 -0
- package/cjs/format/padding.js +39 -0
- package/cjs/generator/format/decoder.js +17 -0
- package/cjs/generator/format/encoder.js +46 -0
- package/cjs/generator/format/index.js +8 -0
- package/cjs/generator/index.js +8 -0
- package/cjs/generator/records/a000.js +8 -0
- package/cjs/generator/records/a100.js +8 -0
- package/cjs/generator/records/b100.js +8 -0
- package/cjs/generator/records/b110.js +8 -0
- package/cjs/generator/records/c100.js +8 -0
- package/cjs/generator/records/d110.js +8 -0
- package/cjs/generator/records/d120.js +8 -0
- package/cjs/generator/records/index.js +15 -0
- package/cjs/generator/records/m100.js +8 -0
- package/cjs/generator/records/z900.js +8 -0
- package/cjs/index.js +19 -0
- package/cjs/package.json +1 -0
- package/cjs/parser/data-parser.js +16 -0
- package/cjs/parser/index.js +8 -0
- package/cjs/parser/ini-parser.js +16 -0
- package/cjs/types/index.js +74 -0
- package/cjs/validation/errors.js +30 -0
- package/cjs/validation/index.js +8 -0
- package/cjs/validation/validate-input.js +56 -0
- package/esm/api/generate-report.js +50 -0
- package/esm/api/parse-files.js +29 -0
- package/esm/format/index.js +5 -0
- package/esm/format/newline.js +7 -0
- package/esm/format/padding.js +35 -0
- package/esm/generator/format/decoder.js +14 -0
- package/esm/generator/format/encoder.js +42 -0
- package/esm/generator/format/index.js +5 -0
- package/esm/generator/index.js +5 -0
- package/esm/generator/records/a000.js +5 -0
- package/esm/generator/records/a100.js +5 -0
- package/esm/generator/records/b100.js +5 -0
- package/esm/generator/records/b110.js +5 -0
- package/esm/generator/records/c100.js +5 -0
- package/esm/generator/records/d110.js +5 -0
- package/esm/generator/records/d120.js +5 -0
- package/esm/generator/records/index.js +12 -0
- package/esm/generator/records/m100.js +5 -0
- package/esm/generator/records/z900.js +5 -0
- package/esm/index.js +13 -0
- package/esm/parser/data-parser.js +13 -0
- package/esm/parser/index.js +5 -0
- package/esm/parser/ini-parser.js +13 -0
- package/esm/types/index.js +71 -0
- package/esm/validation/errors.js +25 -0
- package/esm/validation/index.js +5 -0
- package/esm/validation/validate-input.js +53 -0
- package/package.json +54 -0
- package/typings/api/generate-report.d.cts +13 -0
- package/typings/api/generate-report.d.ts +13 -0
- package/typings/api/parse-files.d.cts +13 -0
- package/typings/api/parse-files.d.ts +13 -0
- package/typings/format/index.d.cts +5 -0
- package/typings/format/index.d.ts +5 -0
- package/typings/format/newline.d.cts +7 -0
- package/typings/format/newline.d.ts +7 -0
- package/typings/format/padding.d.cts +21 -0
- package/typings/format/padding.d.ts +21 -0
- package/typings/generator/format/decoder.d.cts +12 -0
- package/typings/generator/format/decoder.d.ts +12 -0
- package/typings/generator/format/encoder.d.cts +33 -0
- package/typings/generator/format/encoder.d.ts +33 -0
- package/typings/generator/format/index.d.cts +5 -0
- package/typings/generator/format/index.d.ts +5 -0
- package/typings/generator/index.d.cts +5 -0
- package/typings/generator/index.d.ts +5 -0
- package/typings/generator/records/a000.d.cts +4 -0
- package/typings/generator/records/a000.d.ts +4 -0
- package/typings/generator/records/a100.d.cts +4 -0
- package/typings/generator/records/a100.d.ts +4 -0
- package/typings/generator/records/b100.d.cts +4 -0
- package/typings/generator/records/b100.d.ts +4 -0
- package/typings/generator/records/b110.d.cts +4 -0
- package/typings/generator/records/b110.d.ts +4 -0
- package/typings/generator/records/c100.d.cts +4 -0
- package/typings/generator/records/c100.d.ts +4 -0
- package/typings/generator/records/d110.d.cts +4 -0
- package/typings/generator/records/d110.d.ts +4 -0
- package/typings/generator/records/d120.d.cts +4 -0
- package/typings/generator/records/d120.d.ts +4 -0
- package/typings/generator/records/index.d.cts +12 -0
- package/typings/generator/records/index.d.ts +12 -0
- package/typings/generator/records/m100.d.cts +4 -0
- package/typings/generator/records/m100.d.ts +4 -0
- package/typings/generator/records/z900.d.cts +4 -0
- package/typings/generator/records/z900.d.ts +4 -0
- package/typings/index.d.cts +12 -0
- package/typings/index.d.ts +12 -0
- package/typings/parser/data-parser.d.cts +10 -0
- package/typings/parser/data-parser.d.ts +10 -0
- package/typings/parser/index.d.cts +5 -0
- package/typings/parser/index.d.ts +5 -0
- package/typings/parser/ini-parser.d.cts +10 -0
- package/typings/parser/ini-parser.d.ts +10 -0
- package/typings/types/index.d.cts +371 -0
- package/typings/types/index.d.ts +371 -0
- package/typings/validation/errors.d.cts +15 -0
- package/typings/validation/errors.d.ts +15 -0
- package/typings/validation/index.d.cts +5 -0
- package/typings/validation/index.d.ts +5 -0
- package/typings/validation/validate-input.d.cts +12 -0
- package/typings/validation/validate-input.d.ts +12 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Input validation utilities
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateInput = validateInput;
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const index_js_1 = require("../types/index.js");
|
|
9
|
+
const errors_js_1 = require("./errors.js");
|
|
10
|
+
/**
|
|
11
|
+
* Converts Zod errors to ValidationError format
|
|
12
|
+
*/
|
|
13
|
+
function convertZodErrorsToValidationErrors(zodError) {
|
|
14
|
+
return zodError.errors.map((error, index) => ({
|
|
15
|
+
recordType: 'input',
|
|
16
|
+
recordIndex: index,
|
|
17
|
+
field: error.path.join('.') || 'unknown',
|
|
18
|
+
message: error.message,
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Validates report input data against the schema
|
|
23
|
+
*
|
|
24
|
+
* @param input - The input data to validate
|
|
25
|
+
* @param mode - Validation mode ('fail-fast' or 'collect-all')
|
|
26
|
+
* @returns Array of validation errors (empty if valid)
|
|
27
|
+
*/
|
|
28
|
+
function validateInput(input, mode = 'fail-fast') {
|
|
29
|
+
const errors = [];
|
|
30
|
+
try {
|
|
31
|
+
index_js_1.ReportInputSchema.parse(input);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error instanceof zod_1.ZodError) {
|
|
35
|
+
const validationErrors = convertZodErrorsToValidationErrors(error);
|
|
36
|
+
if (mode === 'fail-fast') {
|
|
37
|
+
throw new errors_js_1.ShaamFormatError(`Validation failed: ${validationErrors[0]?.message || 'Unknown error'}`, validationErrors);
|
|
38
|
+
}
|
|
39
|
+
errors.push(...validationErrors);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Handle non-Zod errors
|
|
43
|
+
const unknownError = {
|
|
44
|
+
recordType: 'unknown',
|
|
45
|
+
recordIndex: 0,
|
|
46
|
+
field: 'unknown',
|
|
47
|
+
message: error instanceof Error ? error.message : 'Unknown validation error',
|
|
48
|
+
};
|
|
49
|
+
if (mode === 'fail-fast') {
|
|
50
|
+
throw new errors_js_1.ShaamFormatError('Validation failed', [unknownError]);
|
|
51
|
+
}
|
|
52
|
+
errors.push(unknownError);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return errors;
|
|
56
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main API for generating SHAAM uniform format reports
|
|
3
|
+
*/
|
|
4
|
+
import { ShaamFormatError } from '../validation/errors.js';
|
|
5
|
+
import { validateInput } from '../validation/validate-input.js';
|
|
6
|
+
/**
|
|
7
|
+
* Generates SHAAM uniform format report files (INI.TXT and BKMVDATA.TXT)
|
|
8
|
+
* from a high-level JSON input object.
|
|
9
|
+
*
|
|
10
|
+
* @param input - The report input data
|
|
11
|
+
* @param options - Generation options
|
|
12
|
+
* @returns Report output with generated file content
|
|
13
|
+
*/
|
|
14
|
+
export function generateUniformFormatReport(input, options = {}) {
|
|
15
|
+
// Validate input data first
|
|
16
|
+
const validationMode = options.validationMode || 'fail-fast';
|
|
17
|
+
const validationErrors = validateInput(input, validationMode);
|
|
18
|
+
if (validationErrors.length > 0) {
|
|
19
|
+
if (validationMode === 'fail-fast') {
|
|
20
|
+
// This should have already thrown, but just in case
|
|
21
|
+
throw new ShaamFormatError('Validation failed', validationErrors);
|
|
22
|
+
}
|
|
23
|
+
// For collect-all mode, we still throw if there are errors
|
|
24
|
+
// The user can catch and inspect the errors if needed
|
|
25
|
+
throw new ShaamFormatError('Input validation failed', validationErrors);
|
|
26
|
+
}
|
|
27
|
+
// TODO: Implement the actual generation logic
|
|
28
|
+
const iniText = 'A000placeholder\r\n'; // Placeholder
|
|
29
|
+
const dataText = 'A100placeholder\r\n'; // Placeholder
|
|
30
|
+
// Create virtual File objects
|
|
31
|
+
const iniFile = new File([iniText], `${options.fileNameBase || 'report'}.INI.TXT`, {
|
|
32
|
+
type: 'text/plain',
|
|
33
|
+
});
|
|
34
|
+
const dataFile = new File([dataText], `${options.fileNameBase || 'report'}.BKMVDATA.TXT`, {
|
|
35
|
+
type: 'text/plain',
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
iniText,
|
|
39
|
+
dataText,
|
|
40
|
+
iniFile,
|
|
41
|
+
dataFile,
|
|
42
|
+
summary: {
|
|
43
|
+
totalRecords: 2, // Placeholder
|
|
44
|
+
perType: {
|
|
45
|
+
A000: 1,
|
|
46
|
+
A100: 1,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API for parsing SHAAM uniform format files
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Parses SHAAM uniform format files (INI.TXT and BKMVDATA.TXT)
|
|
6
|
+
* back into structured JSON objects.
|
|
7
|
+
*
|
|
8
|
+
* @param iniContent - Content of the INI.TXT file
|
|
9
|
+
* @param dataContent - Content of the BKMVDATA.TXT file
|
|
10
|
+
* @returns Parsed report input data
|
|
11
|
+
*/
|
|
12
|
+
export function parseUniformFormatFiles(_iniContent, _dataContent) {
|
|
13
|
+
// TODO: Implement the actual parsing logic
|
|
14
|
+
return {
|
|
15
|
+
business: {
|
|
16
|
+
businessId: 'placeholder',
|
|
17
|
+
name: 'Placeholder Business',
|
|
18
|
+
taxId: '000000000',
|
|
19
|
+
reportingPeriod: {
|
|
20
|
+
startDate: '2024-01-01',
|
|
21
|
+
endDate: '2024-12-31',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
documents: [],
|
|
25
|
+
journalEntries: [],
|
|
26
|
+
accounts: [],
|
|
27
|
+
inventory: [],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String padding utilities for fixed-width formatting
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Pads a string on the left (right-aligns the content)
|
|
6
|
+
*
|
|
7
|
+
* @param value - The string to pad
|
|
8
|
+
* @param width - Target width
|
|
9
|
+
* @param fill - Character to use for padding (default: space)
|
|
10
|
+
* @returns Left-padded string
|
|
11
|
+
*/
|
|
12
|
+
export function padLeft(value, width, fill = ' ') {
|
|
13
|
+
if (value.length >= width) {
|
|
14
|
+
return value.substring(0, width);
|
|
15
|
+
}
|
|
16
|
+
const padLength = width - value.length;
|
|
17
|
+
const padding = fill.repeat(padLength);
|
|
18
|
+
return padding + value;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Pads a string on the right (left-aligns the content)
|
|
22
|
+
*
|
|
23
|
+
* @param value - The string to pad
|
|
24
|
+
* @param width - Target width
|
|
25
|
+
* @param fill - Character to use for padding (default: space)
|
|
26
|
+
* @returns Right-padded string
|
|
27
|
+
*/
|
|
28
|
+
export function padRight(value, width, fill = ' ') {
|
|
29
|
+
if (value.length >= width) {
|
|
30
|
+
return value.substring(0, width);
|
|
31
|
+
}
|
|
32
|
+
const padLength = width - value.length;
|
|
33
|
+
const padding = fill.repeat(padLength);
|
|
34
|
+
return value + padding;
|
|
35
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed-width decoding utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Decodes a fixed-width string value
|
|
6
|
+
*
|
|
7
|
+
* @param line - The line to decode from
|
|
8
|
+
* @param start - Start position (0-based)
|
|
9
|
+
* @param length - Field length
|
|
10
|
+
* @returns Decoded and trimmed value
|
|
11
|
+
*/
|
|
12
|
+
export function decodeFixedWidth(line, start, length) {
|
|
13
|
+
return line.substring(start, start + length).trim();
|
|
14
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed-wiexport function formatField(
|
|
3
|
+
value: string,
|
|
4
|
+
width: number,
|
|
5
|
+
align: 'left' | 'right',
|
|
6
|
+
padChar = ' '
|
|
7
|
+
): string {
|
|
8
|
+
if (align === 'left') {
|
|
9
|
+
return padRight(value, width, padChar);
|
|
10
|
+
}
|
|
11
|
+
return padLeft(value, width, padChar);
|
|
12
|
+
} utilities
|
|
13
|
+
*/
|
|
14
|
+
import { padLeft, padRight } from '../../format/padding.js';
|
|
15
|
+
/**
|
|
16
|
+
* Formats a field value with specified width and alignment
|
|
17
|
+
*
|
|
18
|
+
* @param value - The value to format
|
|
19
|
+
* @param width - Target field width
|
|
20
|
+
* @param align - Alignment ('left' or 'right')
|
|
21
|
+
* @param padChar - Character to use for padding (default: space)
|
|
22
|
+
* @returns Formatted fixed-width string
|
|
23
|
+
*/
|
|
24
|
+
export function formatField(value, width, align, padChar = ' ') {
|
|
25
|
+
if (align === 'left') {
|
|
26
|
+
return padRight(value, width, padChar);
|
|
27
|
+
}
|
|
28
|
+
return padLeft(value, width, padChar);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Encodes a value to fixed-width format with padding
|
|
32
|
+
*
|
|
33
|
+
* @param value - The value to encode
|
|
34
|
+
* @param width - Target width
|
|
35
|
+
* @param padChar - Padding character (default: space)
|
|
36
|
+
* @param align - Alignment ('left' or 'right')
|
|
37
|
+
* @returns Fixed-width encoded string
|
|
38
|
+
*/
|
|
39
|
+
export function encodeFixedWidth(value, width, padChar = ' ', align = 'left') {
|
|
40
|
+
const str = String(value);
|
|
41
|
+
return formatField(str, width, align, padChar);
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Record type definitions and generators
|
|
3
|
+
*/
|
|
4
|
+
export * from './a000.js';
|
|
5
|
+
export * from './a100.js';
|
|
6
|
+
export * from './b100.js';
|
|
7
|
+
export * from './b110.js';
|
|
8
|
+
export * from './c100.js';
|
|
9
|
+
export * from './d110.js';
|
|
10
|
+
export * from './d120.js';
|
|
11
|
+
export * from './m100.js';
|
|
12
|
+
export * from './z900.js';
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @accounter/shaam-uniform-format-generator
|
|
3
|
+
*
|
|
4
|
+
* A fully typed TypeScript library for generating, parsing, and validating
|
|
5
|
+
* SHAAM uniform format tax reports (INI.TXT and BKMVDATA.TXT files).
|
|
6
|
+
*/
|
|
7
|
+
export * from './types/index.js';
|
|
8
|
+
export * from './generator/index.js';
|
|
9
|
+
export * from './parser/index.js';
|
|
10
|
+
export * from './validation/index.js';
|
|
11
|
+
// Main API
|
|
12
|
+
export { generateUniformFormatReport } from './api/generate-report.js';
|
|
13
|
+
export { parseUniformFormatFiles } from './api/parse-files.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BKMVDATA.TXT file parsing utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Parses BKMVDATA.TXT file content
|
|
6
|
+
*
|
|
7
|
+
* @param content - Raw BKMVDATA.TXT file content
|
|
8
|
+
* @returns Parsed data structure
|
|
9
|
+
*/
|
|
10
|
+
export function parseDataFile(_content) {
|
|
11
|
+
// TODO: Implement data file parsing logic
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* INI.TXT file parsing utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Parses INI.TXT file content
|
|
6
|
+
*
|
|
7
|
+
* @param content - Raw INI.TXT file content
|
|
8
|
+
* @returns Parsed data structure
|
|
9
|
+
*/
|
|
10
|
+
export function parseIniFile(_content) {
|
|
11
|
+
// TODO: Implement INI file parsing logic
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for SHAAM uniform format generator
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
// Business metadata schema
|
|
6
|
+
export const BusinessMetadataSchema = z.object({
|
|
7
|
+
businessId: z.string().min(1, 'Business ID is required'),
|
|
8
|
+
name: z.string().min(1, 'Business name is required'),
|
|
9
|
+
taxId: z.string().min(1, 'Tax ID is required'),
|
|
10
|
+
reportingPeriod: z.object({
|
|
11
|
+
startDate: z.string().min(1, 'Start date is required'),
|
|
12
|
+
endDate: z.string().min(1, 'End date is required'),
|
|
13
|
+
}),
|
|
14
|
+
});
|
|
15
|
+
// Document schema
|
|
16
|
+
export const DocumentSchema = z.object({
|
|
17
|
+
id: z.string().min(1, 'Document ID is required'),
|
|
18
|
+
type: z.string().min(1, 'Document type is required'),
|
|
19
|
+
date: z.string().min(1, 'Document date is required'),
|
|
20
|
+
amount: z.number(),
|
|
21
|
+
description: z.string().optional(),
|
|
22
|
+
});
|
|
23
|
+
// Journal entry schema
|
|
24
|
+
export const JournalEntrySchema = z.object({
|
|
25
|
+
id: z.string().min(1, 'Journal entry ID is required'),
|
|
26
|
+
date: z.string().min(1, 'Journal entry date is required'),
|
|
27
|
+
amount: z.number(),
|
|
28
|
+
accountId: z.string().min(1, 'Account ID is required'),
|
|
29
|
+
description: z.string().optional(),
|
|
30
|
+
});
|
|
31
|
+
// Account schema
|
|
32
|
+
export const AccountSchema = z.object({
|
|
33
|
+
id: z.string().min(1, 'Account ID is required'),
|
|
34
|
+
name: z.string().min(1, 'Account name is required'),
|
|
35
|
+
type: z.string().min(1, 'Account type is required'),
|
|
36
|
+
balance: z.number(),
|
|
37
|
+
});
|
|
38
|
+
// Inventory item schema
|
|
39
|
+
export const InventoryItemSchema = z.object({
|
|
40
|
+
id: z.string().min(1, 'Inventory item ID is required'),
|
|
41
|
+
name: z.string().min(1, 'Inventory item name is required'),
|
|
42
|
+
quantity: z.number(),
|
|
43
|
+
unitPrice: z.number(),
|
|
44
|
+
});
|
|
45
|
+
// Main input schema
|
|
46
|
+
export const ReportInputSchema = z.object({
|
|
47
|
+
business: BusinessMetadataSchema,
|
|
48
|
+
documents: z.array(DocumentSchema),
|
|
49
|
+
journalEntries: z.array(JournalEntrySchema),
|
|
50
|
+
accounts: z.array(AccountSchema),
|
|
51
|
+
inventory: z.array(InventoryItemSchema),
|
|
52
|
+
});
|
|
53
|
+
// Output schema
|
|
54
|
+
export const ReportOutputSchema = z.object({
|
|
55
|
+
iniText: z.string(),
|
|
56
|
+
dataText: z.string(),
|
|
57
|
+
iniFile: z.instanceof(File),
|
|
58
|
+
dataFile: z.instanceof(File),
|
|
59
|
+
summary: z.object({
|
|
60
|
+
totalRecords: z.number(),
|
|
61
|
+
perType: z.record(z.string(), z.number()),
|
|
62
|
+
errors: z
|
|
63
|
+
.array(z.object({
|
|
64
|
+
recordType: z.string(),
|
|
65
|
+
recordIndex: z.number(),
|
|
66
|
+
field: z.string(),
|
|
67
|
+
message: z.string(),
|
|
68
|
+
}))
|
|
69
|
+
.optional(),
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error handling utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Custom error class for SHAAM format generation errors
|
|
6
|
+
*/
|
|
7
|
+
export class ShaamFormatError extends Error {
|
|
8
|
+
errors;
|
|
9
|
+
constructor(message, errors = []) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.errors = errors;
|
|
12
|
+
this.name = 'ShaamFormatError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a validation error object
|
|
17
|
+
*/
|
|
18
|
+
export function createValidationError(recordType, recordIndex, field, message) {
|
|
19
|
+
return {
|
|
20
|
+
recordType,
|
|
21
|
+
recordIndex,
|
|
22
|
+
field,
|
|
23
|
+
message,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input validation utilities
|
|
3
|
+
*/
|
|
4
|
+
import { ZodError } from 'zod';
|
|
5
|
+
import { ReportInputSchema } from '../types/index.js';
|
|
6
|
+
import { ShaamFormatError } from './errors.js';
|
|
7
|
+
/**
|
|
8
|
+
* Converts Zod errors to ValidationError format
|
|
9
|
+
*/
|
|
10
|
+
function convertZodErrorsToValidationErrors(zodError) {
|
|
11
|
+
return zodError.errors.map((error, index) => ({
|
|
12
|
+
recordType: 'input',
|
|
13
|
+
recordIndex: index,
|
|
14
|
+
field: error.path.join('.') || 'unknown',
|
|
15
|
+
message: error.message,
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validates report input data against the schema
|
|
20
|
+
*
|
|
21
|
+
* @param input - The input data to validate
|
|
22
|
+
* @param mode - Validation mode ('fail-fast' or 'collect-all')
|
|
23
|
+
* @returns Array of validation errors (empty if valid)
|
|
24
|
+
*/
|
|
25
|
+
export function validateInput(input, mode = 'fail-fast') {
|
|
26
|
+
const errors = [];
|
|
27
|
+
try {
|
|
28
|
+
ReportInputSchema.parse(input);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error instanceof ZodError) {
|
|
32
|
+
const validationErrors = convertZodErrorsToValidationErrors(error);
|
|
33
|
+
if (mode === 'fail-fast') {
|
|
34
|
+
throw new ShaamFormatError(`Validation failed: ${validationErrors[0]?.message || 'Unknown error'}`, validationErrors);
|
|
35
|
+
}
|
|
36
|
+
errors.push(...validationErrors);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Handle non-Zod errors
|
|
40
|
+
const unknownError = {
|
|
41
|
+
recordType: 'unknown',
|
|
42
|
+
recordIndex: 0,
|
|
43
|
+
field: 'unknown',
|
|
44
|
+
message: error instanceof Error ? error.message : 'Unknown validation error',
|
|
45
|
+
};
|
|
46
|
+
if (mode === 'fail-fast') {
|
|
47
|
+
throw new ShaamFormatError('Validation failed', [unknownError]);
|
|
48
|
+
}
|
|
49
|
+
errors.push(unknownError);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return errors;
|
|
53
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@accounter/shaam-uniform-format-generator",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Fully typed application that generates, parses, and validates SHAAM uniform format tax reports (INI.TXT and BKMVDATA.TXT).",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"iconv-lite": "0.6.3",
|
|
7
|
+
"zod": "3.25.76"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/urigo/accounter-fullstack.git",
|
|
12
|
+
"directory": "packages/shaam-uniform-format-generator"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/urigo/accounter-fullstack/packages/shaam-uniform-format-generator#readme",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"shaam",
|
|
17
|
+
"uniform-format",
|
|
18
|
+
"accountancy",
|
|
19
|
+
"accountant",
|
|
20
|
+
"accounter",
|
|
21
|
+
"tax-reports",
|
|
22
|
+
"ini",
|
|
23
|
+
"bkmvdata"
|
|
24
|
+
],
|
|
25
|
+
"author": "Gil Gardosh <gilgardosh@gmail.com>",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": "^20.0.0 || >= 22"
|
|
29
|
+
},
|
|
30
|
+
"main": "cjs/index.js",
|
|
31
|
+
"module": "esm/index.js",
|
|
32
|
+
"typings": "typings/index.d.ts",
|
|
33
|
+
"typescript": {
|
|
34
|
+
"definition": "typings/index.d.ts"
|
|
35
|
+
},
|
|
36
|
+
"type": "module",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./typings/index.d.cts",
|
|
41
|
+
"default": "./cjs/index.js"
|
|
42
|
+
},
|
|
43
|
+
"import": {
|
|
44
|
+
"types": "./typings/index.d.ts",
|
|
45
|
+
"default": "./esm/index.js"
|
|
46
|
+
},
|
|
47
|
+
"default": {
|
|
48
|
+
"types": "./typings/index.d.ts",
|
|
49
|
+
"default": "./esm/index.js"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"./package.json": "./package.json"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main API for generating SHAAM uniform format reports
|
|
3
|
+
*/
|
|
4
|
+
import type { GenerationOptions, ReportInput, ReportOutput } from '../types/index.cjs';
|
|
5
|
+
/**
|
|
6
|
+
* Generates SHAAM uniform format report files (INI.TXT and BKMVDATA.TXT)
|
|
7
|
+
* from a high-level JSON input object.
|
|
8
|
+
*
|
|
9
|
+
* @param input - The report input data
|
|
10
|
+
* @param options - Generation options
|
|
11
|
+
* @returns Report output with generated file content
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateUniformFormatReport(input: ReportInput, options?: GenerationOptions): ReportOutput;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main API for generating SHAAM uniform format reports
|
|
3
|
+
*/
|
|
4
|
+
import type { GenerationOptions, ReportInput, ReportOutput } from '../types/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Generates SHAAM uniform format report files (INI.TXT and BKMVDATA.TXT)
|
|
7
|
+
* from a high-level JSON input object.
|
|
8
|
+
*
|
|
9
|
+
* @param input - The report input data
|
|
10
|
+
* @param options - Generation options
|
|
11
|
+
* @returns Report output with generated file content
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateUniformFormatReport(input: ReportInput, options?: GenerationOptions): ReportOutput;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API for parsing SHAAM uniform format files
|
|
3
|
+
*/
|
|
4
|
+
import type { ReportInput } from '../types/index.cjs';
|
|
5
|
+
/**
|
|
6
|
+
* Parses SHAAM uniform format files (INI.TXT and BKMVDATA.TXT)
|
|
7
|
+
* back into structured JSON objects.
|
|
8
|
+
*
|
|
9
|
+
* @param iniContent - Content of the INI.TXT file
|
|
10
|
+
* @param dataContent - Content of the BKMVDATA.TXT file
|
|
11
|
+
* @returns Parsed report input data
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseUniformFormatFiles(_iniContent: string, _dataContent: string): ReportInput;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API for parsing SHAAM uniform format files
|
|
3
|
+
*/
|
|
4
|
+
import type { ReportInput } from '../types/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Parses SHAAM uniform format files (INI.TXT and BKMVDATA.TXT)
|
|
7
|
+
* back into structured JSON objects.
|
|
8
|
+
*
|
|
9
|
+
* @param iniContent - Content of the INI.TXT file
|
|
10
|
+
* @param dataContent - Content of the BKMVDATA.TXT file
|
|
11
|
+
* @returns Parsed report input data
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseUniformFormatFiles(_iniContent: string, _dataContent: string): ReportInput;
|