@clipboard-health/contract-core 2.2.42 → 2.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 CHANGED
@@ -19,6 +19,10 @@ npm install @clipboard-health/contract-core
19
19
 
20
20
  ### Zod schemas
21
21
 
22
+ #### DateTime schema
23
+
24
+ `dateTimeSchema()` validates strict ISO-8601 datetime strings and transforms them to `Date` objects. Unlike `z.coerce.date()`, it rejects loose inputs like epoch numbers and date-only strings. Composable with `.optional()`, `.nullable()`, etc. at the call site.
25
+
22
26
  #### Enum validation helpers
23
27
 
24
28
  This package provides four enum validation helpers to cover different use cases:
@@ -39,6 +43,7 @@ This package provides four enum validation helpers to cover different use cases:
39
43
  import {
40
44
  apiErrors,
41
45
  booleanString,
46
+ dateTimeSchema,
42
47
  nonEmptyString,
43
48
  optionalEnum,
44
49
  optionalEnumWithFallback,
@@ -90,6 +95,39 @@ try {
90
95
  // => Invalid UUID format
91
96
  }
92
97
 
98
+ // DateTime schema examples
99
+ // Validates strict ISO-8601 datetime strings and transforms to Date objects.
100
+ // Composable with .optional(), .nullable(), etc.
101
+ const createdAt = dateTimeSchema().parse("2026-03-15T10:30:00.000Z");
102
+ // => Date object
103
+ console.log(createdAt instanceof Date); // true
104
+ console.log(createdAt.toISOString()); // "2026-03-15T10:30:00.000Z"
105
+
106
+ try {
107
+ dateTimeSchema().parse("2026-03-15"); // date-only string
108
+ } catch (error) {
109
+ logError(error);
110
+ // => Invalid datetime
111
+ }
112
+
113
+ try {
114
+ dateTimeSchema().parse(1_773_340_050_000); // epoch number
115
+ } catch (error) {
116
+ logError(error);
117
+ // => Expected string, received number
118
+ }
119
+
120
+ // Optional usage — compose at the call site
121
+ const schema = dateTimeSchema().optional();
122
+ // eslint-disable-next-line unicorn/no-useless-undefined
123
+ const noDate = schema.parse(undefined);
124
+ // => undefined
125
+ console.log(noDate);
126
+
127
+ const someDate = schema.parse("2026-03-15T10:30:00.000Z");
128
+ // => Date object
129
+ console.log(someDate);
130
+
93
131
  // Enum with fallback examples
94
132
  /* -- required -- */
95
133
  const requiredStatusEnumSchema = requiredEnumWithFallback(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clipboard-health/contract-core",
3
3
  "description": "Shared Zod schemas for Clipboard's contracts.",
4
- "version": "2.2.42",
4
+ "version": "2.3.0",
5
5
  "bugs": "https://github.com/ClipboardHealth/core-utils/issues",
6
6
  "dependencies": {
7
7
  "tslib": "2.8.1"
@@ -0,0 +1,19 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Validates that the input is a strict ISO-8601 datetime string,
4
+ * then transforms it into a Date object.
5
+ *
6
+ * Composable with `.optional()`, `.nullable()`, etc. at the call site:
7
+ * ```ts
8
+ * z.object({
9
+ * start: dateTimeSchema(),
10
+ * clockIn: dateTimeSchema().optional(),
11
+ * });
12
+ * ```
13
+ *
14
+ * z.input → string (what callers send over the wire)
15
+ * z.output → Date (what callers receive after parsing)
16
+ *
17
+ * Requires `parsedApi.ts` so that schemas are parsed at runtime.
18
+ */
19
+ export declare function dateTimeSchema(): z.ZodEffects<z.ZodString, Date, string>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dateTimeSchema = dateTimeSchema;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Validates that the input is a strict ISO-8601 datetime string,
7
+ * then transforms it into a Date object.
8
+ *
9
+ * Composable with `.optional()`, `.nullable()`, etc. at the call site:
10
+ * ```ts
11
+ * z.object({
12
+ * start: dateTimeSchema(),
13
+ * clockIn: dateTimeSchema().optional(),
14
+ * });
15
+ * ```
16
+ *
17
+ * z.input → string (what callers send over the wire)
18
+ * z.output → Date (what callers receive after parsing)
19
+ *
20
+ * Requires `parsedApi.ts` so that schemas are parsed at runtime.
21
+ */
22
+ function dateTimeSchema() {
23
+ return zod_1.z
24
+ .string()
25
+ .datetime()
26
+ .transform((value) => new Date(value));
27
+ }
28
+ //# sourceMappingURL=dateTime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dateTime.js","sourceRoot":"","sources":["../../../../../../packages/contract-core/src/lib/schemas/dateTime.ts"],"names":[],"mappings":";;AAmBA,wCAKC;AAxBD,6BAAwB;AAExB;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,cAAc;IAC5B,OAAO,OAAC;SACL,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3C,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export * from "./apiError";
2
2
  export * from "./booleanString";
3
+ export * from "./dateTime";
3
4
  export * from "./enum";
4
5
  export * from "./money";
5
6
  export * from "./nonEmptyString";
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./apiError"), exports);
5
5
  tslib_1.__exportStar(require("./booleanString"), exports);
6
+ tslib_1.__exportStar(require("./dateTime"), exports);
6
7
  tslib_1.__exportStar(require("./enum"), exports);
7
8
  tslib_1.__exportStar(require("./money"), exports);
8
9
  tslib_1.__exportStar(require("./nonEmptyString"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/contract-core/src/lib/schemas/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B;AAC3B,0DAAgC;AAChC,iDAAuB;AACvB,kDAAwB;AACxB,2DAAiC;AACjC,qDAA2B;AAC3B,iDAAuB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/contract-core/src/lib/schemas/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B;AAC3B,0DAAgC;AAChC,qDAA2B;AAC3B,iDAAuB;AACvB,kDAAwB;AACxB,2DAAiC;AACjC,qDAA2B;AAC3B,iDAAuB"}