@conloca/cloud-astro 0.2.2 → 0.2.4

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 (241) hide show
  1. package/README.md +378 -207
  2. package/dist/.build-inputs.json +69 -0
  3. package/dist/src/component-manifest.d.ts +5 -3
  4. package/dist/src/component-manifest.d.ts.map +1 -1
  5. package/dist/src/component-manifest.js +7 -7
  6. package/dist/src/component-manifest.js.map +1 -1
  7. package/dist/src/constants.d.ts +14 -13
  8. package/dist/src/constants.d.ts.map +1 -1
  9. package/dist/src/constants.js +14 -13
  10. package/dist/src/constants.js.map +1 -1
  11. package/dist/src/d3-build.d.ts +70 -0
  12. package/dist/src/d3-build.d.ts.map +1 -0
  13. package/dist/src/d3-build.js +272 -0
  14. package/dist/src/d3-build.js.map +1 -0
  15. package/dist/src/descriptors.d.ts +2 -2
  16. package/dist/src/descriptors.d.ts.map +1 -1
  17. package/dist/src/descriptors.js +4 -2
  18. package/dist/src/descriptors.js.map +1 -1
  19. package/dist/src/doctor/checks-address.d.ts +18 -0
  20. package/dist/src/doctor/checks-address.d.ts.map +1 -0
  21. package/dist/src/doctor/checks-address.js +163 -0
  22. package/dist/src/doctor/checks-address.js.map +1 -0
  23. package/dist/src/doctor/checks-live.d.ts +8 -5
  24. package/dist/src/doctor/checks-live.d.ts.map +1 -1
  25. package/dist/src/doctor/checks-live.js +226 -188
  26. package/dist/src/doctor/checks-live.js.map +1 -1
  27. package/dist/src/doctor/checks-offline.d.ts +6 -25
  28. package/dist/src/doctor/checks-offline.d.ts.map +1 -1
  29. package/dist/src/doctor/checks-offline.js +30 -259
  30. package/dist/src/doctor/checks-offline.js.map +1 -1
  31. package/dist/src/doctor/checks-preview-limits.d.ts +11 -0
  32. package/dist/src/doctor/checks-preview-limits.d.ts.map +1 -0
  33. package/dist/src/doctor/checks-preview-limits.js +133 -0
  34. package/dist/src/doctor/checks-preview-limits.js.map +1 -0
  35. package/dist/src/doctor/checks-preview-live.d.ts +14 -0
  36. package/dist/src/doctor/checks-preview-live.d.ts.map +1 -0
  37. package/dist/src/doctor/checks-preview-live.js +72 -0
  38. package/dist/src/doctor/checks-preview-live.js.map +1 -0
  39. package/dist/src/doctor/checks-preview.d.ts +7 -0
  40. package/dist/src/doctor/checks-preview.d.ts.map +1 -0
  41. package/dist/src/doctor/checks-preview.js +287 -0
  42. package/dist/src/doctor/checks-preview.js.map +1 -0
  43. package/dist/src/doctor/config-scan.d.ts +12 -3
  44. package/dist/src/doctor/config-scan.d.ts.map +1 -1
  45. package/dist/src/doctor/config-scan.js +38 -11
  46. package/dist/src/doctor/config-scan.js.map +1 -1
  47. package/dist/src/doctor/run.d.ts.map +1 -1
  48. package/dist/src/doctor/run.js +16 -10
  49. package/dist/src/doctor/run.js.map +1 -1
  50. package/dist/src/doctor/types.d.ts +17 -7
  51. package/dist/src/doctor/types.d.ts.map +1 -1
  52. package/dist/src/doctor/types.js +17 -7
  53. package/dist/src/doctor/types.js.map +1 -1
  54. package/dist/src/editor-page/bundle.d.ts +90 -0
  55. package/dist/src/editor-page/bundle.d.ts.map +1 -0
  56. package/dist/src/editor-page/bundle.js +373 -0
  57. package/dist/src/editor-page/bundle.js.map +1 -0
  58. package/dist/src/editor-page/data-schemas.d.ts +16 -0
  59. package/dist/src/editor-page/data-schemas.d.ts.map +1 -0
  60. package/dist/src/editor-page/data-schemas.js +39 -0
  61. package/dist/src/editor-page/data-schemas.js.map +1 -0
  62. package/dist/src/editor-page/emit.d.ts +69 -0
  63. package/dist/src/editor-page/emit.d.ts.map +1 -0
  64. package/dist/src/editor-page/emit.js +254 -0
  65. package/dist/src/editor-page/emit.js.map +1 -0
  66. package/dist/src/editor-page/framing.d.ts +23 -0
  67. package/dist/src/editor-page/framing.d.ts.map +1 -0
  68. package/dist/src/editor-page/framing.js +39 -0
  69. package/dist/src/editor-page/framing.js.map +1 -0
  70. package/dist/src/editor-page/page.d.ts +9 -0
  71. package/dist/src/editor-page/page.d.ts.map +1 -0
  72. package/dist/src/editor-page/page.js +31 -0
  73. package/dist/src/editor-page/page.js.map +1 -0
  74. package/dist/src/editor-page/site-base.d.ts +4 -0
  75. package/dist/src/editor-page/site-base.d.ts.map +1 -0
  76. package/dist/src/editor-page/site-base.js +13 -0
  77. package/dist/src/editor-page/site-base.js.map +1 -0
  78. package/dist/src/git.d.ts +11 -8
  79. package/dist/src/git.d.ts.map +1 -1
  80. package/dist/src/git.js +25 -8
  81. package/dist/src/git.js.map +1 -1
  82. package/dist/src/index.d.ts +4 -1
  83. package/dist/src/index.d.ts.map +1 -1
  84. package/dist/src/index.js +11 -6
  85. package/dist/src/index.js.map +1 -1
  86. package/dist/src/integration.d.ts +1 -1
  87. package/dist/src/integration.d.ts.map +1 -1
  88. package/dist/src/integration.js +377 -416
  89. package/dist/src/integration.js.map +1 -1
  90. package/dist/src/node.d.ts +3 -1
  91. package/dist/src/node.d.ts.map +1 -1
  92. package/dist/src/node.js +7 -2
  93. package/dist/src/node.js.map +1 -1
  94. package/dist/src/preview/_dispatch.d.ts +12 -0
  95. package/dist/src/preview/_dispatch.d.ts.map +1 -1
  96. package/dist/src/preview/_dispatch.js +31 -0
  97. package/dist/src/preview/_dispatch.js.map +1 -1
  98. package/dist/src/preview/_resolve-opts.d.ts +19 -10
  99. package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
  100. package/dist/src/preview/_resolve-opts.js +24 -11
  101. package/dist/src/preview/_resolve-opts.js.map +1 -1
  102. package/dist/src/preview/banner.d.ts +12 -9
  103. package/dist/src/preview/banner.d.ts.map +1 -1
  104. package/dist/src/preview/banner.js +46 -43
  105. package/dist/src/preview/banner.js.map +1 -1
  106. package/dist/src/preview/cloudflare-adapter.d.ts +35 -0
  107. package/dist/src/preview/cloudflare-adapter.d.ts.map +1 -0
  108. package/dist/src/preview/cloudflare-adapter.js +92 -0
  109. package/dist/src/preview/cloudflare-adapter.js.map +1 -0
  110. package/dist/src/preview/cookie.d.ts +13 -14
  111. package/dist/src/preview/cookie.d.ts.map +1 -1
  112. package/dist/src/preview/cookie.js +19 -26
  113. package/dist/src/preview/cookie.js.map +1 -1
  114. package/dist/src/preview/dispatcher.d.ts +73 -0
  115. package/dist/src/preview/dispatcher.d.ts.map +1 -0
  116. package/dist/src/preview/dispatcher.js +329 -0
  117. package/dist/src/preview/dispatcher.js.map +1 -0
  118. package/dist/src/preview/entry-code.d.ts +33 -0
  119. package/dist/src/preview/entry-code.d.ts.map +1 -0
  120. package/dist/src/preview/entry-code.js +33 -0
  121. package/dist/src/preview/entry-code.js.map +1 -0
  122. package/dist/src/preview/headers.d.ts +24 -4
  123. package/dist/src/preview/headers.d.ts.map +1 -1
  124. package/dist/src/preview/headers.js +35 -7
  125. package/dist/src/preview/headers.js.map +1 -1
  126. package/dist/src/preview/label.d.ts +8 -0
  127. package/dist/src/preview/label.d.ts.map +1 -0
  128. package/dist/src/preview/label.js +14 -0
  129. package/dist/src/preview/label.js.map +1 -0
  130. package/dist/src/preview/landing.d.ts +23 -2
  131. package/dist/src/preview/landing.d.ts.map +1 -1
  132. package/dist/src/preview/landing.js +105 -37
  133. package/dist/src/preview/landing.js.map +1 -1
  134. package/dist/src/preview/middleware.d.ts +49 -22
  135. package/dist/src/preview/middleware.d.ts.map +1 -1
  136. package/dist/src/preview/middleware.js +259 -100
  137. package/dist/src/preview/middleware.js.map +1 -1
  138. package/dist/src/preview/preview-path.d.ts +47 -5
  139. package/dist/src/preview/preview-path.d.ts.map +1 -1
  140. package/dist/src/preview/preview-path.js +65 -8
  141. package/dist/src/preview/preview-path.js.map +1 -1
  142. package/dist/src/preview/redeem-url.d.ts +7 -0
  143. package/dist/src/preview/redeem-url.d.ts.map +1 -0
  144. package/dist/src/preview/redeem-url.js +14 -0
  145. package/dist/src/preview/redeem-url.js.map +1 -0
  146. package/dist/src/preview/site-middleware.d.ts +5 -5
  147. package/dist/src/preview/site-middleware.d.ts.map +1 -1
  148. package/dist/src/preview/site-middleware.js +53 -26
  149. package/dist/src/preview/site-middleware.js.map +1 -1
  150. package/dist/src/preview-build.d.ts +29 -15
  151. package/dist/src/preview-build.d.ts.map +1 -1
  152. package/dist/src/preview-build.js +66 -25
  153. package/dist/src/preview-build.js.map +1 -1
  154. package/dist/src/preview.d.ts +1 -1
  155. package/dist/src/preview.d.ts.map +1 -1
  156. package/dist/src/preview.js +1 -1
  157. package/dist/src/preview.js.map +1 -1
  158. package/dist/src/repository.d.ts +1 -1
  159. package/dist/src/repository.js +1 -1
  160. package/dist/src/resolve-options.d.ts +17 -0
  161. package/dist/src/resolve-options.d.ts.map +1 -0
  162. package/dist/src/resolve-options.js +21 -0
  163. package/dist/src/resolve-options.js.map +1 -0
  164. package/dist/src/site-id.d.ts +0 -2
  165. package/dist/src/site-id.d.ts.map +1 -1
  166. package/dist/src/site-id.js +2 -3
  167. package/dist/src/site-id.js.map +1 -1
  168. package/dist/src/skill.d.ts +11 -0
  169. package/dist/src/skill.d.ts.map +1 -1
  170. package/dist/src/skill.js +32 -9
  171. package/dist/src/skill.js.map +1 -1
  172. package/dist/src/types.d.ts +33 -78
  173. package/dist/src/types.d.ts.map +1 -1
  174. package/package.json +63 -13
  175. package/src/component-manifest.ts +11 -8
  176. package/src/constants.ts +15 -13
  177. package/src/d3-build.ts +315 -0
  178. package/src/descriptors.ts +6 -4
  179. package/src/doctor/checks-address.ts +190 -0
  180. package/src/doctor/checks-live.ts +262 -268
  181. package/src/doctor/checks-offline.ts +32 -279
  182. package/src/doctor/checks-preview-limits.ts +137 -0
  183. package/src/doctor/checks-preview-live.ts +77 -0
  184. package/src/doctor/checks-preview.ts +302 -0
  185. package/src/doctor/config-scan.ts +35 -9
  186. package/src/doctor/run.ts +18 -16
  187. package/src/doctor/types.ts +17 -7
  188. package/src/editor-page/bundle.ts +487 -0
  189. package/src/editor-page/data-schemas.ts +47 -0
  190. package/src/editor-page/emit.ts +362 -0
  191. package/src/editor-page/framing.ts +62 -0
  192. package/src/editor-page/page.ts +37 -0
  193. package/src/editor-page/site-base.ts +11 -0
  194. package/src/git.ts +29 -10
  195. package/src/index.ts +22 -6
  196. package/src/integration.ts +399 -469
  197. package/src/node.ts +18 -2
  198. package/src/preview/_dispatch.ts +36 -1
  199. package/src/preview/_resolve-opts.ts +35 -12
  200. package/src/preview/banner.ts +61 -43
  201. package/src/preview/cloudflare-adapter.ts +103 -0
  202. package/src/preview/cookie.ts +18 -24
  203. package/src/preview/dispatcher.ts +407 -0
  204. package/src/preview/entry-code.ts +51 -0
  205. package/src/preview/headers.ts +35 -7
  206. package/src/preview/label.ts +12 -0
  207. package/src/preview/landing.ts +117 -39
  208. package/src/preview/middleware.ts +302 -115
  209. package/src/preview/preview-path.ts +83 -8
  210. package/src/preview/redeem-url.ts +14 -0
  211. package/src/preview/site-middleware.ts +60 -30
  212. package/src/preview-build.ts +85 -26
  213. package/src/preview-handler.astro +12 -9
  214. package/src/preview.ts +0 -1
  215. package/src/repository.ts +1 -1
  216. package/src/resolve-options.ts +37 -0
  217. package/src/site-id.ts +2 -4
  218. package/src/skill/SKILL.md +63 -55
  219. package/src/skill.ts +36 -8
  220. package/src/types.ts +33 -79
  221. package/src/virtual-modules.d.ts +4 -1
  222. package/dist/src/build-commit.d.ts +0 -19
  223. package/dist/src/build-commit.d.ts.map +0 -1
  224. package/dist/src/build-commit.js +0 -6
  225. package/dist/src/build-commit.js.map +0 -1
  226. package/dist/src/bundle.d.ts +0 -181
  227. package/dist/src/bundle.d.ts.map +0 -1
  228. package/dist/src/bundle.js +0 -413
  229. package/dist/src/bundle.js.map +0 -1
  230. package/dist/src/discovery.d.ts +0 -58
  231. package/dist/src/discovery.d.ts.map +0 -1
  232. package/dist/src/discovery.js +0 -133
  233. package/dist/src/discovery.js.map +0 -1
  234. package/dist/src/register.d.ts +0 -98
  235. package/dist/src/register.d.ts.map +0 -1
  236. package/dist/src/register.js +0 -103
  237. package/dist/src/register.js.map +0 -1
  238. package/src/build-commit.ts +0 -22
  239. package/src/bundle.ts +0 -570
  240. package/src/discovery.ts +0 -183
  241. package/src/register.ts +0 -180
@@ -1,81 +1,164 @@
1
+ import { PREVIEW_PROTOCOL, previewBranchSlug } from '@conloca/content-api/editor-host';
1
2
  import { createRemoteJWKSet, customFetch, jwtVerify } from 'jose';
2
- import { parseCookies, serializePreviewCookie } from './cookie.js';
3
- import { renderNoPreviewLanding } from './landing.js';
4
- import { stripPreviewPrefix } from './preview-path.js';
3
+ import { parseCookieValues, serializePreviewCookie } from './cookie.js';
4
+ import { exchangeEntryCode } from './entry-code.js';
5
+ import { PREVIEW_CACHE_HEADERS } from './headers.js';
6
+ import { previewLabel } from './label.js';
7
+ import { renderNoPreviewLanding, renderPreviewUnavailable, renderShareEnded } from './landing.js';
8
+ import { PREVIEW_CODE_PARAM, PREVIEW_LABEL_HEADER, PREVIEW_MODE_HEADER, PREVIEW_PROTOCOL_HEADER, PREVIEW_QUERY_PARAM, previewRoutePrefix, previewScope, stripPreviewPrefix, } from './preview-path.js';
9
+ import { GRANT_REF_RE, grantRef } from './redeem-url.js';
5
10
  /**
6
11
  * Inspects a preview-route request and decides whether to validate, redirect,
7
12
  * or render a landing page. See the docstring on {@link PreviewVerdict} for
8
13
  * the caller contract.
9
14
  *
10
15
  * Order of checks:
11
- * 1. `?conloca_preview_${secret}=<JWT>` query param → validate; on
16
+ * 0. `<base>/_conloca/preview/__exit` → expire the cookie and redirect,
17
+ * carrying this build's public label.
18
+ * 1. `?conloca_code=<code>` → trade the single-use code for the pass on
19
+ * the server; on success issue a 302 with the cookie set and the code
20
+ * stripped. A used code with a valid cookie redirects to the clean path.
21
+ * 2. `?conloca_preview=<JWT>` query param (protocol 1) → validate; on
12
22
  * success issue a 302 with the cookie set and the query stripped.
13
- * 2. `conloca_preview_${secret}=<JWT>` cookie → validate; on success
14
- * return a `preview` verdict with the decoded context.
15
- * 3. Neither present → no-preview landing page response.
23
+ * 3. The pass cookie (`__Host-conloca_preview`; under D3 `__Secure-conloca_preview_<slug>`) → every value sent,
24
+ * the first that verifies; on success return a `preview` verdict with the decoded context.
25
+ * 4. Neither present → no-preview landing page response.
16
26
  *
17
27
  * Invalid JWTs (tampered signature, expired, missing required claim, wrong
18
- * issuer/audience/scope) fall through to the landing page. We deliberately do
28
+ * issuer/audience/scope, or naming another repository, site or branch than
29
+ * this build serves) fall through to the landing page. We deliberately do
19
30
  * NOT return 401 — a 401 to an unauthenticated caller would confirm that
20
31
  * a particular path is preview-only, which leaks information about what
21
32
  * the branch contains.
22
33
  */
23
34
  export async function handlePreviewRequest(request, opts) {
24
35
  const url = new URL(request.url);
25
- const queryName = previewParamName(opts.secret);
26
- const cookieName = previewParamName(opts.secret);
36
+ const mode = opts.mode ?? 'd2';
27
37
  // 0. Exit route: the banner's "Exit Preview" target. The cookie is HttpOnly
28
38
  // on purpose, so leaving preview needs a server response that expires it.
29
39
  // Handled before the credential checks — an expired cookie must not strand
30
- // the visitor in a preview they can no longer exit.
31
- if (url.pathname === `/${previewParamName(opts.secret)}/__exit`) {
32
- return { kind: 'response', response: makeExitRedirect(url, opts.secret) };
40
+ // the visitor in a preview they can no longer exit. Its label lets the
41
+ // endpoint's probe tell which repository, site and branch this server serves.
42
+ // Under D3 the dispatcher answers it through this same function, without loading the preview server.
43
+ if (url.pathname === `${previewRoutePrefix(opts.base)}/__exit`) {
44
+ const label = await previewLabel(opts.repo, opts.siteId, opts.branch);
45
+ return { kind: 'response', response: makeExitRedirect(url, opts, label) };
33
46
  }
34
- // 1. Query-param init path.
35
- const queryToken = url.searchParams.get(queryName);
36
- if (queryToken !== null) {
37
- const ctx = await tryValidate(queryToken, opts);
38
- if (ctx) {
47
+ const landing = () => {
48
+ // Stripped: the landing's "Go to production" link is the same path
49
+ // relative — rendered under the preview route it loops back to itself.
50
+ const pathname = stripPreviewPrefix(url.pathname, opts.base);
51
+ // Under a D3 slug the dispatcher would move that path back under the route, where the same failing cookie lands
52
+ // here again: the slug's exit clears it and then leaves for the published page.
53
+ const liveHref = mode === 'd3' && opts.slug !== undefined
54
+ ? `${previewScope('d3', opts.base, opts.slug).route}/__exit?to=${encodeURIComponent(pathname)}`
55
+ : undefined;
56
+ return {
57
+ kind: 'response',
58
+ response: renderNoPreviewLanding({
59
+ pathname,
60
+ saasEndpoint: opts.saasEndpoint,
61
+ ...(liveHref === undefined ? {} : { liveHref }),
62
+ }),
63
+ };
64
+ };
65
+ const cookie = request.headers.get('cookie');
66
+ const code = url.searchParams.get(PREVIEW_CODE_PARAM);
67
+ // Under D3 only the dispatcher's slug makes a request a preview request, except an entry link without one (an older
68
+ // Conloca's, or a mint that couldn't read the mode): its slug comes from the pass. Anything else is the live site's.
69
+ const slugless = mode === 'd3' && opts.slug === undefined;
70
+ // A code counts only on the preview route: on the live site's own routes, trading it would let anyone make this
71
+ // server call Conloca once per request.
72
+ const entering = code !== null && stripPreviewPrefix(url.pathname, opts.base) !== url.pathname;
73
+ if (slugless && !entering)
74
+ return opts.onMiss === 'pass-through' ? { kind: 'pass-through' } : landing();
75
+ // A slugless entry has no scope until the pass names its branch.
76
+ const scope = slugless ? null : previewScope(mode, opts.base, opts.slug);
77
+ // 1. Entry code (protocol 2): trade it for the pass on the server.
78
+ if (code !== null) {
79
+ const exchanged = await exchangeEntryCode({
80
+ saasEndpoint: opts.saasEndpoint,
81
+ code,
82
+ origin: url.origin,
83
+ repo: opts.repo,
84
+ siteId: opts.siteId,
85
+ fetchFn: opts.fetchFn,
86
+ });
87
+ const path = stripPreviewPrefix(url.pathname, opts.base);
88
+ const route = scope?.route ?? previewRoutePrefix(opts.base);
89
+ const exitHref = `${route}/__exit?to=${encodeURIComponent(path)}`;
90
+ if (exchanged.ok) {
91
+ const ctx = await tryValidate(exchanged.pass, opts);
92
+ if (ctx !== null) {
93
+ const entered = scope ?? previewScope('d3', opts.base, previewBranchSlug(ctx.branch));
94
+ return { kind: 'response', response: makeInitRedirect(url, exchanged.pass, ctx, opts, entered) };
95
+ }
96
+ }
97
+ else if (exchanged.kind === 'ended') {
39
98
  return {
40
99
  kind: 'response',
41
- response: makeInitRedirect(url, queryName, queryToken, opts.secret, ctx.expiresInSeconds),
100
+ response: renderShareEnded(exchanged.ended.verdict, { sharedBy: exchanged.ended.sharedBy, liveHref: exitHref }),
42
101
  };
43
102
  }
44
- // Invalid query-param JWT — fall through to the landing page rather than
45
- // issuing a 401 (see docstring).
103
+ else if (exchanged.kind === 'unavailable') {
104
+ // Never the held pass: it may open another branch than the link names. Under D3 the dispatcher forwarded the
105
+ // entry without its slug, so Retry rebuilds the link it came from; a slugless one is retried as it is.
106
+ const retryHref = mode === 'd3' && scope !== null
107
+ ? `${scope.route}${pageUnderBase(path, opts.base)}${url.search}`
108
+ : `${url.pathname}${url.search}`;
109
+ return { kind: 'response', response: renderPreviewUnavailable({ retryHref, exitHref }) };
110
+ }
111
+ else if (scope !== null && (await firstValid(parseCookieValues(cookie, scope.pass), opts)) !== null) {
112
+ // A used code reopened from history while the cookie still holds a pass: open the page.
113
+ return { kind: 'response', response: makeCleanRedirect(url, opts, scope) };
114
+ }
115
+ return landing();
116
+ }
117
+ if (scope === null)
118
+ return landing();
119
+ // 2. Query-param init path (protocol 1, read for one release). An invalid
120
+ // pass gets the landing page rather than a 401 (see docstring). D3 never had protocol-1 links, so it takes none.
121
+ const queryToken = mode === 'd3' ? null : url.searchParams.get(PREVIEW_QUERY_PARAM);
122
+ if (queryToken !== null) {
123
+ const ctx = await tryValidate(queryToken, opts);
124
+ return ctx === null
125
+ ? landing()
126
+ : { kind: 'response', response: makeInitRedirect(url, queryToken, ctx, opts, scope) };
127
+ }
128
+ // 3. Cookie path.
129
+ const ctx = await firstValid(parseCookieValues(cookie, scope.pass), opts);
130
+ if (ctx !== null)
131
+ return { kind: 'preview', ctx };
132
+ // 4. No valid preview context.
133
+ // Under D3 and D4 a share viewer's expired pass renews through the share link the grant cookie names.
134
+ const ref = scope.grant === null ? undefined : parseCookieValues(cookie, scope.grant).find((v) => GRANT_REF_RE.test(v));
135
+ if (ref !== undefined) {
136
+ const [org, grant] = ref.split('.');
137
+ const to = encodeURIComponent(stripPreviewPrefix(url.pathname, opts.base));
46
138
  return {
47
139
  kind: 'response',
48
- response: renderNoPreviewLanding({ pathname: stripPreviewPrefix(url.pathname), saasEndpoint: opts.saasEndpoint }),
140
+ response: new Response(null, {
141
+ status: 302,
142
+ headers: {
143
+ location: `${opts.saasEndpoint}/preview/redeem/${org}/${grant}?renew=1&to=${to}`,
144
+ ...PREVIEW_CACHE_HEADERS,
145
+ },
146
+ }),
49
147
  };
50
148
  }
51
- // 2. Cookie path.
52
- const cookies = parseCookies(request.headers.get('cookie'));
53
- const cookieToken = cookies.get(cookieName);
54
- if (cookieToken !== undefined) {
55
- const ctx = await tryValidate(cookieToken, opts);
56
- if (ctx) {
57
- return { kind: 'preview', ctx };
58
- }
59
- }
60
- // 3. No valid preview context.
61
- if (opts.onMiss === 'pass-through') {
149
+ if (opts.onMiss === 'pass-through')
62
150
  return { kind: 'pass-through' };
63
- }
64
- return {
65
- kind: 'response',
66
- // Stripped: the landing's "Go to production" link is the same path
67
- // relative — rendered with the secret prefix it loops back to itself.
68
- response: renderNoPreviewLanding({ pathname: stripPreviewPrefix(url.pathname), saasEndpoint: opts.saasEndpoint }),
69
- };
151
+ return landing();
70
152
  }
71
- /**
72
- * Derives the query-param / cookie name from the per-branch secret. The
73
- * name doubles as a load guard: a same-domain request-runtime wrapper
74
- * checks for this exact string before invoking the SSR handler, so random
75
- * `?conloca_preview_*` query strings cannot wake the preview path.
76
- */
77
- export function previewParamName(secret) {
78
- return `conloca_preview_${secret}`;
153
+ /** The first token that verifies, in order; a planted cookie sent first must not lock the viewer out. */
154
+ async function firstValid(tokens, opts) {
155
+ for (const token of tokens) {
156
+ // oxlint-disable-next-line no-await-in-loop -- in order: the first that verifies wins, the rest are never checked.
157
+ const ctx = await tryValidate(token, opts);
158
+ if (ctx !== null)
159
+ return ctx;
160
+ }
161
+ return null;
79
162
  }
80
163
  /**
81
164
  * Validates a JWT and projects its claims into a {@link PreviewContext}.
@@ -87,10 +170,10 @@ async function tryValidate(token, opts) {
87
170
  const getKey = opts.getKey ?? defaultJwksResolver(opts.saasEndpoint, opts.fetchFn);
88
171
  try {
89
172
  const { payload } = await jwtVerify(token, getKey, {
90
- issuer: opts.saasIssuer,
91
173
  audience: opts.saasAudience,
174
+ ...(opts.saasIssuer === undefined ? {} : { issuer: opts.saasIssuer }),
92
175
  });
93
- return projectContext(payload, token);
176
+ return projectContext(payload, token, opts);
94
177
  }
95
178
  catch {
96
179
  return null;
@@ -119,9 +202,12 @@ function defaultJwksResolver(endpoint, fetchFn) {
119
202
  * Project a verified JWT payload into the preview context envelope. Returns
120
203
  * `null` if any required claim is missing or wrong type — a JWT that
121
204
  * validates cryptographically but lacks `branch` names no branch to read,
122
- * so it is treated as invalid here.
205
+ * so it is treated as invalid here — and when the pass is for another build:
206
+ * its `repo` and `site_id` must be the ones this build serves, and its
207
+ * `branch` must be this build's branch unless `served_by` names it (only
208
+ * Conloca sets `served_by`, and only to the default branch).
123
209
  */
124
- function projectContext(payload, jwt) {
210
+ function projectContext(payload, jwt, opts) {
125
211
  if (payload.scope !== 'preview')
126
212
  return null;
127
213
  const branch = readStringClaim(payload, 'branch');
@@ -129,69 +215,142 @@ function projectContext(payload, jwt) {
129
215
  const repo = readStringClaim(payload, 'repo');
130
216
  if (!branch || !org || !repo)
131
217
  return null;
132
- // Remaining token lifetime, so the cookie can be bounded to the credential
133
- // it carries rather than living for the whole browser session. `exp` is
134
- // already verified by `jwtVerify` above, so it is present and in the future.
218
+ if (repo !== opts.repo || readStringClaim(payload, 'site_id') !== opts.siteId)
219
+ return null;
220
+ if (branch !== opts.branch && readStringClaim(payload, 'served_by') !== opts.branch)
221
+ return null;
222
+ // Under D3 the cookie lives under its branch's slug: a pass for another branch never opens this one's pages. A
223
+ // slugless entry has no slug yet; its scope comes from this branch (handlePreviewRequest).
224
+ if (opts.mode === 'd3' && opts.slug !== undefined && previewBranchSlug(branch) !== opts.slug)
225
+ return null;
135
226
  const expiresInSeconds = typeof payload.exp === 'number' ? Math.max(0, payload.exp - Math.floor(Date.now() / 1000)) : undefined;
136
- return { branch, org, repo, jwt, expiresInSeconds };
227
+ // A share pass names its link and the link's expiry; a pass that names a link without one is malformed.
228
+ const grantId = readStringClaim(payload, 'grant');
229
+ const grantExp = payload.grant_exp;
230
+ if (grantId !== undefined && typeof grantExp !== 'number')
231
+ return null;
232
+ const grant = grantId === undefined || typeof grantExp !== 'number'
233
+ ? undefined
234
+ : { id: grantId, expiresAt: grantExp, sharedBy: readStringClaim(payload, 'shared_by') ?? '' };
235
+ const editorUrl = grant === undefined ? editorUrlOf(readStringClaim(payload, 'editor_url')) : undefined;
236
+ return {
237
+ branch,
238
+ org,
239
+ repo,
240
+ jwt,
241
+ expiresInSeconds,
242
+ ...(grant === undefined ? {} : { grant }),
243
+ ...(editorUrl === undefined ? {} : { editorUrl }),
244
+ };
245
+ }
246
+ /** The editor address a pass names, when it is an https URL (http only on `.localhost`). */
247
+ function editorUrlOf(value) {
248
+ if (value === undefined || !URL.canParse(value))
249
+ return undefined;
250
+ const url = new URL(value);
251
+ const local = url.protocol === 'http:' && url.hostname.endsWith('.localhost');
252
+ return url.protocol === 'https:' || local ? url.toString() : undefined;
137
253
  }
138
254
  function readStringClaim(payload, name) {
139
255
  const value = payload[name];
140
256
  return typeof value === 'string' && value.length > 0 ? value : undefined;
141
257
  }
142
258
  /**
143
- * Builds the 302 response that strips the preview query parameter from
144
- * the requested URL and sets the preview cookie. Preserves every other
145
- * query parameter so analytics / utm tags survive the redirect.
146
- *
147
- * The caller passes both the query-param name (so we know which key to
148
- * strip) and the raw secret (so we can derive the cookie name without a
149
- * roundtrip parse). The two are bound by `previewParamName(secret)` ===
150
- * `queryName` at the call site.
259
+ * Builds the 302 that expires the preview cookies and returns the visitor to
260
+ * the published page `?to=` names (see {@link exitTarget}). The headers carry
261
+ * this build's public label, the preview protocol it speaks and its mode.
151
262
  */
263
+ function makeExitRedirect(url, opts, label) {
264
+ const mode = opts.mode ?? 'd2';
265
+ const headers = new Headers({
266
+ location: exitTarget(url, opts),
267
+ ...PREVIEW_CACHE_HEADERS,
268
+ [PREVIEW_LABEL_HEADER]: label,
269
+ // Lets Conloca refuse to link to a preview server below its protocol floor.
270
+ [PREVIEW_PROTOCOL_HEADER]: String(PREVIEW_PROTOCOL),
271
+ // Lets Conloca shape the link: under D3 it starts with the branch slug.
272
+ [PREVIEW_MODE_HEADER]: mode,
273
+ });
274
+ // The probe asks a D3 server without a slug: it names no cookies, so none are expired.
275
+ if (mode === 'd3' && opts.slug === undefined)
276
+ return new Response(null, { status: 302, headers });
277
+ const scope = previewScope(mode, opts.base, opts.slug);
278
+ headers.append('set-cookie', serializePreviewCookie(scope.pass, '', 0, scope.path));
279
+ // Without this the renewal would see the grant and send the viewer straight back in.
280
+ if (scope.grant !== null)
281
+ headers.append('set-cookie', serializePreviewCookie(scope.grant, '', 0, scope.path));
282
+ return new Response(null, { status: 302, headers });
283
+ }
152
284
  /**
153
- * Builds the 302 that expires the preview cookie and returns the visitor to
154
- * the published page. `?to=` names the page the banner was on; only a
155
- * same-origin absolute path is accepted (a full URL or `//host` would turn
156
- * this route into an open redirect), anything else falls back to `/`.
285
+ * Where Exit sends the visitor: `?to=` resolved against this origin and kept
286
+ * only while it stays there, as its path and query with the preview route
287
+ * (under D3, the route and the slug) stripped. Anything else falls back to the
288
+ * site's base: another origin, `//host`, and `/\host` or `/<tab>/host`, which
289
+ * browsers read as `//host`. The emitted path is checked again, because the
290
+ * browser parses it again: `https://site//host`, `/.//host` and
291
+ * `<preview route>//host` all leave a same-origin parse as the path `//host`.
157
292
  */
158
- function makeExitRedirect(url, secret) {
159
- const to = url.searchParams.get('to') ?? '/';
160
- const target = to.startsWith('/') && !to.startsWith('//') ? to : '/';
161
- return new Response(null, {
162
- status: 302,
163
- headers: {
164
- location: target,
165
- 'set-cookie': serializePreviewCookie(previewParamName(secret), '', 0),
166
- 'cache-control': 'private, no-store',
167
- },
168
- });
293
+ function exitTarget(url, opts) {
294
+ const { base } = opts;
295
+ const to = url.searchParams.get('to');
296
+ if (to === null || to === '')
297
+ return base;
298
+ let target;
299
+ try {
300
+ target = new URL(to, url.origin);
301
+ }
302
+ catch {
303
+ return base;
304
+ }
305
+ if (target.origin !== url.origin)
306
+ return base;
307
+ const location = `${pageOf(target.pathname, opts)}${target.search}`;
308
+ return new URL(location, url.origin).origin === url.origin ? location : base;
309
+ }
310
+ /** A pathname with the preview route stripped; under D3 the branch slug goes with it. */
311
+ function pageOf(pathname, opts) {
312
+ if (opts.mode === 'd3' && opts.slug !== undefined) {
313
+ const { route } = previewScope('d3', opts.base, opts.slug);
314
+ if (pathname === route || pathname.startsWith(`${route}/`)) {
315
+ return `${opts.base.replace(/\/+$/u, '')}${pathname.slice(route.length) || '/'}`;
316
+ }
317
+ }
318
+ return stripPreviewPrefix(pathname, opts.base);
319
+ }
320
+ /** A page path under the site's base, as it follows the D3 route: `/docs/blog` under `/docs/` is `/blog`. */
321
+ function pageUnderBase(path, base) {
322
+ return path.slice(base.replace(/\/+$/u, '').length) || '/';
169
323
  }
170
- function makeInitRedirect(url, queryName, token, secret, maxAgeSeconds) {
324
+ /**
325
+ * The requested URL without the code or pass parameter. Under D2 and D4 the cookie is on `Path=/`, so the visitor
326
+ * belongs on the real path; under D3 the pass lives under the route and slug, so the page stays there. Other query
327
+ * parameters (analytics tags) stay.
328
+ */
329
+ function cleanLocation(url, opts, scope) {
171
330
  const cleaned = new URL(url.toString());
172
- cleaned.searchParams.delete(queryName);
173
- // Land the browser on the REAL site path, not the secret-prefixed one.
174
- // The prefix is an entry door: it exists so the endpoint has a URL to link to
175
- // before any cookie exists. Once the cookie is set (Path=/), every
176
- // same-origin request carries the credential, so the visitor belongs on the
177
- // canonical path — otherwise the first internal link they click drops the
178
- // prefix, escapes preview, and silently shows published content.
179
- cleaned.pathname = stripPreviewPrefix(cleaned.pathname);
180
- // Normalise the search string: when the only param was the preview JWT,
181
- // URL.search becomes '' but URL.toString() still emits a trailing `?` only
182
- // if it was already empty. Re-serialising via URL strips that automatically;
183
- // double-check by explicitly clearing the `?` when no params remain.
184
- let location = cleaned.toString();
185
- if (cleaned.search === '' && location.endsWith('?')) {
186
- location = location.slice(0, -1);
331
+ cleaned.searchParams.delete(PREVIEW_QUERY_PARAM);
332
+ cleaned.searchParams.delete(PREVIEW_CODE_PARAM);
333
+ const page = stripPreviewPrefix(cleaned.pathname, opts.base);
334
+ cleaned.pathname = opts.mode === 'd3' ? `${scope.route}${pageUnderBase(page, opts.base)}` : page;
335
+ const location = cleaned.toString();
336
+ return cleaned.search === '' && location.endsWith('?') ? location.slice(0, -1) : location;
337
+ }
338
+ /** The 302 that sets the pass cookie (and, under D3 and D4, the grant cookie) and lands on the page. */
339
+ function makeInitRedirect(url, token, ctx, opts, scope) {
340
+ const headers = new Headers({ location: cleanLocation(url, opts, scope), ...PREVIEW_CACHE_HEADERS });
341
+ headers.append('set-cookie', serializePreviewCookie(scope.pass, token, ctx.expiresInSeconds, scope.path));
342
+ const { org, grant } = ctx;
343
+ if (scope.grant !== null && grant !== undefined) {
344
+ const lifetime = grant.expiresAt - Math.floor(Date.now() / 1000);
345
+ headers.append('set-cookie', serializePreviewCookie(scope.grant, grantRef(org, grant.id), lifetime, scope.path));
187
346
  }
347
+ return new Response(null, { status: 302, headers });
348
+ }
349
+ /** The 302 to the page for a visitor who already holds a valid pass. */
350
+ function makeCleanRedirect(url, opts, scope) {
188
351
  return new Response(null, {
189
352
  status: 302,
190
- headers: {
191
- location,
192
- 'set-cookie': serializePreviewCookie(previewParamName(secret), token, maxAgeSeconds),
193
- 'cache-control': 'private, no-store',
194
- },
353
+ headers: { location: cleanLocation(url, opts, scope), ...PREVIEW_CACHE_HEADERS },
195
354
  });
196
355
  }
197
356
  //# sourceMappingURL=middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/preview/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAyC,SAAS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AAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,GAAG,qBAAqB,EAAE,CAAC,CAAC;IACrG,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,sBAAsB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,gBAAgB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1G,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAC3B,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAChD,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QACjE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,sBAAsB,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACnH,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;AACtD,CAAC;AAED,wEAAwE;AACxE,SAAS,iBAAiB,CAAC,GAAQ,EAAE,IAA8B,EAAE,KAAmB;IACtF,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;QACxB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,EAAE,QAAQ,EAAE,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,GAAG,qBAAqB,EAAE;KACjF,CAAC,CAAC;AACL,CAAC"}
@@ -1,15 +1,57 @@
1
1
  /**
2
- * Strip a leading `/conloca_preview_<secret>` segment from a pathname.
2
+ * The fixed preview route and the names it uses.
3
3
  *
4
4
  * Lives in its own module because the entry-hop middleware, the site
5
5
  * middleware and the page-status client all need it without depending on
6
6
  * each other.
7
7
  *
8
- * The match is anchored at the FIRST segment only — a path like
9
- * `/posts/conloca_preview_x/about` is left untouched, so a page that merely
10
- * mentions the prefix mid-tree is never re-anchored to a different page.
8
+ * The route is public and the same on every site: the signed pass is the
9
+ * lock, checked against the repository, site and branch the preview build
10
+ * was made from.
11
11
  */
12
- export declare function stripPreviewPrefix(pathname: string): string;
12
+ export declare const PREVIEW_ROUTE_SEGMENT = "/_conloca/preview";
13
+ export declare const PREVIEW_QUERY_PARAM = "conloca_preview";
14
+ export declare const PREVIEW_COOKIE_NAME = "__Host-conloca_preview";
15
+ /** Protocol 2: the single-use code a preview link carries instead of the pass. */
16
+ export declare const PREVIEW_CODE_PARAM = "conloca_code";
17
+ /** The share link a viewer's pass came from (D4 only), so an expired pass can renew through it. */
18
+ export declare const PREVIEW_GRANT_COOKIE_NAME = "__Host-conloca_grant";
19
+ /** Response header on the exit route's redirect that carries the public label. */
20
+ export declare const PREVIEW_LABEL_HEADER = "conloca-preview";
21
+ /** Response header on the exit route's redirect that names the preview protocol this build speaks. */
22
+ export declare const PREVIEW_PROTOCOL_HEADER = "conloca-preview-protocol";
23
+ /** D3: the request header the dispatcher names the requested branch slug in. It strips any the browser sent. */
24
+ export declare const PREVIEW_SLUG_HEADER = "conloca-preview-slug";
25
+ /** Response header on the exit route's redirect that names how this build serves previews. */
26
+ export declare const PREVIEW_MODE_HEADER = "conloca-preview-mode";
27
+ /** How one preview server is reached: D2 and D4 at the page's own path, D3 under the route and the branch slug. */
28
+ export type PreviewServeMode = 'd2' | 'd3' | 'd4';
29
+ /** One preview's cookie names, the path they live on, and the route its links and exit sit under. */
30
+ export interface PreviewScope {
31
+ pass: string;
32
+ /** The share link's cookie; D2 has none (a viewer whose pass expired opens the link again). */
33
+ grant: string | null;
34
+ path: string;
35
+ route: string;
36
+ }
37
+ /**
38
+ * D3 scopes both cookies to `<base>_conloca/preview/<slug>`, so two tabs on two branches keep two passes. D2 and D4
39
+ * keep the `__Host-` names on `Path=/`, which is what lets the pass follow every same-origin link there.
40
+ */
41
+ export declare function previewScope(mode: PreviewServeMode, base: string, slug: string | undefined): PreviewScope;
42
+ /** The preview route under Astro's `base` (`'/'` → `/_conloca/preview`, `'/docs/'` → `/docs/_conloca/preview`). */
43
+ export declare function previewRoutePrefix(base: string): string;
44
+ /** The `run_worker_first` entries that belong to the preview, not the site: its route, and the image endpoint drafts use. */
45
+ export declare function previewOwnEntries(base: string): string[];
46
+ /**
47
+ * Strip the preview route from a pathname, leaving the page path under the
48
+ * base. Only the route at the base matches: `/blog/_conloca/preview/x` and
49
+ * `/_conloca/previewer/x` are left untouched, so a page that merely mentions
50
+ * the route is never re-anchored to a different page.
51
+ */
52
+ export declare function stripPreviewPrefix(pathname: string, base: string): string;
53
+ /** A site path without the base, as the editor names pages (`/docs/guide` under `/docs/` → `/guide`). */
54
+ export declare function pathUnderBase(path: string, base: string): string;
13
55
  /**
14
56
  * Canonical path form for page-status lookups and production rewrites: no
15
57
  * trailing slash, except the root itself. Browser-facing links carry trailing
@@ -1 +1 @@
1
- {"version":3,"file":"preview-path.d.ts","sourceRoot":"","sources":["../../../src/preview/preview-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAI3D;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG/D"}
1
+ {"version":3,"file":"preview-path.d.ts","sourceRoot":"","sources":["../../../src/preview/preview-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AACrD,eAAO,MAAM,mBAAmB,2BAA2B,CAAC;AAC5D,kFAAkF;AAClF,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AACjD,mGAAmG;AACnG,eAAO,MAAM,y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