udp-schema 0.1.21 → 0.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/field-helpers.d.ts +55 -0
- package/dist/field-helpers.d.ts.map +1 -0
- package/dist/field-helpers.js +85 -0
- package/dist/field-helpers.js.map +1 -0
- package/dist/field-meta.d.ts +40 -0
- package/dist/field-meta.d.ts.map +1 -0
- package/dist/field-meta.js +1025 -0
- package/dist/field-meta.js.map +1 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/dist/progress-fields.d.ts +28 -0
- package/dist/progress-fields.d.ts.map +1 -0
- package/dist/progress-fields.js +207 -0
- package/dist/progress-fields.js.map +1 -0
- package/dist/step-01.schema.d.ts +5 -5
- package/dist/step-01.schema.d.ts.map +1 -1
- package/dist/step-01.schema.js +5 -5
- package/dist/step-01.schema.js.map +1 -1
- package/dist/step-02.schema.js +1 -1
- package/dist/step-02.schema.js.map +1 -1
- package/dist/step-06.schema.d.ts +1 -1
- package/dist/step-07.schema.js +1 -1
- package/dist/step-07.schema.js.map +1 -1
- package/dist/step-14.schema.d.ts +2 -2
- package/dist/{helpers.d.ts → zod-helpers.d.ts} +1 -1
- package/dist/zod-helpers.d.ts.map +1 -0
- package/dist/{helpers.js → zod-helpers.js} +1 -1
- package/dist/zod-helpers.js.map +1 -0
- package/package.json +1 -1
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convenience helpers for accessing UDP field metadata.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the dating-schema `field-helpers.ts` pattern:
|
|
5
|
+
* pre-built lookup maps with `getUdpFieldOptions()` and `getUdpFieldMeta()`.
|
|
6
|
+
*
|
|
7
|
+
* @module udp-schema/field-helpers
|
|
8
|
+
*/
|
|
9
|
+
import { type UdpFieldMeta, type UdpFieldOption } from './field-meta.js';
|
|
10
|
+
/**
|
|
11
|
+
* Get the `{ value, label }` options array for a UDP field by its key.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { getUdpFieldOptions } from 'udp-schema';
|
|
16
|
+
* const opts = getUdpFieldOptions('desireToBeLeader');
|
|
17
|
+
* // → [{ value: 'YES_STRONGLY', label: 'desireToBeLeader_YES_STRONGLY' }, ...]
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function getUdpFieldOptions(fieldKey: string): readonly UdpFieldOption[];
|
|
21
|
+
/**
|
|
22
|
+
* Get full field metadata (label, step, component, options, etc.) by key.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { getUdpFieldMeta } from 'udp-schema';
|
|
27
|
+
* const meta = getUdpFieldMeta('gender');
|
|
28
|
+
* // → { key: 'gender', step: 1, labelKey: 'gender', component: 'genderSelector', options: [...], immutable: true }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function getUdpFieldMeta(fieldKey: string): UdpFieldMeta | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Get all field metadata entries for a given step number.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { getUdpStepFields } from 'udp-schema';
|
|
38
|
+
* const step5Fields = getUdpStepFields(5);
|
|
39
|
+
* // → [{ key: 'desireToBeLeader', ... }, { key: 'desiredPoliticalPosition', ... }, ...]
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function getUdpStepFields(stepNumber: number): readonly UdpFieldMeta[];
|
|
43
|
+
/**
|
|
44
|
+
* Get the list of field keys that are immutable after volunteer approval.
|
|
45
|
+
* These fields can only be changed by a volunteer in survey-mode once approved.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { getImmutableFields } from 'udp-schema';
|
|
50
|
+
* const locked = getImmutableFields();
|
|
51
|
+
* // → ['firstName', 'middleName', 'lastName', 'gender', 'dateOfBirth', 'phonePrimary']
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function getImmutableFields(): readonly string[];
|
|
55
|
+
//# sourceMappingURL=field-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-helpers.d.ts","sourceRoot":"","sources":["../src/field-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAkB,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA8BzF;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,cAAc,EAAE,CAE9E;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAE1E;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,YAAY,EAAE,CAE5E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEtD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convenience helpers for accessing UDP field metadata.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the dating-schema `field-helpers.ts` pattern:
|
|
5
|
+
* pre-built lookup maps with `getUdpFieldOptions()` and `getUdpFieldMeta()`.
|
|
6
|
+
*
|
|
7
|
+
* @module udp-schema/field-helpers
|
|
8
|
+
*/
|
|
9
|
+
import { UDP_FIELD_META } from './field-meta.js';
|
|
10
|
+
// ─── Pre-built lookup maps ───────────────────────────────────────────────────
|
|
11
|
+
const optionsMap = new Map();
|
|
12
|
+
const fieldMap = new Map();
|
|
13
|
+
const stepFieldsMap = new Map();
|
|
14
|
+
const immutableFieldKeys = [];
|
|
15
|
+
for (const meta of Object.values(UDP_FIELD_META)) {
|
|
16
|
+
fieldMap.set(meta.key, meta);
|
|
17
|
+
if (meta.options) {
|
|
18
|
+
optionsMap.set(meta.key, meta.options);
|
|
19
|
+
}
|
|
20
|
+
if (meta.immutable) {
|
|
21
|
+
immutableFieldKeys.push(meta.key);
|
|
22
|
+
}
|
|
23
|
+
const existing = stepFieldsMap.get(meta.step);
|
|
24
|
+
if (existing) {
|
|
25
|
+
existing.push(meta);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
stepFieldsMap.set(meta.step, [meta]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// ─── Public helpers ──────────────────────────────────────────────────────────
|
|
32
|
+
/**
|
|
33
|
+
* Get the `{ value, label }` options array for a UDP field by its key.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { getUdpFieldOptions } from 'udp-schema';
|
|
38
|
+
* const opts = getUdpFieldOptions('desireToBeLeader');
|
|
39
|
+
* // → [{ value: 'YES_STRONGLY', label: 'desireToBeLeader_YES_STRONGLY' }, ...]
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function getUdpFieldOptions(fieldKey) {
|
|
43
|
+
return optionsMap.get(fieldKey) ?? [];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get full field metadata (label, step, component, options, etc.) by key.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { getUdpFieldMeta } from 'udp-schema';
|
|
51
|
+
* const meta = getUdpFieldMeta('gender');
|
|
52
|
+
* // → { key: 'gender', step: 1, labelKey: 'gender', component: 'genderSelector', options: [...], immutable: true }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function getUdpFieldMeta(fieldKey) {
|
|
56
|
+
return fieldMap.get(fieldKey);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get all field metadata entries for a given step number.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { getUdpStepFields } from 'udp-schema';
|
|
64
|
+
* const step5Fields = getUdpStepFields(5);
|
|
65
|
+
* // → [{ key: 'desireToBeLeader', ... }, { key: 'desiredPoliticalPosition', ... }, ...]
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function getUdpStepFields(stepNumber) {
|
|
69
|
+
return stepFieldsMap.get(stepNumber) ?? [];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the list of field keys that are immutable after volunteer approval.
|
|
73
|
+
* These fields can only be changed by a volunteer in survey-mode once approved.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { getImmutableFields } from 'udp-schema';
|
|
78
|
+
* const locked = getImmutableFields();
|
|
79
|
+
* // → ['firstName', 'middleName', 'lastName', 'gender', 'dateOfBirth', 'phonePrimary']
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export function getImmutableFields() {
|
|
83
|
+
return immutableFieldKeys;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=field-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-helpers.js","sourceRoot":"","sources":["../src/field-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAA0C,MAAM,iBAAiB,CAAC;AAEzF,gFAAgF;AAEhF,MAAM,UAAU,GAAG,IAAI,GAAG,EAAqC,CAAC;AAChE,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;AACjD,MAAM,aAAa,GAAG,IAAI,GAAG,EAA0B,CAAC;AACxD,MAAM,kBAAkB,GAAa,EAAE,CAAC;AAExC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC;IACjD,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAE7B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,QAAQ,EAAE,CAAC;QACb,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAED,gFAAgF;AAEhF;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;AACxC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAkB;IACjD,OAAO,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;AAC7C,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,kBAAkB,CAAC;AAC5B,CAAC","sourcesContent":["/**\n * Convenience helpers for accessing UDP field metadata.\n *\n * Mirrors the dating-schema `field-helpers.ts` pattern:\n * pre-built lookup maps with `getUdpFieldOptions()` and `getUdpFieldMeta()`.\n *\n * @module udp-schema/field-helpers\n */\n\nimport { UDP_FIELD_META, type UdpFieldMeta, type UdpFieldOption } from './field-meta.js';\n\n// ─── Pre-built lookup maps ───────────────────────────────────────────────────\n\nconst optionsMap = new Map<string, readonly UdpFieldOption[]>();\nconst fieldMap = new Map<string, UdpFieldMeta>();\nconst stepFieldsMap = new Map<number, UdpFieldMeta[]>();\nconst immutableFieldKeys: string[] = [];\n\nfor (const meta of Object.values(UDP_FIELD_META)) {\n fieldMap.set(meta.key, meta);\n\n if (meta.options) {\n optionsMap.set(meta.key, meta.options);\n }\n\n if (meta.immutable) {\n immutableFieldKeys.push(meta.key);\n }\n\n const existing = stepFieldsMap.get(meta.step);\n if (existing) {\n existing.push(meta);\n } else {\n stepFieldsMap.set(meta.step, [meta]);\n }\n}\n\n// ─── Public helpers ──────────────────────────────────────────────────────────\n\n/**\n * Get the `{ value, label }` options array for a UDP field by its key.\n *\n * @example\n * ```ts\n * import { getUdpFieldOptions } from 'udp-schema';\n * const opts = getUdpFieldOptions('desireToBeLeader');\n * // → [{ value: 'YES_STRONGLY', label: 'desireToBeLeader_YES_STRONGLY' }, ...]\n * ```\n */\nexport function getUdpFieldOptions(fieldKey: string): readonly UdpFieldOption[] {\n return optionsMap.get(fieldKey) ?? [];\n}\n\n/**\n * Get full field metadata (label, step, component, options, etc.) by key.\n *\n * @example\n * ```ts\n * import { getUdpFieldMeta } from 'udp-schema';\n * const meta = getUdpFieldMeta('gender');\n * // → { key: 'gender', step: 1, labelKey: 'gender', component: 'genderSelector', options: [...], immutable: true }\n * ```\n */\nexport function getUdpFieldMeta(fieldKey: string): UdpFieldMeta | undefined {\n return fieldMap.get(fieldKey);\n}\n\n/**\n * Get all field metadata entries for a given step number.\n *\n * @example\n * ```ts\n * import { getUdpStepFields } from 'udp-schema';\n * const step5Fields = getUdpStepFields(5);\n * // → [{ key: 'desireToBeLeader', ... }, { key: 'desiredPoliticalPosition', ... }, ...]\n * ```\n */\nexport function getUdpStepFields(stepNumber: number): readonly UdpFieldMeta[] {\n return stepFieldsMap.get(stepNumber) ?? [];\n}\n\n/**\n * Get the list of field keys that are immutable after volunteer approval.\n * These fields can only be changed by a volunteer in survey-mode once approved.\n *\n * @example\n * ```ts\n * import { getImmutableFields } from 'udp-schema';\n * const locked = getImmutableFields();\n * // → ['firstName', 'middleName', 'lastName', 'gender', 'dateOfBirth', 'phonePrimary']\n * ```\n */\nexport function getImmutableFields(): readonly string[] {\n return immutableFieldKeys;\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UDP Field Metadata
|
|
3
|
+
* ==================
|
|
4
|
+
* Single source of truth for field-level metadata across all 14 UDP steps.
|
|
5
|
+
* Both frontend and backend import this — NO hardcoded option arrays elsewhere.
|
|
6
|
+
*
|
|
7
|
+
* Labels use i18n translation keys (not hardcoded English strings).
|
|
8
|
+
*
|
|
9
|
+
* @module udp-schema/field-meta
|
|
10
|
+
*/
|
|
11
|
+
export interface UdpFieldOption {
|
|
12
|
+
value: string;
|
|
13
|
+
/** i18n translation key */
|
|
14
|
+
label: string;
|
|
15
|
+
}
|
|
16
|
+
export interface UdpFieldMeta {
|
|
17
|
+
/** Unique field key — matches the Zod schema key and form field key */
|
|
18
|
+
key: string;
|
|
19
|
+
/** Step number (1–14) this field belongs to */
|
|
20
|
+
step: number;
|
|
21
|
+
/** i18n key for the field label */
|
|
22
|
+
labelKey: string;
|
|
23
|
+
/** i18n key for help text / description */
|
|
24
|
+
descriptionKey?: string;
|
|
25
|
+
/** Component type hint (matches frontend FieldComponentType) */
|
|
26
|
+
component: string;
|
|
27
|
+
/** Options for select / radio / multiCheckbox / genderSelector fields */
|
|
28
|
+
options?: readonly UdpFieldOption[];
|
|
29
|
+
/** Whether the field is required to complete the step */
|
|
30
|
+
required?: boolean;
|
|
31
|
+
/** i18n key for the toast shown after saving this field's step */
|
|
32
|
+
successMessageKey?: string;
|
|
33
|
+
/**
|
|
34
|
+
* If true, this field is locked after first volunteer approval.
|
|
35
|
+
* Only a volunteer (survey-mode) can change it once locked.
|
|
36
|
+
*/
|
|
37
|
+
immutable?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare const UDP_FIELD_META: Record<string, UdpFieldMeta>;
|
|
40
|
+
//# sourceMappingURL=field-meta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-meta.d.ts","sourceRoot":"","sources":["../src/field-meta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAC;IACZ,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;IAClB,yEAAyE;IACzE,OAAO,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IACpC,yDAAyD;IACzD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kEAAkE;IAClE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AA66BD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAyM9C,CAAC"}
|