@finsys/core 1.1.0 → 1.2.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/dist/index.cjs +9101 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +375 -0
- package/dist/index.d.ts +374 -18
- package/dist/index.js +9038 -31
- package/dist/index.js.map +1 -0
- package/package.json +12 -10
- package/dist/catalogs.d.ts +0 -13
- package/dist/catalogs.js +0 -35
- package/dist/catalogs.test.d.ts +0 -1
- package/dist/catalogs.test.js +0 -207
- package/dist/form-field-category.d.ts +0 -12
- package/dist/form-field-category.js +0 -21
- package/dist/form-field-validator.d.ts +0 -18
- package/dist/form-field-validator.js +0 -41
- package/dist/form-field.d.ts +0 -81
- package/dist/form-field.js +0 -197
- package/dist/form-field.test.d.ts +0 -1
- package/dist/form-field.test.js +0 -482
- package/dist/form-spec.d.ts +0 -39
- package/dist/form-spec.js +0 -278
- package/dist/form-spec.test.d.ts +0 -1
- package/dist/form-spec.test.js +0 -322
- package/dist/rhf-generator.d.ts +0 -30
- package/dist/rhf-generator.js +0 -267
- package/dist/rhf-generator.test.d.ts +0 -1
- package/dist/rhf-generator.test.js +0 -583
- package/dist/survey-generator.d.ts +0 -153
- package/dist/survey-generator.js +0 -194
- package/dist/survey-generator.test.d.ts +0 -1
- package/dist/survey-generator.test.js +0 -332
- package/dist/utils.d.ts +0 -13
- package/dist/utils.js +0 -56
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -131
- package/dist/validator.d.ts +0 -14
- package/dist/validator.js +0 -49
- package/dist/validator.test.d.ts +0 -1
- package/dist/validator.test.js +0 -142
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ErrorObject } from 'ajv';
|
|
3
|
+
export { IElement, IPage, IPanel, IQuestion, ISurvey } from 'survey-core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Survey Generator - Converts unified form configurations into SurveyJS-compatible JSON
|
|
7
|
+
*
|
|
8
|
+
* This module converts a unified form-config.json into SurveyJS-compatible JSON,
|
|
9
|
+
* resolving field references, applying dynamic titles, and grouping by category.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
interface Category {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
16
|
+
interface Choice {
|
|
17
|
+
value: string;
|
|
18
|
+
text: string;
|
|
19
|
+
}
|
|
20
|
+
interface Validator {
|
|
21
|
+
type: "regex" | "email" | "numeric" | "text" | "expression" | "answercount" | "custom";
|
|
22
|
+
text?: string;
|
|
23
|
+
regex?: string;
|
|
24
|
+
minValue?: number;
|
|
25
|
+
maxValue?: number;
|
|
26
|
+
minLength?: number;
|
|
27
|
+
maxLength?: number;
|
|
28
|
+
minCount?: number;
|
|
29
|
+
maxCount?: number;
|
|
30
|
+
expression?: string;
|
|
31
|
+
validator?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* FieldData - Field definition in the unified form config
|
|
35
|
+
*/
|
|
36
|
+
interface FieldData {
|
|
37
|
+
name?: string;
|
|
38
|
+
displayName?: string;
|
|
39
|
+
type: string;
|
|
40
|
+
inputType?: "text" | "number" | "tel" | "date" | "email" | "password" | "url";
|
|
41
|
+
category?: string;
|
|
42
|
+
maxLength?: number | string;
|
|
43
|
+
min?: number | string;
|
|
44
|
+
max?: number | string;
|
|
45
|
+
step?: number;
|
|
46
|
+
html?: string;
|
|
47
|
+
choices?: Choice[];
|
|
48
|
+
validators?: Validator[];
|
|
49
|
+
visible?: boolean;
|
|
50
|
+
visibleIf?: string;
|
|
51
|
+
required?: boolean;
|
|
52
|
+
isRequired?: boolean;
|
|
53
|
+
placeholder?: string;
|
|
54
|
+
defaultValue?: string | number | boolean | string[];
|
|
55
|
+
readOnly?: boolean;
|
|
56
|
+
startWithNewLine?: boolean;
|
|
57
|
+
enableIf?: string;
|
|
58
|
+
titleLocation?: "default" | "top" | "bottom" | "left" | "hidden";
|
|
59
|
+
ihs_column_names?: string[];
|
|
60
|
+
requiredForEvaluation?: boolean;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* FieldReference - How fields are referenced in pages
|
|
65
|
+
*/
|
|
66
|
+
type FieldReference = string | {
|
|
67
|
+
ref: string;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
} | {
|
|
70
|
+
definition: FieldData & {
|
|
71
|
+
name: string;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
interface PageConfig {
|
|
75
|
+
id: string;
|
|
76
|
+
title?: string;
|
|
77
|
+
description?: string;
|
|
78
|
+
showTOC?: boolean;
|
|
79
|
+
showProgressBar?: boolean;
|
|
80
|
+
showCategoryHeadings?: boolean;
|
|
81
|
+
layout?: "default" | "grid" | "vertical";
|
|
82
|
+
fields: FieldReference[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* UnifiedFormConfig - The main configuration type for the unified form format
|
|
86
|
+
*/
|
|
87
|
+
interface UnifiedFormConfig {
|
|
88
|
+
$schema?: string;
|
|
89
|
+
schemaVersion?: string;
|
|
90
|
+
displayName?: string;
|
|
91
|
+
templateIcon?: string;
|
|
92
|
+
categories: Category[];
|
|
93
|
+
fields: Record<string, FieldData>;
|
|
94
|
+
pages?: PageConfig[];
|
|
95
|
+
}
|
|
96
|
+
interface SurveyElementJSON {
|
|
97
|
+
type: string;
|
|
98
|
+
name: string;
|
|
99
|
+
title?: string;
|
|
100
|
+
isRequired?: boolean;
|
|
101
|
+
maxLength?: number;
|
|
102
|
+
storeDataAsText?: boolean;
|
|
103
|
+
category?: string;
|
|
104
|
+
[key: string]: unknown;
|
|
105
|
+
}
|
|
106
|
+
interface SurveyPageJSON {
|
|
107
|
+
name: string;
|
|
108
|
+
title: string;
|
|
109
|
+
elements: Array<{
|
|
110
|
+
type: string;
|
|
111
|
+
name: string;
|
|
112
|
+
elements: SurveyElementJSON[];
|
|
113
|
+
}>;
|
|
114
|
+
}
|
|
115
|
+
interface SurveyJSON {
|
|
116
|
+
title: string;
|
|
117
|
+
logoPosition?: string;
|
|
118
|
+
pages: SurveyPageJSON[];
|
|
119
|
+
showQuestionNumbers?: string;
|
|
120
|
+
questionErrorLocation?: string;
|
|
121
|
+
completedHtml?: string;
|
|
122
|
+
showTOC?: boolean;
|
|
123
|
+
completeText?: string;
|
|
124
|
+
showPreviewBeforeComplete?: string;
|
|
125
|
+
showProgressBar?: string;
|
|
126
|
+
widthMode?: string;
|
|
127
|
+
width?: string;
|
|
128
|
+
}
|
|
129
|
+
interface ResolvedField extends FieldData {
|
|
130
|
+
name: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Apply dynamic title logic (e.g., bank statements with dynamic month labels,
|
|
134
|
+
* financial statements with dynamic year labels)
|
|
135
|
+
*/
|
|
136
|
+
declare function applyDynamicTitles(field: ResolvedField): ResolvedField;
|
|
137
|
+
/**
|
|
138
|
+
* Generate SurveyJS JSON from unified form config
|
|
139
|
+
*/
|
|
140
|
+
declare function generateSurveyJson(config: UnifiedFormConfig): SurveyJSON | Record<string, never>;
|
|
141
|
+
/**
|
|
142
|
+
* Resolve all fields from a page to full field definitions
|
|
143
|
+
*/
|
|
144
|
+
declare function resolvePageFields(page: PageConfig, fields: Record<string, FieldData>): ResolvedField[];
|
|
145
|
+
/**
|
|
146
|
+
* Get category name from category ID (supports string or number IDs)
|
|
147
|
+
*/
|
|
148
|
+
declare function getCategoryName(categoryId: string | undefined, categories: Category[]): string;
|
|
149
|
+
/**
|
|
150
|
+
* Group fields by their category, maintaining order and creating section breaks
|
|
151
|
+
*/
|
|
152
|
+
interface FieldGroup {
|
|
153
|
+
category: string;
|
|
154
|
+
categoryName: string;
|
|
155
|
+
fields: ResolvedField[];
|
|
156
|
+
}
|
|
157
|
+
declare function groupFieldsByCategory(fields: ResolvedField[], categories: Category[]): FieldGroup[];
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Utility functions for @finsys/core
|
|
161
|
+
*/
|
|
162
|
+
declare function getPastMonthLabel(monthsAgo: number): string;
|
|
163
|
+
declare function getPastYearLabel(yearsAgo: number): string;
|
|
164
|
+
/**
|
|
165
|
+
* Evaluate a SurveyJS-style expression against a data object.
|
|
166
|
+
* e.g. "{totalFinancing} > 50000"
|
|
167
|
+
*
|
|
168
|
+
* NOTE: This is a simplified evaluator that replaces {key} with data[key] access.
|
|
169
|
+
* It does not support complex SurveyJS functions like age() or complicated nested paths unless handled by JS.
|
|
170
|
+
*/
|
|
171
|
+
declare function evaluateExpression(expression: string, data: any): boolean;
|
|
172
|
+
|
|
173
|
+
interface RHFStep {
|
|
174
|
+
id: number;
|
|
175
|
+
title: string;
|
|
176
|
+
description?: string;
|
|
177
|
+
fields: ResolvedField[];
|
|
178
|
+
showCategoryHeadings: boolean;
|
|
179
|
+
layout?: "default" | "grid" | "vertical";
|
|
180
|
+
}
|
|
181
|
+
interface RHFSchemaOutput {
|
|
182
|
+
zodSchema: z.ZodTypeAny;
|
|
183
|
+
baseSchema: z.ZodObject<any>;
|
|
184
|
+
defaultValues: Record<string, any>;
|
|
185
|
+
fields: ResolvedField[];
|
|
186
|
+
groupedFields: FieldGroup[];
|
|
187
|
+
steps: RHFStep[];
|
|
188
|
+
displayName: string;
|
|
189
|
+
categories: Category[];
|
|
190
|
+
templateIcon?: string;
|
|
191
|
+
}
|
|
192
|
+
declare function generateRHFSchema(config: UnifiedFormConfig): RHFSchemaOutput;
|
|
193
|
+
/**
|
|
194
|
+
* Get Zod schema for a specific step
|
|
195
|
+
*/
|
|
196
|
+
declare function getStepSchema(step: RHFStep, fullSchema: any): z.ZodTypeAny;
|
|
197
|
+
/**
|
|
198
|
+
* Extract default values for a specific step
|
|
199
|
+
*/
|
|
200
|
+
declare function getStepDefaultValues(step: RHFStep, allDefaults: Record<string, any>): Record<string, any>;
|
|
201
|
+
|
|
202
|
+
interface ValidationResult {
|
|
203
|
+
valid: boolean;
|
|
204
|
+
errors?: ErrorObject[];
|
|
205
|
+
message?: string;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Validates a unified form-config.json object against its schema
|
|
209
|
+
*/
|
|
210
|
+
declare function validateFormConfig(data: unknown): ValidationResult;
|
|
211
|
+
/** @deprecated Use validateFormConfig instead */
|
|
212
|
+
declare function validateFormSpec(data: unknown): ValidationResult;
|
|
213
|
+
/** @deprecated Use validateFormConfig instead */
|
|
214
|
+
declare function validatePagesConfig(data: unknown): ValidationResult;
|
|
215
|
+
|
|
216
|
+
declare class FormFieldCategory {
|
|
217
|
+
private _id;
|
|
218
|
+
private _name;
|
|
219
|
+
constructor(id: string | number, name: string);
|
|
220
|
+
get id(): string;
|
|
221
|
+
get name(): string;
|
|
222
|
+
set name(value: string);
|
|
223
|
+
toJSON(): {
|
|
224
|
+
id: string;
|
|
225
|
+
name: string;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
declare enum FieldType {
|
|
230
|
+
FILE = "file",
|
|
231
|
+
TEXT = "text",
|
|
232
|
+
DROPDOWN = "dropdown",
|
|
233
|
+
BOOLEAN = "boolean",
|
|
234
|
+
CHECKBOX = "checkbox",
|
|
235
|
+
RADIOGROUP = "radiogroup",
|
|
236
|
+
SLIDER = "slider",
|
|
237
|
+
HTML = "html",
|
|
238
|
+
TAGBOX = "tagbox",
|
|
239
|
+
NUMBER = "number",
|
|
240
|
+
EMAIL = "email",
|
|
241
|
+
COMMENT = "comment",
|
|
242
|
+
RANGE = "range",
|
|
243
|
+
UNKNOWN = "unknown"
|
|
244
|
+
}
|
|
245
|
+
interface FormFieldType {
|
|
246
|
+
name: string;
|
|
247
|
+
displayName: string;
|
|
248
|
+
}
|
|
249
|
+
interface FormFieldInputType {
|
|
250
|
+
name: string;
|
|
251
|
+
displayName: string;
|
|
252
|
+
}
|
|
253
|
+
interface FormFieldTypeDefinitions {
|
|
254
|
+
version: number;
|
|
255
|
+
types: FormFieldType[];
|
|
256
|
+
input_types: FormFieldInputType[];
|
|
257
|
+
}
|
|
258
|
+
interface DropdownOption {
|
|
259
|
+
id: number;
|
|
260
|
+
name: string;
|
|
261
|
+
displayName: string;
|
|
262
|
+
choices: Choice[];
|
|
263
|
+
}
|
|
264
|
+
interface EditorValidator {
|
|
265
|
+
id: number;
|
|
266
|
+
displayName: string;
|
|
267
|
+
class: string;
|
|
268
|
+
description: string;
|
|
269
|
+
isRequired: boolean;
|
|
270
|
+
validators: Validator[];
|
|
271
|
+
}
|
|
272
|
+
declare abstract class FormField {
|
|
273
|
+
fieldObject: FieldData;
|
|
274
|
+
constructor(name: string, displayName: string, type: string, category: string);
|
|
275
|
+
static fromObject(fieldObject: FieldData): FormField;
|
|
276
|
+
abstract getFieldNames(): string[];
|
|
277
|
+
protected cleanObject(obj: any): any;
|
|
278
|
+
toJSON(): any;
|
|
279
|
+
get displayName(): string;
|
|
280
|
+
set displayName(newDisplayName: string);
|
|
281
|
+
get name(): string;
|
|
282
|
+
get type(): FieldType;
|
|
283
|
+
get inputType(): string;
|
|
284
|
+
get categoryId(): string;
|
|
285
|
+
set categoryId(categoryId: string);
|
|
286
|
+
get defaultValue(): any;
|
|
287
|
+
set defaultValue(value: any);
|
|
288
|
+
get placeholder(): string | undefined;
|
|
289
|
+
get validators(): Validator[] | undefined;
|
|
290
|
+
get choices(): Choice[];
|
|
291
|
+
set choices(choices: Choice[]);
|
|
292
|
+
get visible(): boolean;
|
|
293
|
+
get visibleIf(): string | undefined;
|
|
294
|
+
get isRequired(): boolean;
|
|
295
|
+
get startWithNewLine(): boolean;
|
|
296
|
+
get requiredForEvaluation(): boolean;
|
|
297
|
+
get maxLength(): number | undefined;
|
|
298
|
+
get min(): number | undefined;
|
|
299
|
+
get max(): number | undefined;
|
|
300
|
+
}
|
|
301
|
+
declare class BasicFormField extends FormField {
|
|
302
|
+
constructor(name: string, displayName: string, type: string, category: string);
|
|
303
|
+
getFieldNames(): string[];
|
|
304
|
+
}
|
|
305
|
+
declare class FileFormField extends FormField {
|
|
306
|
+
constructor(name: string, displayName: string, type: string, category: string, ihs_column_names: string[]);
|
|
307
|
+
getFieldNames(): string[];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
declare class FormSpec {
|
|
311
|
+
private _categories;
|
|
312
|
+
private _fields;
|
|
313
|
+
private _displayName;
|
|
314
|
+
private _templateIcon?;
|
|
315
|
+
private _schemaVersion;
|
|
316
|
+
private _pages;
|
|
317
|
+
constructor(displayName: string, categories: FormFieldCategory[], fields: FormField[], pages?: PageConfig[], templateIcon?: string, schemaVersion?: string);
|
|
318
|
+
static readonly MIN_PARSER_SCHEMA_VERSION = "v1.0.0";
|
|
319
|
+
static readonly MAX_PARSER_SCHEMA_VERSION = "v2.0.0";
|
|
320
|
+
get fieldNames(): string[];
|
|
321
|
+
get schemaVersion(): string;
|
|
322
|
+
get requiresUpgrade(): boolean;
|
|
323
|
+
upgradeToV2(): void;
|
|
324
|
+
get displayName(): string;
|
|
325
|
+
set displayName(newDisplayName: string);
|
|
326
|
+
get templateIcon(): string | undefined;
|
|
327
|
+
set templateIcon(value: string | undefined);
|
|
328
|
+
get categories(): FormFieldCategory[];
|
|
329
|
+
set categories(categories: FormFieldCategory[]);
|
|
330
|
+
get fields(): FormField[];
|
|
331
|
+
set fields(fields: FormField[]);
|
|
332
|
+
get pages(): PageConfig[];
|
|
333
|
+
set pages(value: PageConfig[]);
|
|
334
|
+
addField(field: FormField): void;
|
|
335
|
+
updateField(field: FormField): void;
|
|
336
|
+
removeField(fieldName: string): void;
|
|
337
|
+
getFieldsByCategory(categoryName: string): FormField[];
|
|
338
|
+
validate(): {
|
|
339
|
+
valid: boolean;
|
|
340
|
+
errors?: any[];
|
|
341
|
+
};
|
|
342
|
+
private cleanObject;
|
|
343
|
+
toJSON(): object;
|
|
344
|
+
static fromJSON(jsonString: string): FormSpec;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
interface FormValidatorDefinitions {
|
|
348
|
+
options: EditorValidator[];
|
|
349
|
+
version: number;
|
|
350
|
+
}
|
|
351
|
+
declare class FormFieldValidator implements EditorValidator {
|
|
352
|
+
id: number;
|
|
353
|
+
displayName: string;
|
|
354
|
+
class: string;
|
|
355
|
+
description: string;
|
|
356
|
+
isRequired: boolean;
|
|
357
|
+
validators: Validator[];
|
|
358
|
+
constructor(validatorData: EditorValidator);
|
|
359
|
+
validate(value: any): boolean;
|
|
360
|
+
private validateNumeric;
|
|
361
|
+
private validateText;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
declare const BASE_FIELD_SPECS: {
|
|
365
|
+
schemaVersion: string;
|
|
366
|
+
categories: Category[];
|
|
367
|
+
fields: FieldData[];
|
|
368
|
+
};
|
|
369
|
+
declare const FIELD_TYPE_DEFINITIONS: FormFieldTypeDefinitions;
|
|
370
|
+
declare const DEFAULT_VALIDATOR_DEFINITIONS: FormValidatorDefinitions;
|
|
371
|
+
declare function getBaseFieldSpecs(): FieldData[];
|
|
372
|
+
declare function getBaseCategories(): Category[];
|
|
373
|
+
declare function getBaseFieldNames(): string[];
|
|
374
|
+
|
|
375
|
+
export { BASE_FIELD_SPECS, BasicFormField, type Category, type Choice, DEFAULT_VALIDATOR_DEFINITIONS, type DropdownOption, type EditorValidator, FIELD_TYPE_DEFINITIONS, type FieldData, type FieldGroup, type FieldReference, FieldType, FileFormField, FormField, FormFieldCategory, type FormFieldInputType, type FormFieldType, type FormFieldTypeDefinitions, FormFieldValidator, FormSpec, type FormValidatorDefinitions, type PageConfig, type RHFSchemaOutput, type RHFStep, type ResolvedField, type SurveyElementJSON, type SurveyJSON, type SurveyPageJSON, type UnifiedFormConfig, type Validator, applyDynamicTitles, evaluateExpression, generateRHFSchema, generateSurveyJson, getBaseCategories, getBaseFieldNames, getBaseFieldSpecs, getCategoryName, getPastMonthLabel, getPastYearLabel, getStepDefaultValues, getStepSchema, groupFieldsByCategory, resolvePageFields, validateFormConfig, validateFormSpec, validatePagesConfig };
|