@confed/sanity-types 0.1.0 → 0.1.2

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 ADDED
@@ -0,0 +1,219 @@
1
+ # @confed/sanity-types
2
+
3
+ A TypeScript types package for the Confederation College Sanity CMS backend. This package provides auto-generated TypeScript definitions for all Sanity schema types, ensuring type safety across your frontend applications and API integrations.
4
+
5
+ > 🎉 **Status: FULLY AUTOMATED** - Types are automatically regenerated on every commit via Husky pre-commit hooks!
6
+
7
+ ## How It Works
8
+
9
+ This package uses [Sanity TypeGen](https://www.sanity.io/docs/sanity-typegen) to automatically generate TypeScript definitions from your Sanity schema. The types are generated from:
10
+
11
+ 1. **Schema definitions** (`schema.json`) - Contains all your content type schemas
12
+ 2. **GROQ queries** - Any TypeScript/JavaScript files in the `src/` directory that contain GROQ queries
13
+
14
+ ### Complete Workflow:
15
+
16
+ 1. **Schema Changes** → You modify Sanity schemas
17
+ 2. **Local Generation** → Pre-commit hook generates types automatically
18
+ 3. **Commit** → Types and schema changes committed together
19
+ 4. **CI/CD Trigger** → GitHub Actions workflow runs on push
20
+ 5. **Verification** → Types regenerated in CI for verification
21
+ 6. **Publishing** → If types changed, version bumped and published to npm
22
+ 7. **No Circular Commits** → CI never commits back to your repository
23
+
24
+ The generated types provide:
25
+
26
+ - Full type safety for all your content types
27
+ - IntelliSense and autocomplete in your IDE
28
+ - Compile-time error checking for content structure
29
+ - Reference type safety for cross-referenced documents
30
+
31
+ ## Available Types
32
+
33
+ ### Content Types
34
+
35
+ - **`Program`** - Academic programs with details, requirements, and metadata
36
+ - **`School`** - Academic schools/departments within the college
37
+ - **`Campus`** - Physical campus locations
38
+ - **`Area`** - Areas of study or interest
39
+ - **`Person`** - Faculty, staff, and other individuals
40
+ - **`Event`** - College events, workshops, and activities
41
+ - **`NewsArticle`** - News and announcements
42
+ - **`Webpage`** - General web pages and content
43
+ - **`Testimonial`** - Student and stakeholder testimonials
44
+ - **`Credential`** - Academic credentials and certifications
45
+ - **`ProgramIntake`** - Program intake periods and delivery methods
46
+ - **`AdmissionRequirements`** - Program admission criteria
47
+ - **`Duration`** - Program duration and time requirements
48
+ - **`ProgramFile`** - Program-related documents and files
49
+
50
+ ### Navigation & Structure
51
+
52
+ - **`Menu`** - Navigation menus (header, footer, sidebar, mobile)
53
+ - **`MenuItem`** - Individual menu items with links and sub-items
54
+ - **`Link`** - Internal and external links with metadata
55
+ - **`Redirect`** - URL redirects for content migration
56
+
57
+ ### Content Blocks & Media
58
+
59
+ - **`PtBasic`** - Portable text content with rich formatting
60
+ - **`Figure`** - Images with accessibility features
61
+ - **`AccessibleImage`** - Accessible image components
62
+ - **`Button`** - Call-to-action buttons
63
+ - **`YoutubeVideo`** - Embedded YouTube videos
64
+
65
+ ### SEO & Metadata
66
+
67
+ - **`Seo`** - Search engine optimization metadata
68
+ - **`Slug`** - URL-friendly identifiers
69
+
70
+ ### Sanity System Types
71
+
72
+ - **`SanityImageAsset`** - Image assets with metadata
73
+ - **`SanityFileAsset`** - File assets
74
+ - **`SanityImageHotspot`** - Image hotspot coordinates
75
+ - **`SanityImageCrop`** - Image cropping data
76
+ - **`SanityImageMetadata`** - Image metadata including dimensions and palette
77
+ - **`Geopoint`** - Geographic coordinates
78
+ - **`MediaTag`** - Media tagging system
79
+
80
+ ## Installation
81
+
82
+ ```bash
83
+ npm install @confed/sanity-types
84
+ ```
85
+
86
+ ## Usage
87
+
88
+ ```typescript
89
+ import type {Program, Event, Person} from '@confed/sanity-types'
90
+
91
+ // Use types in your components or API functions
92
+ const program: Program = {
93
+ _id: 'program-123',
94
+ _type: 'program',
95
+ _createdAt: '2024-01-01T00:00:00Z',
96
+ _updatedAt: '2024-01-01T00:00:00Z',
97
+ _rev: 'rev-123',
98
+ name: 'Computer Programming',
99
+ slug: {_type: 'slug', current: 'computer-programming'},
100
+ // ... other required fields
101
+ }
102
+ ```
103
+
104
+ ## Keeping Types Up to Date
105
+
106
+ The types in this package are automatically generated and should **never be manually edited**. This project is configured with automatic type generation on every commit, so types stay current automatically.
107
+
108
+ **Current Status:** ✅ **FULLY AUTOMATED** - Types are regenerated on every commit via Husky pre-commit hooks, and automatically published to npm via CI/CD when changes are detected.
109
+
110
+ **Workflow:**
111
+
112
+ 1. **Local Development:** Types generated automatically before each commit
113
+ 2. **CI/CD:** Types verified and published to npm if changes detected
114
+ 3. **No Circular Commits:** CI never commits back to your repository
115
+
116
+ To keep them current:
117
+
118
+ ### 1. Generate Types After Schema Changes
119
+
120
+ Whenever you modify your Sanity schemas, regenerate the types:
121
+
122
+ ```bash
123
+ # From the root directory
124
+ npm run gen:types
125
+ ```
126
+
127
+ This command runs:
128
+
129
+ - `npm run schema:extract` - Extracts the latest schema
130
+ - `npm run typegen` - Generates TypeScript definitions
131
+
132
+ ### 2. Automatic Generation (Recommended)
133
+
134
+ Set up automatic type generation in your development workflow:
135
+
136
+ ```bash
137
+ # Watch for schema changes and regenerate types
138
+ npm run typegen -- --watch
139
+ ```
140
+
141
+ ### 3. Pre-commit Hook (Currently Active!)
142
+
143
+ This project has Husky pre-commit hooks already configured and working. The types are automatically regenerated on every commit:
144
+
145
+ ```bash
146
+ # The hook is already set up at .husky/pre-commit
147
+ # It runs: npm run gen:types
148
+
149
+ # To verify it's working, make a schema change and commit:
150
+ git add .
151
+ git commit -m "your message"
152
+ # Types will be automatically regenerated before commit
153
+ ```
154
+
155
+ **Note:** The pre-commit hook is already active in this project, so you don't need to set it up manually.
156
+
157
+ ### 4. CI/CD Integration (Automated Publishing)
158
+
159
+ This project has automated CI/CD that handles npm publishing when types change:
160
+
161
+ ```yaml
162
+ # .github/workflows/publish-types.yml
163
+ # Automatically runs on schema changes:
164
+ # - Generates types in CI for verification
165
+ # - Bumps version and publishes to npm if types changed
166
+ # - Does NOT commit back to repository (no circular commits)
167
+ ```
168
+
169
+ **Note:** The CI workflow only handles publishing to npm. Type generation and commits are handled locally via pre-commit hooks.
170
+
171
+ ## Configuration
172
+
173
+ The type generation is configured in `sanity-typegen.json` at the project root:
174
+
175
+ ```json
176
+ {
177
+ "schema": "./schema.json",
178
+ "path": ["./src/**/*.{ts,tsx,js,jsx}"],
179
+ "generates": "./packages/sanity-types/sanity.types.ts",
180
+ "overloadClientMethods": true
181
+ }
182
+ ```
183
+
184
+ ## Troubleshooting
185
+
186
+ ### Types Not Updating
187
+
188
+ - Ensure you're running `npm run gen:types` from the project root
189
+ - Check that your schema changes are saved
190
+ - Verify the `sanity-typegen.json` configuration
191
+
192
+ ### Type Errors
193
+
194
+ - Regenerate types after schema changes
195
+ - Check that your content structure matches the schema
196
+ - Ensure all required fields are provided
197
+
198
+ ### Build Issues
199
+
200
+ - Clear your TypeScript cache
201
+ - Restart your development server
202
+ - Verify the package is properly linked in your workspace
203
+
204
+ ## Contributing
205
+
206
+ 1. **Never edit `sanity.types.ts` directly** - it's auto-generated
207
+ 2. Make schema changes in the appropriate schema files
208
+ 3. Run `npm run gen:types` to update types
209
+ 4. Commit both schema changes and generated types
210
+
211
+ ## Dependencies
212
+
213
+ - `sanity` - Sanity CMS framework
214
+ - `@sanity/typegen` - Type generation tool
215
+ - `typescript` - TypeScript compiler
216
+
217
+ ## License
218
+
219
+ This package is part of the Confederation College backend project and follows the same licensing terms.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@confed/sanity-types",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "files": [
package/sanity.types.ts CHANGED
@@ -374,7 +374,6 @@ export type ProgramFile = {
374
374
  | 'studentGuide'
375
375
  | 'other'
376
376
  isActive?: boolean
377
- sortOrder?: number
378
377
  }
379
378
 
380
379
  export type Testimonial = {
@@ -561,6 +560,7 @@ export type Program = {
561
560
  name: string
562
561
  slug: Slug
563
562
  shortLink?: string
563
+ publicStatus: 'PLANNED' | 'ACTIVE' | 'PAUSED' | 'RETIRED'
564
564
  featuredImage?: {
565
565
  asset?: {
566
566
  _ref: string