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