{"_id":"@apexdevlabs/contentstack-zod","_rev":"5-d2ef3336ad0f04e878bf0dac9ef7d652","name":"@apexdevlabs/contentstack-zod","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"@apexdevlabs/contentstack-zod","version":"1.0.0","keywords":["contentstack","zod","schema","validation","typescript","content-type","headless-cms","cms"],"author":"","license":"MIT","_id":"@apexdevlabs/contentstack-zod@1.0.0","maintainers":[{"name":"apexdevlabs","email":"vishnupillai403@gmail.com"}],"homepage":"","dist":{"shasum":"a95218650d72bef416fb6ada368e03041418406c","tarball":"https://registry.npmjs.org/@apexdevlabs/contentstack-zod/-/contentstack-zod-1.0.0.tgz","fileCount":9,"integrity":"sha512-kLfo6DzA+Ip2UtsnlWzG1VMjY4LpTKvQZ7n5u6PPcmzoOxjypckWonpGaNjZ3cVAWIchJekQGUdSJg1N6NUsBw==","signatures":[{"sig":"MEUCIQCUUOnb2Zl6q8LmKJn02rPFHIv93l0RYVpnzxaF1Z3GdgIgF1cQ0zYihjN9zvhEqT4XTVvHnQxWqUph/Pj4HLRtn/M=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":58637},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=16.0.0"},"exports":{".":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.ts","default":"./dist/index.js"}}},"gitHead":"83472fda366970727b5811c71b9159268d56b624","scripts":{"dev":"tsup --watch","lint":"eslint src/","test":"vitest run","build":"tsup","typecheck":"tsc --noEmit","test:watch":"vitest","prepublishOnly":"npm run build"},"_npmUser":{"name":"apexdevlabs","email":"vishnupillai403@gmail.com"},"repository":{"url":"","type":"git"},"_npmVersion":"10.9.2","description":"Convert Contentstack content type schemas to Zod validation schemas","directories":{},"_nodeVersion":"22.13.1","_hasShrinkwrap":false,"devDependencies":{"zod":"^3.22.4","tsup":"^8.0.1","vitest":"^1.0.4","typescript":"^5.3.2","@types/node":"^20.10.0"},"peerDependencies":{"zod":">=3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/contentstack-zod_1.0.0_1767650916899_0.9546025522172126","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@apexdevlabs/contentstack-zod","version":"1.1.0","keywords":["contentstack","zod","schema","validation","typescript","content-type","headless-cms","cms"],"author":"","license":"MIT","_id":"@apexdevlabs/contentstack-zod@1.1.0","maintainers":[{"name":"apexdevlabs","email":"vishnupillai403@gmail.com"}],"homepage":"","dist":{"shasum":"c0be4b021377e5110a5beef68e2caa8ace979f2f","tarball":"https://registry.npmjs.org/@apexdevlabs/contentstack-zod/-/contentstack-zod-1.1.0.tgz","fileCount":9,"integrity":"sha512-dqQCINML0Xtq5Pg3IcYgoWQZkGTgK4xazSMVRivf21fyGl7j0+MjWa3rkoUEHoJam6PG8LpCG6PlicASNnsYNQ==","signatures":[{"sig":"MEUCIFx9qXkmcQqeNbo+PHYd9tV69k1erpza2QvA9kXBMpP/AiEAvyPXb9sByE2J6neCiOw6v1sgwMbeNOXxfMb02H4ArjQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":58813},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=16.0.0"},"exports":{".":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.ts","default":"./dist/index.js"}}},"gitHead":"78957fc4673a7a6ce3a0ae7f8082c75bd8426b15","scripts":{"dev":"tsup --watch","lint":"eslint src/","test":"vitest run","build":"tsup","typecheck":"tsc --noEmit","test:watch":"vitest","prepublishOnly":"npm run build"},"_npmUser":{"name":"apexdevlabs","email":"vishnupillai403@gmail.com"},"repository":{"url":"","type":"git"},"_npmVersion":"10.9.2","description":"Convert Contentstack content type schemas to Zod validation schemas","directories":{},"_nodeVersion":"22.13.1","_hasShrinkwrap":false,"devDependencies":{"zod":"^3.25.76","tsup":"^8.0.1","vitest":"^1.0.4","typescript":"^5.3.2","@types/node":"^20.10.0"},"peerDependencies":{"zod":">=3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/contentstack-zod_1.1.0_1767796930490_0.5859622494881447","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"@apexdevlabs/contentstack-zod","version":"1.1.1","keywords":["contentstack","zod","schema","validation","typescript","content-type","headless-cms","cms"],"author":"","license":"MIT","_id":"@apexdevlabs/contentstack-zod@1.1.1","maintainers":[{"name":"apexdevlabs","email":"vishnupillai403@gmail.com"}],"homepage":"","dist":{"shasum":"b21153cb86be1eb1e3376d665489037dcf9ce113","tarball":"https://registry.npmjs.org/@apexdevlabs/contentstack-zod/-/contentstack-zod-1.1.1.tgz","fileCount":9,"integrity":"sha512-CCkNrMbOQCw3QgwLG7zWqCJnz2coADtG5Ui0wJiz3mwWAT1gsTECOxg38mJImofIE9D38xj51BgJwH10UFLpvg==","signatures":[{"sig":"MEUCIDPGkm/dwWTxIupyqbPsSoU4Aa1jhCRXx34SCLa3MddfAiEAobpLrw7obL/oBZezU/CZKS+E05BAARUhg/vXt9jF8ew=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":64061},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=16.0.0"},"exports":{".":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.ts","default":"./dist/index.js"}}},"gitHead":"88c55538d5ab9163409af276c248b02df0ad1d41","scripts":{"dev":"tsup --watch","lint":"eslint src/","test":"vitest run","build":"tsup","typecheck":"tsc --noEmit","test:watch":"vitest","prepublishOnly":"npm run build"},"_npmUser":{"name":"apexdevlabs","email":"vishnupillai403@gmail.com"},"repository":{"url":"","type":"git"},"_npmVersion":"10.9.2","description":"Convert Contentstack content type schemas to Zod validation schemas","directories":{},"_nodeVersion":"22.13.1","_hasShrinkwrap":false,"devDependencies":{"zod":"^4.3.5","tsup":"^8.0.1","vitest":"^1.0.4","typescript":"^5.3.2","@types/node":"^20.10.0"},"peerDependencies":{"zod":">=3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/contentstack-zod_1.1.1_1767798023611_0.8137497400880942","host":"s3://npm-registry-packages-npm-production"}},"1.1.2":{"name":"@apexdevlabs/contentstack-zod","version":"1.1.2","keywords":["contentstack","zod","schema","validation","typescript","content-type","headless-cms","cms"],"author":"","license":"MIT","_id":"@apexdevlabs/contentstack-zod@1.1.2","maintainers":[{"name":"apexdevlabs","email":"vishnupillai403@gmail.com"}],"homepage":"","dist":{"shasum":"a785bd92c785e187096132189988b5b0f18b79bb","tarball":"https://registry.npmjs.org/@apexdevlabs/contentstack-zod/-/contentstack-zod-1.1.2.tgz","fileCount":9,"integrity":"sha512-KzhUDqE7wGNJ4ouzE3BSYiaJZaw3VkJPZP2snzARis5a4gMcP3P7hl53SBG4kukAEyb43lpTSaKax4mJueym9w==","signatures":[{"sig":"MEUCIDn4f6d+E0bar5TIJQgWO4th6r8v/LRV3fP24d1CjDS5AiEA/Qel2843eWWKgB55y+Vv5LHOIh6OvrsGnN3gkYCSAe8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":87429},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=16.0.0"},"exports":{".":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.ts","default":"./dist/index.js"}}},"gitHead":"93ee6be89bb73ae51653d10e1739ef5e62726d7f","scripts":{"dev":"tsup --watch","lint":"eslint src/","test":"vitest run","build":"tsup","typecheck":"tsc --noEmit","test:watch":"vitest","prepublishOnly":"npm run build"},"_npmUser":{"name":"apexdevlabs","email":"vishnupillai403@gmail.com"},"repository":{"url":"","type":"git"},"_npmVersion":"10.9.2","description":"Convert Contentstack content type schemas to Zod validation schemas","directories":{},"_nodeVersion":"22.13.1","_hasShrinkwrap":false,"devDependencies":{"zod":"^4.3.5","tsup":"^8.0.1","vitest":"^1.0.4","typescript":"^5.3.2","@types/node":"^20.10.0"},"peerDependencies":{"zod":">=3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/contentstack-zod_1.1.2_1768383464033_0.547135725163743","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"@apexdevlabs/contentstack-zod","version":"1.2.0","description":"Convert Contentstack content type schemas to Zod validation schemas","main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.ts","default":"./dist/index.js"}}},"scripts":{"build":"tsup","dev":"tsup --watch","test":"vitest run","test:watch":"vitest","typecheck":"tsc --noEmit","lint":"eslint src/","prepublishOnly":"npm run build"},"keywords":["contentstack","zod","schema","validation","typescript","content-type","headless-cms","cms"],"author":"","license":"MIT","repository":{"type":"git","url":""},"homepage":"","peerDependencies":{"zod":">=3.0.0"},"devDependencies":{"@types/node":"^20.10.0","tsup":"^8.0.1","typescript":"^5.3.2","vitest":"^1.0.4","zod":"^4.3.5"},"engines":{"node":">=16.0.0"},"_id":"@apexdevlabs/contentstack-zod@1.2.0","gitHead":"2819582ffac37b341293cd5b9499b455702531c2","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-IJiSXoY2J55qESrQs5URLl16dT9OxIn4fKo1jkkBiCej7t0BI6xRA4VKNDeZK3m+0/3KF0t1aM3Jm53PFS1BOQ==","shasum":"22539c08a29b5d2c60f5f96146d4138c9b727924","tarball":"https://registry.npmjs.org/@apexdevlabs/contentstack-zod/-/contentstack-zod-1.2.0.tgz","fileCount":9,"unpackedSize":90940,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDlybpzSk0T9PWUEAxxBzS0dhkHoSJOEJEEd00x1AF/UAiEAyxZD8HpOmV/RzKofbmcEJTpVUbtiF43A0BnQFwNuqwA="}]},"_npmUser":{"name":"apexdevlabs","email":"vishnupillai403@gmail.com"},"directories":{},"maintainers":[{"name":"apexdevlabs","email":"vishnupillai403@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/contentstack-zod_1.2.0_1768404431979_0.8194839940767464"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-05T22:08:36.801Z","modified":"2026-01-14T15:27:12.263Z","1.0.0":"2026-01-05T22:08:37.052Z","1.1.0":"2026-01-07T14:42:10.651Z","1.1.1":"2026-01-07T15:00:23.764Z","1.1.2":"2026-01-14T09:37:44.202Z","1.2.0":"2026-01-14T15:27:12.148Z"},"license":"MIT","keywords":["contentstack","zod","schema","validation","typescript","content-type","headless-cms","cms"],"repository":{"type":"git","url":""},"description":"Convert Contentstack content type schemas to Zod validation schemas","maintainers":[{"name":"apexdevlabs","email":"vishnupillai403@gmail.com"}],"readme":"# contentstack-zod\n\nConvert [Contentstack](https://www.contentstack.com/) content type schemas to [Zod](https://zod.dev/) validation schemas at runtime.\n\n## Features\n\n- **Full field type support**: text, number, boolean, date, JSON, markdown, RTE, select/enum\n- **Complex structures**: references, assets, links, groups, modular blocks, taxonomy\n- **Nested content**: groups with multiple items, global fields in blocks\n- **Validation helpers**: mandatory/optional fields, multiple values\n- **Draft mode**: partial validation for incomplete entries\n- **TypeScript**: full type definitions included\n\n### What it doesn't do (by design)\n\n- Enforce uniqueness constraints\n- Upload assets\n- Resolve references\n- Enforce workflow or field rules\n\n## Installation\n\n```bash\nnpm install contentstack-zod zod\n# or\nyarn add contentstack-zod zod\n# or\npnpm add contentstack-zod zod\n```\n\n> **Note**: `zod` is a peer dependency and must be installed separately.\n\n## Quick Start\n\n```typescript\nimport { contentTypeToZod, contentTypeToDraftZod } from \"contentstack-zod\";\n\n// Fetch your content type from Contentstack\nconst contentType = await contentstack.contentType(\"blog_post\").fetch();\n\n// Create a strict validation schema\nconst BlogPostSchema = contentTypeToZod(contentType);\n\n// Create a draft schema (all fields optional)\nconst DraftSchema = contentTypeToDraftZod(contentType);\n\n// Validate an entry\nconst result = BlogPostSchema.safeParse(entry);\nif (result.success) {\n  console.log(\"Valid entry:\", result.data);\n} else {\n  console.error(\"Validation errors:\", result.error.issues);\n}\n```\n\n## API Reference\n\n### `contentTypeToZod(contentType)`\n\nConverts a Contentstack content type to a Zod schema where mandatory fields are required.\n\n```typescript\nimport { contentTypeToZod } from \"contentstack-zod\";\n\nconst schema = contentTypeToZod(contentType);\nschema.parse(entry); // throws ZodError if invalid\nschema.safeParse(entry); // returns { success, data } or { success, error }\n```\n\n### `contentTypeToDraftZod(contentType)`\n\nCreates a partial schema where all fields are optional. Useful for:\n- LLM-generated content\n- Partial/draft entries\n- Form validation during editing\n\n```typescript\nimport { contentTypeToDraftZod } from \"contentstack-zod\";\n\nconst draftSchema = contentTypeToDraftZod(contentType);\ndraftSchema.parse({ title: \"Just a title\" }); // OK, even if body is required\n```\n\n### `fieldToZod(field)`\n\nConvert a single Contentstack field definition to a Zod schema.\n\n```typescript\nimport { fieldToZod } from \"contentstack-zod\";\n\nconst field = {\n  uid: \"title\",\n  data_type: \"text\",\n  mandatory: true,\n};\n\nconst schema = fieldToZod(field);\n```\n\n### `validateEntry(contentType, entry)`\n\nValidate an entry and get a typed result.\n\n```typescript\nimport { validateEntry } from \"contentstack-zod\";\n\nconst result = validateEntry(contentType, entry);\n\nif (result.success) {\n  console.log(result.data); // typed entry data\n} else {\n  console.log(result.error); // ZodError\n}\n```\n\n### `validateDraft(contentType, entry)`\n\nValidate a partial/draft entry.\n\n```typescript\nimport { validateDraft } from \"contentstack-zod\";\n\nconst result = validateDraft(contentType, partialEntry);\n```\n\n### `extractMissingFields(zodError)`\n\nExtract missing required field paths from a Zod error.\n\n```typescript\nimport { extractMissingFields } from \"contentstack-zod\";\n\nconst result = schema.safeParse(entry);\nif (!result.success) {\n  const missing = extractMissingFields(result.error);\n  console.log(\"Missing fields:\", missing);\n  // [\"title\", \"seo.meta_title\", \"content.0.text_block.text\"]\n}\n```\n\n## Exported Primitive Schemas\n\nYou can also import the base schemas used internally:\n\n```typescript\nimport {\n  AssetSchema,\n  ReferenceSchema,\n  LinkSchema,\n  IsoDateSchema,\n  TaxonomySchema,\n} from \"contentstack-zod\";\n\n// Use for custom validation\nconst customSchema = z.object({\n  featured_image: AssetSchema,\n  related_posts: z.array(ReferenceSchema),\n});\n```\n\n## Field Type Mapping\n\n| Contentstack Type | Zod Schema |\n|-------------------|------------|\n| `text` | `z.string()` |\n| `text` (with enum) | `z.enum([...])` |\n| `number` | `z.number()` |\n| `boolean` | `z.boolean()` |\n| `isodate` | `z.string().datetime()` |\n| `json` | `z.any()` |\n| `file` | `AssetSchema` |\n| `link` | `LinkSchema` |\n| `reference` | `ReferenceSchema` |\n| `global_field` | `ReferenceSchema` |\n| `taxonomy` | `TaxonomySchema` |\n| `group` | `z.object({...})` |\n| `blocks` | `z.array(z.union([...]))` |\n\n### Field Modifiers\n\n- **`mandatory: true`** → field is required\n- **`mandatory: false`** → field is optional (`.optional()`)\n- **`multiple: true`** → field is an array (`z.array(...)`)\n\n## TypeScript Types\n\n```typescript\nimport type {\n  ContentstackContentType,\n  ContentstackField,\n  ContentstackBlock,\n  ContentstackEnum,\n  Asset,\n  Reference,\n  Link,\n  TaxonomyEntry,\n} from \"contentstack-zod\";\n```\n\n## Examples\n\n### Basic Blog Post\n\n```typescript\nconst blogType = {\n  uid: \"blog_post\",\n  schema: [\n    { uid: \"title\", data_type: \"text\", mandatory: true },\n    { uid: \"slug\", data_type: \"text\", mandatory: true },\n    { uid: \"body\", data_type: \"json\", mandatory: true },\n    { uid: \"published_at\", data_type: \"isodate\", mandatory: false },\n    { uid: \"tags\", data_type: \"text\", mandatory: false, multiple: true },\n  ],\n};\n\nconst schema = contentTypeToZod(blogType);\n\nschema.parse({\n  title: \"Hello World\",\n  slug: \"hello-world\",\n  body: { type: \"doc\", content: [] },\n  tags: [\"welcome\", \"first-post\"],\n});\n```\n\n### With Groups and Modular Blocks\n\n```typescript\nconst pageType = {\n  uid: \"page\",\n  schema: [\n    { uid: \"title\", data_type: \"text\", mandatory: true },\n    {\n      uid: \"seo\",\n      data_type: \"group\",\n      mandatory: true,\n      schema: [\n        { uid: \"meta_title\", data_type: \"text\", mandatory: true },\n        { uid: \"meta_description\", data_type: \"text\", mandatory: false },\n      ],\n    },\n    {\n      uid: \"content\",\n      data_type: \"blocks\",\n      mandatory: true,\n      blocks: [\n        {\n          uid: \"hero\",\n          schema: [\n            { uid: \"heading\", data_type: \"text\", mandatory: true },\n            { uid: \"image\", data_type: \"file\", mandatory: true },\n          ],\n        },\n        {\n          uid: \"text_section\",\n          schema: [\n            { uid: \"body\", data_type: \"json\", mandatory: true },\n          ],\n        },\n      ],\n    },\n  ],\n};\n\nconst schema = contentTypeToZod(pageType);\n\nschema.parse({\n  title: \"Home Page\",\n  seo: {\n    meta_title: \"Welcome to Our Site\",\n    meta_description: \"The best site ever\",\n  },\n  content: [\n    {\n      hero: {\n        heading: \"Welcome!\",\n        image: { uid: \"hero-img-123\", url: \"https://...\" },\n      },\n    },\n    {\n      text_section: {\n        body: { type: \"doc\", content: [] },\n      },\n    },\n  ],\n});\n```\n\n### LLM Content Generation\n\n```typescript\nimport { contentTypeToDraftZod, extractMissingFields, contentTypeToZod } from \"contentstack-zod\";\n\n// 1. Validate LLM output (partial OK)\nconst draftSchema = contentTypeToDraftZod(contentType);\nconst llmOutput = await generateWithLLM(prompt);\ndraftSchema.parse(llmOutput);\n\n// 2. Check what's still missing\nconst fullSchema = contentTypeToZod(contentType);\nconst result = fullSchema.safeParse(llmOutput);\n\nif (!result.success) {\n  const missing = extractMissingFields(result.error);\n  console.log(\"Still need:\", missing);\n  // Prompt user or LLM to fill in missing fields\n}\n```\n\n## Development\n\n```bash\n# Install dependencies\nnpm install\n\n# Run tests\nnpm test\n\n# Build\nnpm run build\n\n# Type check\nnpm run typecheck\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md"}