@conloca/cloud-astro 0.2.3 → 0.2.5

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.
Files changed (159) hide show
  1. package/README.md +155 -37
  2. package/dist/.build-inputs.json +32 -23
  3. package/dist/src/constants.d.ts +12 -3
  4. package/dist/src/constants.d.ts.map +1 -1
  5. package/dist/src/constants.js +12 -3
  6. package/dist/src/constants.js.map +1 -1
  7. package/dist/src/d3-build.d.ts +70 -0
  8. package/dist/src/d3-build.d.ts.map +1 -0
  9. package/dist/src/d3-build.js +272 -0
  10. package/dist/src/d3-build.js.map +1 -0
  11. package/dist/src/descriptors.d.ts.map +1 -1
  12. package/dist/src/descriptors.js +4 -2
  13. package/dist/src/descriptors.js.map +1 -1
  14. package/dist/src/doctor/checks-live.d.ts +2 -2
  15. package/dist/src/doctor/checks-live.d.ts.map +1 -1
  16. package/dist/src/doctor/checks-live.js +10 -4
  17. package/dist/src/doctor/checks-live.js.map +1 -1
  18. package/dist/src/doctor/checks-offline.d.ts +1 -5
  19. package/dist/src/doctor/checks-offline.d.ts.map +1 -1
  20. package/dist/src/doctor/checks-offline.js +15 -27
  21. package/dist/src/doctor/checks-offline.js.map +1 -1
  22. package/dist/src/doctor/checks-preview-limits.d.ts +11 -0
  23. package/dist/src/doctor/checks-preview-limits.d.ts.map +1 -0
  24. package/dist/src/doctor/checks-preview-limits.js +133 -0
  25. package/dist/src/doctor/checks-preview-limits.js.map +1 -0
  26. package/dist/src/doctor/checks-preview-live.d.ts +14 -0
  27. package/dist/src/doctor/checks-preview-live.d.ts.map +1 -0
  28. package/dist/src/doctor/checks-preview-live.js +72 -0
  29. package/dist/src/doctor/checks-preview-live.js.map +1 -0
  30. package/dist/src/doctor/checks-preview.d.ts +7 -0
  31. package/dist/src/doctor/checks-preview.d.ts.map +1 -0
  32. package/dist/src/doctor/checks-preview.js +287 -0
  33. package/dist/src/doctor/checks-preview.js.map +1 -0
  34. package/dist/src/doctor/config-scan.d.ts +6 -0
  35. package/dist/src/doctor/config-scan.d.ts.map +1 -1
  36. package/dist/src/doctor/config-scan.js +17 -0
  37. package/dist/src/doctor/config-scan.js.map +1 -1
  38. package/dist/src/doctor/run.d.ts.map +1 -1
  39. package/dist/src/doctor/run.js +4 -0
  40. package/dist/src/doctor/run.js.map +1 -1
  41. package/dist/src/doctor/types.d.ts +11 -1
  42. package/dist/src/doctor/types.d.ts.map +1 -1
  43. package/dist/src/doctor/types.js +11 -1
  44. package/dist/src/doctor/types.js.map +1 -1
  45. package/dist/src/editor-page/bundle.d.ts +2 -0
  46. package/dist/src/editor-page/bundle.d.ts.map +1 -1
  47. package/dist/src/editor-page/bundle.js +3 -0
  48. package/dist/src/editor-page/bundle.js.map +1 -1
  49. package/dist/src/editor-page/data-schemas.d.ts +16 -0
  50. package/dist/src/editor-page/data-schemas.d.ts.map +1 -0
  51. package/dist/src/editor-page/data-schemas.js +39 -0
  52. package/dist/src/editor-page/data-schemas.js.map +1 -0
  53. package/dist/src/editor-page/emit.d.ts +37 -1
  54. package/dist/src/editor-page/emit.d.ts.map +1 -1
  55. package/dist/src/editor-page/emit.js +75 -4
  56. package/dist/src/editor-page/emit.js.map +1 -1
  57. package/dist/src/index.d.ts +1 -0
  58. package/dist/src/index.d.ts.map +1 -1
  59. package/dist/src/index.js +2 -0
  60. package/dist/src/index.js.map +1 -1
  61. package/dist/src/integration.d.ts.map +1 -1
  62. package/dist/src/integration.js +165 -41
  63. package/dist/src/integration.js.map +1 -1
  64. package/dist/src/preview/_dispatch.d.ts +12 -0
  65. package/dist/src/preview/_dispatch.d.ts.map +1 -1
  66. package/dist/src/preview/_dispatch.js +31 -0
  67. package/dist/src/preview/_dispatch.js.map +1 -1
  68. package/dist/src/preview/_resolve-opts.d.ts +3 -0
  69. package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
  70. package/dist/src/preview/_resolve-opts.js +3 -1
  71. package/dist/src/preview/_resolve-opts.js.map +1 -1
  72. package/dist/src/preview/banner.d.ts +12 -9
  73. package/dist/src/preview/banner.d.ts.map +1 -1
  74. package/dist/src/preview/banner.js +46 -41
  75. package/dist/src/preview/banner.js.map +1 -1
  76. package/dist/src/preview/cloudflare-adapter.d.ts +35 -0
  77. package/dist/src/preview/cloudflare-adapter.d.ts.map +1 -0
  78. package/dist/src/preview/cloudflare-adapter.js +92 -0
  79. package/dist/src/preview/cloudflare-adapter.js.map +1 -0
  80. package/dist/src/preview/cookie.d.ts +9 -13
  81. package/dist/src/preview/cookie.d.ts.map +1 -1
  82. package/dist/src/preview/cookie.js +15 -25
  83. package/dist/src/preview/cookie.js.map +1 -1
  84. package/dist/src/preview/dispatcher.d.ts +73 -0
  85. package/dist/src/preview/dispatcher.d.ts.map +1 -0
  86. package/dist/src/preview/dispatcher.js +329 -0
  87. package/dist/src/preview/dispatcher.js.map +1 -0
  88. package/dist/src/preview/entry-code.d.ts +33 -0
  89. package/dist/src/preview/entry-code.d.ts.map +1 -0
  90. package/dist/src/preview/entry-code.js +33 -0
  91. package/dist/src/preview/entry-code.js.map +1 -0
  92. package/dist/src/preview/headers.d.ts +24 -4
  93. package/dist/src/preview/headers.d.ts.map +1 -1
  94. package/dist/src/preview/headers.js +35 -7
  95. package/dist/src/preview/headers.js.map +1 -1
  96. package/dist/src/preview/landing.d.ts +21 -0
  97. package/dist/src/preview/landing.d.ts.map +1 -1
  98. package/dist/src/preview/landing.js +103 -35
  99. package/dist/src/preview/landing.js.map +1 -1
  100. package/dist/src/preview/middleware.d.ts +29 -7
  101. package/dist/src/preview/middleware.d.ts.map +1 -1
  102. package/dist/src/preview/middleware.js +238 -84
  103. package/dist/src/preview/middleware.js.map +1 -1
  104. package/dist/src/preview/preview-path.d.ts +29 -0
  105. package/dist/src/preview/preview-path.d.ts.map +1 -1
  106. package/dist/src/preview/preview-path.js +41 -0
  107. package/dist/src/preview/preview-path.js.map +1 -1
  108. package/dist/src/preview/redeem-url.d.ts +7 -0
  109. package/dist/src/preview/redeem-url.d.ts.map +1 -0
  110. package/dist/src/preview/redeem-url.js +14 -0
  111. package/dist/src/preview/redeem-url.js.map +1 -0
  112. package/dist/src/preview/site-middleware.d.ts.map +1 -1
  113. package/dist/src/preview/site-middleware.js +39 -12
  114. package/dist/src/preview/site-middleware.js.map +1 -1
  115. package/dist/src/preview-build.d.ts +19 -8
  116. package/dist/src/preview-build.d.ts.map +1 -1
  117. package/dist/src/preview-build.js +47 -21
  118. package/dist/src/preview-build.js.map +1 -1
  119. package/dist/src/skill.d.ts +11 -0
  120. package/dist/src/skill.d.ts.map +1 -1
  121. package/dist/src/skill.js +32 -9
  122. package/dist/src/skill.js.map +1 -1
  123. package/dist/src/types.d.ts +15 -12
  124. package/dist/src/types.d.ts.map +1 -1
  125. package/package.json +33 -7
  126. package/src/constants.ts +14 -3
  127. package/src/d3-build.ts +315 -0
  128. package/src/descriptors.ts +4 -2
  129. package/src/doctor/checks-live.ts +10 -4
  130. package/src/doctor/checks-offline.ts +16 -25
  131. package/src/doctor/checks-preview-limits.ts +137 -0
  132. package/src/doctor/checks-preview-live.ts +77 -0
  133. package/src/doctor/checks-preview.ts +302 -0
  134. package/src/doctor/config-scan.ts +14 -0
  135. package/src/doctor/run.ts +4 -0
  136. package/src/doctor/types.ts +11 -1
  137. package/src/editor-page/bundle.ts +5 -0
  138. package/src/editor-page/data-schemas.ts +47 -0
  139. package/src/editor-page/emit.ts +124 -8
  140. package/src/index.ts +2 -0
  141. package/src/integration.ts +176 -40
  142. package/src/preview/_dispatch.ts +36 -1
  143. package/src/preview/_resolve-opts.ts +6 -1
  144. package/src/preview/banner.ts +61 -41
  145. package/src/preview/cloudflare-adapter.ts +103 -0
  146. package/src/preview/cookie.ts +14 -23
  147. package/src/preview/dispatcher.ts +407 -0
  148. package/src/preview/entry-code.ts +51 -0
  149. package/src/preview/headers.ts +35 -7
  150. package/src/preview/landing.ts +115 -37
  151. package/src/preview/middleware.ts +264 -88
  152. package/src/preview/preview-path.ts +57 -0
  153. package/src/preview/redeem-url.ts +14 -0
  154. package/src/preview/site-middleware.ts +47 -12
  155. package/src/preview-build.ts +67 -24
  156. package/src/preview-handler.astro +2 -1
  157. package/src/skill/SKILL.md +14 -2
  158. package/src/skill.ts +36 -8
  159. package/src/types.ts +15 -12
@@ -1,3 +1,38 @@
1
+ import { PREVIEW_CACHE_HEADERS } from './headers.js';
2
+ const PAGE_STYLE = 'body{font-family:system-ui,sans-serif;max-width:32rem;margin:8rem auto;padding:0 1rem;line-height:1.5;color:#1a1a1a}h1{margin-bottom:1rem}a.btn{display:inline-block;padding:0.75rem 1.25rem;margin-right:0.5rem;border-radius:6px;text-decoration:none}a.btn.primary{background:#111;color:#fff}a.btn.secondary{border:1px solid #ccc;color:#1a1a1a}';
3
+ /**
4
+ * Headers of both pages below: noindex, never cached, and a tight own CSP.
5
+ * They are Conloca-authored (only an inline <style>, no scripts), so no
6
+ * script runs and nothing may frame them.
7
+ */
8
+ const PAGE_HEADERS = {
9
+ 'content-type': 'text/html; charset=utf-8',
10
+ 'x-robots-tag': 'noindex',
11
+ ...PREVIEW_CACHE_HEADERS,
12
+ 'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'",
13
+ };
14
+ /** A heading, one paragraph and link buttons; the first link is the primary one. Hrefs are escaped here. */
15
+ function renderPage(content) {
16
+ return [
17
+ '<!doctype html>',
18
+ '<html lang="en">',
19
+ '<head>',
20
+ '<meta charset="utf-8">',
21
+ '<meta name="viewport" content="width=device-width, initial-scale=1">',
22
+ '<meta name="robots" content="noindex, nofollow">',
23
+ `<title>${content.title}</title>`,
24
+ `<style>${PAGE_STYLE}</style>`,
25
+ '</head>',
26
+ '<body>',
27
+ `<h1>${content.heading}</h1>`,
28
+ `<p>${content.text}</p>`,
29
+ '<p>',
30
+ ...content.links.map(([label, href], index) => `<a class="btn ${index === 0 ? 'primary' : 'secondary'}" href="${escapeHtml(href)}">${label}</a>`),
31
+ '</p>',
32
+ '</body>',
33
+ '</html>',
34
+ ].join('');
35
+ }
1
36
  /**
2
37
  * Renders the "no preview context" landing page returned when a request
3
38
  * hits the preview route but carries neither a fresh query param nor a
@@ -20,44 +55,77 @@ export function renderNoPreviewLanding(opts) {
20
55
  // was trying to preview and the endpoint that issues the JWT.
21
56
  const loginUrl = new URL('/login', opts.saasEndpoint);
22
57
  loginUrl.searchParams.set('return', opts.pathname);
23
- const escapedPath = escapeHtml(opts.pathname);
24
- const escapedLogin = escapeHtml(loginUrl.toString());
25
- const body = [
26
- '<!doctype html>',
27
- '<html lang="en">',
28
- '<head>',
29
- '<meta charset="utf-8">',
30
- '<meta name="viewport" content="width=device-width, initial-scale=1">',
31
- '<meta name="robots" content="noindex, nofollow">',
32
- '<title>Conloca preview</title>',
33
- '<style>body{font-family:system-ui,sans-serif;max-width:32rem;margin:8rem auto;padding:0 1rem;line-height:1.5;color:#1a1a1a}h1{margin-bottom:1rem}a.btn{display:inline-block;padding:0.75rem 1.25rem;margin-right:0.5rem;border-radius:6px;text-decoration:none}a.btn.primary{background:#111;color:#fff}a.btn.secondary{border:1px solid #ccc;color:#1a1a1a}</style>',
34
- '</head>',
35
- '<body>',
36
- '<h1>This is a Conloca preview environment</h1>',
37
- '<p>To preview unreleased content you need to log in. Otherwise visit the production site.</p>',
38
- '<p>',
39
- `<a class="btn primary" href="${escapedLogin}">Log in to edit</a>`,
40
- `<a class="btn secondary" href="${escapedPath}">Go to production</a>`,
41
- '</p>',
42
- '</body>',
43
- '</html>',
44
- ].join('');
45
- return new Response(body, {
46
- status: 200,
47
- headers: {
48
- 'content-type': 'text/html; charset=utf-8',
49
- 'x-robots-tag': 'noindex',
50
- 'cache-control': 'private, no-store',
51
- // This is a Conloca-authored page (only an inline <style>, no scripts),
52
- // so it carries a tight own CSP — no script execution, no framing.
53
- 'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'",
54
- },
58
+ const body = renderPage({
59
+ title: 'Conloca preview',
60
+ heading: 'This is a Conloca preview environment',
61
+ text: 'To preview unreleased content you need to log in. Otherwise visit the production site.',
62
+ links: [
63
+ ['Log in to edit', loginUrl.toString()],
64
+ ['Go to production', opts.liveHref ?? opts.pathname],
65
+ ],
66
+ });
67
+ return new Response(body, { status: 200, headers: PAGE_HEADERS });
68
+ }
69
+ /**
70
+ * The page a preview request gets when its draft could not be loaded (the
71
+ * page-status call failed). Never the published page: under preview,
72
+ * published bytes would pass for the draft. Retry reloads the page; Exit
73
+ * leaves preview, since the visitor can't remove the HttpOnly cookie
74
+ * themselves.
75
+ */
76
+ export function renderPreviewUnavailable(opts) {
77
+ const body = renderPage({
78
+ title: 'Preview unavailable',
79
+ heading: "Preview couldn't load the draft",
80
+ text: 'The draft could not be fetched just now. Your published site is not affected.',
81
+ links: [
82
+ ['Retry', opts.retryHref],
83
+ ['Exit preview', opts.exitHref],
84
+ ],
85
+ });
86
+ return new Response(body, { status: 503, headers: PAGE_HEADERS });
87
+ }
88
+ /** Each ended link's words; the sharer's name arrives escaped. */
89
+ const SHARE_ENDED_COPY = {
90
+ 'grant-expired': (sharer) => ({
91
+ heading: 'This preview link has expired',
92
+ text: `Ask ${sharer || 'the person who shared it'} for a new link.`,
93
+ link: 'View the live site',
94
+ }),
95
+ 'grant-revoked': (sharer) => ({
96
+ heading: 'This preview link was turned off',
97
+ text: `${sharer || 'The person who shared it'} or a workspace admin turned it off.`,
98
+ link: 'View the live site',
99
+ }),
100
+ 'draft-published': () => ({
101
+ heading: 'This draft was published',
102
+ text: 'Its changes are on the live site now.',
103
+ link: 'View live',
104
+ }),
105
+ 'draft-discarded': () => ({
106
+ heading: 'This draft was discarded',
107
+ text: 'Its changes were thrown away, so there is nothing left to preview.',
108
+ link: 'View the live site',
109
+ }),
110
+ };
111
+ /**
112
+ * The page a share viewer gets once the link no longer opens. Never the published page: under preview it would
113
+ * pass for the draft. The one link leaves preview for the live page.
114
+ */
115
+ export function renderShareEnded(kind, opts) {
116
+ const copy = SHARE_ENDED_COPY[kind](escapeHtml(opts.sharedBy));
117
+ const body = renderPage({
118
+ title: copy.heading,
119
+ heading: copy.heading,
120
+ text: copy.text,
121
+ links: [[copy.link, opts.liveHref]],
55
122
  });
123
+ return new Response(body, { status: 410, headers: PAGE_HEADERS });
56
124
  }
57
125
  /**
58
- * Minimal HTML attribute/text escaper — enough to prevent the rendered
59
- * pathname from breaking out of an attribute or injecting markup. We do
60
- * not pull in a dependency for one helper used in one place.
126
+ * Minimal HTML attribute/text escaper — enough to prevent a rendered
127
+ * path from breaking out of an attribute or injecting markup. We do
128
+ * not pull in a dependency for one helper.
61
129
  */
62
130
  function escapeHtml(value) {
63
131
  return value
@@ -1 +1 @@
1
- {"version":3,"file":"landing.js","sourceRoot":"","sources":["../../../src/preview/landing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAgD;IACrF,0EAA0E;IAC1E,8DAA8D;IAC9D,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACtD,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnD,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9C,MAAM,YAAY,GAAG,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IAErD,MAAM,IAAI,GAAG;QACX,iBAAiB;QACjB,kBAAkB;QAClB,QAAQ;QACR,wBAAwB;QACxB,sEAAsE;QACtE,kDAAkD;QAClD,gCAAgC;QAChC,sWAAsW;QACtW,SAAS;QACT,QAAQ;QACR,gDAAgD;QAChD,+FAA+F;QAC/F,KAAK;QACL,gCAAgC,YAAY,sBAAsB;QAClE,kCAAkC,WAAW,wBAAwB;QACrE,MAAM;QACN,SAAS;QACT,SAAS;KACV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,CAAC,QAAQ,CAAC,CAAC;KACpC,CAAC,CAAC;IACH,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;AACpE,CAAC;AAED;;;;GAIG;AACH,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK;SACT,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { type JWTVerifyGetKey } from 'jose';
2
+ import { type PreviewServeMode } from './preview-path.js';
2
3
  /**
3
4
  * Options consumed by {@link handlePreviewRequest}.
4
5
  *
@@ -17,7 +18,8 @@ import { type JWTVerifyGetKey } from 'jose';
17
18
  */
18
19
  export interface PreviewMiddlewareOptions {
19
20
  saasEndpoint: string;
20
- saasIssuer: string;
21
+ /** When set, every pass must name it (`iss`); unset, the signature by the endpoint's published keys is the check. */
22
+ saasIssuer?: string;
21
23
  saasAudience: string;
22
24
  /** The repository the preview build was made from, as passes name it (`owner/name`). */
23
25
  repo: string;
@@ -35,7 +37,7 @@ export interface PreviewMiddlewareOptions {
35
37
  buildCommit?: string;
36
38
  getKey?: JWTVerifyGetKey;
37
39
  /**
38
- * Transport for the JWKS fetch. A deployment that cannot reach the endpoint
40
+ * Transport for the JWKS fetch and the entry-code exchange. A deployment that cannot reach the endpoint
39
41
  * with a plain fetch by hostname supplies a Cloudflare binding's fetch here;
40
42
  * otherwise key discovery gets another server's answer and every token
41
43
  * looks forged.
@@ -52,6 +54,15 @@ export interface PreviewMiddlewareOptions {
52
54
  * screen on every URL.
53
55
  */
54
56
  onMiss?: 'landing' | 'pass-through';
57
+ /**
58
+ * How this build serves previews. `d2` (default): on the site's own deploy, where a share viewer whose pass
59
+ * expires opens the share link again. `d3`: behind the dispatcher next to a static site, under the route and the
60
+ * branch slug, with cookies scoped there. `d4`: on a separate preview deploy that has no other visitors. Under D3 and
61
+ * D4 a grant cookie lets an expired pass renew through the share link.
62
+ */
63
+ mode?: PreviewServeMode;
64
+ /** D3: the requested branch slug, as the dispatcher names it; a pass opens only under its own branch's slug. */
65
+ slug?: string;
55
66
  }
56
67
  /**
57
68
  * Decoded preview context placed on `Astro.locals.conlocaPreview` for the
@@ -68,6 +79,14 @@ export interface PreviewContext {
68
79
  jwt: string;
69
80
  /** Seconds until the JWT expires — bounds the preview cookie's Max-Age. */
70
81
  expiresInSeconds?: number;
82
+ /** Set when the pass came from a share link: the link's id, its expiry (epoch seconds) and who shared it. */
83
+ grant?: {
84
+ id: string;
85
+ expiresAt: number;
86
+ sharedBy: string;
87
+ };
88
+ /** The editor this branch is edited in; set only on an editor's own pass. */
89
+ editorUrl?: string;
71
90
  }
72
91
  declare global {
73
92
  namespace App {
@@ -106,11 +125,14 @@ export type PreviewVerdict = {
106
125
  * Order of checks:
107
126
  * 0. `<base>/_conloca/preview/__exit` → expire the cookie and redirect,
108
127
  * carrying this build's public label.
109
- * 1. `?conloca_preview=<JWT>` query param → validate; on success issue a
110
- * 302 with the cookie set and the query stripped.
111
- * 2. `__Host-conloca_preview=<JWT>` cookie → validate; on success return a
112
- * `preview` verdict with the decoded context.
113
- * 3. Neither present → no-preview landing page response.
128
+ * 1. `?conloca_code=<code>` → trade the single-use code for the pass on
129
+ * the server; on success issue a 302 with the cookie set and the code
130
+ * stripped. A used code with a valid cookie redirects to the clean path.
131
+ * 2. `?conloca_preview=<JWT>` query param (protocol 1) → validate; on
132
+ * success issue a 302 with the cookie set and the query stripped.
133
+ * 3. The pass cookie (`__Host-conloca_preview`; under D3 `__Secure-conloca_preview_<slug>`) → every value sent,
134
+ * the first that verifies; on success return a `preview` verdict with the decoded context.
135
+ * 4. Neither present → no-preview landing page response.
114
136
  *
115
137
  * Invalid JWTs (tampered signature, expired, missing required claim, wrong
116
138
  * issuer/audience/scope, or naming another repository, site or branch than
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/preview/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoD,KAAK,eAAe,EAAa,MAAM,MAAM,CAAC;AAYzG;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,wBAAwB;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,wFAAwF;IACxF,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,SAAS,GAAG,cAAc,CAAC;CACrC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAOD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,GAAG,CAAC;QACZ,UAAU,MAAM;YACd,cAAc,CAAC,EAAE,cAAc,CAAC;SACjC;KACF;CACF;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GACxB;IAAE,IAAI,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