@conloca/cloud-astro 0.2.2 → 0.2.3

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 (176) hide show
  1. package/README.md +261 -208
  2. package/dist/.build-inputs.json +60 -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 +5 -13
  8. package/dist/src/constants.d.ts.map +1 -1
  9. package/dist/src/constants.js +5 -13
  10. package/dist/src/constants.js.map +1 -1
  11. package/dist/src/descriptors.d.ts +2 -2
  12. package/dist/src/descriptors.d.ts.map +1 -1
  13. package/dist/src/doctor/checks-address.d.ts +18 -0
  14. package/dist/src/doctor/checks-address.d.ts.map +1 -0
  15. package/dist/src/doctor/checks-address.js +163 -0
  16. package/dist/src/doctor/checks-address.js.map +1 -0
  17. package/dist/src/doctor/checks-live.d.ts +8 -5
  18. package/dist/src/doctor/checks-live.d.ts.map +1 -1
  19. package/dist/src/doctor/checks-live.js +220 -188
  20. package/dist/src/doctor/checks-live.js.map +1 -1
  21. package/dist/src/doctor/checks-offline.d.ts +8 -23
  22. package/dist/src/doctor/checks-offline.d.ts.map +1 -1
  23. package/dist/src/doctor/checks-offline.js +22 -239
  24. package/dist/src/doctor/checks-offline.js.map +1 -1
  25. package/dist/src/doctor/config-scan.d.ts +6 -3
  26. package/dist/src/doctor/config-scan.d.ts.map +1 -1
  27. package/dist/src/doctor/config-scan.js +21 -11
  28. package/dist/src/doctor/config-scan.js.map +1 -1
  29. package/dist/src/doctor/run.d.ts.map +1 -1
  30. package/dist/src/doctor/run.js +12 -10
  31. package/dist/src/doctor/run.js.map +1 -1
  32. package/dist/src/doctor/types.d.ts +7 -7
  33. package/dist/src/doctor/types.d.ts.map +1 -1
  34. package/dist/src/doctor/types.js +7 -7
  35. package/dist/src/doctor/types.js.map +1 -1
  36. package/dist/src/editor-page/bundle.d.ts +88 -0
  37. package/dist/src/editor-page/bundle.d.ts.map +1 -0
  38. package/dist/src/editor-page/bundle.js +370 -0
  39. package/dist/src/editor-page/bundle.js.map +1 -0
  40. package/dist/src/editor-page/emit.d.ts +33 -0
  41. package/dist/src/editor-page/emit.d.ts.map +1 -0
  42. package/dist/src/editor-page/emit.js +183 -0
  43. package/dist/src/editor-page/emit.js.map +1 -0
  44. package/dist/src/editor-page/framing.d.ts +23 -0
  45. package/dist/src/editor-page/framing.d.ts.map +1 -0
  46. package/dist/src/editor-page/framing.js +39 -0
  47. package/dist/src/editor-page/framing.js.map +1 -0
  48. package/dist/src/editor-page/page.d.ts +9 -0
  49. package/dist/src/editor-page/page.d.ts.map +1 -0
  50. package/dist/src/editor-page/page.js +31 -0
  51. package/dist/src/editor-page/page.js.map +1 -0
  52. package/dist/src/editor-page/site-base.d.ts +4 -0
  53. package/dist/src/editor-page/site-base.d.ts.map +1 -0
  54. package/dist/src/editor-page/site-base.js +13 -0
  55. package/dist/src/editor-page/site-base.js.map +1 -0
  56. package/dist/src/git.d.ts +11 -8
  57. package/dist/src/git.d.ts.map +1 -1
  58. package/dist/src/git.js +25 -8
  59. package/dist/src/git.js.map +1 -1
  60. package/dist/src/index.d.ts +3 -1
  61. package/dist/src/index.d.ts.map +1 -1
  62. package/dist/src/index.js +9 -6
  63. package/dist/src/index.js.map +1 -1
  64. package/dist/src/integration.d.ts +1 -1
  65. package/dist/src/integration.d.ts.map +1 -1
  66. package/dist/src/integration.js +245 -408
  67. package/dist/src/integration.js.map +1 -1
  68. package/dist/src/node.d.ts +3 -1
  69. package/dist/src/node.d.ts.map +1 -1
  70. package/dist/src/node.js +7 -2
  71. package/dist/src/node.js.map +1 -1
  72. package/dist/src/preview/_resolve-opts.d.ts +16 -10
  73. package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
  74. package/dist/src/preview/_resolve-opts.js +21 -10
  75. package/dist/src/preview/_resolve-opts.js.map +1 -1
  76. package/dist/src/preview/banner.d.ts.map +1 -1
  77. package/dist/src/preview/banner.js +2 -4
  78. package/dist/src/preview/banner.js.map +1 -1
  79. package/dist/src/preview/cookie.d.ts +5 -2
  80. package/dist/src/preview/cookie.d.ts.map +1 -1
  81. package/dist/src/preview/cookie.js +5 -2
  82. package/dist/src/preview/cookie.js.map +1 -1
  83. package/dist/src/preview/label.d.ts +8 -0
  84. package/dist/src/preview/label.d.ts.map +1 -0
  85. package/dist/src/preview/label.js +14 -0
  86. package/dist/src/preview/label.js.map +1 -0
  87. package/dist/src/preview/landing.d.ts +2 -2
  88. package/dist/src/preview/landing.js +2 -2
  89. package/dist/src/preview/middleware.d.ts +25 -20
  90. package/dist/src/preview/middleware.d.ts.map +1 -1
  91. package/dist/src/preview/middleware.js +56 -51
  92. package/dist/src/preview/middleware.js.map +1 -1
  93. package/dist/src/preview/preview-path.d.ts +18 -5
  94. package/dist/src/preview/preview-path.d.ts.map +1 -1
  95. package/dist/src/preview/preview-path.js +24 -8
  96. package/dist/src/preview/preview-path.js.map +1 -1
  97. package/dist/src/preview/site-middleware.d.ts +5 -5
  98. package/dist/src/preview/site-middleware.d.ts.map +1 -1
  99. package/dist/src/preview/site-middleware.js +16 -16
  100. package/dist/src/preview/site-middleware.js.map +1 -1
  101. package/dist/src/preview-build.d.ts +18 -15
  102. package/dist/src/preview-build.d.ts.map +1 -1
  103. package/dist/src/preview-build.js +36 -21
  104. package/dist/src/preview-build.js.map +1 -1
  105. package/dist/src/preview.d.ts +1 -1
  106. package/dist/src/preview.d.ts.map +1 -1
  107. package/dist/src/preview.js +1 -1
  108. package/dist/src/preview.js.map +1 -1
  109. package/dist/src/repository.d.ts +1 -1
  110. package/dist/src/repository.js +1 -1
  111. package/dist/src/resolve-options.d.ts +17 -0
  112. package/dist/src/resolve-options.d.ts.map +1 -0
  113. package/dist/src/resolve-options.js +21 -0
  114. package/dist/src/resolve-options.js.map +1 -0
  115. package/dist/src/site-id.d.ts +0 -2
  116. package/dist/src/site-id.d.ts.map +1 -1
  117. package/dist/src/site-id.js +2 -3
  118. package/dist/src/site-id.js.map +1 -1
  119. package/dist/src/types.d.ts +21 -69
  120. package/dist/src/types.d.ts.map +1 -1
  121. package/package.json +37 -13
  122. package/src/component-manifest.ts +11 -8
  123. package/src/constants.ts +5 -14
  124. package/src/descriptors.ts +2 -2
  125. package/src/doctor/checks-address.ts +190 -0
  126. package/src/doctor/checks-live.ts +256 -268
  127. package/src/doctor/checks-offline.ts +24 -262
  128. package/src/doctor/config-scan.ts +21 -9
  129. package/src/doctor/run.ts +14 -16
  130. package/src/doctor/types.ts +7 -7
  131. package/src/editor-page/bundle.ts +482 -0
  132. package/src/editor-page/emit.ts +246 -0
  133. package/src/editor-page/framing.ts +62 -0
  134. package/src/editor-page/page.ts +37 -0
  135. package/src/editor-page/site-base.ts +11 -0
  136. package/src/git.ts +29 -10
  137. package/src/index.ts +20 -6
  138. package/src/integration.ts +255 -461
  139. package/src/node.ts +18 -2
  140. package/src/preview/_resolve-opts.ts +29 -11
  141. package/src/preview/banner.ts +2 -4
  142. package/src/preview/cookie.ts +5 -2
  143. package/src/preview/label.ts +12 -0
  144. package/src/preview/landing.ts +2 -2
  145. package/src/preview/middleware.ts +77 -66
  146. package/src/preview/preview-path.ts +26 -8
  147. package/src/preview/site-middleware.ts +16 -21
  148. package/src/preview-build.ts +42 -26
  149. package/src/preview-handler.astro +10 -8
  150. package/src/preview.ts +0 -1
  151. package/src/repository.ts +1 -1
  152. package/src/resolve-options.ts +37 -0
  153. package/src/site-id.ts +2 -4
  154. package/src/skill/SKILL.md +51 -55
  155. package/src/types.ts +21 -70
  156. package/src/virtual-modules.d.ts +4 -1
  157. package/dist/src/build-commit.d.ts +0 -19
  158. package/dist/src/build-commit.d.ts.map +0 -1
  159. package/dist/src/build-commit.js +0 -6
  160. package/dist/src/build-commit.js.map +0 -1
  161. package/dist/src/bundle.d.ts +0 -181
  162. package/dist/src/bundle.d.ts.map +0 -1
  163. package/dist/src/bundle.js +0 -413
  164. package/dist/src/bundle.js.map +0 -1
  165. package/dist/src/discovery.d.ts +0 -58
  166. package/dist/src/discovery.d.ts.map +0 -1
  167. package/dist/src/discovery.js +0 -133
  168. package/dist/src/discovery.js.map +0 -1
  169. package/dist/src/register.d.ts +0 -98
  170. package/dist/src/register.d.ts.map +0 -1
  171. package/dist/src/register.js +0 -103
  172. package/dist/src/register.js.map +0 -1
  173. package/src/build-commit.ts +0 -22
  174. package/src/bundle.ts +0 -570
  175. package/src/discovery.ts +0 -183
  176. package/src/register.ts +0 -180
@@ -1,56 +1,63 @@
1
1
  import { createRemoteJWKSet, customFetch, jwtVerify } from 'jose';
2
2
  import { parseCookies, serializePreviewCookie } from './cookie.js';
3
+ import { previewLabel } from './label.js';
3
4
  import { renderNoPreviewLanding } from './landing.js';
4
- import { stripPreviewPrefix } from './preview-path.js';
5
+ import { PREVIEW_COOKIE_NAME, PREVIEW_LABEL_HEADER, PREVIEW_QUERY_PARAM, previewRoutePrefix, stripPreviewPrefix, } from './preview-path.js';
5
6
  /**
6
7
  * Inspects a preview-route request and decides whether to validate, redirect,
7
8
  * or render a landing page. See the docstring on {@link PreviewVerdict} for
8
9
  * the caller contract.
9
10
  *
10
11
  * Order of checks:
11
- * 1. `?conloca_preview_${secret}=<JWT>` query param → validate; on
12
- * 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.
12
+ * 0. `<base>/_conloca/preview/__exit` → expire the cookie and redirect,
13
+ * carrying this build's public label.
14
+ * 1. `?conloca_preview=<JWT>` query param → validate; on success issue a
15
+ * 302 with the cookie set and the query stripped.
16
+ * 2. `__Host-conloca_preview=<JWT>` cookie → validate; on success return a
17
+ * `preview` verdict with the decoded context.
15
18
  * 3. Neither present → no-preview landing page response.
16
19
  *
17
20
  * Invalid JWTs (tampered signature, expired, missing required claim, wrong
18
- * issuer/audience/scope) fall through to the landing page. We deliberately do
21
+ * issuer/audience/scope, or naming another repository, site or branch than
22
+ * this build serves) fall through to the landing page. We deliberately do
19
23
  * NOT return 401 — a 401 to an unauthenticated caller would confirm that
20
24
  * a particular path is preview-only, which leaks information about what
21
25
  * the branch contains.
22
26
  */
23
27
  export async function handlePreviewRequest(request, opts) {
24
28
  const url = new URL(request.url);
25
- const queryName = previewParamName(opts.secret);
26
- const cookieName = previewParamName(opts.secret);
27
29
  // 0. Exit route: the banner's "Exit Preview" target. The cookie is HttpOnly
28
30
  // on purpose, so leaving preview needs a server response that expires it.
29
31
  // 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) };
32
+ // the visitor in a preview they can no longer exit. Its label lets the
33
+ // endpoint's probe tell which repository, site and branch this server serves.
34
+ if (url.pathname === `${previewRoutePrefix(opts.base)}/__exit`) {
35
+ const label = await previewLabel(opts.repo, opts.siteId, opts.branch);
36
+ return { kind: 'response', response: makeExitRedirect(url, opts.base, label) };
33
37
  }
34
38
  // 1. Query-param init path.
35
- const queryToken = url.searchParams.get(queryName);
39
+ const queryToken = url.searchParams.get(PREVIEW_QUERY_PARAM);
36
40
  if (queryToken !== null) {
37
41
  const ctx = await tryValidate(queryToken, opts);
38
42
  if (ctx) {
39
43
  return {
40
44
  kind: 'response',
41
- response: makeInitRedirect(url, queryName, queryToken, opts.secret, ctx.expiresInSeconds),
45
+ response: makeInitRedirect(url, queryToken, opts.base, ctx.expiresInSeconds),
42
46
  };
43
47
  }
44
48
  // Invalid query-param JWT — fall through to the landing page rather than
45
49
  // issuing a 401 (see docstring).
46
50
  return {
47
51
  kind: 'response',
48
- response: renderNoPreviewLanding({ pathname: stripPreviewPrefix(url.pathname), saasEndpoint: opts.saasEndpoint }),
52
+ response: renderNoPreviewLanding({
53
+ pathname: stripPreviewPrefix(url.pathname, opts.base),
54
+ saasEndpoint: opts.saasEndpoint,
55
+ }),
49
56
  };
50
57
  }
51
58
  // 2. Cookie path.
52
59
  const cookies = parseCookies(request.headers.get('cookie'));
53
- const cookieToken = cookies.get(cookieName);
60
+ const cookieToken = cookies.get(PREVIEW_COOKIE_NAME);
54
61
  if (cookieToken !== undefined) {
55
62
  const ctx = await tryValidate(cookieToken, opts);
56
63
  if (ctx) {
@@ -64,19 +71,13 @@ export async function handlePreviewRequest(request, opts) {
64
71
  return {
65
72
  kind: 'response',
66
73
  // 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 }),
74
+ // relative — rendered under the preview route it loops back to itself.
75
+ response: renderNoPreviewLanding({
76
+ pathname: stripPreviewPrefix(url.pathname, opts.base),
77
+ saasEndpoint: opts.saasEndpoint,
78
+ }),
69
79
  };
70
80
  }
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}`;
79
- }
80
81
  /**
81
82
  * Validates a JWT and projects its claims into a {@link PreviewContext}.
82
83
  * Returns `null` on any validation failure — the failure reason is not
@@ -90,7 +91,7 @@ async function tryValidate(token, opts) {
90
91
  issuer: opts.saasIssuer,
91
92
  audience: opts.saasAudience,
92
93
  });
93
- return projectContext(payload, token);
94
+ return projectContext(payload, token, opts);
94
95
  }
95
96
  catch {
96
97
  return null;
@@ -119,9 +120,12 @@ function defaultJwksResolver(endpoint, fetchFn) {
119
120
  * Project a verified JWT payload into the preview context envelope. Returns
120
121
  * `null` if any required claim is missing or wrong type — a JWT that
121
122
  * validates cryptographically but lacks `branch` names no branch to read,
122
- * so it is treated as invalid here.
123
+ * so it is treated as invalid here — and when the pass is for another build:
124
+ * its `repo` and `site_id` must be the ones this build serves, and its
125
+ * `branch` must be this build's branch unless `served_by` names it (only
126
+ * Conloca sets `served_by`, and only to the default branch).
123
127
  */
124
- function projectContext(payload, jwt) {
128
+ function projectContext(payload, jwt, opts) {
125
129
  if (payload.scope !== 'preview')
126
130
  return null;
127
131
  const branch = readStringClaim(payload, 'branch');
@@ -129,6 +133,10 @@ function projectContext(payload, jwt) {
129
133
  const repo = readStringClaim(payload, 'repo');
130
134
  if (!branch || !org || !repo)
131
135
  return null;
136
+ if (repo !== opts.repo || readStringClaim(payload, 'site_id') !== opts.siteId)
137
+ return null;
138
+ if (branch !== opts.branch && readStringClaim(payload, 'served_by') !== opts.branch)
139
+ return null;
132
140
  // Remaining token lifetime, so the cookie can be bounded to the credential
133
141
  // it carries rather than living for the whole browser session. `exp` is
134
142
  // already verified by `jwtVerify` above, so it is present and in the future.
@@ -139,44 +147,41 @@ function readStringClaim(payload, name) {
139
147
  const value = payload[name];
140
148
  return typeof value === 'string' && value.length > 0 ? value : undefined;
141
149
  }
142
- /**
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.
151
- */
152
150
  /**
153
151
  * Builds the 302 that expires the preview cookie and returns the visitor to
154
152
  * the published page. `?to=` names the page the banner was on; only a
155
153
  * 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 `/`.
154
+ * this route into an open redirect), anything else falls back to the site's
155
+ * base. The `conloca-preview` header carries this build's public label.
157
156
  */
158
- function makeExitRedirect(url, secret) {
159
- const to = url.searchParams.get('to') ?? '/';
160
- const target = to.startsWith('/') && !to.startsWith('//') ? to : '/';
157
+ function makeExitRedirect(url, base, label) {
158
+ const to = url.searchParams.get('to') ?? base;
159
+ const target = to.startsWith('/') && !to.startsWith('//') ? to : base;
161
160
  return new Response(null, {
162
161
  status: 302,
163
162
  headers: {
164
163
  location: target,
165
- 'set-cookie': serializePreviewCookie(previewParamName(secret), '', 0),
164
+ 'set-cookie': serializePreviewCookie(PREVIEW_COOKIE_NAME, '', 0),
166
165
  'cache-control': 'private, no-store',
166
+ [PREVIEW_LABEL_HEADER]: label,
167
167
  },
168
168
  });
169
169
  }
170
- function makeInitRedirect(url, queryName, token, secret, maxAgeSeconds) {
170
+ /**
171
+ * Builds the 302 response that strips the preview query parameter from
172
+ * the requested URL and sets the preview cookie. Preserves every other
173
+ * query parameter so analytics / utm tags survive the redirect.
174
+ */
175
+ function makeInitRedirect(url, token, base, maxAgeSeconds) {
171
176
  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
177
+ cleaned.searchParams.delete(PREVIEW_QUERY_PARAM);
178
+ // Land the browser on the REAL site path, not the preview route.
179
+ // The route is an entry door: it exists so the endpoint has a URL to link to
175
180
  // before any cookie exists. Once the cookie is set (Path=/), every
176
181
  // same-origin request carries the credential, so the visitor belongs on the
177
182
  // 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);
183
+ // route, escapes preview, and silently shows published content.
184
+ cleaned.pathname = stripPreviewPrefix(cleaned.pathname, base);
180
185
  // Normalise the search string: when the only param was the preview JWT,
181
186
  // URL.search becomes '' but URL.toString() still emits a trailing `?` only
182
187
  // if it was already empty. Re-serialising via URL strips that automatically;
@@ -189,7 +194,7 @@ function makeInitRedirect(url, queryName, token, secret, maxAgeSeconds) {
189
194
  status: 302,
190
195
  headers: {
191
196
  location,
192
- 'set-cookie': serializePreviewCookie(previewParamName(secret), token, maxAgeSeconds),
197
+ 'set-cookie': serializePreviewCookie(PREVIEW_COOKIE_NAME, token, maxAgeSeconds),
193
198
  'cache-control': 'private, no-store',
194
199
  },
195
200
  });
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/preview/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAyC,SAAS,EAAE,MAAM,MAAM,CAAC;AACzG,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAgGvD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAAgB,EAAE,IAA8B;IACzF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,MAAM,SAAS,GAAG,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEjD,4EAA4E;IAC5E,0EAA0E;IAC1E,2EAA2E;IAC3E,oDAAoD;IACpD,IAAI,GAAG,CAAC,QAAQ,KAAK,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QAChE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IAC5E,CAAC;IAED,4BAA4B;IAC5B,MAAM,UAAU,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACnD,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAChD,IAAI,GAAG,EAAE,CAAC;YACR,OAAO;gBACL,IA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ClC,IAAI,OAAO,CAAC,MAAM,KAAK,EAAE,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACpD,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;QACxB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE;YACP,QAAQ;YACR,YAAY,EAAE,sBAAsB,CAAC,mBAAmB,EAAE,KAAK,EAAE,aAAa,CAAC;YAC/E,eAAe,EAAE,mBAAmB;SACrC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -1,15 +1,28 @@
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
+ /** Response header on the exit route's redirect that carries the public label. */
16
+ export declare const PREVIEW_LABEL_HEADER = "conloca-preview";
17
+ /** The preview route under Astro's `base` (`'/'` → `/_conloca/preview`, `'/docs/'` → `/docs/_conloca/preview`). */
18
+ export declare function previewRoutePrefix(base: string): string;
19
+ /**
20
+ * Strip the preview route from a pathname, leaving the page path under the
21
+ * base. Only the route at the base matches: `/blog/_conloca/preview/x` and
22
+ * `/_conloca/previewer/x` are left untouched, so a page that merely mentions
23
+ * the route is never re-anchored to a different page.
24
+ */
25
+ export declare function stripPreviewPrefix(pathname: string, base: string): string;
13
26
  /**
14
27
  * Canonical path form for page-status lookups and production rewrites: no
15
28
  * 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,oBAAoB,oBAAoB,CAAC;AAEtD,mHAAmH;AACnH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAKzE;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG/D"}
@@ -1,19 +1,35 @@
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 function stripPreviewPrefix(pathname) {
13
- const match = /^\/conloca_preview_[^/]+(\/.*)?$/.exec(pathname);
14
- if (!match)
12
+ export const PREVIEW_ROUTE_SEGMENT = '/_conloca/preview';
13
+ export const PREVIEW_QUERY_PARAM = 'conloca_preview';
14
+ export const PREVIEW_COOKIE_NAME = '__Host-conloca_preview';
15
+ /** Response header on the exit route's redirect that carries the public label. */
16
+ export const PREVIEW_LABEL_HEADER = 'conloca-preview';
17
+ /** The preview route under Astro's `base` (`'/'` → `/_conloca/preview`, `'/docs/'` → `/docs/_conloca/preview`). */
18
+ export function previewRoutePrefix(base) {
19
+ return `${base.replace(/\/+$/u, '')}${PREVIEW_ROUTE_SEGMENT}`;
20
+ }
21
+ /**
22
+ * Strip the preview route from a pathname, leaving the page path under the
23
+ * base. Only the route at the base matches: `/blog/_conloca/preview/x` and
24
+ * `/_conloca/previewer/x` are left untouched, so a page that merely mentions
25
+ * the route is never re-anchored to a different page.
26
+ */
27
+ export function stripPreviewPrefix(pathname, base) {
28
+ const prefix = previewRoutePrefix(base);
29
+ if (pathname !== prefix && !pathname.startsWith(`${prefix}/`))
15
30
  return pathname;
16
- return match[1] ?? '/';
31
+ const rest = pathname.slice(prefix.length);
32
+ return `${base.replace(/\/+$/u, '')}${rest === '' ? '/' : rest}`;
17
33
  }
18
34
  /**
19
35
  * Canonical path form for page-status lookups and production rewrites: no
@@ -1 +1 @@
1
- {"version":3,"file":"preview-path.js","sourceRoot":"","sources":["../../../src/preview/preview-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,MAAM,KAAK,GAAG,kCAAkC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChE,IAAI,CAAC,KAAK;QAAE,OAAO,QAAQ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AAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACnE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAAgB;IACrD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC/C,OAAO,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC1C,CAAC"}
@@ -2,15 +2,15 @@
2
2
  * Site-wide preview middleware for the recursive preview build — the SERVING
3
3
  * SURFACE of draft preview.
4
4
  *
5
- * WHY THIS EXISTS — the secret path prefix is an entry door, not the serving
5
+ * WHY THIS EXISTS — the fixed preview route is an entry door, not the serving
6
6
  * surface. Without this, preview survives exactly one page view: the visitor
7
- * lands on `/conloca_preview_<secret>/about`, clicks a link, and the
8
- * root-absolute `/blog` the site's template emitted drops the prefix and
9
- * silently serves the PUBLISHED page. The preview cookie is already `Path=/`,
7
+ * lands on `/_conloca/preview/about`, clicks a link, and the root-absolute
8
+ * `/blog` the site's template emitted drops the route and silently serves the
9
+ * PUBLISHED page. The preview cookie is already `Path=/`,
10
10
  * so the browser is sending the credential on that request — this listens.
11
11
  *
12
12
  * WHY THE RENDER HAPPENS HERE, VIA `next()` — a middleware rewrite onto the
13
- * secret-prefixed handler (the previous design) forced the render through
13
+ * preview route's handler (an earlier design) forced the render through
14
14
  * `Astro.rewrite`, whose route matching does not fall through prerendered
15
15
  * routes: with two root catch-alls (the CMS pages route on demand, a docs
16
16
  * integration's route prerendered) the rewrite matched the prerendered one
@@ -1 +1 @@
1
- {"version":3,"file":"site-middleware.d.ts","sourceRoot":"","sources":["../../../src/preview/site-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAKvD,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,wBAAw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qB,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,sFAAsF;IACtF,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IACvC,+EAA+E;IAC/E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,MAAM,wBAAwB,EAAE,KAAK,EAAE,kBAAkB,aACvE,wBAAwB,QAAQ,qBAAqB,KAAG,OAAO,CAAC,QAAQ,CAAC,CA8GnH"}
@@ -2,15 +2,15 @@
2
2
  * Site-wide preview middleware for the recursive preview build — the SERVING
3
3
  * SURFACE of draft preview.
4
4
  *
5
- * WHY THIS EXISTS — the secret path prefix is an entry door, not the serving
5
+ * WHY THIS EXISTS — the fixed preview route is an entry door, not the serving
6
6
  * surface. Without this, preview survives exactly one page view: the visitor
7
- * lands on `/conloca_preview_<secret>/about`, clicks a link, and the
8
- * root-absolute `/blog` the site's template emitted drops the prefix and
9
- * silently serves the PUBLISHED page. The preview cookie is already `Path=/`,
7
+ * lands on `/_conloca/preview/about`, clicks a link, and the root-absolute
8
+ * `/blog` the site's template emitted drops the route and silently serves the
9
+ * PUBLISHED page. The preview cookie is already `Path=/`,
10
10
  * so the browser is sending the credential on that request — this listens.
11
11
  *
12
12
  * WHY THE RENDER HAPPENS HERE, VIA `next()` — a middleware rewrite onto the
13
- * secret-prefixed handler (the previous design) forced the render through
13
+ * preview route's handler (an earlier design) forced the render through
14
14
  * `Astro.rewrite`, whose route matching does not fall through prerendered
15
15
  * routes: with two root catch-alls (the CMS pages route on demand, a docs
16
16
  * integration's route prerendered) the rewrite matched the prerendered one
@@ -29,8 +29,8 @@ import { fetchPageStatus } from './_dispatch.js';
29
29
  import { injectPreviewBanner } from './banner.js';
30
30
  import { PreviewContentAPI } from './content-api.js';
31
31
  import { applyPreviewHeaders } from './headers.js';
32
- import { handlePreviewRequest, previewParamName, } from './middleware.js';
33
- import { normalizeTrailingSlash, stripPreviewPrefix } from './preview-path.js';
32
+ import { handlePreviewRequest } from './middleware.js';
33
+ import { normalizeTrailingSlash, previewRoutePrefix, stripPreviewPrefix } from './preview-path.js';
34
34
  /**
35
35
  * Builds the Astro middleware `onRequest` handler.
36
36
  *
@@ -47,8 +47,8 @@ export function createPreviewSiteMiddleware(resolveOpts, seams) {
47
47
  // ALSO at build time, where Astro runs middleware while prerendering pages
48
48
  // and the deployer's runtime vars do not exist yet. Neither is a reason to
49
49
  // break the site's build or the whole site over a feature it may
50
- // not use, so pass through and warn once. The secret-prefixed entry route
51
- // still fails loudly: reaching it means someone explicitly asked to preview.
50
+ // not use, so pass through and warn once. The preview entry route still
51
+ // fails loudly: reaching it means someone explicitly asked to preview.
52
52
  let opts;
53
53
  try {
54
54
  opts = resolveOpts();
@@ -66,12 +66,12 @@ export function createPreviewSiteMiddleware(resolveOpts, seams) {
66
66
  return verdict.response;
67
67
  if (verdict.kind !== 'preview')
68
68
  return next();
69
- // A valid credential on the LITERAL secret-prefixed URL: canonicalize to
70
- // the clean site path instead of rendering under the prefix — links,
71
- // assets and the page lookup all assume clean paths.
69
+ // A valid credential on the preview route itself: canonicalize to the
70
+ // clean site path instead of rendering under the route — links, assets
71
+ // and the page lookup all assume clean paths.
72
72
  const rawPath = context.url.pathname;
73
- const path = normalizeTrailingSlash(stripPreviewPrefix(rawPath));
74
- if (stripPreviewPrefix(rawPath) !== rawPath) {
73
+ const path = normalizeTrailingSlash(stripPreviewPrefix(rawPath, opts.base));
74
+ if (stripPreviewPrefix(rawPath, opts.base) !== rawPath) {
75
75
  return new Response(null, {
76
76
  status: 302,
77
77
  headers: { location: path, 'cache-control': 'private, no-store' },
@@ -136,7 +136,7 @@ export function createPreviewSiteMiddleware(resolveOpts, seams) {
136
136
  // through with the preview headers only.
137
137
  return applyPreviewHeaders(rendered);
138
138
  }
139
- const html = injectPreviewBanner(await rendered.text(), verdict.ctx, opts.saasEndpoint, `/${previewParamName(opts.secret)}/__exit`);
139
+ const html = injectPreviewBanner(await rendered.text(), verdict.ctx, opts.saasEndpoint, `${previewRoutePrefix(opts.base)}/__exit`);
140
140
  return applyPreviewHeaders(new Response(html, { status: rendered.status, headers: rendered.headers }));
141
141
  };
142
142
  }
@@ -154,7 +154,7 @@ function warnUnconfiguredOnce(error) {
154
154
  const detail = error instanceof Error ? error.message : String(error);
155
155
  console.warn(`[@conloca/cloud-astro] draft preview is INERT — ${detail}\n` +
156
156
  ' Requests are being served as the ordinary published site.\n' +
157
- ' Draft previews on your own deployment are not available yet: keep previewBuild: false ' +
157
+ ' The preview server is missing its baked settings: rebuild with previewBuild given as an object ' +
158
158
  '(see the cloud-astro README "Draft previews").');
159
159
  }
160
160
  //# sourceMappingURL=site-middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"site-middleware.js","sourceRoot":"","sources":["../../../src/preview/site-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EAAE,eAAe,EAAmB,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EACL,oBAAoB,EAGpB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAiC/E;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CAAC,WAA2C,EAAE,KAAyB;IAChH,OAAO,KAAK,UAAU,SAAS,CAAC,OAAiC,EAAE,IAA2B;QAC5F,uEAAuE;QACvE,IAAI,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AAU,GAAG,UAAU,CAAC;QAEvC,MAAM,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAC;QAC9B,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;QAC/D,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YACvC,sEAAsE;YACtE,yCAAyC;YACzC,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QACvC,CAAC;QACD,MAAM,IAAI,GAAG,mBAAmB,CAC9B,MAAM,QAAQ,CAAC,IAAI,EAAE,EACrB,OAAO,CAAC,GAAG,EACX,IAAI,CAAC,YAAY,EACjB,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAC1C,CAAC;QACF,OAAO,mBAAmB,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACzG,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,IAAI,MAAM,GAAG,KAAK,CAAC;AACnB,SAAS,oBAAoB,CAAC,KAAc;IAC1C,IAAI,MAAM;QAAE,OAAO;IACnB,MAAM,GAAG,IAAI,CAAC;IACd,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACtE,OAAO,CAAC,IAAI,CACV,mDAAmD,MAAM,IAAI;QAC3D,+DAA+D;QAC/D,mGAAmG;QACnG,gDAAgD,CACnD,CAAC;AACJ,CAAC"}
@@ -1,6 +1,11 @@
1
- import { PREVIEW_SECRET_ENV_FLAG } from './constants.js';
2
1
  import type { PreviewBuildOptions } from './types.js';
3
- export { PREVIEW_SECRET_ENV_FLAG };
2
+ /**
3
+ * Whether the recursive preview build runs: only when `previewBuild` is given
4
+ * as an object (strict opt-in, so a plain deploy never gets a second build),
5
+ * and then only with an SSR adapter that is not refused. Throws for a refused
6
+ * adapter or a missing one, so the build fails before it deploys anything.
7
+ */
8
+ export declare function previewBuildMode(previewBuild: PreviewBuildOptions | false | undefined, adapterName: string | undefined): 'off' | 'on';
4
9
  /**
5
10
  * The minimal child-process surface this module relies on. Letting
6
11
  * {@link _spawnPreviewBuildWith} accept any function that produces a process
@@ -17,14 +22,15 @@ export type PreviewBuildSpawn = (command: string, args: readonly string[], optio
17
22
  }) => PreviewBuildChildProcess;
18
23
  /**
19
24
  * Pure constructor for the child-process environment passed to the recursive
20
- * preview build. Extracted so tests can verify the contract (env flag + secret
21
- * + parent-env inheritance) without spinning up a child process — and so the
25
+ * preview build. Extracted so tests can verify the contract (env flag +
26
+ * parent-env inheritance) without spinning up a child process — and so the
22
27
  * real-process smoke test can call it the same way the integration does.
23
28
  *
24
29
  * Inherits the parent environment so PATH, credentials, and any host-specific
25
- * build vars (CF_PAGES_*, GITHUB_*) reach the child.
30
+ * build vars (CF_PAGES_*, WORKERS_CI_*, GITHUB_*) reach the child, which reads
31
+ * the branch and commit it serves from them.
26
32
  */
27
- export declare function buildPreviewChildEnv(parentEnv: NodeJS.ProcessEnv, previewSecret: string): NodeJS.ProcessEnv;
33
+ export declare function buildPreviewChildEnv(parentEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
28
34
  /**
29
35
  * Locate the `astro` CLI binary in the site's `node_modules/.bin/`. We
30
36
  * resolve relative to the current working directory (where `astro build` is
@@ -41,13 +47,10 @@ export declare function resolveAstroBin(cwd?: string): string;
41
47
  * Spawns the recursive preview `astro build` from the primary build's
42
48
  * `astro:build:done` hook.
43
49
  *
44
- * The child process inherits the parent environment and additionally receives:
45
- * - {@link PREVIEW_BUILD_ENV_FLAG} set to `'1'` so the integration's own
46
- * `astro:build:done` short-circuits inside the child (recursion guard
47
- * contract).
48
- * - {@link PREVIEW_SECRET_ENV_FLAG} set to the per-branch secret so the
49
- * child's `astro:config:setup` can inject the literal secret-scoped
50
- * preview route (`/conloca_preview_${SECRET}/[...path]`).
50
+ * The child process inherits the parent environment and additionally receives
51
+ * {@link PREVIEW_BUILD_ENV_FLAG} set to `'1'`: the child's `astro:config:setup`
52
+ * mounts the preview route on it, and its `astro:build:done` short-circuits
53
+ * on it (recursion guard contract).
51
54
  *
52
55
  * If this function is itself called from within a recursive build (i.e. the
53
56
  * env flag is already set to `'1'`), it returns immediately without spawning,
@@ -58,7 +61,7 @@ export declare function resolveAstroBin(cwd?: string): string;
58
61
  * - `false` → resolves and logs a warning so onboarding setups can continue
59
62
  * when the preview build is not yet wired correctly.
60
63
  */
61
- export declare function spawnPreviewBuild(previewSecret: string, opts: PreviewBuildOptions): Promise<void>;
64
+ export declare function spawnPreviewBuild(opts: PreviewBuildOptions): Promise<void>;
62
65
  /**
63
66
  * Internal seam that takes the spawn function as a parameter so tests can
64
67
  * substitute a fake. Public callers should use {@link spawnPreviewBuild}.
@@ -67,5 +70,5 @@ export declare function spawnPreviewBuild(previewSecret: string, opts: PreviewBu
67
70
  * and not part of the package's public surface; it is not re-exported from
68
71
  * `src/index.ts` or `src/node.ts`.
69
72
  */
70
- export declare function _spawnPreviewBuildWith(spawnFn: PreviewBuildSpawn, previewSecret: string, opts: PreviewBuildOptions): Promise<void>;
73
+ export declare function _spawnPreviewBuildWith(spawnFn: PreviewBuildSpawn, opts: PreviewBuildOptions): Promise<void>;
71
74
  //# sourceMappingURL=preview-build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"preview-build.d.ts","sourceRoot":"","sources":["../../src/preview-build.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwC,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC/F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAEnC;;;;;;GAMG;AACH,MAAM,WAAW,wBAAwB;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