@goldenhippo/builder-cart-schemas 0.1.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 +141 -0
- package/dist/data/index.d.mts +604 -0
- package/dist/data/index.d.ts +604 -0
- package/dist/data/index.js +3487 -0
- package/dist/data/index.js.map +1 -0
- package/dist/data/index.mjs +3476 -0
- package/dist/data/index.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4233 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4219 -0
- package/dist/index.mjs.map +1 -0
- package/dist/page/index.d.mts +147 -0
- package/dist/page/index.d.ts +147 -0
- package/dist/page/index.js +691 -0
- package/dist/page/index.js.map +1 -0
- package/dist/page/index.mjs +689 -0
- package/dist/page/index.mjs.map +1 -0
- package/dist/section/index.d.mts +22 -0
- package/dist/section/index.d.ts +22 -0
- package/dist/section/index.js +63 -0
- package/dist/section/index.js.map +1 -0
- package/dist/section/index.mjs +60 -0
- package/dist/section/index.mjs.map +1 -0
- package/package.json +100 -0
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# @goldenhippo/builder-cart-schemas
|
|
2
|
+
|
|
3
|
+
Shared TypeScript types and Builder.io model definitions for Golden Hippo's cart/commerce Builder.io integration. This package provides factory functions for creating Builder.io content models and corresponding TypeScript content types for consuming model data.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @goldenhippo/builder-cart-schemas
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Exports
|
|
12
|
+
|
|
13
|
+
The package provides multiple entry points for granular imports:
|
|
14
|
+
|
|
15
|
+
| Entry Point | Description |
|
|
16
|
+
| ------------------------------------------- | -------------------------------------------------- |
|
|
17
|
+
| `@goldenhippo/builder-cart-schemas` | All model creators and content types |
|
|
18
|
+
| `@goldenhippo/builder-cart-schemas/data` | Data model creators and content types |
|
|
19
|
+
| `@goldenhippo/builder-cart-schemas/page` | Page model creator and content types |
|
|
20
|
+
| `@goldenhippo/builder-cart-schemas/section` | Section/component model creators and content types |
|
|
21
|
+
|
|
22
|
+
Core types (`ModelShape`, `BuilderIOFieldTypes`, etc.) are available from `@goldenhippo/builder-types`.
|
|
23
|
+
|
|
24
|
+
## Models
|
|
25
|
+
|
|
26
|
+
### Data Models
|
|
27
|
+
|
|
28
|
+
| Model | Creator | Content Type |
|
|
29
|
+
| ------------------------- | ---------------------------------------------------------- | -------------------------------------- |
|
|
30
|
+
| Product | `createProductModel(props)` | `BuilderProductContent` |
|
|
31
|
+
| Product Category | `createCategoryModel()` | `BuilderProductCategoryContent` |
|
|
32
|
+
| Product Tag | `createProductTagModel()` | `BuilderProductTagContent` |
|
|
33
|
+
| Product Ingredient | `createIngredientsModel()` | `BuilderIngredientContent` |
|
|
34
|
+
| Product Use Case | `createProductUseCaseModel()` | `BuilderProductUseCaseContent` |
|
|
35
|
+
| Product Grid Filter Group | `createProductGridConfigModel(models)` | `BuilderProductGridFilterGroupContent` |
|
|
36
|
+
| Blog Category | `createBlogCategoryModel()` | `BuilderBlogCategoryContent` |
|
|
37
|
+
| Blog Comment | `createBlogCommentModel(pageModelId)` | `BuilderBlogCommentContent` |
|
|
38
|
+
| Brand Config | `createBrandConfigModel(gridFilterModelId, bannerModelId)` | `BuilderBrandConfigContent` |
|
|
39
|
+
|
|
40
|
+
### Page Models
|
|
41
|
+
|
|
42
|
+
| Model | Creator | Content Type |
|
|
43
|
+
| ----- | ------------------------ | -------------------------------------------------------------------------------------------------------------- |
|
|
44
|
+
| Page | `createPageModel(props)` | `BuilderPageContent` (union of `BuilderPdpPageContent`, `BuilderBlogPageContent`, `BuilderGeneralPageContent`) |
|
|
45
|
+
|
|
46
|
+
### Section Models
|
|
47
|
+
|
|
48
|
+
| Model | Creator | Content Type |
|
|
49
|
+
| ----------------------- | ------------------------------------------- | ------------------------------------- |
|
|
50
|
+
| Site Banner | `createSiteBannerModel(editUrl)` | `BuilderSiteBannerModelContent` |
|
|
51
|
+
| Default Website Section | `createDefaultWebsiteSectionModel(editUrl)` | `BuilderDefaultWebsiteSectionContent` |
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
### Creating model definitions
|
|
56
|
+
|
|
57
|
+
Model creators return a `ModelShape` object suitable for registration with Builder.io's API. Some models require IDs of other models they reference.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { createCategoryModel, createProductModel, createPageModel } from '@goldenhippo/builder-cart-schemas';
|
|
61
|
+
|
|
62
|
+
// Simple model (no dependencies)
|
|
63
|
+
const categoryModel = createCategoryModel();
|
|
64
|
+
|
|
65
|
+
// Model with dependencies (requires other model IDs)
|
|
66
|
+
const productModel = createProductModel({
|
|
67
|
+
ingredientsModelId: '<builder-model-id>',
|
|
68
|
+
categoryModelId: '<builder-model-id>',
|
|
69
|
+
tagModelId: '<builder-model-id>',
|
|
70
|
+
useCaseModelId: '<builder-model-id>',
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Page model (references multiple models)
|
|
74
|
+
const pageModel = createPageModel({
|
|
75
|
+
productModelId: '<builder-model-id>',
|
|
76
|
+
productGroupModelId: '<builder-model-id>',
|
|
77
|
+
categoryModelId: '<builder-model-id>',
|
|
78
|
+
bannerModelId: '<builder-model-id>',
|
|
79
|
+
blogCategoryModelId: '<builder-model-id>',
|
|
80
|
+
editUrl: 'https://your-dev-site.com',
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Using content types
|
|
85
|
+
|
|
86
|
+
Content types extend `BuilderContent` from `@builder.io/sdk` and represent the shape of data returned from Builder.io's Content API.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import type { BuilderProductContent, BuilderPageContent } from '@goldenhippo/builder-cart-schemas';
|
|
90
|
+
|
|
91
|
+
// Type-safe access to product content
|
|
92
|
+
function getProductName(product: BuilderProductContent): string {
|
|
93
|
+
return product?.data?.displayName ?? product?.data?.name ?? '';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Page content is a union type based on page type
|
|
97
|
+
function handlePage(page: BuilderPageContent) {
|
|
98
|
+
if (page?.data?.pageType === 'Product') {
|
|
99
|
+
// TypeScript narrows to BuilderPdpPageContent
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Using core types
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import type { ModelShape, BuilderIOFieldTypes } from '@goldenhippo/builder-types';
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Model Dependencies
|
|
111
|
+
|
|
112
|
+
Models that reference other models require their Builder.io model IDs at creation time:
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
createProductModel → ingredients, category, tag, useCase
|
|
116
|
+
createProductGridConfigModel → category, useCase, ingredient, tag
|
|
117
|
+
createBlogCommentModel → page
|
|
118
|
+
createBrandConfigModel → gridFilter, banner
|
|
119
|
+
createPageModel → product, productGroup, category, banner, blogCategory
|
|
120
|
+
createSiteBannerModel → editUrl
|
|
121
|
+
createDefaultWebsiteSectionModel → editUrl
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Development
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
npm run build # Build with tsup (CJS + ESM + declarations)
|
|
128
|
+
npm run dev # Watch mode
|
|
129
|
+
npm run typecheck # Type-check with tsc
|
|
130
|
+
npm run test # Run tests with vitest
|
|
131
|
+
npm run lint # Lint with eslint
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Build Output
|
|
135
|
+
|
|
136
|
+
Built with [tsup](https://tsup.egoist.dev/) producing:
|
|
137
|
+
|
|
138
|
+
- **CJS** (`.cjs`) — CommonJS for Node.js / legacy bundlers
|
|
139
|
+
- **ESM** (`.js`) — ES modules for modern bundlers
|
|
140
|
+
- **Declarations** (`.d.ts`, `.d.cts`) — TypeScript type definitions
|
|
141
|
+
- **Source maps** (`.map`) — for debugging
|