@vulcantech/cms 0.2.0 → 0.4.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 +31 -15
- package/package.json +7 -7
- package/src/collections.ts +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Nine entry points: one namespaced root and eight subpaths. Every subpath is a th
|
|
|
21
21
|
| `@vulcantech/cms/collections` | `@vulcantech/collections` | server | `fetchCollectionItems`, `fetchCollectionItemBySlug`, `fetchCollections`, `sanitizeHtml`, tag helpers, `PortfolioItemData` | [README](https://www.npmjs.com/package/@vulcantech/collections) |
|
|
22
22
|
| `@vulcantech/cms/seo-files` | `@vulcantech/seo-files` | server | `createSeoFileRoute`, `fetchSeoFiles`, `tagsForSeoFiles`, `SeoFilesPayload` | [README](https://www.npmjs.com/package/@vulcantech/seo-files) |
|
|
23
23
|
| `@vulcantech/cms/forms` | `@vulcantech/forms` | client | `DynamicForm`, `FormDefinition`, `buildYupSchema`, `buildInitialValues`, transform/crypto helpers | [README](https://www.npmjs.com/package/@vulcantech/forms) |
|
|
24
|
-
| `@vulcantech/cms/banners` | `@vulcantech/banners` | client | `CMSBanners`, `BannerBar`, `BannerData` | [README](https://www.npmjs.com/package/@vulcantech/banners) |
|
|
24
|
+
| `@vulcantech/cms/banners` | `@vulcantech/banners` | client | `SiteBanners`, `CMSBanners`, `BannerBar`, `BannerData` | [README](https://www.npmjs.com/package/@vulcantech/banners) |
|
|
25
25
|
| `@vulcantech/cms/analytics` | `@vulcantech/analytics` | client | `AnalyticsTracker`, `trackEvent`, `trackFormSubmit`, … | [README](https://www.npmjs.com/package/@vulcantech/analytics) |
|
|
26
26
|
| `@vulcantech/cms/analytics/tags` | `@vulcantech/analytics/tags` | server | `CMSTags` (async server component), `fetchTrackingTags`, `TrackingTags` | ↑ same |
|
|
27
27
|
| `@vulcantech/cms/analytics/route` | `@vulcantech/analytics/route` | server | `POST` / `OPTIONS` — the `/api/a` ingest proxy | ↑ same |
|
|
@@ -47,7 +47,7 @@ Direct named imports, and the required form inside `"use client"` files:
|
|
|
47
47
|
|
|
48
48
|
```tsx
|
|
49
49
|
import { DynamicForm } from "@vulcantech/cms/forms";
|
|
50
|
-
import {
|
|
50
|
+
import { SiteBanners } from "@vulcantech/cms/banners";
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
Route files re-export as usual:
|
|
@@ -76,6 +76,7 @@ All CMS-reading modules resolve config from `process.env` **at call time** (not
|
|
|
76
76
|
| `VULCANTECH_API_KEY` | yes | same as above | Server-only — **never** prefix with `NEXT_PUBLIC_` |
|
|
77
77
|
| `VULCANTECH_CMS_URL` | no | same as above | CMS origin; defaults to `https://cms.vulcantech.io` |
|
|
78
78
|
| `VULCANTECH_BLOG_NO_CACHE` | no | blog only | `1` / `true` bypasses ISR on every blog fetch (debugging) |
|
|
79
|
+
| `VULCANTECH_REVALIDATE_SECRET` | no* | your `api/revalidate` route | Shared secret the CMS sends on every ISR purge. *Required for instant invalidation — see [ISR revalidation](#isr-revalidation) |
|
|
79
80
|
| `NEXT_PUBLIC_GA_ID` | no | analytics/tags | Per-field fallback when the CMS omits `ga4Id` |
|
|
80
81
|
| `NEXT_PUBLIC_GOOGLE_ADS_ID` | no | analytics/tags | Fallback for `googleAdsId` |
|
|
81
82
|
| `NEXT_PUBLIC_META_PIXEL_ID` | no | analytics/tags | Fallback for `metaPixelId` |
|
|
@@ -90,6 +91,7 @@ One key per site, scoped in the CMS dashboard (Settings → API keys). Grant onl
|
|
|
90
91
|
| --- | --- |
|
|
91
92
|
| `blog:read` | `@vulcantech/cms/blog` |
|
|
92
93
|
| `portfolio:read` | `@vulcantech/cms/collections` |
|
|
94
|
+
| `media:read` | `@vulcantech/cms/collections` (`fetchMediaItems` only) |
|
|
93
95
|
| `seo-files:read` | `@vulcantech/cms/seo-files` |
|
|
94
96
|
| `analytics:read` | `@vulcantech/cms/analytics/tags` (`CMSTags`) |
|
|
95
97
|
| `analytics:write` | `@vulcantech/cms/analytics/route` (event ingest) |
|
|
@@ -113,7 +115,7 @@ Verified per module:
|
|
|
113
115
|
| `analytics/tags` — `fetchTrackingTags` / `CMSTags` | `null` (renders nothing) | No |
|
|
114
116
|
| `analytics/route` — `POST` | `503` unconfigured, `400` bad body, `204` when the CMS send fails | No |
|
|
115
117
|
| `forms` — `DynamicForm` | catches its own submit errors → error state + `onError(err)` | No (nothing reaches an error boundary) |
|
|
116
|
-
| `banners` — `CMSBanners` / `BannerBar` | n/a — presentational only, no I/O | No |
|
|
118
|
+
| `banners` — `SiteBanners` / `CMSBanners` / `BannerBar` | n/a — presentational only, no I/O | No |
|
|
117
119
|
|
|
118
120
|
**The one exception.** In `blog` and `collections`, the response-body parse (`res.json()`) sits outside the `try` that guards the request. A `2xx` response whose body is not JSON — a proxy or CDN returning an HTML error page under a 200 — rejects rather than degrading. Transport failures, non-2xx statuses, 404s, and unconfigured env are all handled. `seo-files` and `analytics/tags` guard the parse too and have no such gap.
|
|
119
121
|
|
|
@@ -126,24 +128,38 @@ Not every integration ships its own fetch layer — this trips up planning, so c
|
|
|
126
128
|
|
|
127
129
|
**You write the fetcher** — the package ships only the renderer, and your app owns the ISR-cached fetch against the CMS API:
|
|
128
130
|
- **`forms`** → fetch `GET {CMS_URL}/api/forms` into `src/lib/cms/forms.ts`, pass the `FormDefinition` to `<DynamicForm>`.
|
|
129
|
-
- **`banners`** → fetch `GET {CMS_URL}/api/banners` into `src/lib/cms/banners.ts`, pass `BannerData[]` to `<
|
|
131
|
+
- **`banners`** → fetch `GET {CMS_URL}/api/banners` into `src/lib/cms/banners.ts`, pass `BannerData[]` to `<SiteBanners>` (path-aware, so page targeting works).
|
|
130
132
|
|
|
131
133
|
Both leaf READMEs carry a copy-paste implementation. Keep them fail-open (`return []` / `null` on error) to match the convention above.
|
|
132
134
|
|
|
133
135
|
## ISR revalidation
|
|
134
136
|
|
|
135
|
-
Every CMS-reading fetch is tagged so the CMS can purge it the moment content changes.
|
|
137
|
+
Every CMS-reading fetch is tagged so the CMS can purge it the moment content changes. Without the wiring below **edits are not lost, just slow**: each fetch simply waits out its revalidate window (60s for blog, tracking tags, and the app-side forms/banners fetchers; 3600s for SEO files). With it, the CMS pushes a purge to your site the instant content is saved.
|
|
136
138
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
139
|
+
This is one piece of wiring per site, shared by every integration. Do it once, even if you only use the blog:
|
|
140
|
+
|
|
141
|
+
**1. Add the secret** — set `VULCANTECH_REVALIDATE_SECRET` in the consumer site's env to any long random string.
|
|
142
|
+
|
|
143
|
+
**2. Add the webhook route** `src/app/api/revalidate/route.ts`. No package exports one; copy `apps/castlerents/src/app/api/revalidate/route.ts` (the reference implementation). The contract the CMS speaks:
|
|
144
|
+
|
|
145
|
+
- `POST`, JSON body `{ projectId, tags: string[], paths?: string[], slug?, formId? }`.
|
|
146
|
+
- Header `x-revalidate-secret` must equal `VULCANTECH_REVALIDATE_SECRET`; answer `401` otherwise, `503` if the env var is unset, `400` if neither `tags` nor `paths` is given.
|
|
147
|
+
- Call `revalidateTag(tag, "default")` for every tag and `revalidatePath(path)` for every path, then respond `{ revalidated: true, tags, paths, at }`.
|
|
148
|
+
|
|
149
|
+
The CMS fires this fire-and-forget with a 5s timeout, so a slow or failing route never blocks a save.
|
|
150
|
+
|
|
151
|
+
**3. Register the site in the CMS** — Dashboard → **Settings → Form Consumers (ISR Revalidation)**. Add an entry with the site's full route URL (`https://example.com/api/revalidate`) and paste the same secret. Use the **Test** button on the entry to confirm a `200`.
|
|
152
|
+
|
|
153
|
+
> The section is named "Form Consumers" for historical reasons — forms were the first integration to revalidate — but it is the **single fan-out list for every dispatcher**: blog, forms, banners, SEO files, and tracking tags all POST to every entry. A blog-only site still has to register here.
|
|
154
|
+
|
|
155
|
+
| Integration | Tags purged | Paths purged |
|
|
156
|
+
| --- | --- | --- |
|
|
157
|
+
| blog | `blog:{projectId}`, `blog:{projectId}:{slug}` (and the previous slug on rename) | `/blog` |
|
|
158
|
+
| seo-files | `seo-files:{projectId}` | `/robots.txt`, `/llms.txt` |
|
|
159
|
+
| analytics/tags | `tracking-tags:{projectId}` | — |
|
|
160
|
+
| forms (app-side) | `forms:{projectId}`, `form:{projectId}:{formId}` | — |
|
|
161
|
+
| banners (app-side) | `banners:{projectId}` | — |
|
|
162
|
+
| collections | `portfolio:{projectId}`, `collection:{projectId}:{slug}`, `item:{projectId}:{slug}` | **no dispatcher** — fetches expire on the 60s window only |
|
|
147
163
|
|
|
148
164
|
## Gotchas
|
|
149
165
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulcantech/cms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Umbrella entry point for the VulcanTech CMS integration packages — one dependency, radix-ui-style imports for blog, collections, forms, banners, analytics, and seo-files.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -79,12 +79,12 @@
|
|
|
79
79
|
"access": "public"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@vulcantech/analytics": "^0.
|
|
83
|
-
"@vulcantech/banners": "^0.
|
|
84
|
-
"@vulcantech/blog": "^0.
|
|
85
|
-
"@vulcantech/collections": "^0.
|
|
86
|
-
"@vulcantech/forms": "^0.
|
|
87
|
-
"@vulcantech/seo-files": "^0.1.
|
|
82
|
+
"@vulcantech/analytics": "^0.2.0",
|
|
83
|
+
"@vulcantech/banners": "^0.2.0",
|
|
84
|
+
"@vulcantech/blog": "^0.3.0",
|
|
85
|
+
"@vulcantech/collections": "^0.3.0",
|
|
86
|
+
"@vulcantech/forms": "^0.4.0",
|
|
87
|
+
"@vulcantech/seo-files": "^0.1.3"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"tsconfig": "*",
|
package/src/collections.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* import { fetchCollectionItems } from "@vulcantech/cms/collections";
|
|
6
6
|
*
|
|
7
7
|
* SERVER-ONLY: reads VULCANTECH_PROJECT_ID / VULCANTECH_API_KEY (scope
|
|
8
|
-
* `portfolio:read`). The fetchers fail soft (`[]` / `null` + a warning)
|
|
8
|
+
* `portfolio:read`; `media:read` for `fetchMediaItems`). The fetchers fail soft (`[]` / `null` + a warning)
|
|
9
9
|
* rather than throwing. Item shape and `displayMode` rules: the
|
|
10
10
|
* @vulcantech/collections README.
|
|
11
11
|
*/
|