@ampless/runtime 1.0.0-beta.70 → 1.0.0-beta.72

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 CHANGED
@@ -403,9 +403,13 @@ interface PluginHeadApi {
403
403
  /**
404
404
  * Resolve the per-plugin `PluginPublicRenderContext` snapshot used by
405
405
  * `contentFields` renderers. Same `settings()` binding the public
406
- * surfaces (`publicHead` / `publicBodyEnd`) use. Async because it
407
- * reads the S3 site-settings cache once per request via
408
- * `pluginSettings.loadAll()`.
406
+ * surfaces (`publicHead` / `publicBodyEnd`) use. Async because it reads
407
+ * the S3 site-settings cache once per request — both plugin settings
408
+ * (`pluginSettings.loadAll()`) AND, when `siteSettings` was passed to
409
+ * `createPluginHead`, the effective `site` block
410
+ * (`siteSettings.loadSiteSettings()`, admin overrides included; falls
411
+ * back to `cmsConfig.site` on fetch failure or when `siteSettings` was
412
+ * not supplied).
409
413
  */
410
414
  contextForPlugins(): Promise<(plugin: AmplessPlugin) => PluginPublicRenderContext>;
411
415
  /**
@@ -453,7 +457,7 @@ interface PublicHtmlForPostResult {
453
457
  * U+2029 → '\u2029'
454
458
  */
455
459
  declare function escapeJsonLdInlineBody(value: string): string;
456
- declare function createPluginHead(cmsConfig: Config, pluginSettings: PluginSettingsApi): PluginHeadApi;
460
+ declare function createPluginHead(cmsConfig: Config, pluginSettings: PluginSettingsApi, siteSettings?: SiteSettingsApi): PluginHeadApi;
457
461
 
458
462
  interface ThemesRegistry {
459
463
  /** Map of theme name → loaded theme module. */
package/dist/index.js CHANGED
@@ -1336,6 +1336,25 @@ function makeCtx(plugin, site, snapshot) {
1336
1336
  }
1337
1337
  };
1338
1338
  }
1339
+ async function resolveEffectiveSite(cmsConfig, siteSettings) {
1340
+ if (!siteSettings) return cmsConfig.site;
1341
+ try {
1342
+ const { site } = await siteSettings.loadSiteSettings();
1343
+ return site;
1344
+ } catch (err) {
1345
+ warn(
1346
+ `effective site settings fetch failed \u2014 falling back to cms.config.ts site block: ${err instanceof Error ? err.message : String(err)}`
1347
+ );
1348
+ return cmsConfig.site;
1349
+ }
1350
+ }
1351
+ async function resolveRenderContext(cmsConfig, pluginSettings, siteSettings) {
1352
+ const [snapshot, site] = await Promise.all([
1353
+ pluginSettings.loadAll(),
1354
+ resolveEffectiveSite(cmsConfig, siteSettings)
1355
+ ]);
1356
+ return { snapshot, site };
1357
+ }
1339
1358
  function collectFor(plugins, site, snapshot, surface, renderOne) {
1340
1359
  const entries = [];
1341
1360
  for (const plugin of plugins) {
@@ -1532,7 +1551,7 @@ async function isPublicRequest() {
1532
1551
  if (h.get(PREVIEW_THEME_HEADER) || h.get(PREVIEW_COLOR_SCHEME_HEADER)) return false;
1533
1552
  return true;
1534
1553
  }
1535
- function createPluginHead(cmsConfig, pluginSettings) {
1554
+ function createPluginHead(cmsConfig, pluginSettings, siteSettings) {
1536
1555
  const plugins = (cmsConfig.plugins ?? []).filter(isPlugin2);
1537
1556
  const validPlugins = [];
1538
1557
  const seenNamespaces = /* @__PURE__ */ new Set();
@@ -1638,10 +1657,10 @@ function createPluginHead(cmsConfig, pluginSettings) {
1638
1657
  return {
1639
1658
  async renderHead() {
1640
1659
  if (!await isPublicRequest()) return null;
1641
- const snapshot = await pluginSettings.loadAll();
1660
+ const { snapshot, site } = await resolveRenderContext(cmsConfig, pluginSettings, siteSettings);
1642
1661
  return collectFor(
1643
1662
  validPlugins,
1644
- cmsConfig.site,
1663
+ site,
1645
1664
  snapshot,
1646
1665
  (p) => p.publicHead,
1647
1666
  renderHeadDescriptor
@@ -1649,38 +1668,38 @@ function createPluginHead(cmsConfig, pluginSettings) {
1649
1668
  },
1650
1669
  async renderBodyEnd() {
1651
1670
  if (!await isPublicRequest()) return null;
1652
- const snapshot = await pluginSettings.loadAll();
1671
+ const { snapshot, site } = await resolveRenderContext(cmsConfig, pluginSettings, siteSettings);
1653
1672
  return collectFor(
1654
1673
  validPlugins,
1655
- cmsConfig.site,
1674
+ site,
1656
1675
  snapshot,
1657
1676
  (p) => p.publicBodyEnd,
1658
1677
  renderBodyDescriptor
1659
1678
  );
1660
1679
  },
1661
1680
  async renderBodyForPost(post) {
1662
- const snapshot = await pluginSettings.loadAll();
1663
- return collectForPost(validPlugins, cmsConfig.site, snapshot, post);
1681
+ const { snapshot, site } = await resolveRenderContext(cmsConfig, pluginSettings, siteSettings);
1682
+ return collectForPost(validPlugins, site, snapshot, post);
1664
1683
  },
1665
1684
  async renderHtmlForPost(post) {
1666
- const snapshot = await pluginSettings.loadAll();
1667
- return collectHtmlForPost(validPlugins, cmsConfig.site, snapshot, post);
1685
+ const { snapshot, site } = await resolveRenderContext(cmsConfig, pluginSettings, siteSettings);
1686
+ return collectHtmlForPost(validPlugins, site, snapshot, post);
1668
1687
  },
1669
1688
  async renderPostScriptsForPage(posts) {
1670
- const snapshot = await pluginSettings.loadAll();
1671
- return collectPostScriptsForPage(validPlugins, cmsConfig.site, snapshot, posts);
1689
+ const { snapshot, site } = await resolveRenderContext(cmsConfig, pluginSettings, siteSettings);
1690
+ return collectPostScriptsForPage(validPlugins, site, snapshot, posts);
1672
1691
  },
1673
1692
  contentFieldsRegistry,
1674
1693
  markdownAdapters,
1675
1694
  async contextForPlugins() {
1676
- const snapshot = await pluginSettings.loadAll();
1677
- return (plugin) => makeCtx(plugin, cmsConfig.site, snapshot);
1695
+ const { snapshot, site } = await resolveRenderContext(cmsConfig, pluginSettings, siteSettings);
1696
+ return (plugin) => makeCtx(plugin, site, snapshot);
1678
1697
  },
1679
1698
  async renderHeadForPreview() {
1680
- const snapshot = await pluginSettings.loadAll();
1699
+ const { snapshot, site } = await resolveRenderContext(cmsConfig, pluginSettings, siteSettings);
1681
1700
  return collectFor(
1682
1701
  validPlugins,
1683
- cmsConfig.site,
1702
+ site,
1684
1703
  snapshot,
1685
1704
  (p) => p.publicHead,
1686
1705
  renderHeadDescriptor
@@ -1910,7 +1929,7 @@ function createAmpless(opts) {
1910
1929
  const settings = createSiteSettings(cmsConfig, storage);
1911
1930
  const seo = createSeo(cmsConfig, settings);
1912
1931
  const pluginSettings = createPluginSettings(storage);
1913
- const pluginHead = createPluginHead(cmsConfig, pluginSettings);
1932
+ const pluginHead = createPluginHead(cmsConfig, pluginSettings, settings);
1914
1933
  const themeActive = createThemeActive(themes, storage);
1915
1934
  const themeConfig = createThemeConfig(themeActive, storage);
1916
1935
  return {
@@ -207,6 +207,7 @@ function createMarkdownRouteHandler(ampless) {
207
207
  }
208
208
 
209
209
  // src/routes/llms.ts
210
+ import { collectBounded } from "ampless";
210
211
  var DEFAULT_LIMIT = 100;
211
212
  var MIN_LIMIT = 1;
212
213
  var MAX_LIMIT = 1e3;
@@ -241,36 +242,10 @@ function fixedEncodeURIComponent(s) {
241
242
  );
242
243
  }
243
244
  async function collectPosts(ampless, limit) {
244
- const items = [];
245
- const seenTokens = /* @__PURE__ */ new Set();
246
- let token;
247
- let truncated = null;
248
- for (let page = 0; page < MAX_PAGES; page++) {
249
- const remaining = limit + 1 - items.length;
250
- const pageLimit = Math.min(PAGE_SIZE_CAP, remaining);
251
- const res = await ampless.listPublishedPosts({ limit: pageLimit, nextToken: token });
252
- items.push(...res.items);
253
- if (items.length > limit) {
254
- truncated = "limit";
255
- break;
256
- }
257
- if (!res.nextToken) {
258
- break;
259
- }
260
- if (seenTokens.has(res.nextToken)) {
261
- truncated = "early";
262
- break;
263
- }
264
- seenTokens.add(res.nextToken);
265
- token = res.nextToken;
266
- if (page === MAX_PAGES - 1) {
267
- truncated = "early";
268
- }
269
- }
270
- return {
271
- items: truncated === "limit" ? items.slice(0, limit) : items,
272
- truncated
273
- };
245
+ return collectBounded(
246
+ (args) => ampless.listPublishedPosts({ limit: args.limit, nextToken: args.nextToken }),
247
+ { limit, pageSizeCap: PAGE_SIZE_CAP, maxPages: MAX_PAGES }
248
+ );
274
249
  }
275
250
  function truncationNote(truncated, limit) {
276
251
  if (truncated === "limit") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampless/runtime",
3
- "version": "1.0.0-beta.70",
3
+ "version": "1.0.0-beta.72",
4
4
  "description": "Public-side runtime for ampless: post fetching, theme dispatch, middleware, public route handlers",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -51,8 +51,8 @@
51
51
  "marked": "^18.0.4",
52
52
  "sanitize-html": "^2.17.4",
53
53
  "tailwind-merge": "^3.6.0",
54
- "@ampless/plugin-og-image": "0.2.0-beta.57",
55
- "ampless": "1.0.0-beta.57"
54
+ "@ampless/plugin-og-image": "0.2.0-beta.59",
55
+ "ampless": "1.0.0-beta.59"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@aws-amplify/adapter-nextjs": "^1",