@ampless/runtime 1.0.0-alpha.19 → 1.0.0-alpha.20
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/dist/index.d.ts +19 -0
- package/dist/index.js +17 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -108,6 +108,18 @@ interface ResolvedTheme {
|
|
|
108
108
|
}
|
|
109
109
|
interface ThemeActiveApi {
|
|
110
110
|
resolveActiveTheme(): Promise<ResolvedTheme>;
|
|
111
|
+
/**
|
|
112
|
+
* Read the stored `theme.active` value directly from the S3 cache
|
|
113
|
+
* with `cache: 'no-store'` — bypassing Next.js's fetch cache and
|
|
114
|
+
* any tag-based revalidation. Returns the raw stored name (which
|
|
115
|
+
* may be a theme that isn't in the registry) or `null` when the
|
|
116
|
+
* S3 file is missing / unreadable.
|
|
117
|
+
*
|
|
118
|
+
* Used by the admin theme-switch flow to poll until the trusted
|
|
119
|
+
* processor has propagated a KvStore write to S3, so the post-
|
|
120
|
+
* switch hard reload doesn't race the cache rebuild.
|
|
121
|
+
*/
|
|
122
|
+
readStoredActiveThemeFresh(): Promise<string | null>;
|
|
111
123
|
}
|
|
112
124
|
|
|
113
125
|
type ColorScheme = 'auto' | 'light' | 'dark';
|
|
@@ -213,6 +225,13 @@ interface Ampless {
|
|
|
213
225
|
listPostsByTag(tag: string, opts?: ListPostsByTagOptions): Promise<ListPostsResult>;
|
|
214
226
|
loadSiteSettings(): Promise<EffectiveSiteSettings>;
|
|
215
227
|
resolveActiveTheme(): Promise<ResolvedTheme>;
|
|
228
|
+
/**
|
|
229
|
+
* Fresh-read of the stored `theme.active` value from S3, bypassing
|
|
230
|
+
* the Next.js fetch cache. Returns the raw stored name (no fallback
|
|
231
|
+
* to defaultTheme) or `null` when the cache file is missing. Used
|
|
232
|
+
* by the admin to poll for processor propagation after a switch.
|
|
233
|
+
*/
|
|
234
|
+
readStoredActiveThemeFresh(): Promise<string | null>;
|
|
216
235
|
loadThemeConfig(): Promise<EffectiveThemeConfig>;
|
|
217
236
|
postMetadata(post: Post): Promise<Metadata>;
|
|
218
237
|
siteMetadata(): Promise<Metadata>;
|
package/dist/index.js
CHANGED
|
@@ -178,14 +178,17 @@ function createSeo(cmsConfig, settingsApi) {
|
|
|
178
178
|
// src/theme-active.ts
|
|
179
179
|
import { headers } from "next/headers";
|
|
180
180
|
function createThemeActive(registry, storage) {
|
|
181
|
-
|
|
181
|
+
function settingsUrl() {
|
|
182
182
|
if (!storage.isStorageConfigured()) return null;
|
|
183
|
-
let url;
|
|
184
183
|
try {
|
|
185
|
-
|
|
184
|
+
return storage.publicAssetUrl("public/site-settings.json");
|
|
186
185
|
} catch {
|
|
187
186
|
return null;
|
|
188
187
|
}
|
|
188
|
+
}
|
|
189
|
+
async function fetchActiveFromCache() {
|
|
190
|
+
const url = settingsUrl();
|
|
191
|
+
if (!url) return null;
|
|
189
192
|
const res = await fetch(url, {
|
|
190
193
|
next: { revalidate: 60, tags: ["site-settings"] }
|
|
191
194
|
});
|
|
@@ -194,7 +197,17 @@ function createThemeActive(registry, storage) {
|
|
|
194
197
|
const v = flat["theme.active"];
|
|
195
198
|
return typeof v === "string" ? v : null;
|
|
196
199
|
}
|
|
200
|
+
async function fetchActiveFresh() {
|
|
201
|
+
const url = settingsUrl();
|
|
202
|
+
if (!url) return null;
|
|
203
|
+
const res = await fetch(url, { cache: "no-store" });
|
|
204
|
+
if (!res.ok) return null;
|
|
205
|
+
const flat = await res.json();
|
|
206
|
+
const v = flat["theme.active"];
|
|
207
|
+
return typeof v === "string" ? v : null;
|
|
208
|
+
}
|
|
197
209
|
return {
|
|
210
|
+
readStoredActiveThemeFresh: () => fetchActiveFresh(),
|
|
198
211
|
async resolveActiveTheme() {
|
|
199
212
|
let previewOverride = null;
|
|
200
213
|
try {
|
|
@@ -601,6 +614,7 @@ function createAmpless(opts) {
|
|
|
601
614
|
listPostsByTag: (tag, o) => posts.listPostsByTag(tag, o),
|
|
602
615
|
loadSiteSettings: () => settings.loadSiteSettings(),
|
|
603
616
|
resolveActiveTheme: () => themeActive.resolveActiveTheme(),
|
|
617
|
+
readStoredActiveThemeFresh: () => themeActive.readStoredActiveThemeFresh(),
|
|
604
618
|
loadThemeConfig: () => themeConfig.loadThemeConfig(),
|
|
605
619
|
postMetadata: (post) => seo.postMetadata(post),
|
|
606
620
|
siteMetadata: () => seo.siteMetadata(),
|
package/package.json
CHANGED