@ampless/runtime 1.0.0-alpha.59 → 1.0.0-beta.61

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.ja.md CHANGED
@@ -5,14 +5,14 @@
5
5
 
6
6
  [ampless](https://github.com/heavymoons/ampless) 向けパブリックサイドランタイム。投稿取得クライアント、サイト設定、テーマ解決、SEO メタデータ集約、ミドルウェア、パブリックルートハンドラーを `createAmpless()` ひとつのファクトリーにまとめます。
7
7
 
8
- > **プレリリース / アルファ版。** v1.0 まではマイナーバージョンでも破壊的変更が入る可能性があります。
8
+ > **プレリリース / ベータ版。** v1.0 まではマイナーバージョンでも破壊的変更が入る可能性があります。
9
9
 
10
10
  テンプレートから切り出すことで、スキャフォールドされたファイルに触れずに `npm update @ampless/runtime` でアップデートできます — パブリックサイトの動作改善はスキャフォールダーの再実行ではなく、パッケージを通じて届きます。
11
11
 
12
12
  ## インストール
13
13
 
14
14
  ```bash
15
- npm install @ampless/runtime@alpha ampless@alpha
15
+ npm install @ampless/runtime@beta ampless@beta
16
16
  ```
17
17
 
18
18
  `@ampless/runtime` は `next`(15+)、`react`(18/19)、`aws-amplify`(6+)、`@aws-amplify/adapter-nextjs`(1+)をピア依存として宣言します。CLI スキャフォールダーがテンプレートの `package.json` に互換バージョンをピン留めします。
package/README.md CHANGED
@@ -5,14 +5,14 @@
5
5
 
6
6
  Public-side runtime for [ampless](https://github.com/heavymoons/ampless). Bundles the post-fetching client, site settings, theme resolution, SEO metadata aggregation, middleware, and public route handlers behind a single `createAmpless()` factory.
7
7
 
8
- > **Pre-release / alpha.** Breaking changes possible in any minor version until v1.0.
8
+ > **Pre-release / beta.** Breaking changes possible in any minor version until v1.0.
9
9
 
10
10
  Splitting this out of the template lets you `npm update @ampless/runtime` without touching scaffolded files — public-site behaviour upgrades come in through the package, not by re-running the scaffolder.
11
11
 
12
12
  ## Install
13
13
 
14
14
  ```bash
15
- npm install @ampless/runtime@alpha ampless@alpha
15
+ npm install @ampless/runtime@beta ampless@beta
16
16
  ```
17
17
 
18
18
  `@ampless/runtime` declares peer dependencies on `next` (15+), `react` (18/19), `aws-amplify` (6+), and `@aws-amplify/adapter-nextjs` (1+). The CLI scaffolder pins compatible versions in the template's `package.json`.
@@ -0,0 +1,10 @@
1
+ // src/request-headers.ts
2
+ var AMPLESS_PATHNAME_HEADER = "x-ampless-pathname";
3
+ var PREVIEW_THEME_HEADER = "x-preview-theme";
4
+ var PREVIEW_COLOR_SCHEME_HEADER = "x-preview-color-scheme";
5
+
6
+ export {
7
+ AMPLESS_PATHNAME_HEADER,
8
+ PREVIEW_THEME_HEADER,
9
+ PREVIEW_COLOR_SCHEME_HEADER
10
+ };
package/dist/index.d.ts CHANGED
@@ -367,18 +367,6 @@ interface PublicHtmlForPostResult {
367
367
  * U+2029 → '\u2029'
368
368
  */
369
369
  declare function escapeJsonLdInlineBody(value: string): string;
370
- /**
371
- * Create the head/body renderer for a `Config`. The constructor-time
372
- * pass logs a single dev warning when two plugins share an
373
- * `instanceId ?? name`; everything else happens at render time so
374
- * descriptors reflect per-request site config.
375
- *
376
- * `pluginSettings` (Phase 2) is the runtime accessor that pulls
377
- * admin-managed `settings.public` values from the S3 site-settings
378
- * cache. Within a single request we fetch once via `loadAll()` and
379
- * bind a per-plugin `ctx.setting(key)` accessor before invoking
380
- * either `publicHead` or `publicBodyEnd`.
381
- */
382
370
  declare function createPluginHead(cmsConfig: Config, pluginSettings: PluginSettingsApi): PluginHeadApi;
383
371
 
384
372
  interface ThemesRegistry {
@@ -461,9 +449,9 @@ declare function renderThemeCss(cssVars: Record<string, string>): string;
461
449
  * Failure modes that resolve to `null`:
462
450
  * - Package not installed at this resolution root
463
451
  * (`ERR_MODULE_NOT_FOUND`)
464
- * - `package.json` not in the package's `exports`
465
- * (`ERR_PACKAGE_PATH_NOT_EXPORTED`) — see the spec under
466
- * `docs/tmp/plugin-extension-phase5.md` §B
452
+ * - `package.json` not in the package's `exports`
453
+ * (`ERR_PACKAGE_PATH_NOT_EXPORTED`) — see the package manifest
454
+ * convention above
467
455
  * - `readFileSync` throws (e.g. ENOENT, permissions)
468
456
  * - JSON parse error
469
457
  * - `amplessPlugin` field absent or not an object
@@ -629,7 +617,7 @@ interface Ampless {
629
617
  *
630
618
  * <div>{await ampless.renderBody(post)}</div>
631
619
  *
632
- * Phase 7 alpha breaking: this signature replaced the prior sync
620
+ * Phase 7 pre-1.0 breaking: this signature replaced the prior sync
633
621
  * `string` return shape. The sync string flavour is still available
634
622
  * via `renderBodyHtmlString` for routes (raw HTML response) that
635
623
  * cannot await — but those callsites bypass the `contentFields`
package/dist/index.js CHANGED
@@ -1,3 +1,8 @@
1
+ import {
2
+ AMPLESS_PATHNAME_HEADER,
3
+ PREVIEW_COLOR_SCHEME_HEADER,
4
+ PREVIEW_THEME_HEADER
5
+ } from "./chunk-BS7KLDDE.js";
1
6
  import {
2
7
  _resetStreamS3Cache,
3
8
  streamS3Object,
@@ -238,6 +243,7 @@ function createSeo(cmsConfig, settingsApi) {
238
243
  }
239
244
 
240
245
  // src/plugin-head.ts
246
+ import { headers } from "next/headers";
241
247
  import {
242
248
  Fragment as Fragment2,
243
249
  createElement as createElement2
@@ -1428,6 +1434,20 @@ function collectHtmlForPost(plugins, site, snapshot, post) {
1428
1434
  afterContent: toReactNode(after, "afterContent")
1429
1435
  };
1430
1436
  }
1437
+ async function isPublicRequest() {
1438
+ let h;
1439
+ try {
1440
+ h = await headers();
1441
+ } catch {
1442
+ return false;
1443
+ }
1444
+ const p = h.get(AMPLESS_PATHNAME_HEADER);
1445
+ if (!p) return false;
1446
+ if (p === "/admin" || p.startsWith("/admin/")) return false;
1447
+ if (p === "/login" || p.startsWith("/login/")) return false;
1448
+ if (h.get(PREVIEW_THEME_HEADER) || h.get(PREVIEW_COLOR_SCHEME_HEADER)) return false;
1449
+ return true;
1450
+ }
1431
1451
  function createPluginHead(cmsConfig, pluginSettings) {
1432
1452
  const plugins = (cmsConfig.plugins ?? []).filter(isPlugin2);
1433
1453
  const validPlugins = [];
@@ -1532,6 +1552,7 @@ function createPluginHead(cmsConfig, pluginSettings) {
1532
1552
  }
1533
1553
  return {
1534
1554
  async renderHead() {
1555
+ if (!await isPublicRequest()) return null;
1535
1556
  const snapshot = await pluginSettings.loadAll();
1536
1557
  return collectFor(
1537
1558
  validPlugins,
@@ -1542,6 +1563,7 @@ function createPluginHead(cmsConfig, pluginSettings) {
1542
1563
  );
1543
1564
  },
1544
1565
  async renderBodyEnd() {
1566
+ if (!await isPublicRequest()) return null;
1545
1567
  const snapshot = await pluginSettings.loadAll();
1546
1568
  return collectFor(
1547
1569
  validPlugins,
@@ -1664,7 +1686,7 @@ function createPluginSettings(storage) {
1664
1686
  }
1665
1687
 
1666
1688
  // src/theme-active.ts
1667
- import { headers } from "next/headers";
1689
+ import { headers as headers2 } from "next/headers";
1668
1690
  function createThemeActive(registry, storage) {
1669
1691
  function settingsUrl() {
1670
1692
  if (!storage.isStorageConfigured()) return null;
@@ -1699,8 +1721,8 @@ function createThemeActive(registry, storage) {
1699
1721
  async resolveActiveTheme() {
1700
1722
  let previewOverride = null;
1701
1723
  try {
1702
- const h = await headers();
1703
- previewOverride = h.get("x-preview-theme");
1724
+ const h = await headers2();
1725
+ previewOverride = h.get(PREVIEW_THEME_HEADER);
1704
1726
  } catch {
1705
1727
  }
1706
1728
  if (previewOverride && previewOverride in registry.themes) {
@@ -37,6 +37,12 @@ declare function computeCacheControl(flags: {
37
37
  * - `?previewTheme` / `?previewColorScheme` → `x-preview-theme` /
38
38
  * `x-preview-color-scheme` header forwarding for the admin's
39
39
  * iframe-based theme preview.
40
+ * - `x-ampless-pathname` marker header set unconditionally on every
41
+ * request this middleware handles (public routes only). Server
42
+ * components such as `renderHead` / `renderBodyEnd` read this header
43
+ * to confirm a public, non-preview request before emitting analytics
44
+ * or consent scripts. Routes excluded from the matcher (admin / api /
45
+ * login) never receive a runtime-set marker, so those layouts stay clean.
40
46
  */
41
47
  declare function createAmplessMiddleware(opts: CreateMiddlewareOpts): MiddlewareFn;
42
48
  /**
@@ -1,3 +1,9 @@
1
+ import {
2
+ AMPLESS_PATHNAME_HEADER,
3
+ PREVIEW_COLOR_SCHEME_HEADER,
4
+ PREVIEW_THEME_HEADER
5
+ } from "./chunk-BS7KLDDE.js";
6
+
1
7
  // src/middleware.ts
2
8
  import { NextResponse } from "next/server";
3
9
  var runtime = "nodejs";
@@ -137,10 +143,13 @@ function createAmplessMiddleware(opts) {
137
143
  const previewTheme = url.searchParams.get("previewTheme");
138
144
  const previewColorScheme = url.searchParams.get("previewColorScheme");
139
145
  const requestHeaders = new Headers(request.headers);
140
- if (previewTheme) requestHeaders.set("x-preview-theme", previewTheme);
146
+ requestHeaders.delete(PREVIEW_THEME_HEADER);
147
+ requestHeaders.delete(PREVIEW_COLOR_SCHEME_HEADER);
148
+ if (previewTheme) requestHeaders.set(PREVIEW_THEME_HEADER, previewTheme);
141
149
  if (previewColorScheme) {
142
- requestHeaders.set("x-preview-color-scheme", previewColorScheme);
150
+ requestHeaders.set(PREVIEW_COLOR_SCHEME_HEADER, previewColorScheme);
143
151
  }
152
+ requestHeaders.set(AMPLESS_PATHNAME_HEADER, url.pathname);
144
153
  const passthrough = () => NextResponse.next({ request: { headers: requestHeaders } });
145
154
  const segments = url.pathname.split("/").filter(Boolean);
146
155
  if (segments.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampless/runtime",
3
- "version": "1.0.0-alpha.59",
3
+ "version": "1.0.0-beta.61",
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-alpha.50",
55
- "ampless": "1.0.0-alpha.50"
54
+ "@ampless/plugin-og-image": "0.2.0-beta.52",
55
+ "ampless": "1.0.0-beta.52"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@aws-amplify/adapter-nextjs": "^1",