@conloca/cloud-astro 0.0.0-bootstrap.0 → 0.2.1

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 (196) hide show
  1. package/README.md +327 -2
  2. package/dist/src/build-commit.d.ts +19 -0
  3. package/dist/src/build-commit.d.ts.map +1 -0
  4. package/dist/src/build-commit.js +6 -0
  5. package/dist/src/build-commit.js.map +1 -0
  6. package/dist/src/bundle.d.ts +173 -0
  7. package/dist/src/bundle.d.ts.map +1 -0
  8. package/dist/src/bundle.js +413 -0
  9. package/dist/src/bundle.js.map +1 -0
  10. package/dist/src/component-manifest.d.ts +29 -0
  11. package/dist/src/component-manifest.d.ts.map +1 -0
  12. package/dist/src/component-manifest.js +53 -0
  13. package/dist/src/component-manifest.js.map +1 -0
  14. package/dist/src/constants.d.ts +26 -0
  15. package/dist/src/constants.d.ts.map +1 -0
  16. package/dist/src/constants.js +26 -0
  17. package/dist/src/constants.js.map +1 -0
  18. package/dist/src/descriptors.d.ts +25 -0
  19. package/dist/src/descriptors.d.ts.map +1 -0
  20. package/dist/src/descriptors.js +65 -0
  21. package/dist/src/descriptors.js.map +1 -0
  22. package/dist/src/discovery.d.ts +58 -0
  23. package/dist/src/discovery.d.ts.map +1 -0
  24. package/dist/src/discovery.js +133 -0
  25. package/dist/src/discovery.js.map +1 -0
  26. package/dist/src/doctor/checks-live.d.ts +15 -0
  27. package/dist/src/doctor/checks-live.d.ts.map +1 -0
  28. package/dist/src/doctor/checks-live.js +229 -0
  29. package/dist/src/doctor/checks-live.js.map +1 -0
  30. package/dist/src/doctor/checks-offline.d.ts +36 -0
  31. package/dist/src/doctor/checks-offline.d.ts.map +1 -0
  32. package/dist/src/doctor/checks-offline.js +301 -0
  33. package/dist/src/doctor/checks-offline.js.map +1 -0
  34. package/dist/src/doctor/config-scan.d.ts +55 -0
  35. package/dist/src/doctor/config-scan.d.ts.map +1 -0
  36. package/dist/src/doctor/config-scan.js +178 -0
  37. package/dist/src/doctor/config-scan.js.map +1 -0
  38. package/dist/src/doctor/run.d.ts +4 -0
  39. package/dist/src/doctor/run.d.ts.map +1 -0
  40. package/dist/src/doctor/run.js +29 -0
  41. package/dist/src/doctor/run.js.map +1 -0
  42. package/dist/src/doctor/types.d.ts +60 -0
  43. package/dist/src/doctor/types.d.ts.map +1 -0
  44. package/dist/src/doctor/types.js +18 -0
  45. package/dist/src/doctor/types.js.map +1 -0
  46. package/dist/src/doctor.d.ts +9 -0
  47. package/dist/src/doctor.d.ts.map +1 -0
  48. package/dist/src/doctor.js +12 -0
  49. package/dist/src/doctor.js.map +1 -0
  50. package/dist/src/git.d.ts +38 -0
  51. package/dist/src/git.d.ts.map +1 -0
  52. package/dist/src/git.js +43 -0
  53. package/dist/src/git.js.map +1 -0
  54. package/dist/src/index.d.ts +3 -0
  55. package/dist/src/index.d.ts.map +1 -0
  56. package/dist/src/index.js +7 -0
  57. package/dist/src/index.js.map +1 -0
  58. package/dist/src/integration.d.ts +6 -0
  59. package/dist/src/integration.d.ts.map +1 -0
  60. package/dist/src/integration.js +532 -0
  61. package/dist/src/integration.js.map +1 -0
  62. package/dist/src/message-of.d.ts +3 -0
  63. package/dist/src/message-of.d.ts.map +1 -0
  64. package/dist/src/message-of.js +5 -0
  65. package/dist/src/message-of.js.map +1 -0
  66. package/dist/src/node.d.ts +3 -0
  67. package/dist/src/node.d.ts.map +1 -0
  68. package/dist/src/node.js +4 -0
  69. package/dist/src/node.js.map +1 -0
  70. package/dist/src/package-version.d.ts +7 -0
  71. package/dist/src/package-version.d.ts.map +1 -0
  72. package/dist/src/package-version.js +17 -0
  73. package/dist/src/package-version.js.map +1 -0
  74. package/dist/src/preview/_dispatch.d.ts +52 -0
  75. package/dist/src/preview/_dispatch.d.ts.map +1 -0
  76. package/dist/src/preview/_dispatch.js +70 -0
  77. package/dist/src/preview/_dispatch.js.map +1 -0
  78. package/dist/src/preview/_resolve-opts.d.ts +28 -0
  79. package/dist/src/preview/_resolve-opts.d.ts.map +1 -0
  80. package/dist/src/preview/_resolve-opts.js +70 -0
  81. package/dist/src/preview/_resolve-opts.js.map +1 -0
  82. package/dist/src/preview/banner.d.ts +29 -0
  83. package/dist/src/preview/banner.d.ts.map +1 -0
  84. package/dist/src/preview/banner.js +94 -0
  85. package/dist/src/preview/banner.js.map +1 -0
  86. package/dist/src/preview/content-api.d.ts +110 -0
  87. package/dist/src/preview/content-api.d.ts.map +1 -0
  88. package/dist/src/preview/content-api.js +216 -0
  89. package/dist/src/preview/content-api.js.map +1 -0
  90. package/dist/src/preview/cookie.d.ts +36 -0
  91. package/dist/src/preview/cookie.d.ts.map +1 -0
  92. package/dist/src/preview/cookie.js +59 -0
  93. package/dist/src/preview/cookie.js.map +1 -0
  94. package/dist/src/preview/headers.d.ts +25 -0
  95. package/dist/src/preview/headers.d.ts.map +1 -0
  96. package/dist/src/preview/headers.js +31 -0
  97. package/dist/src/preview/headers.js.map +1 -0
  98. package/dist/src/preview/landing.d.ts +22 -0
  99. package/dist/src/preview/landing.d.ts.map +1 -0
  100. package/dist/src/preview/landing.js +70 -0
  101. package/dist/src/preview/landing.js.map +1 -0
  102. package/dist/src/preview/middleware.d.ts +112 -0
  103. package/dist/src/preview/middleware.d.ts.map +1 -0
  104. package/dist/src/preview/middleware.js +197 -0
  105. package/dist/src/preview/middleware.js.map +1 -0
  106. package/dist/src/preview/preview-path.d.ts +21 -0
  107. package/dist/src/preview/preview-path.d.ts.map +1 -0
  108. package/dist/src/preview/preview-path.js +29 -0
  109. package/dist/src/preview/preview-path.js.map +1 -0
  110. package/dist/src/preview/satteri-workerd.d.ts +17 -0
  111. package/dist/src/preview/satteri-workerd.d.ts.map +1 -0
  112. package/dist/src/preview/satteri-workerd.js +18 -0
  113. package/dist/src/preview/satteri-workerd.js.map +1 -0
  114. package/dist/src/preview/site-middleware.d.ts +69 -0
  115. package/dist/src/preview/site-middleware.d.ts.map +1 -0
  116. package/dist/src/preview/site-middleware.js +159 -0
  117. package/dist/src/preview/site-middleware.js.map +1 -0
  118. package/dist/src/preview/workerd-shim.d.ts +19 -0
  119. package/dist/src/preview/workerd-shim.d.ts.map +1 -0
  120. package/dist/src/preview/workerd-shim.js +33 -0
  121. package/dist/src/preview/workerd-shim.js.map +1 -0
  122. package/dist/src/preview-build.d.ts +71 -0
  123. package/dist/src/preview-build.d.ts.map +1 -0
  124. package/dist/src/preview-build.js +115 -0
  125. package/dist/src/preview-build.js.map +1 -0
  126. package/dist/src/preview.d.ts +6 -0
  127. package/dist/src/preview.d.ts.map +1 -0
  128. package/dist/src/preview.js +12 -0
  129. package/dist/src/preview.js.map +1 -0
  130. package/dist/src/register.d.ts +98 -0
  131. package/dist/src/register.d.ts.map +1 -0
  132. package/dist/src/register.js +103 -0
  133. package/dist/src/register.js.map +1 -0
  134. package/dist/src/repository.d.ts +18 -0
  135. package/dist/src/repository.d.ts.map +1 -0
  136. package/dist/src/repository.js +46 -0
  137. package/dist/src/repository.js.map +1 -0
  138. package/dist/src/site-id.d.ts +18 -0
  139. package/dist/src/site-id.d.ts.map +1 -0
  140. package/dist/src/site-id.js +70 -0
  141. package/dist/src/site-id.js.map +1 -0
  142. package/dist/src/site-middleware.d.ts +18 -0
  143. package/dist/src/site-middleware.d.ts.map +1 -0
  144. package/dist/src/site-middleware.js +47 -0
  145. package/dist/src/site-middleware.js.map +1 -0
  146. package/dist/src/skill.d.ts +26 -0
  147. package/dist/src/skill.d.ts.map +1 -0
  148. package/dist/src/skill.js +67 -0
  149. package/dist/src/skill.js.map +1 -0
  150. package/dist/src/types.d.ts +125 -0
  151. package/dist/src/types.d.ts.map +1 -0
  152. package/dist/src/types.js +2 -0
  153. package/dist/src/types.js.map +1 -0
  154. package/package.json +170 -5
  155. package/src/build-commit.ts +22 -0
  156. package/src/bundle.ts +563 -0
  157. package/src/component-manifest.ts +75 -0
  158. package/src/constants.ts +28 -0
  159. package/src/descriptors.ts +92 -0
  160. package/src/discovery.ts +183 -0
  161. package/src/doctor/checks-live.ts +324 -0
  162. package/src/doctor/checks-offline.ts +325 -0
  163. package/src/doctor/config-scan.ts +205 -0
  164. package/src/doctor/run.ts +39 -0
  165. package/src/doctor/types.ts +71 -0
  166. package/src/doctor.ts +14 -0
  167. package/src/git.ts +66 -0
  168. package/src/index.ts +8 -0
  169. package/src/integration.ts +595 -0
  170. package/src/message-of.ts +4 -0
  171. package/src/node.ts +5 -0
  172. package/src/package-version.ts +16 -0
  173. package/src/preview/_dispatch.ts +101 -0
  174. package/src/preview/_resolve-opts.ts +84 -0
  175. package/src/preview/banner.ts +96 -0
  176. package/src/preview/content-api.ts +293 -0
  177. package/src/preview/cookie.ts +54 -0
  178. package/src/preview/headers.ts +30 -0
  179. package/src/preview/landing.ts +73 -0
  180. package/src/preview/middleware.ts +303 -0
  181. package/src/preview/preview-path.ts +28 -0
  182. package/src/preview/satteri-workerd.ts +24 -0
  183. package/src/preview/site-middleware.ts +209 -0
  184. package/src/preview/workerd-shim.ts +31 -0
  185. package/src/preview-build.ts +147 -0
  186. package/src/preview-handler.astro +55 -0
  187. package/src/preview-handler.d.ts +6 -0
  188. package/src/preview.ts +22 -0
  189. package/src/register.ts +180 -0
  190. package/src/repository.ts +54 -0
  191. package/src/site-id.ts +86 -0
  192. package/src/site-middleware.ts +55 -0
  193. package/src/skill/SKILL.md +69 -0
  194. package/src/skill.ts +66 -0
  195. package/src/types.ts +127 -0
  196. package/src/virtual-modules.d.ts +51 -0
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Per-request preview-aware `ContentAPI` reader.
3
+ *
4
+ * The page handler boundary reads through `Astro.locals.contentApi` when
5
+ * present; the preview dispatcher installs an instance of this class on that
6
+ * property. For unchanged dependencies the reader transparently
7
+ * falls back to the baseline so the production assets are reused; for changed
8
+ * dependencies the reader fetches `/preview/content` from the endpoint,
9
+ * carrying the preview JWT in the `Authorization` header.
10
+ *
11
+ * Write methods always return a failure result — preview SSR is strictly
12
+ * read-only: no write reaches the endpoint from the preview reader.
13
+ */
14
+ export class PreviewContentAPI {
15
+ /**
16
+ * Fragments/Data facades delegate to the baseline reader. The preview
17
+ * renderer reads fragment / data dependencies through `getLocalized` once
18
+ * the page handler has resolved the dependency id, so the facades only
19
+ * need to surface the baseline's listing semantics for legacy callers.
20
+ */
21
+ fragments;
22
+ data;
23
+ opts;
24
+ fetchImpl;
25
+ /** The branch's page set, once {@link loadBranchManifests} has run. */
26
+ branchManifests;
27
+ localizedReads = new Map();
28
+ constructor(opts) {
29
+ this.opts = opts;
30
+ // Bind the global fetch: `this.fetchImpl(...)` is a method call, and on
31
+ // Cloudflare Workers an unbound fetch invoked with a foreign `this` throws
32
+ // "Illegal invocation" (Node does not care, so only workerd catches it).
33
+ this.fetchImpl = opts.fetchFn ?? fetch.bind(globalThis);
34
+ this.fragments = opts.baselineApi.fragments;
35
+ this.data = opts.baselineApi.data;
36
+ }
37
+ get sitesConfig() {
38
+ return this.opts.baselineApi.sitesConfig;
39
+ }
40
+ // -------------------------------------------------------------------------
41
+ // Reads — the actual preview behaviour.
42
+ // -------------------------------------------------------------------------
43
+ async getContent(id) {
44
+ const manifest = this.branchManifests === undefined
45
+ ? await this.opts.baselineApi.getContent(id)
46
+ : (this.branchManifests.find((entry) => entry.id === id) ?? null);
47
+ if (!manifest)
48
+ return null;
49
+ const locales = {};
50
+ for (const locale of Object.keys(manifest.locales)) {
51
+ const localized = await this.getLocalized(id, locale);
52
+ if (localized) {
53
+ locales[locale] = withContent(localized);
54
+ }
55
+ }
56
+ if (Object.keys(locales).length === 0)
57
+ return null;
58
+ return { ...manifest, locales };
59
+ }
60
+ async getLocalized(id, locale) {
61
+ const embedded = this.opts.embeddedPayloads?.get(embeddedKey(id, locale));
62
+ if (embedded)
63
+ return embedded;
64
+ // Request-scoped memoization (the instance lives for one render, so this
65
+ // is not a long-lived cache): the render enumerates the
66
+ // same entries repeatedly — page listing, fragment listing, dependency
67
+ // reads — and every duplicate would be another round trip to the endpoint
68
+ // against the Cloudflare Workers subrequest budget. Failures are evicted so a later read
69
+ // can retry.
70
+ const key = embeddedKey(id, locale);
71
+ const inFlight = this.localizedReads.get(key);
72
+ if (inFlight)
73
+ return inFlight;
74
+ const read = this.fetchLocalized(id, locale);
75
+ this.localizedReads.set(key, read);
76
+ read.catch(() => this.localizedReads.delete(key));
77
+ return read;
78
+ }
79
+ async fetchLocalized(id, locale) {
80
+ const url = `${this.opts.saasEndpoint}/preview/content/${id}/${locale}`;
81
+ const response = await this.fetchImpl(url, {
82
+ headers: { authorization: `Bearer ${this.opts.ctx.jwt}` },
83
+ });
84
+ if (response.status === 304) {
85
+ return this.opts.baselineApi.getLocalized(id, locale);
86
+ }
87
+ if (response.status === 404)
88
+ return null;
89
+ if (!response.ok) {
90
+ throw new Error(`preview fetch ${id}/${locale}: ${response.status}`);
91
+ }
92
+ const data = await response.json();
93
+ if (!isLocalizedEntry(data)) {
94
+ throw new Error(`preview fetch ${id}/${locale}: malformed payload`);
95
+ }
96
+ return data;
97
+ }
98
+ async getContentAsBuffer(id, locale) {
99
+ return this.opts.baselineApi.getContentAsBuffer(id, locale);
100
+ }
101
+ // -------------------------------------------------------------------------
102
+ // Sites / listings.
103
+ // -------------------------------------------------------------------------
104
+ getSite(siteName) {
105
+ return this.opts.baselineApi.getSite(siteName);
106
+ }
107
+ /**
108
+ * Prefetch the branch's own manifest listing.
109
+ *
110
+ * The baseline is a snapshot of the last PRODUCTION build, so it cannot know
111
+ * about a page created on the branch and still contains pages the branch
112
+ * deleted — listing from it makes new pages unpreviewable and deleted ones
113
+ * linger. The branch is the authority for the page set; the baseline stays
114
+ * the fallback for unchanged dependency CONTENT.
115
+ *
116
+ * Prefetched rather than fetched lazily because `ContentAPI.listAllContent`
117
+ * is a synchronous generator. On any failure the listing is left unset and
118
+ * `listAllContent` degrades to the baseline — a stale page set renders
119
+ * something, an exception renders nothing.
120
+ */
121
+ async loadBranchManifests() {
122
+ try {
123
+ // /preview/manifests admits the preview scope; the editor listing at
124
+ // /api/v1/content/manifests filters a preview JWT to `*`-prefixed ids
125
+ // and would return an empty page set here.
126
+ const response = await this.fetchImpl(`${this.opts.saasEndpoint}/preview/manifests`, {
127
+ headers: { authorization: `Bearer ${this.opts.ctx.jwt}` },
128
+ });
129
+ if (!response.ok)
130
+ return;
131
+ const data = await response.json();
132
+ if (Array.isArray(data))
133
+ this.branchManifests = data;
134
+ }
135
+ catch {
136
+ // Network/parse failure — keep the baseline listing.
137
+ }
138
+ }
139
+ *listAllContent(filters) {
140
+ if (this.branchManifests === undefined) {
141
+ yield* this.opts.baselineApi.listAllContent(filters);
142
+ return;
143
+ }
144
+ for (const manifest of this.branchManifests) {
145
+ if (filters?.collection !== undefined && manifest.collection !== filters.collection)
146
+ continue;
147
+ if (filters?.kind !== undefined && manifest.kind !== filters.kind)
148
+ continue;
149
+ if (filters?.site !== undefined && manifest.site !== filters.site)
150
+ continue;
151
+ yield manifest;
152
+ }
153
+ }
154
+ *findUntranslatedContent(targetLocale, options) {
155
+ yield* this.opts.baselineApi.findUntranslatedContent(targetLocale, options);
156
+ }
157
+ // -------------------------------------------------------------------------
158
+ // Writes — always rejected. Preview SSR never mutates branch state;
159
+ // edits go through the editor at the endpoint, never through the site.
160
+ // -------------------------------------------------------------------------
161
+ async createContent(_input) {
162
+ return { success: false, reason: 'write_error', error: new Error(WRITE_REJECTED_MESSAGE) };
163
+ }
164
+ async updateLocalized(_input) {
165
+ return { success: false, reason: 'write_error', error: new Error(WRITE_REJECTED_MESSAGE) };
166
+ }
167
+ async deleteContent(_id, _etag) {
168
+ return { success: false, reason: 'delete_error', error: new Error(WRITE_REJECTED_MESSAGE) };
169
+ }
170
+ async deleteLocalized(_input) {
171
+ return { success: false, reason: 'delete_error', error: new Error(WRITE_REJECTED_MESSAGE) };
172
+ }
173
+ async batchUpdate(operations) {
174
+ return {
175
+ operations: operations.map((operation) => ({
176
+ id: operation.id,
177
+ locale: operation.locale,
178
+ updated: false,
179
+ error: new Error(WRITE_REJECTED_MESSAGE),
180
+ })),
181
+ success: false,
182
+ failed: operations.length,
183
+ updated: 0,
184
+ };
185
+ }
186
+ }
187
+ const WRITE_REJECTED_MESSAGE = 'preview SSR is read-only; edits must go through the editor at the endpoint';
188
+ /**
189
+ * Composes the embedded-payload map key. Public so the dispatcher (and the
190
+ * page-status response decoder) can build keys that the reader will match
191
+ * without leaking the encoding choice across modules.
192
+ */
193
+ export function embeddedKey(id, locale) {
194
+ return `${id} ${locale}`;
195
+ }
196
+ /**
197
+ * Lift a localized entry into the `LocaleVersion & { content }` shape that
198
+ * `ContentEntry.locales` expects. The entry is already the right shape — the
199
+ * helper exists so the dependency on `LocaleVersion` is documented at the
200
+ * call site rather than buried in a structural cast.
201
+ */
202
+ function withContent(entry) {
203
+ return entry.localized;
204
+ }
205
+ function isLocalizedEntry(value) {
206
+ if (typeof value !== 'object' || value === null)
207
+ return false;
208
+ const v = value;
209
+ if (typeof v.id !== 'string')
210
+ return false;
211
+ if (typeof v.localized !== 'object' || v.localized === null)
212
+ return false;
213
+ const l = v.localized;
214
+ return typeof l.etag === 'string' && typeof l.locale === 'string' && typeof l.content === 'object';
215
+ }
216
+ //# sourceMappingURL=content-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-api.js","sourceRoot":"","sources":["../../../src/preview/content-api.ts"],"names":[],"mappings":"AA8DA;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,iBAAiB;IAC5B;;;;;OAKG;IACM,SAAS,CAAY;IACrB,IAAI,CAAiB;IAEb,IAAI,CAA2B;IAC/B,SAAS,CAAe;IACzC,uEAAuE;IAC/D,eAAe,CAAqB;IAC3B,cAAc,GAAG,IAAI,GAAG,EAA0C,CAAC;IAEpF,YAAY,IAA8B;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,wEAAwE;QACxE,2EAA2E;QAC3E,yEAAyE;QACzE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxD,IAAI,CAA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AAG,KAA8C,CAAC;IACzD,IAAI,OAAO,CAAC,CAAC,EAAE,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC3C,IAAI,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ,IAAI,CAAC,CAAC,SAAS,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC1E,MAAM,CAAC,GAAG,CAAC,CAAC,SAAoE,CAAC;IACjF,OAAO,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC;AACrG,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Minimal cookie-header parser. We only need to look up cookies by exact name
3
+ * (the secret-derived preview cookie); a full RFC 6265 parser would be
4
+ * overkill, and pulling in a dependency for this would be YAGNI.
5
+ *
6
+ * The parser intentionally rejects malformed segments silently rather than
7
+ * throwing — a bad cookie header from a misbehaving client must not crash
8
+ * the SSR handler. Callers always check whether the requested cookie was
9
+ * actually present.
10
+ */
11
+ export declare function parseCookies(cookieHeader: string | null | undefined): Map<string, string>;
12
+ /**
13
+ * Serializes a `Set-Cookie` value with the security defaults the preview
14
+ * middleware requires: HttpOnly + Secure + SameSite=Lax + Path=/.
15
+ *
16
+ * Splitting this out from the middleware keeps the request handler
17
+ * declarative and lets the cookie defaults be reviewed in one place: the
18
+ * secret must never leak into a script-readable cookie.
19
+ *
20
+ * `SameSite=Lax`, not `Strict`: the share link always arrives from the editor
21
+ * origin, and Chrome withholds a `Strict` cookie on the request that FOLLOWS a
22
+ * cross-site redirect — so the init 302 would land without the cookie and loop
23
+ * straight back to the landing page. `Lax` still withholds the cookie from
24
+ * cross-site POSTs and subresource loads, which is the threat that matters for
25
+ * a read-only preview credential.
26
+ *
27
+ * `Path=/` is load-bearing: the browser sends the cookie on every same-origin
28
+ * request, which is what lets the preview follow internal links instead of
29
+ * surviving exactly one page view.
30
+ *
31
+ * `maxAgeSeconds` bounds the cookie to the credential it carries — pass the
32
+ * JWT's remaining lifetime so a stale cookie cannot outlive the token and
33
+ * strand the visitor on the landing page.
34
+ */
35
+ export declare function serializePreviewCookie(name: string, value: string, maxAgeSeconds?: number): string;
36
+ //# sourceMappingURL=cookie.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../src/preview/cookie.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAczF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAIlG"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Minimal cookie-header parser. We only need to look up cookies by exact name
3
+ * (the secret-derived preview cookie); a full RFC 6265 parser would be
4
+ * overkill, and pulling in a dependency for this would be YAGNI.
5
+ *
6
+ * The parser intentionally rejects malformed segments silently rather than
7
+ * throwing — a bad cookie header from a misbehaving client must not crash
8
+ * the SSR handler. Callers always check whether the requested cookie was
9
+ * actually present.
10
+ */
11
+ export function parseCookies(cookieHeader) {
12
+ const out = new Map();
13
+ if (!cookieHeader)
14
+ return out;
15
+ for (const segment of cookieHeader.split(';')) {
16
+ const eq = segment.indexOf('=');
17
+ if (eq <= 0)
18
+ continue;
19
+ const name = segment.slice(0, eq).trim();
20
+ const value = segment.slice(eq + 1).trim();
21
+ if (!name)
22
+ continue;
23
+ // First occurrence wins; matches the spec-compliant behaviour of the
24
+ // browsers' document.cookie reader for duplicate names.
25
+ if (!out.has(name))
26
+ out.set(name, value);
27
+ }
28
+ return out;
29
+ }
30
+ /**
31
+ * Serializes a `Set-Cookie` value with the security defaults the preview
32
+ * middleware requires: HttpOnly + Secure + SameSite=Lax + Path=/.
33
+ *
34
+ * Splitting this out from the middleware keeps the request handler
35
+ * declarative and lets the cookie defaults be reviewed in one place: the
36
+ * secret must never leak into a script-readable cookie.
37
+ *
38
+ * `SameSite=Lax`, not `Strict`: the share link always arrives from the editor
39
+ * origin, and Chrome withholds a `Strict` cookie on the request that FOLLOWS a
40
+ * cross-site redirect — so the init 302 would land without the cookie and loop
41
+ * straight back to the landing page. `Lax` still withholds the cookie from
42
+ * cross-site POSTs and subresource loads, which is the threat that matters for
43
+ * a read-only preview credential.
44
+ *
45
+ * `Path=/` is load-bearing: the browser sends the cookie on every same-origin
46
+ * request, which is what lets the preview follow internal links instead of
47
+ * surviving exactly one page view.
48
+ *
49
+ * `maxAgeSeconds` bounds the cookie to the credential it carries — pass the
50
+ * JWT's remaining lifetime so a stale cookie cannot outlive the token and
51
+ * strand the visitor on the landing page.
52
+ */
53
+ export function serializePreviewCookie(name, value, maxAgeSeconds) {
54
+ const base = `${name}=${value}; HttpOnly; Secure; SameSite=Lax; Path=/`;
55
+ if (maxAgeSeconds === undefined)
56
+ return base;
57
+ return `${base}; Max-Age=${Math.max(0, Math.floor(maxAgeSeconds))}`;
58
+ }
59
+ //# sourceMappingURL=cookie.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/preview/cookie.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAC,YAAuC;IAClE,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,IAAI,CAAC,YAAY;QAAE,OAAO,GAAG,CAAC;IAC9B,KAAK,MAAM,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9C,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,EAAE,IAAI,CAAC;YAAE,SAAS;QACtB,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACzC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC3C,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,qEAAqE;QACrE,wDAAwD;QACxD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAY,EAAE,KAAa,EAAE,aAAsB;IACxF,MAAM,IAAI,GAAG,GAAG,IAAI,IAAI,KAAK,0CAA0C,CAAC;IACxE,IAAI,aAAa,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAC7C,OAAO,GAAG,IAAI,aAAa,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC;AACtE,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Wraps a rendered preview response with the SEO/cache protection headers
3
+ * required for all preview responses:
4
+ *
5
+ * - `x-robots-tag: noindex` — defence-in-depth against accidental
6
+ * indexing if the request escapes the preview-domain or robots.txt
7
+ * containment. Cloudflare Pages preview deployments already set this
8
+ * for their own preview URLs; we set it again so the protection
9
+ * survives custom domains, non-Pages hosts, and on-prem deployments.
10
+ * - `cache-control: private, no-store` — overrides whatever the renderer
11
+ * emitted. Preview content is per-branch, per-JWT, and must never enter
12
+ * a shared cache. `no-store` also prevents browser disk persistence so
13
+ * a shared workstation doesn't expose draft pages.
14
+ * - `content-security-policy: frame-ancestors 'none'` — appended (not set)
15
+ * so it stacks with any CSP the site's own rendered page carries
16
+ * (browsers enforce the intersection of comma-joined policies). This
17
+ * stops a third party from framing an unreleased draft for clickjacking
18
+ * without clamping the site page's own resource loading. The editor
19
+ * and preview surfaces carry the same CSP posture; this is its
20
+ * library-side half.
21
+ *
22
+ * Other headers from the wrapped response are preserved.
23
+ */
24
+ export declare function applyPreviewHeaders(response: Response): Response;
25
+ //# sourceMappingURL=headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../../src/preview/headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAMhE"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Wraps a rendered preview response with the SEO/cache protection headers
3
+ * required for all preview responses:
4
+ *
5
+ * - `x-robots-tag: noindex` — defence-in-depth against accidental
6
+ * indexing if the request escapes the preview-domain or robots.txt
7
+ * containment. Cloudflare Pages preview deployments already set this
8
+ * for their own preview URLs; we set it again so the protection
9
+ * survives custom domains, non-Pages hosts, and on-prem deployments.
10
+ * - `cache-control: private, no-store` — overrides whatever the renderer
11
+ * emitted. Preview content is per-branch, per-JWT, and must never enter
12
+ * a shared cache. `no-store` also prevents browser disk persistence so
13
+ * a shared workstation doesn't expose draft pages.
14
+ * - `content-security-policy: frame-ancestors 'none'` — appended (not set)
15
+ * so it stacks with any CSP the site's own rendered page carries
16
+ * (browsers enforce the intersection of comma-joined policies). This
17
+ * stops a third party from framing an unreleased draft for clickjacking
18
+ * without clamping the site page's own resource loading. The editor
19
+ * and preview surfaces carry the same CSP posture; this is its
20
+ * library-side half.
21
+ *
22
+ * Other headers from the wrapped response are preserved.
23
+ */
24
+ export function applyPreviewHeaders(response) {
25
+ const headers = new Headers(response.headers);
26
+ headers.set('x-robots-tag', 'noindex');
27
+ headers.set('cache-control', 'private, no-store');
28
+ headers.append('content-security-policy', "frame-ancestors 'none'");
29
+ return new Response(response.body, { status: response.status, headers });
30
+ }
31
+ //# sourceMappingURL=headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.js","sourceRoot":"","sources":["../../../src/preview/headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAkB;IACpD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;IAClD,OAAO,CAAC,MAAM,CAAC,yBAAyB,EAAE,wBAAwB,CAAC,CAAC;IACpE,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Renders the "no preview context" landing page returned when a request
3
+ * hits the secret-scoped preview route but carries neither a fresh query
4
+ * param nor a valid cookie.
5
+ *
6
+ * With no preview context the page must offer two routes out:
7
+ * - "Log in to edit" deep-link, preserving the requested pathname so
8
+ * the editor knows which page the user was trying to preview.
9
+ * - "Go to production" link pointing at the same path on the production
10
+ * domain. The middleware does not know the production hostname here
11
+ * (preview can run on a separate `previewDomain` or on the production
12
+ * host itself), so the link is rendered as a same-path relative URL
13
+ * and the user navigates from there.
14
+ *
15
+ * The page is wrapped with `x-robots-tag: noindex` so a leak of the URL
16
+ * cannot get indexed.
17
+ */
18
+ export declare function renderNoPreviewLanding(opts: {
19
+ pathname: string;
20
+ saasEndpoint: string;
21
+ }): Response;
22
+ //# sourceMappingURL=landing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"landing.d.ts","sourceRoot":"","sources":["../../../src/preview/landing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG,QAAQ,CAyCjG"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Renders the "no preview context" landing page returned when a request
3
+ * hits the secret-scoped preview route but carries neither a fresh query
4
+ * param nor a valid cookie.
5
+ *
6
+ * With no preview context the page must offer two routes out:
7
+ * - "Log in to edit" deep-link, preserving the requested pathname so
8
+ * the editor knows which page the user was trying to preview.
9
+ * - "Go to production" link pointing at the same path on the production
10
+ * domain. The middleware does not know the production hostname here
11
+ * (preview can run on a separate `previewDomain` or on the production
12
+ * host itself), so the link is rendered as a same-path relative URL
13
+ * and the user navigates from there.
14
+ *
15
+ * The page is wrapped with `x-robots-tag: noindex` so a leak of the URL
16
+ * cannot get indexed.
17
+ */
18
+ export function renderNoPreviewLanding(opts) {
19
+ // The deep-link to the endpoint's editor preserves both the path the user
20
+ // was trying to preview and the endpoint that issues the JWT.
21
+ const loginUrl = new URL('/login', opts.saasEndpoint);
22
+ 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
+ },
55
+ });
56
+ }
57
+ /**
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.
61
+ */
62
+ function escapeHtml(value) {
63
+ return value
64
+ .replace(/&/g, '&amp;')
65
+ .replace(/</g, '&lt;')
66
+ .replace(/>/g, '&gt;')
67
+ .replace(/"/g, '&quot;')
68
+ .replace(/'/g, '&#39;');
69
+ }
70
+ //# sourceMappingURL=landing.js.map
@@ -0,0 +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,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEX,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;QACxB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE;YACP,cAAc,EAAE,0BAA0B;YAC1C,cAAc,EAAE,SAAS;YACzB,eAAe,EAAE,mBAAmB;YACpC,wEAAwE;YACxE,mEAAmE;YACnE,yBAAyB,EACvB,kIAAkI;SACrI;KACF,CAAC,CAAC;AACL,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"}
@@ -0,0 +1,112 @@
1
+ import { type JWTVerifyGetKey } from 'jose';
2
+ /**
3
+ * Options consumed by {@link handlePreviewRequest}.
4
+ *
5
+ * `secret` is the per-branch preview secret the endpoint issued at
6
+ * registration time. It scopes both the query-parameter name
7
+ * (`?conloca_preview_${secret}=`) and the cookie name, and must never land in
8
+ * a browser bundle.
9
+ *
10
+ * `getKey` is an optional JWKS resolver injection seam. When omitted, the
11
+ * middleware constructs a `createRemoteJWKSet` pointed at
12
+ * `${saasEndpoint}/.well-known/jwks.json` and uses jose's built-in JWKS
13
+ * cache. Tests inject a local public-key resolver so JWT validation runs
14
+ * deterministically without touching the network.
15
+ */
16
+ export interface PreviewMiddlewareOptions {
17
+ secret: string;
18
+ saasEndpoint: string;
19
+ saasIssuer: string;
20
+ saasAudience: string;
21
+ getKey?: JWTVerifyGetKey;
22
+ /**
23
+ * Transport for the JWKS fetch. A deployment that cannot reach the endpoint
24
+ * with a plain fetch by hostname supplies a Cloudflare binding's fetch here;
25
+ * otherwise key discovery gets another server's answer and every token
26
+ * looks forged.
27
+ */
28
+ fetchFn?: typeof fetch;
29
+ /**
30
+ * What to do when the request carries no valid preview credential.
31
+ *
32
+ * - `'landing'` (default) — the no-preview landing page. Correct for the
33
+ * secret-prefixed entry route, which nobody reaches by accident.
34
+ * - `'pass-through'` — let the request continue to the ordinary page. Correct
35
+ * for the site-wide interceptor, which sees every request in the preview
36
+ * build: an uncredentialed visitor must get the normal site, not a landing
37
+ * screen on every URL.
38
+ */
39
+ onMiss?: 'landing' | 'pass-through';
40
+ }
41
+ /**
42
+ * Decoded preview context placed on `Astro.locals.conlocaPreview` for the
43
+ * downstream renderer.
44
+ *
45
+ * The `PreviewContentAPI` reader consumes the same shape; this module owns
46
+ * the type rather than importing it from the reader, so the middleware stands
47
+ * alone.
48
+ */
49
+ export interface PreviewContext {
50
+ branch: string;
51
+ org: string;
52
+ repo: string;
53
+ jwt: string;
54
+ /** Seconds until the JWT expires — bounds the preview cookie's Max-Age. */
55
+ expiresInSeconds?: number;
56
+ }
57
+ declare global {
58
+ namespace App {
59
+ interface Locals {
60
+ conlocaPreview?: PreviewContext;
61
+ }
62
+ }
63
+ }
64
+ /**
65
+ * The three verdicts the preview middleware can return to its caller.
66
+ *
67
+ * - `response` — the caller MUST return this Response unchanged (used for
68
+ * the 302 init redirect and the no-preview landing page).
69
+ * - `preview` — the caller MUST set `Astro.locals.conlocaPreview = ctx`
70
+ * and dispatch to the preview renderer.
71
+ * - `pass-through` — the caller MAY delegate to the ordinary page or
72
+ * static-asset handler. Returned when `onMiss: 'pass-through'` is set —
73
+ * the site-wide interceptor's mode, where an uncredentialed request must
74
+ * get the normal site. The secret-prefixed entry route omits `onMiss`
75
+ * and never sees this verdict.
76
+ */
77
+ export type PreviewVerdict = {
78
+ kind: 'pass-through';
79
+ } | {
80
+ kind: 'preview';
81
+ ctx: PreviewContext;
82
+ } | {
83
+ kind: 'response';
84
+ response: Response;
85
+ };
86
+ /**
87
+ * Inspects a preview-route request and decides whether to validate, redirect,
88
+ * or render a landing page. See the docstring on {@link PreviewVerdict} for
89
+ * the caller contract.
90
+ *
91
+ * Order of checks:
92
+ * 1. `?conloca_preview_${secret}=<JWT>` query param → validate; on
93
+ * success issue a 302 with the cookie set and the query stripped.
94
+ * 2. `conloca_preview_${secret}=<JWT>` cookie → validate; on success
95
+ * return a `preview` verdict with the decoded context.
96
+ * 3. Neither present → no-preview landing page response.
97
+ *
98
+ * Invalid JWTs (tampered signature, expired, missing required claim, wrong
99
+ * issuer/audience/scope) fall through to the landing page. We deliberately do
100
+ * NOT return 401 — a 401 to an unauthenticated caller would confirm that
101
+ * a particular path is preview-only, which leaks information about what
102
+ * the branch contains.
103
+ */
104
+ export declare function handlePreviewRequest(request: Request, opts: PreviewMiddlewareOptions): Promise<PreviewVerdict>;
105
+ /**
106
+ * Derives the query-param / cookie name from the per-branch secret. The
107
+ * name doubles as a load guard: a same-domain request-runtime wrapper
108
+ * checks for this exact string before invoking the SSR handler, so random
109
+ * `?conloca_preview_*` query strings cannot wake the preview path.
110
+ */
111
+ export declare function previewParamName(secret: string): string;
112
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +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;AAKzG;;;;;;;;;;;;;GAaG;AACH,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