@betterinternship/core 1.2.73 → 1.2.74
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.
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import { ZodType } from 'zod';
|
|
2
|
-
import { ClientField } from './fields.client';
|
|
3
|
-
import { ServerField } from './fields.server';
|
|
4
|
-
export declare const SCHEMA_VERSION = 0;
|
|
5
|
-
export declare const PARTIES: string[];
|
|
6
|
-
export declare const SOURCES: string[];
|
|
7
|
-
export declare const FIELD_TYPES: string[];
|
|
8
|
-
export interface IFormMetadata {
|
|
9
|
-
name: string;
|
|
10
|
-
label: string;
|
|
11
|
-
schema_version: number;
|
|
12
|
-
schema: IFormField[];
|
|
13
|
-
schema_phantoms?: IFormPhantomField[];
|
|
14
|
-
subscribers: IFormSubscriber[];
|
|
15
|
-
signatories: IFormSignatory[];
|
|
16
|
-
required_parties: ('university' | 'entity' | 'student' | 'student-guardian')[];
|
|
17
|
-
params?: IFormParams;
|
|
18
|
-
}
|
|
19
|
-
export interface IFormParams {
|
|
20
|
-
[key: string]: string | IFormParams;
|
|
21
|
-
}
|
|
22
|
-
interface IFormContact {
|
|
23
|
-
name: string;
|
|
24
|
-
honorific: string;
|
|
25
|
-
title: string;
|
|
26
|
-
email: string;
|
|
27
|
-
}
|
|
28
|
-
export type IFormSubscriber = IFormContact;
|
|
29
|
-
export interface IFormSignatory extends IFormContact {
|
|
30
|
-
field: string;
|
|
31
|
-
}
|
|
32
|
-
export interface IFormField {
|
|
33
|
-
field: string;
|
|
34
|
-
type: 'text' | 'signature';
|
|
35
|
-
x: number;
|
|
36
|
-
y: number;
|
|
37
|
-
w: number;
|
|
38
|
-
h: number;
|
|
39
|
-
page: number;
|
|
40
|
-
align_h?: 'left' | 'center' | 'right';
|
|
41
|
-
align_v?: 'top' | 'middle' | 'bottom';
|
|
42
|
-
label: string;
|
|
43
|
-
source: 'auto' | 'prefill' | 'derived' | 'manual';
|
|
44
|
-
party: 'university' | 'entity' | 'student' | 'student-guardian';
|
|
45
|
-
shared: boolean;
|
|
46
|
-
descriptor?: boolean;
|
|
47
|
-
tooltip_label: string;
|
|
48
|
-
validator: string;
|
|
49
|
-
prefiller: string;
|
|
50
|
-
}
|
|
51
|
-
export interface IFormPhantomField {
|
|
52
|
-
field: string;
|
|
53
|
-
label: string;
|
|
54
|
-
type: 'email' | 'param';
|
|
55
|
-
source: 'auto' | 'prefill' | 'derived' | 'manual';
|
|
56
|
-
party: 'university' | 'entity' | 'student' | 'student-guardian';
|
|
57
|
-
shared: boolean;
|
|
58
|
-
descriptor?: boolean;
|
|
59
|
-
tooltip_label: string;
|
|
60
|
-
validator: string;
|
|
61
|
-
prefiller: string;
|
|
62
|
-
}
|
|
63
|
-
export type IFormSourceDomains<SourceDomains extends any[]> = Record<string, SourceDomains[number]>;
|
|
64
|
-
export type IFormFieldValidator = ZodType;
|
|
65
|
-
export type IFormFieldPrefiller<SourceDomains extends any[]> = (sourceDomains: IFormSourceDomains<SourceDomains>) => string;
|
|
66
|
-
export declare class FormMetadata<SourceDomains extends any[]> {
|
|
67
|
-
private readonly formMetadata;
|
|
68
|
-
private readonly fields;
|
|
69
|
-
constructor(formMetadata: IFormMetadata);
|
|
70
|
-
encodeAsJSON(): string;
|
|
71
|
-
static decodeFromJSON<SourceDomains extends any[]>(json: string): FormMetadata<SourceDomains>;
|
|
72
|
-
getLabel(): string;
|
|
73
|
-
getFieldForClient(index: number, sourceDomains?: IFormSourceDomains<SourceDomains>, derivationBase?: IFormParams): ClientField<SourceDomains>;
|
|
74
|
-
getFieldsForClient(sourceDomains?: IFormSourceDomains<SourceDomains>, derivationBase?: IFormParams): ClientField<SourceDomains>[];
|
|
75
|
-
getFieldsForServer(): ServerField[];
|
|
76
|
-
getPhantomFields(): IFormPhantomField[];
|
|
77
|
-
inferParams(): string[];
|
|
78
|
-
getParams(): IFormParams;
|
|
79
|
-
getDescriptors(): IFormField[];
|
|
80
|
-
getSignatoryAsValues(): Record<string, string>;
|
|
81
|
-
private parseValidator;
|
|
82
|
-
private parsePrefiller;
|
|
83
|
-
private enumerateParams;
|
|
84
|
-
private populateParams;
|
|
85
|
-
getSignatories():
|
|
86
|
-
getSubscribers():
|
|
87
|
-
getRequiredParties(): string[];
|
|
88
|
-
}
|
|
89
|
-
export {};
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
import { ClientField } from './fields.client';
|
|
3
|
+
import { ServerField } from './fields.server';
|
|
4
|
+
export declare const SCHEMA_VERSION = 0;
|
|
5
|
+
export declare const PARTIES: string[];
|
|
6
|
+
export declare const SOURCES: string[];
|
|
7
|
+
export declare const FIELD_TYPES: string[];
|
|
8
|
+
export interface IFormMetadata {
|
|
9
|
+
name: string;
|
|
10
|
+
label: string;
|
|
11
|
+
schema_version: number;
|
|
12
|
+
schema: IFormField[];
|
|
13
|
+
schema_phantoms?: IFormPhantomField[];
|
|
14
|
+
subscribers: IFormSubscriber[];
|
|
15
|
+
signatories: IFormSignatory[];
|
|
16
|
+
required_parties: ('university' | 'entity' | 'student' | 'student-guardian')[];
|
|
17
|
+
params?: IFormParams;
|
|
18
|
+
}
|
|
19
|
+
export interface IFormParams {
|
|
20
|
+
[key: string]: string | IFormParams;
|
|
21
|
+
}
|
|
22
|
+
interface IFormContact {
|
|
23
|
+
name: string;
|
|
24
|
+
honorific: string;
|
|
25
|
+
title: string;
|
|
26
|
+
email: string;
|
|
27
|
+
}
|
|
28
|
+
export type IFormSubscriber = IFormContact;
|
|
29
|
+
export interface IFormSignatory extends IFormContact {
|
|
30
|
+
field: string;
|
|
31
|
+
}
|
|
32
|
+
export interface IFormField {
|
|
33
|
+
field: string;
|
|
34
|
+
type: 'text' | 'signature';
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
w: number;
|
|
38
|
+
h: number;
|
|
39
|
+
page: number;
|
|
40
|
+
align_h?: 'left' | 'center' | 'right';
|
|
41
|
+
align_v?: 'top' | 'middle' | 'bottom';
|
|
42
|
+
label: string;
|
|
43
|
+
source: 'auto' | 'prefill' | 'derived' | 'manual';
|
|
44
|
+
party: 'university' | 'entity' | 'student' | 'student-guardian';
|
|
45
|
+
shared: boolean;
|
|
46
|
+
descriptor?: boolean;
|
|
47
|
+
tooltip_label: string;
|
|
48
|
+
validator: string;
|
|
49
|
+
prefiller: string;
|
|
50
|
+
}
|
|
51
|
+
export interface IFormPhantomField {
|
|
52
|
+
field: string;
|
|
53
|
+
label: string;
|
|
54
|
+
type: 'email' | 'param';
|
|
55
|
+
source: 'auto' | 'prefill' | 'derived' | 'manual';
|
|
56
|
+
party: 'university' | 'entity' | 'student' | 'student-guardian';
|
|
57
|
+
shared: boolean;
|
|
58
|
+
descriptor?: boolean;
|
|
59
|
+
tooltip_label: string;
|
|
60
|
+
validator: string;
|
|
61
|
+
prefiller: string;
|
|
62
|
+
}
|
|
63
|
+
export type IFormSourceDomains<SourceDomains extends any[]> = Record<string, SourceDomains[number]>;
|
|
64
|
+
export type IFormFieldValidator = ZodType;
|
|
65
|
+
export type IFormFieldPrefiller<SourceDomains extends any[]> = (sourceDomains: IFormSourceDomains<SourceDomains>) => string;
|
|
66
|
+
export declare class FormMetadata<SourceDomains extends any[]> {
|
|
67
|
+
private readonly formMetadata;
|
|
68
|
+
private readonly fields;
|
|
69
|
+
constructor(formMetadata: IFormMetadata);
|
|
70
|
+
encodeAsJSON(): string;
|
|
71
|
+
static decodeFromJSON<SourceDomains extends any[]>(json: string): FormMetadata<SourceDomains>;
|
|
72
|
+
getLabel(): string;
|
|
73
|
+
getFieldForClient(index: number, sourceDomains?: IFormSourceDomains<SourceDomains>, derivationBase?: IFormParams): ClientField<SourceDomains>;
|
|
74
|
+
getFieldsForClient(sourceDomains?: IFormSourceDomains<SourceDomains>, derivationBase?: IFormParams): ClientField<SourceDomains>[];
|
|
75
|
+
getFieldsForServer(): ServerField[];
|
|
76
|
+
getPhantomFields(): IFormPhantomField[];
|
|
77
|
+
inferParams(): string[];
|
|
78
|
+
getParams(): IFormParams;
|
|
79
|
+
getDescriptors(): IFormField[];
|
|
80
|
+
getSignatoryAsValues(): Record<string, string>;
|
|
81
|
+
private parseValidator;
|
|
82
|
+
private parsePrefiller;
|
|
83
|
+
private enumerateParams;
|
|
84
|
+
private populateParams;
|
|
85
|
+
getSignatories(): IFormContact[];
|
|
86
|
+
getSubscribers(): IFormContact[];
|
|
87
|
+
getRequiredParties(): string[];
|
|
88
|
+
}
|
|
89
|
+
export {};
|
|
@@ -1,227 +1,225 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.FormMetadata =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
exports.FormMetadata = FormMetadata;
|
|
227
|
-
//# sourceMappingURL=form-metadata.js.map
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormMetadata = exports.FIELD_TYPES = exports.SOURCES = exports.PARTIES = exports.SCHEMA_VERSION = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const fields_client_1 = require("./fields.client");
|
|
6
|
+
exports.SCHEMA_VERSION = 0;
|
|
7
|
+
exports.PARTIES = ['student', 'student-guardian', 'university', 'entity'];
|
|
8
|
+
exports.SOURCES = ['auto', 'prefill', 'derived', 'manual'];
|
|
9
|
+
exports.FIELD_TYPES = ['text', 'signature'];
|
|
10
|
+
class FormMetadata {
|
|
11
|
+
formMetadata;
|
|
12
|
+
fields;
|
|
13
|
+
constructor(formMetadata) {
|
|
14
|
+
this.formMetadata = formMetadata;
|
|
15
|
+
this.fields = formMetadata.schema;
|
|
16
|
+
}
|
|
17
|
+
encodeAsJSON() {
|
|
18
|
+
return JSON.stringify(this.formMetadata);
|
|
19
|
+
}
|
|
20
|
+
static decodeFromJSON(json) {
|
|
21
|
+
return JSON.parse(json);
|
|
22
|
+
}
|
|
23
|
+
getLabel() {
|
|
24
|
+
return this.formMetadata.label;
|
|
25
|
+
}
|
|
26
|
+
getFieldForClient(index, sourceDomains, derivationBase) {
|
|
27
|
+
const field = this.fields[index];
|
|
28
|
+
if (!field)
|
|
29
|
+
throw new Error('Field does not exist');
|
|
30
|
+
const finalParams = {
|
|
31
|
+
...derivationBase,
|
|
32
|
+
...sourceDomains,
|
|
33
|
+
...this.formMetadata.params,
|
|
34
|
+
};
|
|
35
|
+
const validator = this.parseValidator(field.field, finalParams);
|
|
36
|
+
const prefiller = this.parsePrefiller(field.field, finalParams);
|
|
37
|
+
const section = field.field.split('.')[0];
|
|
38
|
+
let options = undefined;
|
|
39
|
+
if (validator?.type === 'enum')
|
|
40
|
+
options = validator.options;
|
|
41
|
+
if (validator?.type === 'array') {
|
|
42
|
+
const element = validator.element;
|
|
43
|
+
if (element?.options)
|
|
44
|
+
options = element.options;
|
|
45
|
+
}
|
|
46
|
+
const type = field.type === 'signature'
|
|
47
|
+
? 'signature'
|
|
48
|
+
: validator
|
|
49
|
+
? (0, fields_client_1.getSchemaClientType)(validator)
|
|
50
|
+
: 'text';
|
|
51
|
+
const coerce = (value) => {
|
|
52
|
+
switch (type) {
|
|
53
|
+
case 'number': {
|
|
54
|
+
const n = parseInt(value);
|
|
55
|
+
return isNaN(n) ? 0 : n;
|
|
56
|
+
}
|
|
57
|
+
case 'date': {
|
|
58
|
+
const n = parseInt(value);
|
|
59
|
+
return isNaN(n) ? new Date() : new Date(n);
|
|
60
|
+
}
|
|
61
|
+
case 'checkbox': {
|
|
62
|
+
return !!value?.trim();
|
|
63
|
+
}
|
|
64
|
+
case 'multiselect': {
|
|
65
|
+
return value?.split('\n');
|
|
66
|
+
}
|
|
67
|
+
default:
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
field: field.field,
|
|
73
|
+
shared: field.shared,
|
|
74
|
+
label: field.label,
|
|
75
|
+
source: field.source,
|
|
76
|
+
party: field.party,
|
|
77
|
+
tooltip_label: field.tooltip_label,
|
|
78
|
+
descriptor: field.descriptor,
|
|
79
|
+
coerce,
|
|
80
|
+
type,
|
|
81
|
+
section,
|
|
82
|
+
validator,
|
|
83
|
+
prefiller,
|
|
84
|
+
options,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
getFieldsForClient(sourceDomains, derivationBase) {
|
|
88
|
+
return this.fields
|
|
89
|
+
.map((field, i) => this.getFieldForClient(i, sourceDomains, derivationBase))
|
|
90
|
+
.filter((field) => field !== null);
|
|
91
|
+
}
|
|
92
|
+
getFieldsForServer() {
|
|
93
|
+
return this.fields
|
|
94
|
+
.map((field) => ({
|
|
95
|
+
field: field.field,
|
|
96
|
+
type: field.type,
|
|
97
|
+
x: field.x,
|
|
98
|
+
y: field.y,
|
|
99
|
+
w: field.w,
|
|
100
|
+
h: field.h,
|
|
101
|
+
align_h: field.align_h ?? 'center',
|
|
102
|
+
align_v: field.align_v ?? 'bottom',
|
|
103
|
+
page: field.page,
|
|
104
|
+
}))
|
|
105
|
+
.filter((field) => field !== null);
|
|
106
|
+
}
|
|
107
|
+
getPhantomFields() {
|
|
108
|
+
return this.formMetadata.schema_phantoms ?? [];
|
|
109
|
+
}
|
|
110
|
+
inferParams() {
|
|
111
|
+
const inferenceRegex = /params\[\s*(['"])(.*?)\1\s*\]/g;
|
|
112
|
+
const params = [];
|
|
113
|
+
let match;
|
|
114
|
+
for (const field of this.formMetadata.schema) {
|
|
115
|
+
while ((match = inferenceRegex.exec(field.validator)) !== null)
|
|
116
|
+
if (!params.includes(match[2]))
|
|
117
|
+
params.push(match[2]);
|
|
118
|
+
while ((match = inferenceRegex.exec(field.prefiller)) !== null)
|
|
119
|
+
if (!params.includes(match[2]))
|
|
120
|
+
params.push(match[2]);
|
|
121
|
+
}
|
|
122
|
+
for (const field of this.formMetadata.schema_phantoms ?? []) {
|
|
123
|
+
while ((match = inferenceRegex.exec(field.validator)) !== null)
|
|
124
|
+
if (!params.includes(match[2]))
|
|
125
|
+
params.push(match[2]);
|
|
126
|
+
while ((match = inferenceRegex.exec(field.prefiller)) !== null)
|
|
127
|
+
if (!params.includes(match[2]))
|
|
128
|
+
params.push(match[2]);
|
|
129
|
+
}
|
|
130
|
+
return params;
|
|
131
|
+
}
|
|
132
|
+
getParams() {
|
|
133
|
+
return this.formMetadata.params ?? {};
|
|
134
|
+
}
|
|
135
|
+
getDescriptors() {
|
|
136
|
+
return this.fields.filter((f) => f.descriptor);
|
|
137
|
+
}
|
|
138
|
+
getSignatoryAsValues() {
|
|
139
|
+
const signatories = this.formMetadata.signatories;
|
|
140
|
+
const values = {};
|
|
141
|
+
for (const signatory of signatories)
|
|
142
|
+
values[signatory.field] = signatory.name;
|
|
143
|
+
return values;
|
|
144
|
+
}
|
|
145
|
+
parseValidator(fieldname, params = {}) {
|
|
146
|
+
const field = this.fields.find((f) => f.field === fieldname);
|
|
147
|
+
if (!field)
|
|
148
|
+
return null;
|
|
149
|
+
const d = new Date();
|
|
150
|
+
const defaults = {
|
|
151
|
+
currentDate: d,
|
|
152
|
+
currentDateTimestamp: d.getTime(),
|
|
153
|
+
};
|
|
154
|
+
const internalParams = this.formMetadata.params ?? {};
|
|
155
|
+
const validator = this.populateParams(field.validator, {
|
|
156
|
+
...params,
|
|
157
|
+
...internalParams,
|
|
158
|
+
});
|
|
159
|
+
const ret = `return ${validator}`;
|
|
160
|
+
const evaluator = new Function('z', 'params', ret);
|
|
161
|
+
return evaluator(zod_1.default, { ...params, ...defaults });
|
|
162
|
+
}
|
|
163
|
+
parsePrefiller(fieldname, params = {}) {
|
|
164
|
+
const field = this.fields.find((f) => f.field === fieldname);
|
|
165
|
+
if (!field)
|
|
166
|
+
return null;
|
|
167
|
+
const internalParams = this.formMetadata.params ?? {};
|
|
168
|
+
const prefiller = this.populateParams(field.prefiller, {
|
|
169
|
+
...params,
|
|
170
|
+
...internalParams,
|
|
171
|
+
});
|
|
172
|
+
const ret = `return ${prefiller}`;
|
|
173
|
+
const evaluator = new Function('params', ret);
|
|
174
|
+
return evaluator(params ?? {});
|
|
175
|
+
}
|
|
176
|
+
enumerateParams(s) {
|
|
177
|
+
const detectedParams = s.match(/#\{[^}]*\}/g) ?? [];
|
|
178
|
+
const params = detectedParams.map((dp) => {
|
|
179
|
+
const [fieldName, propertyTree] = dp
|
|
180
|
+
.replaceAll('#{', '')
|
|
181
|
+
.replaceAll('}', '')
|
|
182
|
+
.replaceAll(')', '')
|
|
183
|
+
.split('(');
|
|
184
|
+
const properties = propertyTree?.split('.') ?? [];
|
|
185
|
+
return [fieldName, ...properties];
|
|
186
|
+
});
|
|
187
|
+
return params?.reduce((acc, cur, i) => ((acc[detectedParams[i]] = cur), acc), {});
|
|
188
|
+
}
|
|
189
|
+
populateParams(s, params) {
|
|
190
|
+
const paramsReflection = this.enumerateParams(s);
|
|
191
|
+
const paramsValues = {};
|
|
192
|
+
for (const match in paramsReflection) {
|
|
193
|
+
const path = paramsReflection[match];
|
|
194
|
+
paramsValues[match] = path.reduce((acc, cur) => acc?.[cur], params) ?? '';
|
|
195
|
+
}
|
|
196
|
+
let out = s;
|
|
197
|
+
for (const match in paramsValues) {
|
|
198
|
+
const m = paramsValues[match];
|
|
199
|
+
const replacement = typeof m === 'string' ? m : JSON.stringify(m);
|
|
200
|
+
out = out.replaceAll(match, replacement);
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
getSignatories() {
|
|
205
|
+
return this.formMetadata.signatories.map((signatory) => ({
|
|
206
|
+
name: signatory.name,
|
|
207
|
+
title: signatory.title,
|
|
208
|
+
email: signatory.email,
|
|
209
|
+
honorific: signatory.honorific,
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
getSubscribers() {
|
|
213
|
+
return this.formMetadata.subscribers.map((subscriber) => ({
|
|
214
|
+
name: subscriber.name,
|
|
215
|
+
title: subscriber.title,
|
|
216
|
+
email: subscriber.email,
|
|
217
|
+
honorific: subscriber.honorific,
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
getRequiredParties() {
|
|
221
|
+
return this.formMetadata.required_parties;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
exports.FormMetadata = FormMetadata;
|
|
225
|
+
//# sourceMappingURL=form-metadata.js.map
|