@u-krupaveho-kraba/form-schemas 0.2.0 → 0.3.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 +12 -9
- package/index.js +9 -6
- package/package.json +1 -1
- package/schema/{campaign.schema.json → campaignItem.schema.json} +1966 -1391
- package/schemas/campaign.js +53 -36
- package/schemas/element.js +13 -2
- package/schemas/elementProperties.js +78 -8
- package/schemas/form.js +31 -6
- package/schemas/formDisplay.js +1 -0
- package/types/index.d.ts +7 -4
- package/types/schemas/campaign.d.ts +7371 -6685
- package/types/schemas/element.d.ts +407 -3
- package/types/schemas/elementProperties.d.ts +98 -2
- package/types/schemas/form.d.ts +1556 -43
- package/types/schemas/formDisplay.d.ts +6 -0
- package/types/schemas/step.d.ts +189 -1
package/README.md
CHANGED
|
@@ -18,16 +18,19 @@ npm install @topol/form-schemas zod
|
|
|
18
18
|
- **Form schemas** — `FormSchema`, `StepSchema`, `FormElementSchema`, and the
|
|
19
19
|
per-element-type property schemas, describing the full form JSON tree
|
|
20
20
|
rendered by the Topol form widget.
|
|
21
|
-
- **Campaign schemas** — `
|
|
22
|
-
`CampaignTargetingSchema`, `TriggerConditionSchema`, and
|
|
23
|
-
describing
|
|
21
|
+
- **Campaign schemas** — `CampaignItemSchema`, `VariantSchema`,
|
|
22
|
+
`CampaignTargetingSchema`, `TriggerConditionSchema`, and
|
|
23
|
+
`CampaignItemsFileSchema`, describing one independently-evaluated
|
|
24
|
+
CampaignItem's targeting rules, display trigger, and A/B variants (there is
|
|
25
|
+
no `Campaign` wrapper -- `CampaignItem` is the atomic authored/published
|
|
26
|
+
unit, ADR 0025).
|
|
24
27
|
|
|
25
28
|
## Usage
|
|
26
29
|
|
|
27
30
|
```ts
|
|
28
|
-
import {
|
|
31
|
+
import { CampaignItemSchema } from "@topol/form-schemas";
|
|
29
32
|
|
|
30
|
-
const result =
|
|
33
|
+
const result = CampaignItemSchema.safeParse(payload);
|
|
31
34
|
if (!result.success) {
|
|
32
35
|
// result.error describes exactly which field failed and why
|
|
33
36
|
}
|
|
@@ -40,14 +43,14 @@ Both schema families can be serialized to standard JSON Schema (draft
|
|
|
40
43
|
feeding an LLM the exact shape of valid JSON:
|
|
41
44
|
|
|
42
45
|
```ts
|
|
43
|
-
import { getFormJsonSchema,
|
|
46
|
+
import { getFormJsonSchema, getCampaignItemJsonSchema } from "@topol/form-schemas";
|
|
44
47
|
|
|
45
48
|
const formSchema = getFormJsonSchema();
|
|
46
|
-
const
|
|
49
|
+
const campaignItemSchema = getCampaignItemJsonSchema();
|
|
47
50
|
```
|
|
48
51
|
|
|
49
|
-
The generated
|
|
50
|
-
`schema/
|
|
52
|
+
The generated CampaignItem JSON Schema also ships pre-built in the package at
|
|
53
|
+
`schema/campaignItem.schema.json`, so non-TypeScript consumers (e.g. a backend
|
|
51
54
|
service in another language) can validate against the exact same contract
|
|
52
55
|
without needing to run TypeScript or zod themselves.
|
|
53
56
|
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as z from "zod/mini";
|
|
2
2
|
import { FormSchema } from "./schemas/form.js";
|
|
3
|
-
import {
|
|
3
|
+
import { CampaignItemSchema } from "./schemas/campaign.js";
|
|
4
4
|
export * from "./schemas/helpers.js";
|
|
5
5
|
export * from "./schemas/formDisplay.js";
|
|
6
6
|
export * from "./schemas/elementProperties.js";
|
|
@@ -16,10 +16,13 @@ export function getFormJsonSchema() {
|
|
|
16
16
|
return z.toJSONSchema(FormSchema);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Serializes the
|
|
20
|
-
* exported to ecomailapp so its PHP publish job can validate
|
|
21
|
-
* real schema instead of drifting silently
|
|
19
|
+
* Serializes the CampaignItem contract as standard JSON Schema — the
|
|
20
|
+
* artifact exported to ecomailapp so its PHP publish job can validate each
|
|
21
|
+
* item it builds against the real schema instead of drifting silently
|
|
22
|
+
* (ticket 115/118, ADR 0017). Renamed from `getCampaignJsonSchema` by ADR
|
|
23
|
+
* 0025: there is no `Campaign` wrapper left to serialize, `CampaignItem` is
|
|
24
|
+
* now the atomic authored/published unit.
|
|
22
25
|
*/
|
|
23
|
-
export function
|
|
24
|
-
return z.toJSONSchema(
|
|
26
|
+
export function getCampaignItemJsonSchema() {
|
|
27
|
+
return z.toJSONSchema(CampaignItemSchema);
|
|
25
28
|
}
|