@fastly/compute-js-static-publish 8.1.0-beta.5 → 8.1.0-beta.6

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/CHANGELOG.md CHANGED
@@ -12,9 +12,9 @@ This file does not list v7 releases after 7.0.8, or v6 releases after 6.3.0. For
12
12
  ### Added
13
13
 
14
14
  - `scaffold --template hono` (and `managed.template: 'hono'` in a managed project): a TypeScript Hono app. `src/index.ts` uses `selectCollection()`, `serveStatic()`, and `serveFallback()` of `@fastly/compute-js-static-publish/hono`, and `fire()` of `@fastly/hono-fastly-compute`. The app has `tsconfig.json`, and `typescript` as a dev dependency; the build does not check types (run `npx tsc`). In a managed project, a change of `managed.template` generates the app again with the new template, and changes the fingerprint.
15
- - Hono extensions for the `hono` template: modules in `hono-extensions/` default-export `defineExtension()` (from `@fastly/compute-js-static-publish/hono`), with a function for each phase that they use: `middleware`, `beforeFiles` (before the published files), and `afterFiles` (for the requests that no published file matches). Each phase function gets the app, the options of the module, and the helpers of the app (`serveStatic()`, `staticResponse()`, `serveFallback()`, and `publisherServer`). `c.env` in a module has the types of its bindings. The build bundles them into the app; the packages that the app provides stay imports. Options come from `templateOptions.hono.extensions` and bindings from `templateOptions.hono.bindings`, and `build.hono.extensionsDir` sets another folder. `template init` makes or updates the folder (with a `.gitignore` for `node_modules/`), and `template init --check` fails with the new error code `template-init-needed` if it is out of date. `dev -- --watch` and `npm run dev:watch` also watch the folder. `status --json` has `template`, with the packages that the template provides.
15
+ - Hono extensions for the `hono` template: modules in `hono-extensions/` default-export `defineExtension()` (from `@fastly/compute-js-static-publish/hono`), with a function for each phase that they use: `middleware`, `beforeFiles` (before the published files), and `afterFiles` (for the requests that no published file matches). Each phase function gets the app, the options of the module, and the helpers of the app (`serveStatic()`, `staticResponse()`, `serveFallback()`, `fallbackResponse()`, `isCollectionAvailable()`, and `publisherServer`). `c.env` in a module has the types of its bindings. The build bundles them into the app; the packages that the app provides stay imports. Options come from `templateOptions.hono.extensions` and bindings from `templateOptions.hono.bindings`, and `build.hono.extensionsDir` sets another folder. `template init` makes or updates the folder (with a `.gitignore` for `node_modules/`), and `template init --check` fails with the new error code `template-init-needed` if it is out of date. `dev -- --watch` and `npm run dev:watch` also watch the folder. `status --json` has `template`, with the packages that the template provides.
16
16
  - Examples of Hono extensions in `examples/hono/` (in the repository, not in the npm package): `grip` (realtime streams and Server-Sent Events with Fastly Fanout) and `oauth` (a login with GitHub or Google).
17
- - Hono support: `@fastly/compute-js-static-publish/hono`. `fromStaticPublishRc(rc)` (or `fromPublisherServer(server)`) returns `serveStatic()` (middleware that serves the published files with `serveRequest()`, and calls the next handler if no file matches; the option `onMissing` replaces `collectionSelection.onMissing` for one route), `staticResponse(c)` (the same response for use in a handler, or `null`; never the SPA file or the 404 page), `serveFallback()` (for `app.notFound()`: the SPA file or the 404 page), `selectCollection()` (collection selection for a Hono app; it sets `c.var.staticPublisher`, and `serveStatic()` and `serveFallback()` use the selected collection), and `publisherServer`. The type `StaticPublisherVariables` is for the variables of the app. `hono` v4 is an optional peer dependency. This replaces `@fastly/hono-compute-js-static-publish`, which supports only v6 and v7; `MIGRATING.md` has the steps.
17
+ - Hono support: `@fastly/compute-js-static-publish/hono`. `fromStaticPublishRc(rc)` (or `fromPublisherServer(server)`) returns `serveStatic()` (middleware that serves the published files with `serveRequest()`, and calls the next handler if no file matches; the option `onMissing` replaces `collectionSelection.onMissing` for one route), `staticResponse(c)` (the same response for use in a handler, or `null`; never the SPA file or the 404 page), `serveFallback()` (for `app.notFound()`: the SPA file or the 404 page), `fallbackResponse(c)` (the same response for use in a handler, or `null`), `isCollectionAvailable(c)` (whether the selected collection, or another one, is published and not expired), `selectCollection()` (collection selection for a Hono app; it sets `c.var.staticPublisher`, and `serveStatic()` and `serveFallback()` use the selected collection), and `publisherServer`. The type `StaticPublisherVariables` is for the variables of the app. The options `status` and `headers` change the response of a file. `hono` v4 is an optional peer dependency. This replaces `@fastly/hono-compute-js-static-publish`, which supports only v6 and v7; `MIGRATING.md` has the steps.
18
18
  - `--project-dir`: run a command for the app in another directory, for example from the root of the repo in CI. All relative paths are then relative to that directory.
19
19
  - `--version`: print the version of this package. It works in any directory.
20
20
  - `--non-interactive`: the CLI never asks a question, and missing input is an error. It is also on when the `CI` environment variable is set (to a value that is not empty, `false`, or `0`).
@@ -49,6 +49,7 @@ This file does not list v7 releases after 7.0.8, or v6 releases after 6.3.0. For
49
49
  - `--json`: `publish-content`, `collections list`, `collections delete`, `collections promote`, `status`, `deploy` (in a managed project), and `--version` write their result as one JSON object to stdout, with `schemaVersion: 1`. The log lines then go to stderr. With another command, `--json` is an error. The `publish-content` result shows the purge result for each environment (`purge.ok` is `false` if a purge failed).
50
50
  - Error codes: with `--json`, an error gives `{ "schemaVersion": 1, "error": { "code", "message" } }`. The README lists the codes, for example `collection-name-invalid` and `credentials-missing`.
51
51
  - README: "Using the CLI in CI", with the exit codes, the JSON output, and the error codes.
52
+ - `PublisherServer`: the options `status` and `headers` of `serveRequest()` and `serveFallback()` change the status and the headers of the response of a file, for one call. For a status other than `2xx`, the server does not evaluate the preconditions of the request.
52
53
 
53
54
  ### Changed
54
55
 
@@ -77,6 +78,7 @@ This file does not list v7 releases after 7.0.8, or v6 releases after 6.3.0. For
77
78
 
78
79
  ### Fixed
79
80
 
81
+ - `PublisherServer`: a request for the 404 page with an `If-None-Match` that matched its `ETag` (or an `If-Modified-Since` after its time) got a `304` with no body. Now the server evaluates the preconditions only for a `2xx` response, as RFC 9110 says, so the response is always the `404` with the page.
80
82
  - `collections promote` now purges the target collection, as `publish-content` and `collections delete` do. Before, after a promote (for example to `live`), the service could serve the old content of the target from the cache until it expired. The new options `--fastly-service-id` and `--purge-environment` work as in `publish-content`. If a Service ID is found, the command needs an API token, also in S3 mode, and stops before it writes anything if the token is missing.
81
83
  - `collections promote --local`: the target collection got the index and settings files of the source collection. Thus a later `publish-content --local` to the source also changed the target, for example `live` after a promote from `staging`. Now the target has its own files. The KV Store and S3 modes were not affected.
82
84
  - `scaffold --storage-mode s3` without `--s3-endpoint` (a bucket on AWS): the command stopped with an uncaught `CredentialsProviderError` when the computer had no usable AWS credentials. Now it computes the host name of the bucket (`<bucket>.s3.<region>.amazonaws.com`, the same host name that the server uses), with no credentials and no network. A bucket name with a dot needs `--s3-endpoint`, and the command says so.
package/DOCUMENTATION.md CHANGED
@@ -1061,10 +1061,12 @@ async function handleRequest(request) {
1061
1061
  | `fallback` | `false`: if no file matches, do not serve the SPA file or the 404 page. Return `null`. | `true` |
1062
1062
  | `healthCheck` | `false`: do not answer `/healthz`. | `true` |
1063
1063
  | `onMissing` | With [collection selection](#-previews-collection-selection): what to do for this call when the selected collection is not published or has expired. `'not-found'`: the `404` below. `'default'`: serve the default collection, as a normal response of the default collection (its headers, without `X-Robots-Tag: noindex`). Without collection selection, it does nothing. | `collectionSelection.onMissing` |
1064
+ | `status` | The status of the response of a file (also of the SPA file and the 404 page). For a status other than `2xx`, the server does not evaluate the preconditions of the request (`If-None-Match` and the others), so the response always has the body. It does not change other responses, such as the `404` of a collection that is not available. | The status of the file: `200`, or `404` for the 404 page |
1065
+ | `headers` | Headers to set on the response of a file. Each one replaces the header of the same name. | |
1064
1066
 
1065
1067
  `serveRequest()` returns `null` for a method other than `GET` and `HEAD`, and when there is no response (no file matches, and there is no fallback page or `fallback` is `false`). If the default collection has no settings in storage, the response is `500`. A collection other than the default collection that is not published, or that expired, gets a plain-text `404` that names it.
1066
1068
 
1067
- `serveFallback(request, { collectionName, onMissing })` serves the SPA file (`200`) or the 404 page (`404`) of the collection, as `serveRequest()` does when no file matches. It returns `null` for a method other than `GET` and `HEAD`, for a client that does not accept HTML, or when the collection has no fallback page. Use it with `fallback: false`, to run your own logic between the files and the fallback page. The scaffolded app (`src/index.js`) uses this order:
1069
+ `serveFallback(request, { collectionName, onMissing, status, headers })` serves the SPA file (`200`) or the 404 page (`404`) of the collection, as `serveRequest()` does when no file matches. It returns `null` for a method other than `GET` and `HEAD`, for a client that does not accept HTML, or when the collection has no fallback page. Use it with `fallback: false`, to run your own logic between the files and the fallback page. The scaffolded app (`src/index.js`) uses this order:
1068
1070
 
1069
1071
  ```js
1070
1072
  async function handleRequest(request) {
@@ -1258,23 +1260,67 @@ templateOptions: {
1258
1260
  },
1259
1261
  ```
1260
1262
 
1261
- **Helpers:** the third argument of each phase function has the `serveStatic()`, `staticResponse()`, `serveFallback()`, and `publisherServer` that the app uses (see [Using Hono](#-using-hono)). They are made once when the app starts, with the same `collectionSelection`, so a module can serve published files in its own order, with its own rules. For example, to serve `/theme/*` before a login check, on a preview, from the selected collection or from the default collection if the preview is missing, and with a plain `404` (never the 404 page of the collection):
1263
+ **The files step:** between `beforeFiles` and `afterFiles`, the app has a fixed step that serves the published files with `serveStatic()`. It is not a phase, and a module cannot remove it. A module can serve files in another way before it: a request that the module answers does not get to this step, and a request that the module passes on with `next()` does.
1264
+
1265
+ **Helpers:** the third argument of each phase function has the `serveStatic()`, `staticResponse()`, `serveFallback()`, `fallbackResponse()`, `isCollectionAvailable()`, and `publisherServer` that the app uses (see [Using Hono](#-using-hono)). They are made once when the app starts, with the same `collectionSelection`, so a module can serve published files in its own place in the order, with its own rules.
1266
+
1267
+ For example, a module that runs before a login check, and serves `/theme/*` on a preview: from the selected collection, or from the default collection if the preview is missing, and with a plain `404` (not the 404 page of the collection, which would show the preview without a login). Without a preview, the module does nothing, and the app serves the request as usual. In Hono, a handler cannot skip the handlers that come after it in the same `app.use()`, so the module decides first whether it takes part. Two ways to write it, which do the same:
1262
1268
 
1263
1269
  ```ts
1264
- // hono-extensions/10-theme.ts
1270
+ // hono-extensions/10-theme.ts: one handler with staticResponse()
1265
1271
  import { defineExtension } from '@fastly/compute-js-static-publish/hono';
1266
1272
 
1267
1273
  export default defineExtension((app, options, { staticResponse }) => {
1268
1274
  app.use('/theme/*', async (c, next) => {
1269
1275
  if (c.var.staticPublisher.collectionName == null) {
1270
- return next(); // not a preview: the published files of the app serve it
1276
+ return next(); // not a preview: the app serves it as usual
1271
1277
  }
1272
1278
  return await staticResponse(c, { onMissing: 'default' }) ?? c.text('Not found', 404);
1273
1279
  });
1274
1280
  });
1275
1281
  ```
1276
1282
 
1277
- With `onMissing: 'default'`, a missing preview gets a normal response of the default collection, with its headers. When the preview is published, the next request gets the file of the preview: `PublisherServer` checks the selected collection before it reads the response cache. This example is for a `host`, `query`, `cookie`, or `header` source. With a `path` source, the request path has the prefix (for example `/_preview/pr-1/theme/site.css`), so the route `/theme/*` does not match it: add the handler on `*`, and check `c.var.staticPublisher.pathname`, the path without the prefix. `staticResponse()` looks up that path.
1283
+ ```ts
1284
+ // hono-extensions/10-theme.ts: serveStatic() with except() of hono/combine
1285
+ import { defineExtension } from '@fastly/compute-js-static-publish/hono';
1286
+ import { except } from 'hono/combine';
1287
+
1288
+ export default defineExtension((app, options, { serveStatic }) => {
1289
+ const notPreview = (c) => c.var.staticPublisher.collectionName == null;
1290
+ app.use('/theme/*', except(notPreview,
1291
+ serveStatic({ onMissing: 'default' }),
1292
+ (c) => c.text('Not found', 404),
1293
+ ));
1294
+ });
1295
+ ```
1296
+
1297
+ `except(condition, ...middleware)` skips the middleware when the condition is true, and runs it in order otherwise. `serveStatic()` calls the next middleware when no file matches; `staticResponse()` returns `null`. To give the normal 404 page in place of the plain `404`, use `return c.notFound()`.
1298
+
1299
+ With `onMissing: 'default'`, a missing preview gets a normal response of the default collection, with its headers. When the preview is published, the next request gets the file of the preview: `PublisherServer` checks the selected collection before it reads the response cache. These examples are for a `host`, `query`, `cookie`, or `header` source. With a `path` source, the request path has the prefix (for example `/_preview/pr-1/theme/site.css`), so the route `/theme/*` does not match it: add the handler on `*`, and check `c.var.staticPublisher.pathname`, the path without the prefix. `serveStatic()` and `staticResponse()` look up that path.
1300
+
1301
+ For example, a module that runs after a login check, and shows the page `/preview-not-found/` of the default collection, with a `404`, when the selected preview is not available. Because it is a module, it can come after the login check, so that a visitor who is not logged in cannot learn which previews exist:
1302
+
1303
+ ```ts
1304
+ // hono-extensions/30-preview-not-found.ts
1305
+ import { defineExtension } from '@fastly/compute-js-static-publish/hono';
1306
+
1307
+ export default defineExtension((app, options, { isCollectionAvailable, staticResponse }) => {
1308
+ app.use('*', async (c, next) => {
1309
+ if (await isCollectionAvailable(c)) {
1310
+ return next();
1311
+ }
1312
+ return await staticResponse(c, { path: '/preview-not-found/', collectionName: null, status: 404 })
1313
+ ?? c.text('Preview not found', 404);
1314
+ });
1315
+ });
1316
+ ```
1317
+
1318
+ **`publisherServer` in a module:** the app has one `PublisherServer` for all requests. Use the other helpers where you can: they use the selected collection, and the path without the prefix of a `path` source. In a handler, a module can call these methods of `publisherServer`:
1319
+
1320
+ - `isCollectionAvailable()`, `serveRequest()`, `serveFallback()`, and `resolveCollection()`.
1321
+ - The methods that read the collection of the request: `getServerConfig()`, `getStaticItems()`, `getAssetEntryMap()`, `getMatchingAsset()`, and `testExtendedCache()`. They use the collection of the last `serveRequest()` or `serveFallback()` in the request (also through `serveStatic()` and the other helpers), or of `beginRequest()`, which uses the active collection, not the selected one. If neither ran in the request, call `publisherServer.beginRequest(c.req.raw)` first.
1322
+
1323
+ Do not call the `set…()` methods (`setActiveCollectionName()`, `setCollectionSelection()`, `setResponseCache()`, and the others) in a handler: they change the server for all requests. In the phase function, which runs one time when the app starts, they change the configuration of the whole app. Do not call the lower-level methods (`serveAsset()`, `serveCached()`, `loadAssetVariant()`, `handlePreconditions()`, and `findAcceptEncodingsGroups()`). Use `staticResponse()` and `fallbackResponse()` in their place.
1278
1324
 
1279
1325
  **Bindings** put Fastly resources on `c.env`, as `buildFire()` of `@fastly/hono-fastly-compute` does. A module declares the bindings that it uses in the first argument of `defineExtension()`, and `c.env` in its handlers has their types, for example `ConfigStore | undefined` for `'ConfigStore:site_config'` (`undefined` if the resource does not exist or is not linked to the service). `templateOptions.hono.bindings` adds bindings for the app. The same name with the same resource in two places is allowed. The same name with two different resources stops the build, and the message names both places. `c.var` is not typed in a module, so that a module can set its own variables.
1280
1326
 
@@ -1340,6 +1386,8 @@ fire(app);
1340
1386
  - `serveStatic(options?)`: middleware that serves the file that matches the request. If no file matches, or the method is not `GET` or `HEAD`, it calls the next handler, so a route after it gets the request. It does not serve the SPA file or the 404 page, and it does not answer `/healthz`.
1341
1387
  - `staticResponse(c, options?)`: the same response as `serveStatic()`, for use inside a handler: the response of the file that matches the request, or `null` if no file matches or the method is not `GET` or `HEAD`. It takes the options of `serveStatic()`. Like `serveStatic()`, it never returns the SPA file or the 404 page.
1342
1388
  - `serveFallback(options?)`: for `app.notFound()`. It serves the SPA file or the 404 page. If there is neither, or the client does not accept HTML, it gives Hono's default 404 response.
1389
+ - `fallbackResponse(c, options?)`: the response of the SPA file or the 404 page, for use inside a handler, or `null` if there is neither, the client does not accept HTML, or the method is not `GET` or `HEAD`. It takes the options of `serveFallback()`.
1390
+ - `isCollectionAvailable(c, collectionName?)`: `true` if the collection is published, has not expired, and this version of the app can serve it. Without `collectionName`, it checks the collection that `selectCollection()` selected, or else the active collection. `collectionName` is as in the option of `serveStatic()`.
1343
1391
  - `selectCollection()`: middleware that selects the collection of each request with the [`collectionSelection`](#-previews-collection-selection) of `static-publish.rc.js`. It returns the redirects of the selection (a `sticky` source, and the activate and reset paths of the `cookie` source), and sets `c.var.staticPublisher`. Then `serveStatic()` and `serveFallback()` use the selected collection. For a `path` source, `serveStatic()` looks up the path without the prefix.
1344
1392
  - `publisherServer`: the `PublisherServer`, to configure it. For example, `publisherServer.setResponseCache({ maxAge: 3600 })`.
1345
1393
 
@@ -1354,6 +1402,8 @@ If you make the `PublisherServer` yourself, use `fromPublisherServer(publisherSe
1354
1402
  | `rewriteRequestPath` | `(path, c) => string`. Changes the request path before it is resolved against `root`. |
1355
1403
  | `collectionName` | The collection: a string, `null` for the default collection, or `(c) => string \| null \| undefined`. Without it, or if the function returns `undefined`, the collection is the one that `selectCollection()` selected, or else the active collection. |
1356
1404
  | `onMissing` | With collection selection: `'not-found'` or `'default'` when the selected collection is not published or has expired, for this route only. The default is `collectionSelection.onMissing`. With `'default'`, the response is a normal response of the default collection, with its headers (no `X-Robots-Tag: noindex`). |
1405
+ | `status` | The status of the response of a file. For a status other than `2xx`, the preconditions of the request are not evaluated, so the response always has the body. See the [options of `serveRequest()`](#options-of-serverequest). |
1406
+ | `headers` | Headers to set on the response of a file. Each one replaces the header of the same name. |
1357
1407
 
1358
1408
  For example, to serve `/assets/*` from the `static` directory:
1359
1409
 
@@ -1372,7 +1422,25 @@ app.use('/theme/*', async (c, next) => {
1372
1422
  });
1373
1423
  ```
1374
1424
 
1375
- `serveFallback()` takes the `collectionName` and `onMissing` options, too. To give a default to all the middleware, pass it to `fromStaticPublishRc(rc, { collectionName, onMissing })`. An option in a call replaces the default.
1425
+ To serve a page with another status, use `status`. For example, a `404` with the page `/preview-not-found/` of the default collection, when the selected preview is not available:
1426
+
1427
+ ```ts
1428
+ app.use('*', async (c, next) => {
1429
+ if (await isCollectionAvailable(c)) {
1430
+ return next();
1431
+ }
1432
+ return await staticResponse(c, { path: '/preview-not-found/', collectionName: null, status: 404 })
1433
+ ?? c.text('Preview not found', 404);
1434
+ });
1435
+ ```
1436
+
1437
+ `fallbackResponse()` is the same for the SPA file or the 404 page. For example, a `410` with the 404 page of the site, for a removed page:
1438
+
1439
+ ```ts
1440
+ app.get('/blog/removed-post', async (c) => await fallbackResponse(c, { status: 410 }) ?? c.text('Gone', 410));
1441
+ ```
1442
+
1443
+ `serveFallback()` and `fallbackResponse()` take the `collectionName`, `onMissing`, `status`, and `headers` options, too. To give a default to all the middleware, pass it to `fromStaticPublishRc(rc, { collectionName, onMissing })`. An option in a call replaces the default.
1376
1444
 
1377
1445
  In TypeScript, use `StaticPublisherVariables` for the variables of the app, so that `c.var.staticPublisher` has a type:
1378
1446
 
@@ -25,7 +25,7 @@ export type ExtensionEnv<B extends ExtensionBindings> = {
25
25
  };
26
26
  export declare const EXTENSION_PHASES: readonly ['middleware', 'beforeFiles', 'afterFiles'];
27
27
  export type ExtensionPhase = typeof EXTENSION_PHASES[number];
28
- export type ExtensionHelpers = Pick<PublisherServerMiddleware, 'publisherServer' | 'serveStatic' | 'staticResponse' | 'serveFallback'>;
28
+ export type ExtensionHelpers = Pick<PublisherServerMiddleware, 'publisherServer' | 'serveStatic' | 'staticResponse' | 'serveFallback' | 'fallbackResponse' | 'isCollectionAvailable'>;
29
29
  export type ExtensionPhaseFunction<B extends ExtensionBindings = ExtensionBindings, O = any> = (app: Hono<ExtensionEnv<B>, any, any>, options: O | undefined, helpers: ExtensionHelpers) => void;
30
30
  export type ExtensionPhases<B extends ExtensionBindings = ExtensionBindings, O = any> = {
31
31
  [P in ExtensionPhase]?: ExtensionPhaseFunction<B, O>;
@@ -1 +1 @@
1
- {"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../../../src/hono/extensions.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAI5D,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEvD,KAAK,aAAa,GAAG;IACnB,GAAG,EAAE,GAAG,CAAC;IACT,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,C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K,CAAC,CAAC,SAAS,iBAAiB,EAAE,CAAC,GAAG,GAAG,EAAE,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;AAwBzL,wBAAgB,aAAa,CAAC,WAAW,EAAE,iBAAiB,GAAG,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,iBAAiB,CAgDtH"}
@@ -1,5 +1,5 @@
1
1
  import type { Context, MiddlewareHandler, NotFoundHandler } from 'hono';
2
- import { PublisherServer, type StaticPublishRc } from '../server/index.js';
2
+ import { PublisherServer, type ResponseOverrides, type StaticPublishRc } from '../server/index.js';
3
3
  import { type ServeStaticPathOptions } from './path.js';
4
4
  export { type BindingResource, type DefineExtensionOptions, EXTENSION_PHASES, type Extension, type ExtensionBindings, type ExtensionEntry, type ExtensionEnv, type ExtensionHelpers, type ExtensionPhase, type ExtensionPhaseFunction, type ExtensionPhases, defineExtension, mergeBindings, } from './extensions.js';
5
5
  export type StaticPublisherVariables = {
@@ -11,11 +11,11 @@ export type StaticPublisherVariables = {
11
11
  };
12
12
  export type CollectionNameOption = string | null | ((c: Context) => string | null | undefined);
13
13
  export type OnMissingOption = 'not-found' | 'default';
14
- export type ServeStaticOptions = ServeStaticPathOptions<Context> & {
14
+ export type ServeStaticOptions = ServeStaticPathOptions<Context> & ResponseOverrides & {
15
15
  collectionName?: CollectionNameOption;
16
16
  onMissing?: OnMissingOption;
17
17
  };
18
- export type ServeFallbackOptions = {
18
+ export type ServeFallbackOptions = ResponseOverrides & {
19
19
  collectionName?: CollectionNameOption;
20
20
  onMissing?: OnMissingOption;
21
21
  };
@@ -28,6 +28,8 @@ export type PublisherServerMiddleware = {
28
28
  serveStatic: (options?: ServeStaticOptions) => MiddlewareHandler;
29
29
  staticResponse: (c: Context, options?: ServeStaticOptions) => Promise<Response | null>;
30
30
  serveFallback: (options?: ServeFallbackOptions) => NotFoundHandler;
31
+ fallbackResponse: (c: Context, options?: ServeFallbackOptions) => Promise<Response | null>;
32
+ isCollectionAvailable: (c: Context, collectionName?: CollectionNameOption) => Promise<boolean>;
31
33
  selectCollection: () => MiddlewareHandler;
32
34
  };
33
35
  export declare function fromPublisherServer(server: PublisherServer, defaults?: PublisherServerMiddlewareDefaults): PublisherServerMiddleware;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hono/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAGxE,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,KAAK,sBAAsB,EAA8B,MAAM,WAAW,CAAC;AAEpF,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,eAAe,EACf,aAAa,GACd,MAAM,iBAAiB,CAAC;AAIzB,MAAM,MAAM,wBAAwB,GAAG;IACrC,eAAe,EAAE;QACf,eAAe,EAAE,eAAe,CAAC;QAGjC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;QAE9B,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAC;AAMF,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAM/F,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,SAAS,CAAC;AAEtD,MAAM,MAAM,kBAAkB,GAAG,s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AC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAIvF,aAAa,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,eAAe,CAAC;IAKnE,gBAAgB,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAK3F,qBAAqB,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAK/F,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;CAC3C,CAAC;AAsBF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,GAAE,iCAAsC,GAAG,yBAAyB,CAgFxI;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,eAAe,EAAE,QAAQ,GAAE,iCAAsC,GAAG,yBAAyB,CAEpI"}
@@ -37,6 +37,8 @@ export function fromPublisherServer(server, defaults = {}) {
37
37
  fallback: false,
38
38
  healthCheck: false,
39
39
  onMissing: options.onMissing,
40
+ status: options.status,
41
+ headers: options.headers,
40
42
  });
41
43
  };
42
44
  const serveStatic = (callOptions = {}) => {
@@ -49,16 +51,25 @@ export function fromPublisherServer(server, defaults = {}) {
49
51
  return response;
50
52
  };
51
53
  };
52
- const serveFallback = (callOptions = {}) => {
54
+ const fallbackResponse = async (c, callOptions = {}) => {
53
55
  const options = { ...defaults, ...callOptions };
56
+ return server.serveFallback(c.req.raw, {
57
+ collectionName: resolveCollectionName(c, options.collectionName, getSelection(c, server)),
58
+ onMissing: options.onMissing,
59
+ status: options.status,
60
+ headers: options.headers,
61
+ });
62
+ };
63
+ const serveFallback = (callOptions = {}) => {
54
64
  return async (c) => {
55
- const response = await server.serveFallback(c.req.raw, {
56
- collectionName: resolveCollectionName(c, options.collectionName, getSelection(c, server)),
57
- onMissing: options.onMissing,
58
- });
59
- return response ?? c.text('404 Not Found', 404);
65
+ return await fallbackResponse(c, callOptions) ?? c.text('404 Not Found', 404);
60
66
  };
61
67
  };
68
+ const isCollectionAvailable = async (c, collectionName) => {
69
+ const option = collectionName !== undefined ? collectionName : defaults.collectionName;
70
+ const name = resolveCollectionName(c, option, getSelection(c, server));
71
+ return server.isCollectionAvailable(c.req.raw, name === undefined ? server.activeCollectionName : name);
72
+ };
62
73
  const selectCollection = () => {
63
74
  return async (c, next) => {
64
75
  const selection = server.resolveCollection(c.req.raw);
@@ -73,7 +84,15 @@ export function fromPublisherServer(server, defaults = {}) {
73
84
  await next();
74
85
  };
75
86
  };
76
- return { publisherServer: server, serveStatic, staticResponse, serveFallback, selectCollection };
87
+ return {
88
+ publisherServer: server,
89
+ serveStatic,
90
+ staticResponse,
91
+ serveFallback,
92
+ fallbackResponse,
93
+ isCollectionAvailable,
94
+ selectCollection,
95
+ };
77
96
  }
78
97
  export function fromStaticPublishRc(rc, defaults = {}) {
79
98
  return fromPublisherServer(PublisherServer.fromStaticPublishRc(rc), defaults);
@@ -7,5 +7,5 @@ export { type CollectionSelection, type CollectionSelectionSource, previewUrl, v
7
7
  export { CookieCollectionSelector, type CookieCollectionSelectorOpts, } from './collection-selector/from-cookie.js';
8
8
  export { type StorageProvider, type StorageProviderBuilder, type StorageEntry, registerStorageProviderBuilder, } from './storage/storage-provider.js';
9
9
  export { setSecretStoreForS3Credentials, setSecretStoreKeyForS3AccessKeyId, setSecretStoreKeyForS3SecretAccessKey, setS3CredentialsBuilder, } from './storage/s3-storage-provider.js';
10
- export { type GetMatchingAssetOptions, type ServeFallbackOptions, type ServeRequestOptions, PublisherServer, } from './publisher-server/index.js';
10
+ export { type GetMatchingAssetOptions, type ResponseOverrides, type ServeFallbackOptions, type ServeRequestOptions, PublisherServer, } from './publisher-server/index.js';
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACL,KAAK,uBAAuB,EAC5B,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,UAAU,EACV,2BAA2B,GAC5B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,wBAAwB,EACxB,KAAK,4BAA4B,GAClC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,8BAA8B,EAC9B,iCAAiC,EACjC,qCAAqC,EACrC,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,eAAe,GAChB,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACL,KAAK,uBAAuB,EAC5B,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,UAAU,EACV,2BAA2B,GAC5B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,wBAAwB,EACxB,KAAK,4BAA4B,GAClC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,8BAA8B,EAC9B,iCAAiC,EACjC,qCAAqC,EACrC,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,eAAe,GAChB,MAAM,6BAA6B,CAAC"}
@@ -26,10 +26,14 @@ export type ServeRequestOptions = {
26
26
  fallback?: boolean;
27
27
  healthCheck?: boolean;
28
28
  onMissing?: 'not-found' | 'default';
29
- };
29
+ } & ResponseOverrides;
30
30
  export type ServeFallbackOptions = {
31
31
  collectionName?: string | null;
32
32
  onMissing?: 'not-found' | 'default';
33
+ } & ResponseOverrides;
34
+ export type ResponseOverrides = {
35
+ status?: number;
36
+ headers?: HeadersInit;
33
37
  };
34
38
  export declare class PublisherServer {
35
39
  constructor(publishId: string, storageProvider: StorageProvider, defaultCollectionName: string);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,+BAA+B,EACrC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAI1B,MAAM,8BAA8B,CAAC;AAEtC,OAAO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, Date, ETag, and Vary
36
36
  // * Cache-Control and Expires
37
37
  const headersToPreserveForUnmodified = ['Content-Location', 'ETag', 'Vary', 'Cache-Control', 'Expires'];
38
+ // RFC 9110 evaluates the preconditions only for a response that would be 2xx.
39
+ function isSuccessStatus(status) {
40
+ return status >= 200 && status < 300;
41
+ }
42
+ const PRECONDITION_HEADERS = ['If-Match', 'If-None-Match', 'If-Modified-Since', 'If-Unmodified-Since', 'If-Range'];
43
+ // The request without its precondition headers, for a response with a status
44
+ // other than 2xx.
45
+ function requestForStatus(request, status) {
46
+ if (status == null || isSuccessStatus(status)) {
47
+ return request;
48
+ }
49
+ const headers = new Headers(request.headers);
50
+ for (const name of PRECONDITION_HEADERS) {
51
+ headers.delete(name);
52
+ }
53
+ return new Request(request.url, { method: request.method, headers });
54
+ }
55
+ // Apply the overrides to the response of a file. The response of a file always
56
+ // has an ETag.
57
+ function applyResponseOverrides(response, overrides) {
58
+ if (response == null ||
59
+ (overrides.status == null && overrides.headers == null) ||
60
+ response.status === 304 ||
61
+ !response.headers.has('ETag')) {
62
+ return response;
63
+ }
64
+ const headers = new Headers(response.headers);
65
+ new Headers(overrides.headers).forEach((value, name) => {
66
+ headers.set(name, value);
67
+ });
68
+ const status = overrides.status ?? response.status;
69
+ return new Response(response.body, {
70
+ status,
71
+ statusText: status === response.status ? response.statusText : '',
72
+ headers,
73
+ });
74
+ }
38
75
  // The response for a collection other than the default collection that is not
39
76
  // published, or that expired. It can be published at any time, so no cache
40
77
  // stores this response.
@@ -499,16 +536,19 @@ export class PublisherServer {
499
536
  if (scope.serverTiming != null) {
500
537
  headers.append('Server-Timing', scope.serverTiming.toHeaderValue());
501
538
  }
502
- const preconditionResponse = this.handlePreconditions(request, asset, headers);
503
- if (preconditionResponse != null) {
504
- return preconditionResponse;
539
+ const status = init?.status ?? 200;
540
+ if (isSuccessStatus(status)) {
541
+ const preconditionResponse = this.handlePreconditions(request, asset, headers);
542
+ if (preconditionResponse != null) {
543
+ return preconditionResponse;
544
+ }
505
545
  }
506
546
  // If the body does not have the size in its metadata, the response must not
507
547
  // look complete. An empty body throws here, and any other mismatch causes an
508
548
  // error in the body stream, so that the client gets an incomplete response.
509
549
  const body = await checkBodyLength(assetVariant.storageEntry.body, assetVariant.size, `File ${asset.key} (${assetVariant.contentEncoding ?? 'identity'})`);
510
550
  return new Response(body, {
511
- status: init?.status ?? 200,
551
+ status,
512
552
  headers,
513
553
  });
514
554
  }
@@ -631,9 +671,11 @@ export class PublisherServer {
631
671
  const lastModified = headers.get('Last-Modified');
632
672
  const lastModifiedMs = lastModified != null ? Date.parse(lastModified) : NaN;
633
673
  const lastModifiedTime = Number.isNaN(lastModifiedMs) ? 0 : Math.floor(lastModifiedMs / 1000);
634
- const preconditionResponse = this.handlePreconditionsForLastModified(request, lastModifiedTime, headers);
635
- if (preconditionResponse != null) {
636
- return preconditionResponse;
674
+ if (isSuccessStatus(metadata.status)) {
675
+ const preconditionResponse = this.handlePreconditionsForLastModified(request, lastModifiedTime, headers);
676
+ if (preconditionResponse != null) {
677
+ return preconditionResponse;
678
+ }
637
679
  }
638
680
  return new Response(request.method === 'HEAD' ? null : body, {
639
681
  status: metadata.status,
@@ -672,7 +714,7 @@ export class PublisherServer {
672
714
  // With fallback: false, the response does not depend on HTML, so it has its own cache key.
673
715
  const fallback = options.fallback !== false && requestAcceptsTextHtml(request);
674
716
  const keyPath = fallback ? pathname : `${pathname}|no-html`;
675
- const response = await this.serveCachedFor(scope, request, keyPath, (fillRequest) => this.serveRequestFromStorage(scope, fillRequest, pathname, fallback));
717
+ const response = applyResponseOverrides(await this.serveCachedFor(scope, requestForStatus(request, options.status), keyPath, (fillRequest) => this.serveRequestFromStorage(scope, fillRequest, pathname, fallback)), options);
676
718
  return selected.preview ? this.markPreviewResponse(request, selected.scope, response) : response;
677
719
  }
678
720
  // Serve the SPA file or the 404 page, as serveRequest() does when no file
@@ -695,13 +737,13 @@ export class PublisherServer {
695
737
  scope = selected.scope;
696
738
  // The fallback response is the same for all paths, so it has one cache key.
697
739
  // A path always starts with a slash, so this key is not the key of a path.
698
- const response = await this.serveCachedFor(scope, request, '|fallback', async (fillRequest) => {
740
+ const response = applyResponseOverrides(await this.serveCachedFor(scope, requestForStatus(request, options.status), '|fallback', async (fillRequest) => {
699
741
  const serverConfig = await this.getServerConfigFor(scope);
700
742
  if (serverConfig == null) {
701
743
  return null;
702
744
  }
703
745
  return this.serveFallbackFromStorage(scope, fillRequest, serverConfig);
704
- });
746
+ }), options);
705
747
  return selected.preview ? this.markPreviewResponse(request, selected.scope, response) : response;
706
748
  }
707
749
  // Returns true if the collection is published, has not expired, and can
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "8.1.0-beta.5",
4
+ "version": "8.1.0-beta.6",
5
5
  "description": "Static Publisher for Fastly Compute JavaScript",
6
6
  "main": "build/server/server/index.js",
7
7
  "exports": {
@@ -16,10 +16,18 @@ const honoOptions = rc.templateOptions?.hono;
16
16
  // with two different resources stops the build.
17
17
  const fire = buildFire(mergeBindings(honoOptions?.bindings, extensions) as BindingsDefs);
18
18
 
19
- const { serveStatic, staticResponse, serveFallback, selectCollection, publisherServer } = fromStaticPublishRc(rc);
19
+ const {
20
+ serveStatic,
21
+ staticResponse,
22
+ serveFallback,
23
+ fallbackResponse,
24
+ isCollectionAvailable,
25
+ selectCollection,
26
+ publisherServer,
27
+ } = fromStaticPublishRc(rc);
20
28
 
21
29
  // The helpers of the app that each phase of the extensions gets.
22
- const helpers = { serveStatic, staticResponse, serveFallback, publisherServer };
30
+ const helpers = { serveStatic, staticResponse, serveFallback, fallbackResponse, isCollectionAvailable, publisherServer };
23
31
 
24
32
  const app = new Hono<{ Bindings: typeof fire.Bindings, Variables: StaticPublisherVariables }>();
25
33