@clipboard-health/contract-core
Advanced tools
Comparing version 0.1.1 to 0.2.0
{ | ||
"name": "@clipboard-health/contract-core", | ||
"description": "Core schemas for Clipboard Health's API contracts.", | ||
"version": "0.1.1", | ||
"description": "Shared Zod schemas for Clipboard Health's contracts.", | ||
"version": "0.2.0", | ||
"dependencies": { | ||
@@ -10,3 +10,3 @@ "tslib": "2.8.0", | ||
"devDependencies": { | ||
"@clipboard-health/testing-core": "0.1.1" | ||
"@clipboard-health/testing-core": "0.2.0" | ||
}, | ||
@@ -19,2 +19,5 @@ "keywords": [], | ||
}, | ||
"scripts": { | ||
"embed": "embedme README.md" | ||
}, | ||
"type": "commonjs", | ||
@@ -21,0 +24,0 @@ "typings": "./src/index.d.ts", |
# @clipboard-health/contract-core <!-- omit from toc --> | ||
Core schemas for Clipboard Health's API contracts. | ||
Shared Zod schemas for Clipboard Health's contracts. | ||
@@ -9,2 +9,3 @@ ## Table of contents <!-- omit from toc --> | ||
- [Usage](#usage) | ||
- [Zod schemas](#zod-schemas) | ||
- [Local development commands](#local-development-commands) | ||
@@ -20,4 +21,57 @@ | ||
### Zod schemas | ||
<!-- prettier-ignore --> | ||
```ts | ||
// ./examples/schemas.ts | ||
import { apiErrors, booleanString, nonEmptyString, uuid } from "@clipboard-health/contract-core"; | ||
import { type ZodError } from "zod"; | ||
function logError(error: unknown) { | ||
console.error((error as ZodError).issues[0]!.message); | ||
} | ||
apiErrors.parse({ | ||
errors: [ | ||
{ | ||
code: "NotFound", | ||
detail: "Resource 'b146a790-9ed1-499f-966d-6c4905dc667f' not found", | ||
id: "6191a8a0-96ff-4d4b-8e0f-746a5ab215f9", | ||
status: "404", | ||
title: "Not Found", | ||
}, | ||
], | ||
}); | ||
booleanString.parse("true"); | ||
try { | ||
booleanString.parse("invalid"); | ||
} catch (error) { | ||
logError(error); | ||
// => Invalid enum value. Expected 'true' | 'false', received 'invalid' | ||
} | ||
nonEmptyString.parse("hello"); | ||
try { | ||
nonEmptyString.parse(""); | ||
} catch (error) { | ||
logError(error); | ||
// => String must contain at least 1 character(s) | ||
} | ||
// UUID validation examples | ||
uuid.parse("b8d617bb-edef-4262-a6e3-6cc807fa1b26"); | ||
try { | ||
uuid.parse("invalid"); | ||
} catch (error) { | ||
logError(error); | ||
// => Invalid UUID format | ||
} | ||
``` | ||
## Local development commands | ||
See [`package.json`](./package.json) `scripts` for a list of commands. |
@@ -5,3 +5,3 @@ import { z } from "zod"; | ||
*/ | ||
declare const apiError: z.ZodObject<{ | ||
export declare const apiError: z.ZodObject<{ | ||
code: z.ZodString; | ||
@@ -69,2 +69,1 @@ detail: z.ZodOptional<z.ZodString>; | ||
export type ApiError = z.infer<typeof apiError>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.apiErrors = void 0; | ||
exports.apiErrors = exports.apiError = void 0; | ||
const zod_1 = require("zod"); | ||
@@ -9,3 +9,3 @@ const nonEmptyString_1 = require("./nonEmptyString"); | ||
*/ | ||
const apiError = zod_1.z.object({ | ||
exports.apiError = zod_1.z.object({ | ||
code: nonEmptyString_1.nonEmptyString, | ||
@@ -21,4 +21,4 @@ detail: zod_1.z.string().optional(), | ||
exports.apiErrors = zod_1.z.object({ | ||
errors: apiError.array().min(0).max(100), | ||
errors: exports.apiError.array().min(0).max(100), | ||
}); | ||
//# sourceMappingURL=apiError.js.map |
@@ -13,3 +13,5 @@ "use strict"; | ||
// eslint-disable-next-line unicorn/better-regex | ||
.regex(/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i); | ||
.regex(/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i, { | ||
message: "Invalid UUID format", | ||
}); | ||
//# sourceMappingURL=uuid.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9060
163
76
1