@clipboard-health/ai-rules 2.7.3 → 2.8.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clipboard-health/ai-rules",
3
3
  "description": "Pre-built AI agent rules for consistent coding standards.",
4
- "version": "2.7.3",
4
+ "version": "2.8.0",
5
5
  "bugs": "https://github.com/ClipboardHealth/core-utils/issues",
6
6
  "keywords": [
7
7
  "ai",
@@ -91,6 +91,26 @@ GET /shifts?filter[verified]=true&sort=startDate,-urgency&page[cursor]=abc&page[
91
91
  - Add contracts to `contract-<microservice-name>` package
92
92
  - Use `ts-rest` with composable Zod schemas (enforced by `enforce-ts-rest-in-controllers`)
93
93
 
94
+ ### Schema rules
95
+
96
+ Use helpers from `@clipboard-health/contract-core` instead of raw Zod methods in contract packages:
97
+
98
+ - Use `dateTimeSchema()` for date fields — not `z.coerce.date()` (too permissive), `z.string().datetime()` (gives string, not Date), or `z.date()` (won't parse JSON strings)
99
+ - Use `requiredEnumWithFallback`/`optionalEnumWithFallback` for enums — not bare `z.enum()` (breaks old mobile clients when new values are added) or `z.enum().catch()` (doesn't compose with `.optional()`)
100
+ - Do not use `.default()` in contracts — client and server can drift on defaults. Set defaults in the service layer.
101
+ - Name schemas with a `Schema` suffix: `ShiftAttributeSchema`, not `shiftAttribute`
102
+ - Export at the DTO boundary (request/response schemas), not every intermediate schema
103
+ - Compose relationships from shared schemas — don't redefine `type` literals per contract
104
+
105
+ ### `parsedApi.ts` vs `api.ts`
106
+
107
+ Frontend repos have two API layers:
108
+
109
+ - **`api.ts`** (legacy) — does not parse responses through Zod schemas. Inferred types say `Date` for `dateTimeSchema()` fields but the runtime value is still a string. Zod transforms (`.transform()`, `dateTimeSchema()`, enum fallbacks) produce **incorrect types at runtime**.
110
+ - **`parsedApi.ts`** — parses both inputs (`z.input`) and outputs (`z.output`) through schemas. Types match runtime values.
111
+
112
+ Use `parsedApi.ts` for all new API calls. However, `parsedApi.ts` means invalid contract schemas will fail at runtime — ensure contracts are forwards-compatible. Do not use `parsedApi.ts` if the contract contains bare `z.enum()` values that the backend may extend, as new enum values will cause parse failures on old clients. Migrate bare `z.enum()` to `requiredEnumWithFallback`/`optionalEnumWithFallback` first.
113
+
94
114
  ## Data Transfer
95
115
 
96
116
  - Do not return database models through APIs or events; map to DTOs exposing only what clients need
@@ -95,6 +95,7 @@ throw new ServiceError({
95
95
  - Use `@clipboard-health/date-time` for all user-facing date formatting and all timezone-dependent operations (start-of-day-in-timezone, business hours, `setHours`, etc.) with an explicit `timeZone` parameter
96
96
  - Use `date-fns` only for timezone-agnostic timestamp math and parsing
97
97
  - Never import `date-fns-tz`, `@date-fns/tz`, `moment`, or `moment-timezone`
98
+ - In contracts, use `dateTimeSchema()` from `contract-core` for date fields — not `z.coerce.date()`, `z.string().datetime()`, or `z.date()`
98
99
 
99
100
  ## Internal Libraries
100
101