@confed/sanity-types 0.1.0 → 0.1.2-2508111348

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