@conloca/cloud-astro 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/README.md +155 -37
  2. package/dist/.build-inputs.json +32 -23
  3. package/dist/src/constants.d.ts +12 -3
  4. package/dist/src/constants.d.ts.map +1 -1
  5. package/dist/src/constants.js +12 -3
  6. package/dist/src/constants.js.map +1 -1
  7. package/dist/src/d3-build.d.ts +70 -0
  8. package/dist/src/d3-build.d.ts.map +1 -0
  9. package/dist/src/d3-build.js +272 -0
  10. package/dist/src/d3-build.js.map +1 -0
  11. package/dist/src/descriptors.d.ts.map +1 -1
  12. package/dist/src/descriptors.js +4 -2
  13. package/dist/src/descriptors.js.map +1 -1
  14. package/dist/src/doctor/checks-live.d.ts +2 -2
  15. package/dist/src/doctor/checks-live.d.ts.map +1 -1
  16. package/dist/src/doctor/checks-live.js +10 -4
  17. package/dist/src/doctor/checks-live.js.map +1 -1
  18. package/dist/src/doctor/checks-offline.d.ts +1 -5
  19. package/dist/src/doctor/checks-offline.d.ts.map +1 -1
  20. package/dist/src/doctor/checks-offline.js +15 -27
  21. package/dist/src/doctor/checks-offline.js.map +1 -1
  22. package/dist/src/doctor/checks-preview-limits.d.ts +11 -0
  23. package/dist/src/doctor/checks-preview-limits.d.ts.map +1 -0
  24. package/dist/src/doctor/checks-preview-limits.js +133 -0
  25. package/dist/src/doctor/checks-preview-limits.js.map +1 -0
  26. package/dist/src/doctor/checks-preview-live.d.ts +14 -0
  27. package/dist/src/doctor/checks-preview-live.d.ts.map +1 -0
  28. package/dist/src/doctor/checks-preview-live.js +72 -0
  29. package/dist/src/doctor/checks-preview-live.js.map +1 -0
  30. package/dist/src/doctor/checks-preview.d.ts +7 -0
  31. package/dist/src/doctor/checks-preview.d.ts.map +1 -0
  32. package/dist/src/doctor/checks-preview.js +287 -0
  33. package/dist/src/doctor/checks-preview.js.map +1 -0
  34. package/dist/src/doctor/config-scan.d.ts +6 -0
  35. package/dist/src/doctor/config-scan.d.ts.map +1 -1
  36. package/dist/src/doctor/config-scan.js +17 -0
  37. package/dist/src/doctor/config-scan.js.map +1 -1
  38. package/dist/src/doctor/run.d.ts.map +1 -1
  39. package/dist/src/doctor/run.js +4 -0
  40. package/dist/src/doctor/run.js.map +1 -1
  41. package/dist/src/doctor/types.d.ts +11 -1
  42. package/dist/src/doctor/types.d.ts.map +1 -1
  43. package/dist/src/doctor/types.js +11 -1
  44. package/dist/src/doctor/types.js.map +1 -1
  45. package/dist/src/editor-page/bundle.d.ts +2 -0
  46. package/dist/src/editor-page/bundle.d.ts.map +1 -1
  47. package/dist/src/editor-page/bundle.js +3 -0
  48. package/dist/src/editor-page/bundle.js.map +1 -1
  49. package/dist/src/editor-page/data-schemas.d.ts +16 -0
  50. package/dist/src/editor-page/data-schemas.d.ts.map +1 -0
  51. package/dist/src/editor-page/data-schemas.js +39 -0
  52. package/dist/src/editor-page/data-schemas.js.map +1 -0
  53. package/dist/src/editor-page/emit.d.ts +37 -1
  54. package/dist/src/editor-page/emit.d.ts.map +1 -1
  55. package/dist/src/editor-page/emit.js +75 -4
  56. package/dist/src/editor-page/emit.js.map +1 -1
  57. package/dist/src/index.d.ts +1 -0
  58. package/dist/src/index.d.ts.map +1 -1
  59. package/dist/src/index.js +2 -0
  60. package/dist/src/index.js.map +1 -1
  61. package/dist/src/integration.d.ts.map +1 -1
  62. package/dist/src/integration.js +165 -41
  63. package/dist/src/integration.js.map +1 -1
  64. package/dist/src/preview/_dispatch.d.ts +12 -0
  65. package/dist/src/preview/_dispatch.d.ts.map +1 -1
  66. package/dist/src/preview/_dispatch.js +31 -0
  67. package/dist/src/preview/_dispatch.js.map +1 -1
  68. package/dist/src/preview/_resolve-opts.d.ts +3 -0
  69. package/dist/src/preview/_resolve-opts.d.ts.map +1 -1
  70. package/dist/src/preview/_resolve-opts.js +3 -1
  71. package/dist/src/preview/_resolve-opts.js.map +1 -1
  72. package/dist/src/preview/banner.d.ts +12 -9
  73. package/dist/src/preview/banner.d.ts.map +1 -1
  74. package/dist/src/preview/banner.js +46 -41
  75. package/dist/src/preview/banner.js.map +1 -1
  76. package/dist/src/preview/cloudflare-adapter.d.ts +35 -0
  77. package/dist/src/preview/cloudflare-adapter.d.ts.map +1 -0
  78. package/dist/src/preview/cloudflare-adapter.js +92 -0
  79. package/dist/src/preview/cloudflare-adapter.js.map +1 -0
  80. package/dist/src/preview/cookie.d.ts +9 -13
  81. package/dist/src/preview/cookie.d.ts.map +1 -1
  82. package/dist/src/preview/cookie.js +15 -25
  83. package/dist/src/preview/cookie.js.map +1 -1
  84. package/dist/src/preview/dispatcher.d.ts +73 -0
  85. package/dist/src/preview/dispatcher.d.ts.map +1 -0
  86. package/dist/src/preview/dispatcher.js +329 -0
  87. package/dist/src/preview/dispatcher.js.map +1 -0
  88. package/dist/src/preview/entry-code.d.ts +33 -0
  89. package/dist/src/preview/entry-code.d.ts.map +1 -0
  90. package/dist/src/preview/entry-code.js +33 -0
  91. package/dist/src/preview/entry-code.js.map +1 -0
  92. package/dist/src/preview/headers.d.ts +24 -4
  93. package/dist/src/preview/headers.d.ts.map +1 -1
  94. package/dist/src/preview/headers.js +35 -7
  95. package/dist/src/preview/headers.js.map +1 -1
  96. package/dist/src/preview/landing.d.ts +21 -0
  97. package/dist/src/preview/landing.d.ts.map +1 -1
  98. package/dist/src/preview/landing.js +103 -35
  99. package/dist/src/preview/landing.js.map +1 -1
  100. package/dist/src/preview/middleware.d.ts +29 -7
  101. package/dist/src/preview/middleware.d.ts.map +1 -1
  102. package/dist/src/preview/middleware.js +238 -84
  103. package/dist/src/preview/middleware.js.map +1 -1
  104. package/dist/src/preview/preview-path.d.ts +29 -0
  105. package/dist/src/preview/preview-path.d.ts.map +1 -1
  106. package/dist/src/preview/preview-path.js +41 -0
  107. package/dist/src/preview/preview-path.js.map +1 -1
  108. package/dist/src/preview/redeem-url.d.ts +7 -0
  109. package/dist/src/preview/redeem-url.d.ts.map +1 -0
  110. package/dist/src/preview/redeem-url.js +14 -0
  111. package/dist/src/preview/redeem-url.js.map +1 -0
  112. package/dist/src/preview/site-middleware.d.ts.map +1 -1
  113. package/dist/src/preview/site-middleware.js +39 -12
  114. package/dist/src/preview/site-middleware.js.map +1 -1
  115. package/dist/src/preview-build.d.ts +19 -8
  116. package/dist/src/preview-build.d.ts.map +1 -1
  117. package/dist/src/preview-build.js +47 -21
  118. package/dist/src/preview-build.js.map +1 -1
  119. package/dist/src/skill.d.ts +11 -0
  120. package/dist/src/skill.d.ts.map +1 -1
  121. package/dist/src/skill.js +32 -9
  122. package/dist/src/skill.js.map +1 -1
  123. package/dist/src/types.d.ts +15 -12
  124. package/dist/src/types.d.ts.map +1 -1
  125. package/package.json +33 -7
  126. package/src/constants.ts +14 -3
  127. package/src/d3-build.ts +315 -0
  128. package/src/descriptors.ts +4 -2
  129. package/src/doctor/checks-live.ts +10 -4
  130. package/src/doctor/checks-offline.ts +16 -25
  131. package/src/doctor/checks-preview-limits.ts +137 -0
  132. package/src/doctor/checks-preview-live.ts +77 -0
  133. package/src/doctor/checks-preview.ts +302 -0
  134. package/src/doctor/config-scan.ts +14 -0
  135. package/src/doctor/run.ts +4 -0
  136. package/src/doctor/types.ts +11 -1
  137. package/src/editor-page/bundle.ts +5 -0
  138. package/src/editor-page/data-schemas.ts +47 -0
  139. package/src/editor-page/emit.ts +124 -8
  140. package/src/index.ts +2 -0
  141. package/src/integration.ts +176 -40
  142. package/src/preview/_dispatch.ts +36 -1
  143. package/src/preview/_resolve-opts.ts +6 -1
  144. package/src/preview/banner.ts +61 -41
  145. package/src/preview/cloudflare-adapter.ts +103 -0
  146. package/src/preview/cookie.ts +14 -23
  147. package/src/preview/dispatcher.ts +407 -0
  148. package/src/preview/entry-code.ts +51 -0
  149. package/src/preview/headers.ts +35 -7
  150. package/src/preview/landing.ts +115 -37
  151. package/src/preview/middleware.ts +264 -88
  152. package/src/preview/preview-path.ts +57 -0
  153. package/src/preview/redeem-url.ts +14 -0
  154. package/src/preview/site-middleware.ts +47 -12
  155. package/src/preview-build.ts +67 -24
  156. package/src/preview-handler.astro +2 -1
  157. package/src/skill/SKILL.md +14 -2
  158. package/src/skill.ts +36 -8
  159. package/src/types.ts +15 -12
@@ -1,8 +1,12 @@
1
+ import { PREVIEW_PROTOCOL, previewBranchSlug } from '@conloca/content-api/editor-host';
1
2
  import { createRemoteJWKSet, customFetch, jwtVerify } from 'jose';
2
- import { parseCookies, serializePreviewCookie } from './cookie.js';
3
+ import { parseCookieValues, serializePreviewCookie } from './cookie.js';
4
+ import { exchangeEntryCode } from './entry-code.js';
5
+ import { PREVIEW_CACHE_HEADERS } from './headers.js';
3
6
  import { previewLabel } from './label.js';
4
- import { renderNoPreviewLanding } from './landing.js';
5
- import { PREVIEW_COOKIE_NAME, PREVIEW_LABEL_HEADER, PREVIEW_QUERY_PARAM, previewRoutePrefix, stripPreviewPrefix, } from './preview-path.js';
7
+ import { renderNoPreviewLanding, renderPreviewUnavailable, renderShareEnded } from './landing.js';
8
+ import { PREVIEW_CODE_PARAM, PREVIEW_LABEL_HEADER, PREVIEW_MODE_HEADER, PREVIEW_PROTOCOL_HEADER, PREVIEW_QUERY_PARAM, previewRoutePrefix, previewScope, stripPreviewPrefix, } from './preview-path.js';
9
+ import { GRANT_REF_RE, grantRef } from './redeem-url.js';
6
10
  /**
7
11
  * Inspects a preview-route request and decides whether to validate, redirect,
8
12
  * or render a landing page. See the docstring on {@link PreviewVerdict} for
@@ -11,11 +15,14 @@ import { PREVIEW_COOKIE_NAME, PREVIEW_LABEL_HEADER, PREVIEW_QUERY_PARAM, preview
11
15
  * Order of checks:
12
16
  * 0. `<base>/_conloca/preview/__exit` → expire the cookie and redirect,
13
17
  * 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.
18
- * 3. Neither present → no-preview landing page response.
18
+ * 1. `?conloca_code=<code>` → trade the single-use code for the pass on
19
+ * the server; on success issue a 302 with the cookie set and the code
20
+ * stripped. A used code with a valid cookie redirects to the clean path.
21
+ * 2. `?conloca_preview=<JWT>` query param (protocol 1) → validate; on
22
+ * success issue a 302 with the cookie set and the query stripped.
23
+ * 3. The pass cookie (`__Host-conloca_preview`; under D3 `__Secure-conloca_preview_<slug>`) → every value sent,
24
+ * the first that verifies; on success return a `preview` verdict with the decoded context.
25
+ * 4. Neither present → no-preview landing page response.
19
26
  *
20
27
  * Invalid JWTs (tampered signature, expired, missing required claim, wrong
21
28
  * issuer/audience/scope, or naming another repository, site or branch than
@@ -26,57 +33,132 @@ import { PREVIEW_COOKIE_NAME, PREVIEW_LABEL_HEADER, PREVIEW_QUERY_PARAM, preview
26
33
  */
27
34
  export async function handlePreviewRequest(request, opts) {
28
35
  const url = new URL(request.url);
36
+ const mode = opts.mode ?? 'd2';
29
37
  // 0. Exit route: the banner's "Exit Preview" target. The cookie is HttpOnly
30
38
  // on purpose, so leaving preview needs a server response that expires it.
31
39
  // Handled before the credential checks — an expired cookie must not strand
32
40
  // the visitor in a preview they can no longer exit. Its label lets the
33
41
  // endpoint's probe tell which repository, site and branch this server serves.
42
+ // Under D3 the dispatcher answers it through this same function, without loading the preview server.
34
43
  if (url.pathname === `${previewRoutePrefix(opts.base)}/__exit`) {
35
44
  const label = await previewLabel(opts.repo, opts.siteId, opts.branch);
36
- return { kind: 'response', response: makeExitRedirect(url, opts.base, label) };
45
+ return { kind: 'response', response: makeExitRedirect(url, opts, label) };
37
46
  }
38
- // 1. Query-param init path.
39
- const queryToken = url.searchParams.get(PREVIEW_QUERY_PARAM);
40
- if (queryToken !== null) {
41
- const ctx = await tryValidate(queryToken, opts);
42
- if (ctx) {
47
+ const landing = () => {
48
+ // Stripped: the landing's "Go to production" link is the same path
49
+ // relative — rendered under the preview route it loops back to itself.
50
+ const pathname = stripPreviewPrefix(url.pathname, opts.base);
51
+ // Under a D3 slug the dispatcher would move that path back under the route, where the same failing cookie lands
52
+ // here again: the slug's exit clears it and then leaves for the published page.
53
+ const liveHref = mode === 'd3' && opts.slug !== undefined
54
+ ? `${previewScope('d3', opts.base, opts.slug).route}/__exit?to=${encodeURIComponent(pathname)}`
55
+ : undefined;
56
+ return {
57
+ kind: 'response',
58
+ response: renderNoPreviewLanding({
59
+ pathname,
60
+ saasEndpoint: opts.saasEndpoint,
61
+ ...(liveHref === undefined ? {} : { liveHref }),
62
+ }),
63
+ };
64
+ };
65
+ const cookie = request.headers.get('cookie');
66
+ const code = url.searchParams.get(PREVIEW_CODE_PARAM);
67
+ // Under D3 only the dispatcher's slug makes a request a preview request, except an entry link without one (an older
68
+ // Conloca's, or a mint that couldn't read the mode): its slug comes from the pass. Anything else is the live site's.
69
+ const slugless = mode === 'd3' && opts.slug === undefined;
70
+ // A code counts only on the preview route: on the live site's own routes, trading it would let anyone make this
71
+ // server call Conloca once per request.
72
+ const entering = code !== null && stripPreviewPrefix(url.pathname, opts.base) !== url.pathname;
73
+ if (slugless && !entering)
74
+ return opts.onMiss === 'pass-through' ? { kind: 'pass-through' } : landing();
75
+ // A slugless entry has no scope until the pass names its branch.
76
+ const scope = slugless ? null : previewScope(mode, opts.base, opts.slug);
77
+ // 1. Entry code (protocol 2): trade it for the pass on the server.
78
+ if (code !== null) {
79
+ const exchanged = await exchangeEntryCode({
80
+ saasEndpoint: opts.saasEndpoint,
81
+ code,
82
+ origin: url.origin,
83
+ repo: opts.repo,
84
+ siteId: opts.siteId,
85
+ fetchFn: opts.fetchFn,
86
+ });
87
+ const path = stripPreviewPrefix(url.pathname, opts.base);
88
+ const route = scope?.route ?? previewRoutePrefix(opts.base);
89
+ const exitHref = `${route}/__exit?to=${encodeURIComponent(path)}`;
90
+ if (exchanged.ok) {
91
+ const ctx = await tryValidate(exchanged.pass, opts);
92
+ if (ctx !== null) {
93
+ const entered = scope ?? previewScope('d3', opts.base, previewBranchSlug(ctx.branch));
94
+ return { kind: 'response', response: makeInitRedirect(url, exchanged.pass, ctx, opts, entered) };
95
+ }
96
+ }
97
+ else if (exchanged.kind === 'ended') {
43
98
  return {
44
99
  kind: 'response',
45
- response: makeInitRedirect(url, queryToken, opts.base, ctx.expiresInSeconds),
100
+ response: renderShareEnded(exchanged.ended.verdict, { sharedBy: exchanged.ended.sharedBy, liveHref: exitHref }),
46
101
  };
47
102
  }
48
- // Invalid query-param JWT — fall through to the landing page rather than
49
- // issuing a 401 (see docstring).
103
+ else if (exchanged.kind === 'unavailable') {
104
+ // Never the held pass: it may open another branch than the link names. Under D3 the dispatcher forwarded the
105
+ // entry without its slug, so Retry rebuilds the link it came from; a slugless one is retried as it is.
106
+ const retryHref = mode === 'd3' && scope !== null
107
+ ? `${scope.route}${pageUnderBase(path, opts.base)}${url.search}`
108
+ : `${url.pathname}${url.search}`;
109
+ return { kind: 'response', response: renderPreviewUnavailable({ retryHref, exitHref }) };
110
+ }
111
+ else if (scope !== null && (await firstValid(parseCookieValues(cookie, scope.pass), opts)) !== null) {
112
+ // A used code reopened from history while the cookie still holds a pass: open the page.
113
+ return { kind: 'response', response: makeCleanRedirect(url, opts, scope) };
114
+ }
115
+ return landing();
116
+ }
117
+ if (scope === null)
118
+ return landing();
119
+ // 2. Query-param init path (protocol 1, read for one release). An invalid
120
+ // pass gets the landing page rather than a 401 (see docstring). D3 never had protocol-1 links, so it takes none.
121
+ const queryToken = mode === 'd3' ? null : url.searchParams.get(PREVIEW_QUERY_PARAM);
122
+ if (queryToken !== null) {
123
+ const ctx = await tryValidate(queryToken, opts);
124
+ return ctx === null
125
+ ? landing()
126
+ : { kind: 'response', response: makeInitRedirect(url, queryToken, ctx, opts, scope) };
127
+ }
128
+ // 3. Cookie path.
129
+ const ctx = await firstValid(parseCookieValues(cookie, scope.pass), opts);
130
+ if (ctx !== null)
131
+ return { kind: 'preview', ctx };
132
+ // 4. No valid preview context.
133
+ // Under D3 and D4 a share viewer's expired pass renews through the share link the grant cookie names.
134
+ const ref = scope.grant === null ? undefined : parseCookieValues(cookie, scope.grant).find((v) => GRANT_REF_RE.test(v));
135
+ if (ref !== undefined) {
136
+ const [org, grant] = ref.split('.');
137
+ const to = encodeURIComponent(stripPreviewPrefix(url.pathname, opts.base));
50
138
  return {
51
139
  kind: 'response',
52
- response: renderNoPreviewLanding({
53
- pathname: stripPreviewPrefix(url.pathname, opts.base),
54
- saasEndpoint: opts.saasEndpoint,
140
+ response: new Response(null, {
141
+ status: 302,
142
+ headers: {
143
+ location: `${opts.saasEndpoint}/preview/redeem/${org}/${grant}?renew=1&to=${to}`,
144
+ ...PREVIEW_CACHE_HEADERS,
145
+ },
55
146
  }),
56
147
  };
57
148
  }
58
- // 2. Cookie path.
59
- const cookies = parseCookies(request.headers.get('cookie'));
60
- const cookieToken = cookies.get(PREVIEW_COOKIE_NAME);
61
- if (cookieToken !== undefined) {
62
- const ctx = await tryValidate(cookieToken, opts);
63
- if (ctx) {
64
- return { kind: 'preview', ctx };
65
- }
66
- }
67
- // 3. No valid preview context.
68
- if (opts.onMiss === 'pass-through') {
149
+ if (opts.onMiss === 'pass-through')
69
150
  return { kind: 'pass-through' };
151
+ return landing();
152
+ }
153
+ /** The first token that verifies, in order; a planted cookie sent first must not lock the viewer out. */
154
+ async function firstValid(tokens, opts) {
155
+ for (const token of tokens) {
156
+ // oxlint-disable-next-line no-await-in-loop -- in order: the first that verifies wins, the rest are never checked.
157
+ const ctx = await tryValidate(token, opts);
158
+ if (ctx !== null)
159
+ return ctx;
70
160
  }
71
- return {
72
- kind: 'response',
73
- // Stripped: the landing's "Go to production" link is the same path
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
- }),
79
- };
161
+ return null;
80
162
  }
81
163
  /**
82
164
  * Validates a JWT and projects its claims into a {@link PreviewContext}.
@@ -88,8 +170,8 @@ async function tryValidate(token, opts) {
88
170
  const getKey = opts.getKey ?? defaultJwksResolver(opts.saasEndpoint, opts.fetchFn);
89
171
  try {
90
172
  const { payload } = await jwtVerify(token, getKey, {
91
- issuer: opts.saasIssuer,
92
173
  audience: opts.saasAudience,
174
+ ...(opts.saasIssuer === undefined ? {} : { issuer: opts.saasIssuer }),
93
175
  });
94
176
  return projectContext(payload, token, opts);
95
177
  }
@@ -137,66 +219,138 @@ function projectContext(payload, jwt, opts) {
137
219
  return null;
138
220
  if (branch !== opts.branch && readStringClaim(payload, 'served_by') !== opts.branch)
139
221
  return null;
140
- // Remaining token lifetime, so the cookie can be bounded to the credential
141
- // it carries rather than living for the whole browser session. `exp` is
142
- // already verified by `jwtVerify` above, so it is present and in the future.
222
+ // Under D3 the cookie lives under its branch's slug: a pass for another branch never opens this one's pages. A
223
+ // slugless entry has no slug yet; its scope comes from this branch (handlePreviewRequest).
224
+ if (opts.mode === 'd3' && opts.slug !== undefined && previewBranchSlug(branch) !== opts.slug)
225
+ return null;
143
226
  const expiresInSeconds = typeof payload.exp === 'number' ? Math.max(0, payload.exp - Math.floor(Date.now() / 1000)) : undefined;
144
- return { branch, org, repo, jwt, expiresInSeconds };
227
+ // A share pass names its link and the link's expiry; a pass that names a link without one is malformed.
228
+ const grantId = readStringClaim(payload, 'grant');
229
+ const grantExp = payload.grant_exp;
230
+ if (grantId !== undefined && typeof grantExp !== 'number')
231
+ return null;
232
+ const grant = grantId === undefined || typeof grantExp !== 'number'
233
+ ? undefined
234
+ : { id: grantId, expiresAt: grantExp, sharedBy: readStringClaim(payload, 'shared_by') ?? '' };
235
+ const editorUrl = grant === undefined ? editorUrlOf(readStringClaim(payload, 'editor_url')) : undefined;
236
+ return {
237
+ branch,
238
+ org,
239
+ repo,
240
+ jwt,
241
+ expiresInSeconds,
242
+ ...(grant === undefined ? {} : { grant }),
243
+ ...(editorUrl === undefined ? {} : { editorUrl }),
244
+ };
245
+ }
246
+ /** The editor address a pass names, when it is an https URL (http only on `.localhost`). */
247
+ function editorUrlOf(value) {
248
+ if (value === undefined || !URL.canParse(value))
249
+ return undefined;
250
+ const url = new URL(value);
251
+ const local = url.protocol === 'http:' && url.hostname.endsWith('.localhost');
252
+ return url.protocol === 'https:' || local ? url.toString() : undefined;
145
253
  }
146
254
  function readStringClaim(payload, name) {
147
255
  const value = payload[name];
148
256
  return typeof value === 'string' && value.length > 0 ? value : undefined;
149
257
  }
150
258
  /**
151
- * Builds the 302 that expires the preview cookie and returns the visitor to
152
- * the published page. `?to=` names the page the banner was on; only a
153
- * same-origin absolute path is accepted (a full URL or `//host` would turn
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.
259
+ * Builds the 302 that expires the preview cookies and returns the visitor to
260
+ * the published page `?to=` names (see {@link exitTarget}). The headers carry
261
+ * this build's public label, the preview protocol it speaks and its mode.
156
262
  */
157
- function makeExitRedirect(url, base, label) {
158
- const to = url.searchParams.get('to') ?? base;
159
- const target = to.startsWith('/') && !to.startsWith('//') ? to : base;
160
- return new Response(null, {
161
- status: 302,
162
- headers: {
163
- location: target,
164
- 'set-cookie': serializePreviewCookie(PREVIEW_COOKIE_NAME, '', 0),
165
- 'cache-control': 'private, no-store',
166
- [PREVIEW_LABEL_HEADER]: label,
167
- },
263
+ function makeExitRedirect(url, opts, label) {
264
+ const mode = opts.mode ?? 'd2';
265
+ const headers = new Headers({
266
+ location: exitTarget(url, opts),
267
+ ...PREVIEW_CACHE_HEADERS,
268
+ [PREVIEW_LABEL_HEADER]: label,
269
+ // Lets Conloca refuse to link to a preview server below its protocol floor.
270
+ [PREVIEW_PROTOCOL_HEADER]: String(PREVIEW_PROTOCOL),
271
+ // Lets Conloca shape the link: under D3 it starts with the branch slug.
272
+ [PREVIEW_MODE_HEADER]: mode,
168
273
  });
274
+ // The probe asks a D3 server without a slug: it names no cookies, so none are expired.
275
+ if (mode === 'd3' && opts.slug === undefined)
276
+ return new Response(null, { status: 302, headers });
277
+ const scope = previewScope(mode, opts.base, opts.slug);
278
+ headers.append('set-cookie', serializePreviewCookie(scope.pass, '', 0, scope.path));
279
+ // Without this the renewal would see the grant and send the viewer straight back in.
280
+ if (scope.grant !== null)
281
+ headers.append('set-cookie', serializePreviewCookie(scope.grant, '', 0, scope.path));
282
+ return new Response(null, { status: 302, headers });
169
283
  }
170
284
  /**
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.
285
+ * Where Exit sends the visitor: `?to=` resolved against this origin and kept
286
+ * only while it stays there, as its path and query with the preview route
287
+ * (under D3, the route and the slug) stripped. Anything else falls back to the
288
+ * site's base: another origin, `//host`, and `/\host` or `/<tab>/host`, which
289
+ * browsers read as `//host`. The emitted path is checked again, because the
290
+ * browser parses it again: `https://site//host`, `/.//host` and
291
+ * `<preview route>//host` all leave a same-origin parse as the path `//host`.
174
292
  */
175
- function makeInitRedirect(url, token, base, maxAgeSeconds) {
293
+ function exitTarget(url, opts) {
294
+ const { base } = opts;
295
+ const to = url.searchParams.get('to');
296
+ if (to === null || to === '')
297
+ return base;
298
+ let target;
299
+ try {
300
+ target = new URL(to, url.origin);
301
+ }
302
+ catch {
303
+ return base;
304
+ }
305
+ if (target.origin !== url.origin)
306
+ return base;
307
+ const location = `${pageOf(target.pathname, opts)}${target.search}`;
308
+ return new URL(location, url.origin).origin === url.origin ? location : base;
309
+ }
310
+ /** A pathname with the preview route stripped; under D3 the branch slug goes with it. */
311
+ function pageOf(pathname, opts) {
312
+ if (opts.mode === 'd3' && opts.slug !== undefined) {
313
+ const { route } = previewScope('d3', opts.base, opts.slug);
314
+ if (pathname === route || pathname.startsWith(`${route}/`)) {
315
+ return `${opts.base.replace(/\/+$/u, '')}${pathname.slice(route.length) || '/'}`;
316
+ }
317
+ }
318
+ return stripPreviewPrefix(pathname, opts.base);
319
+ }
320
+ /** A page path under the site's base, as it follows the D3 route: `/docs/blog` under `/docs/` is `/blog`. */
321
+ function pageUnderBase(path, base) {
322
+ return path.slice(base.replace(/\/+$/u, '').length) || '/';
323
+ }
324
+ /**
325
+ * The requested URL without the code or pass parameter. Under D2 and D4 the cookie is on `Path=/`, so the visitor
326
+ * belongs on the real path; under D3 the pass lives under the route and slug, so the page stays there. Other query
327
+ * parameters (analytics tags) stay.
328
+ */
329
+ function cleanLocation(url, opts, scope) {
176
330
  const cleaned = new URL(url.toString());
177
331
  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
180
- // before any cookie exists. Once the cookie is set (Path=/), every
181
- // same-origin request carries the credential, so the visitor belongs on the
182
- // canonical path — otherwise the first internal link they click drops the
183
- // route, escapes preview, and silently shows published content.
184
- cleaned.pathname = stripPreviewPrefix(cleaned.pathname, base);
185
- // Normalise the search string: when the only param was the preview JWT,
186
- // URL.search becomes '' but URL.toString() still emits a trailing `?` only
187
- // if it was already empty. Re-serialising via URL strips that automatically;
188
- // double-check by explicitly clearing the `?` when no params remain.
189
- let location = cleaned.toString();
190
- if (cleaned.search === '' && location.endsWith('?')) {
191
- location = location.slice(0, -1);
332
+ cleaned.searchParams.delete(PREVIEW_CODE_PARAM);
333
+ const page = stripPreviewPrefix(cleaned.pathname, opts.base);
334
+ cleaned.pathname = opts.mode === 'd3' ? `${scope.route}${pageUnderBase(page, opts.base)}` : page;
335
+ const location = cleaned.toString();
336
+ return cleaned.search === '' && location.endsWith('?') ? location.slice(0, -1) : location;
337
+ }
338
+ /** The 302 that sets the pass cookie (and, under D3 and D4, the grant cookie) and lands on the page. */
339
+ function makeInitRedirect(url, token, ctx, opts, scope) {
340
+ const headers = new Headers({ location: cleanLocation(url, opts, scope), ...PREVIEW_CACHE_HEADERS });
341
+ headers.append('set-cookie', serializePreviewCookie(scope.pass, token, ctx.expiresInSeconds, scope.path));
342
+ const { org, grant } = ctx;
343
+ if (scope.grant !== null && grant !== undefined) {
344
+ const lifetime = grant.expiresAt - Math.floor(Date.now() / 1000);
345
+ headers.append('set-cookie', serializePreviewCookie(scope.grant, grantRef(org, grant.id), lifetime, scope.path));
192
346
  }
347
+ return new Response(null, { status: 302, headers });
348
+ }
349
+ /** The 302 to the page for a visitor who already holds a valid pass. */
350
+ function makeCleanRedirect(url, opts, scope) {
193
351
  return new Response(null, {
194
352
  status: 302,
195
- headers: {
196
- location,
197
- 'set-cookie': serializePreviewCookie(PREVIEW_COOKIE_NAME, token, maxAgeSeconds),
198
- 'cache-control': 'private, no-store',
199
- },
353
+ headers: { location: cleanLocation(url, opts, scope), ...PREVIEW_CACHE_HEADERS },
200
354
  });
201
355
  }
202
356
  //# sourceMappingURL=middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/preview/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAyC,SAAS,EAAE,MAAM,MAAM,CAAC;AACzG,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAyG3B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAAgB,EAAE,IAA8B;IACzF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAEjC,4EAA4E;IAC5E,0EAA0E;IAC1E,2EAA2E;IAC3E,uEAAuE;IACvE,8EAA8E;IAC9E,IAAI,GAAG,CAAC,QAAQ,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QAC/D,MAAM,KAAK,GAAG,MAAM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AI,KAAK,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAChD,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QACjE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,sBAAsB,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACnH,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;AACtD,CAAC;AAED,wEAAwE;AACxE,SAAS,iBAAiB,CAAC,GAAQ,EAAE,IAA8B,EAAE,KAAmB;IACtF,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;QACxB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,EAAE,QAAQ,EAAE,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,GAAG,qBAAqB,EAAE;KACjF,CAAC,CAAC;AACL,CAAC"}
@@ -12,10 +12,37 @@
12
12
  export declare const PREVIEW_ROUTE_SEGMENT = "/_conloca/preview";
13
13
  export declare const PREVIEW_QUERY_PARAM = "conloca_preview";
14
14
  export declare const PREVIEW_COOKIE_NAME = "__Host-conloca_preview";
15
+ /** Protocol 2: the single-use code a preview link carries instead of the pass. */
16
+ export declare const PREVIEW_CODE_PARAM = "conloca_code";
17
+ /** The share link a viewer's pass came from (D4 only), so an expired pass can renew through it. */
18
+ export declare const PREVIEW_GRANT_COOKIE_NAME = "__Host-conloca_grant";
15
19
  /** Response header on the exit route's redirect that carries the public label. */
16
20
  export declare const PREVIEW_LABEL_HEADER = "conloca-preview";
21
+ /** Response header on the exit route's redirect that names the preview protocol this build speaks. */
22
+ export declare const PREVIEW_PROTOCOL_HEADER = "conloca-preview-protocol";
23
+ /** D3: the request header the dispatcher names the requested branch slug in. It strips any the browser sent. */
24
+ export declare const PREVIEW_SLUG_HEADER = "conloca-preview-slug";
25
+ /** Response header on the exit route's redirect that names how this build serves previews. */
26
+ export declare const PREVIEW_MODE_HEADER = "conloca-preview-mode";
27
+ /** How one preview server is reached: D2 and D4 at the page's own path, D3 under the route and the branch slug. */
28
+ export type PreviewServeMode = 'd2' | 'd3' | 'd4';
29
+ /** One preview's cookie names, the path they live on, and the route its links and exit sit under. */
30
+ export interface PreviewScope {
31
+ pass: string;
32
+ /** The share link's cookie; D2 has none (a viewer whose pass expired opens the link again). */
33
+ grant: string | null;
34
+ path: string;
35
+ route: string;
36
+ }
37
+ /**
38
+ * D3 scopes both cookies to `<base>_conloca/preview/<slug>`, so two tabs on two branches keep two passes. D2 and D4
39
+ * keep the `__Host-` names on `Path=/`, which is what lets the pass follow every same-origin link there.
40
+ */
41
+ export declare function previewScope(mode: PreviewServeMode, base: string, slug: string | undefined): PreviewScope;
17
42
  /** The preview route under Astro's `base` (`'/'` → `/_conloca/preview`, `'/docs/'` → `/docs/_conloca/preview`). */
18
43
  export declare function previewRoutePrefix(base: string): string;
44
+ /** The `run_worker_first` entries that belong to the preview, not the site: its route, and the image endpoint drafts use. */
45
+ export declare function previewOwnEntries(base: string): string[];
19
46
  /**
20
47
  * Strip the preview route from a pathname, leaving the page path under the
21
48
  * base. Only the route at the base matches: `/blog/_conloca/preview/x` and
@@ -23,6 +50,8 @@ export declare function previewRoutePrefix(base: string): string;
23
50
  * the route is never re-anchored to a different page.
24
51
  */
25
52
  export declare function stripPreviewPrefix(pathname: string, base: string): string;
53
+ /** A site path without the base, as the editor names pages (`/docs/guide` under `/docs/` → `/guide`). */
54
+ export declare function pathUnderBase(path: string, base: string): string;
26
55
  /**
27
56
  * Canonical path form for page-status lookups and production rewrites: no
28
57
  * trailing slash, except the root itself. Browser-facing links carry trailing
@@ -1 +1 @@
1
- {"version":3,"file":"preview-path.d.ts","sourceRoot":"","sources":["../../../src/preview/preview-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,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
+ {"version":3,"file":"preview-path.d.ts","sourceRoot":"","sources":["../../../src/preview/preview-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AACrD,eAAO,MAAM,mBAAmB,2BAA2B,CAAC;AAC5D,kFAAkF;AAClF,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AACjD,mGAAmG;AACnG,eAAO,MAAM,yBAAyB,yBAAyB,CAAC;AAChE,kFAAkF;AAClF,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AAEtD,sGAAsG;AACtG,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAElE,gHAAgH;AAChH,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAE1D,8FAA8F;AAC9F,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAE1D,mHAAmH;AACnH,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAElD,qGAAqG;AACrG,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,+FAA+F;IAC/F,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,YAAY,CAazG;AAED,mHAAmH;AACnH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,6HAA6H;AAC7H,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAGxD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAKzE;AAED,yGAAyG;AACzG,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIhE;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG/D"}
@@ -12,12 +12,46 @@
12
12
  export const PREVIEW_ROUTE_SEGMENT = '/_conloca/preview';
13
13
  export const PREVIEW_QUERY_PARAM = 'conloca_preview';
14
14
  export const PREVIEW_COOKIE_NAME = '__Host-conloca_preview';
15
+ /** Protocol 2: the single-use code a preview link carries instead of the pass. */
16
+ export const PREVIEW_CODE_PARAM = 'conloca_code';
17
+ /** The share link a viewer's pass came from (D4 only), so an expired pass can renew through it. */
18
+ export const PREVIEW_GRANT_COOKIE_NAME = '__Host-conloca_grant';
15
19
  /** Response header on the exit route's redirect that carries the public label. */
16
20
  export const PREVIEW_LABEL_HEADER = 'conloca-preview';
21
+ /** Response header on the exit route's redirect that names the preview protocol this build speaks. */
22
+ export const PREVIEW_PROTOCOL_HEADER = 'conloca-preview-protocol';
23
+ /** D3: the request header the dispatcher names the requested branch slug in. It strips any the browser sent. */
24
+ export const PREVIEW_SLUG_HEADER = 'conloca-preview-slug';
25
+ /** Response header on the exit route's redirect that names how this build serves previews. */
26
+ export const PREVIEW_MODE_HEADER = 'conloca-preview-mode';
27
+ /**
28
+ * D3 scopes both cookies to `<base>_conloca/preview/<slug>`, so two tabs on two branches keep two passes. D2 and D4
29
+ * keep the `__Host-` names on `Path=/`, which is what lets the pass follow every same-origin link there.
30
+ */
31
+ export function previewScope(mode, base, slug) {
32
+ const prefix = previewRoutePrefix(base);
33
+ if (mode !== 'd3') {
34
+ return {
35
+ pass: PREVIEW_COOKIE_NAME,
36
+ grant: mode === 'd4' ? PREVIEW_GRANT_COOKIE_NAME : null,
37
+ path: '/',
38
+ route: prefix,
39
+ };
40
+ }
41
+ if (slug === undefined)
42
+ throw new Error('@conloca/cloud-astro: a d3 preview scope needs the branch slug');
43
+ const route = `${prefix}/${slug}`;
44
+ return { pass: `__Secure-conloca_preview_${slug}`, grant: `__Secure-conloca_grant_${slug}`, path: route, route };
45
+ }
17
46
  /** The preview route under Astro's `base` (`'/'` → `/_conloca/preview`, `'/docs/'` → `/docs/_conloca/preview`). */
18
47
  export function previewRoutePrefix(base) {
19
48
  return `${base.replace(/\/+$/u, '')}${PREVIEW_ROUTE_SEGMENT}`;
20
49
  }
50
+ /** The `run_worker_first` entries that belong to the preview, not the site: its route, and the image endpoint drafts use. */
51
+ export function previewOwnEntries(base) {
52
+ const prefix = previewRoutePrefix(base);
53
+ return [prefix, `${prefix}/*`, `${base.replace(/\/+$/u, '')}/_image`];
54
+ }
21
55
  /**
22
56
  * Strip the preview route from a pathname, leaving the page path under the
23
57
  * base. Only the route at the base matches: `/blog/_conloca/preview/x` and
@@ -31,6 +65,13 @@ export function stripPreviewPrefix(pathname, base) {
31
65
  const rest = pathname.slice(prefix.length);
32
66
  return `${base.replace(/\/+$/u, '')}${rest === '' ? '/' : rest}`;
33
67
  }
68
+ /** A site path without the base, as the editor names pages (`/docs/guide` under `/docs/` → `/guide`). */
69
+ export function pathUnderBase(path, base) {
70
+ const root = base.replace(/\/+$/u, '');
71
+ if (root === '' || (path !== root && !path.startsWith(`${root}/`)))
72
+ return path;
73
+ return path.slice(root.length) || '/';
74
+ }
34
75
  /**
35
76
  * Canonical path form for page-status lookups and production rewrites: no
36
77
  * trailing slash, except the root itself. Browser-facing links carry trailing
@@ -1 +1 @@
1
- {"version":3,"file":"preview-path.js","sourceRoot":"","sources":["../../../src/preview/preview-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AACzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AACrD,MAAM,CAAC,MAAM,mBAAmB,GAAG,wBAAwB,CAAC;AAC5D,kFAAkF;AAClF,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAEtD,mHAAmH;AACnH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,qBAAqB,EAAE,CAAC;AAChE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB,EAAE,IAAY;IAC/D,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,QAAQ,KAAK,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,MAAM,GAAG,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC/E,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3C,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC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AED,yGAAyG;AACzG,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,IAAY;IACtD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACvC,IAAI,IAAI,KAAK,EAAE,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAChF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC;AACxC,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"}
@@ -0,0 +1,7 @@
1
+ /** The org id as unpadded base64url: the form share links, entry codes and the grant cookie carry it in. */
2
+ export declare function orgToken(org: string): string;
3
+ /** `<orgToken>.<grantId>`: names one share link without naming the org in clear. */
4
+ export declare function grantRef(org: string, grantId: string): string;
5
+ /** A grant reference as the grant cookie holds it. */
6
+ export declare const GRANT_REF_RE: RegExp;
7
+ //# sourceMappingURL=redeem-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redeem-url.d.ts","sourceRoot":"","sources":["../../../src/preview/redeem-url.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI5C;AAED,oFAAoF;AACpF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,sDAAsD;AACtD,eAAO,MAAM,YAAY,QAAyC,CAAC"}
@@ -0,0 +1,14 @@
1
+ /** The org id as unpadded base64url: the form share links, entry codes and the grant cookie carry it in. */
2
+ export function orgToken(org) {
3
+ let binary = '';
4
+ for (const byte of new TextEncoder().encode(org))
5
+ binary += String.fromCharCode(byte);
6
+ return btoa(binary).replace(/\+/gu, '-').replace(/\//gu, '_').replace(/=+$/u, '');
7
+ }
8
+ /** `<orgToken>.<grantId>`: names one share link without naming the org in clear. */
9
+ export function grantRef(org, grantId) {
10
+ return `${orgToken(org)}.${grantId}`;
11
+ }
12
+ /** A grant reference as the grant cookie holds it. */
13
+ export const GRANT_REF_RE = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]{22}$/u;
14
+ //# sourceMappingURL=redeem-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redeem-url.js","sourceRoot":"","sources":["../../../src/preview/redeem-url.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACtF,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACpF,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,QAAQ,CAAC,GAAW,EAAE,OAAe;IACnD,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC;AACvC,CAAC;AAED,sDAAsD;AACtD,MAAM,CAAC,MAAM,YAAY,GAAG,sCAAsC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"site-middleware.d.ts","sourceRoot":"","sources":["../../../src/preview/site-middleware.ts"],"names":[],"mappings":"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