@fastly/compute-js-static-publish 8.1.0-beta.7 → 8.1.0-beta.8

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,7 +12,7 @@ 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()`, `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.
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`, `beforeFilesRoutes` (before the published files), and `afterFilesRoutes` (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
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.
package/DOCUMENTATION.md CHANGED
@@ -1227,15 +1227,39 @@ hono-extensions/
1227
1227
 
1228
1228
  - **Modules** are the files directly in the folder, with the extension `.ts`, `.mts`, `.js`, or `.mjs`. Files that start with `_` or `.`, and `.d.ts` files, are not modules. The build does not look in subfolders, so use them, for example `lib/`, for your helpers.
1229
1229
  - **The name** of a module is the file name without the number prefix and the extension: `10-auth.ts` is `auth`. Two modules with the same name are an error.
1230
- - **The phases:** a module adds its handlers to the app in one or more phases. The app runs the phases in this order, and in each phase the modules in the order of the file names (add a number prefix to set the order):
1230
+ - **The phases:** a module adds its handlers to the app in one or more phases. In each phase, the app takes the modules in the order of the file names (add a number prefix to set the order). The phases are on two axes:
1231
1231
 
1232
1232
  ```
1233
- selectCollection() → middleware → beforeFiles → serveStatic() → afterFiles → serveFallback()
1233
+ selectCollection()
1234
+ middleware processing: wraps all of the routing below
1235
+ beforeFilesRoutes routing: the first route that answers wins
1236
+ → published files (serveStatic())
1237
+ → afterFilesRoutes
1238
+ → serveFallback()
1234
1239
  ```
1235
1240
 
1236
- - `middleware`: before all other phases. All modules add their middleware before any module adds its routes, so a middleware such as a login check also applies to the routes of the other modules.
1237
- - `beforeFiles`: before the published files.
1238
- - `afterFiles`: after the published files. These handlers get only the requests that no published file matches, for example to make a page for a path that has no file, before the 404 page. The published files are served only for `GET` and `HEAD`, so these handlers also get all other methods.
1241
+ - **Processing:** `middleware` wraps each request, for example a login check, a header on each response, or the time of a request. In a middleware, the code before `await next()` runs before the routes. The code after it runs after the response is made, also when a published file answered, and in the reverse order of the modules. All modules add their middleware before any module adds its routes, so a middleware such as a login check also applies to the routes of the other modules.
1242
+ - **Routing:** the routes that can answer a request, in this order. The first one that answers wins.
1243
+ - `beforeFilesRoutes`: before the published files. A route here wins over a file at the same path, for example an API.
1244
+ - The published files (`serveStatic()`).
1245
+ - `afterFilesRoutes`: only for the requests that no published file matches, before the SPA file or the 404 page. A file at the same path wins, for example for a redirect from an old URL, which stops when a file is published at that URL again. The published files are served only for `GET` and `HEAD`, so these routes also get all other methods.
1246
+
1247
+ A middleware that measures the time of each request, with the code before and after `await next()`:
1248
+
1249
+ ```ts
1250
+ // hono-extensions/05-timing.ts
1251
+ import { defineExtension } from '@fastly/compute-js-static-publish/hono';
1252
+
1253
+ export default defineExtension((app) => {
1254
+ app.use('*', async (c, next) => {
1255
+ const start = performance.now();
1256
+ await next();
1257
+ console.log(`${c.req.method} ${c.req.path} ${c.res.status} ${(performance.now() - start).toFixed(1)} ms`);
1258
+ });
1259
+ });
1260
+ ```
1261
+
1262
+ The time ends when the response is made. The body of a large file can still be on its way to the visitor then.
1239
1263
 
1240
1264
  A module default-exports `defineExtension()`. Give it a function for each phase that the module uses. Each function gets the Hono app, the options of the module, and the helpers of the app (see below), and adds handlers with `app.use()`, `app.get()`, `app.post()`, and the other methods of Hono. With only a function in place of the object, the function is the `middleware` phase:
1241
1265
 
@@ -1262,10 +1286,10 @@ export default defineExtension({ bindings: { config: 'ConfigStore:site_config' }
1262
1286
  c.header('cache-control', 'no-store');
1263
1287
  });
1264
1288
  },
1265
- beforeFiles: (app) => {
1289
+ beforeFilesRoutes: (app) => {
1266
1290
  app.get('/api/greeting', async (c) => c.json({ greeting: await c.env.config?.get('greeting') }));
1267
1291
  },
1268
- afterFiles: (app) => {
1292
+ afterFilesRoutes: (app) => {
1269
1293
  app.get('/blog/:slug', (c) => c.redirect(`/archive/${c.req.param('slug')}/`, 301));
1270
1294
  },
1271
1295
  });
@@ -1282,7 +1306,7 @@ templateOptions: {
1282
1306
  },
1283
1307
  ```
1284
1308
 
1285
- **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.
1309
+ **The files step:** between `beforeFilesRoutes` and `afterFilesRoutes`, 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.
1286
1310
 
1287
1311
  **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.
1288
1312
 
@@ -1361,7 +1385,7 @@ Do not call the `set…()` methods (`setActiveCollectionName()`, `setCollectionS
1361
1385
 
1362
1386
  **Examples** in [`examples/hono/`](https://github.com/fastly/compute-js-static-publish/tree/beta/8.1/examples/hono) show complete extensions. They are not part of the npm package, and you cannot scaffold an app with them: for a new project, copy the `hono-extensions/` folder of an example into your project, and set it up as the README of the example shows. The README also shows how to add an example to a project that exists.
1363
1387
 
1364
- - [`grip`](https://github.com/fastly/compute-js-static-publish/tree/beta/8.1/examples/hono/grip): realtime streams and Server-Sent Events with Fastly Fanout, and a publish endpoint with a shared key. One module with two phases: the `middleware` phase hands off only `/events/*` to Fanout, and the `beforeFiles` phase has the endpoints.
1388
+ - [`grip`](https://github.com/fastly/compute-js-static-publish/tree/beta/8.1/examples/hono/grip): realtime streams and Server-Sent Events with Fastly Fanout, and a publish endpoint with a shared key. One module with two phases: the `middleware` phase hands off only `/events/*` to Fanout, and the `beforeFilesRoutes` phase has the endpoints.
1365
1389
  - [`oauth`](https://github.com/fastly/compute-js-static-publish/tree/beta/8.1/examples/hono/oauth): a login with GitHub or Google in front of some paths of the site (`protect`), with a signed session cookie.
1366
1390
 
1367
1391
  Each example takes its secrets from a Secret Store. For `dev`, `managed.fastlyToml` adds a local Secret Store that reads environment variables.
package/MIGRATING.md CHANGED
@@ -105,8 +105,8 @@ my-site/
105
105
  Managed mode generates `src/index.js` again for each build, so your changes to it would be lost. With the `hono`
106
106
  template, you can keep your code in Hono extensions: modules in the folder `hono-extensions/`, beside the project file.
107
107
  The build bundles them into the app. Code that ran before `serveRequest()`, for example a redirect of an old host name,
108
- a login check, or a proxy to another service, goes into a `middleware` or `beforeFiles` phase. Code that ran when no
109
- file matched, for example a special page for a path, goes into an `afterFiles` phase. Each module gets its own options,
108
+ a login check, or a proxy to another service, goes into a `middleware` or `beforeFilesRoutes` phase. Code that ran when no
109
+ file matched, for example a special page for a path, goes into an `afterFilesRoutes` phase. Each module gets its own options,
110
110
  and declares the Fastly resources that it uses (bindings).
111
111
 
112
112
  1. In step 2, add `template: "hono"` to `managed`.
@@ -23,7 +23,7 @@ export type ExtensionEnv<B extends ExtensionBindings> = {
23
23
  };
24
24
  Variables: Record<string, any>;
25
25
  };
26
- export declare const EXTENSION_PHASES: readonly ['middleware', 'beforeFiles', 'afterFiles'];
26
+ export declare const EXTENSION_PHASES: readonly ['middleware', 'beforeFilesRoutes', 'afterFilesRoutes'];
27
27
  export type ExtensionPhase = typeof EXTENSION_PHASES[number];
28
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;
@@ -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,OA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,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;AACpH,wBAAgB,eAAe,CAAC,KAAK,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,CAoDtH"}
@@ -2,12 +2,23 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
- // The phases of the app, in the order that the app runs them:
6
- // - middleware: before all other phases, for example a login check.
7
- // - beforeFiles: before the published files.
8
- // - afterFiles: after the published files, only for the requests that no
9
- // published file matches.
10
- export const EXTENSION_PHASES = ['middleware', 'beforeFiles', 'afterFiles'];
5
+ // The phases of the app, in the order that the app adds them. They are on two
6
+ // axes:
7
+ // - Processing: middleware wraps each request, for example a login check, or
8
+ // the time of a request. The code before await next() runs before the routes,
9
+ // and the code after it runs after the response is made, in the reverse order.
10
+ // - Routing: the routes that can answer a request, in this order:
11
+ // - beforeFilesRoutes: before the published files. These routes win over a file.
12
+ // - (the published files, with serveStatic())
13
+ // - afterFilesRoutes: only for the requests that no published file matches,
14
+ // before the fallback (the SPA file or the 404 page).
15
+ export const EXTENSION_PHASES = ['middleware', 'beforeFilesRoutes', 'afterFilesRoutes'];
16
+ // The names of the phases in earlier betas of 8.1, and the phase that has
17
+ // each one now. mergeBindings() names the new phase in its error.
18
+ const RENAMED_PHASES = {
19
+ beforeFiles: 'beforeFilesRoutes',
20
+ afterFiles: 'afterFilesRoutes',
21
+ };
11
22
  export function defineExtension(optionsOrPhases, phases) {
12
23
  const [options, value] = phases === undefined ?
13
24
  [{}, optionsOrPhases] :
@@ -57,7 +68,11 @@ export function mergeBindings(appBindings, entries) {
57
68
  throw new Error(`${source}: defineExtension() needs a function, or an object with a function ` +
58
69
  `for one or more of the phases ${EXTENSION_PHASES.join(', ')}.` +
59
70
  (unknown.length === 1 ? ` '${unknown[0]}' is not a phase.` : '') +
60
- (unknown.length > 1 ? ` ${unknown.map(x => `'${x}'`).join(', ')} are not phases.` : ''));
71
+ (unknown.length > 1 ? ` ${unknown.map(x => `'${x}'`).join(', ')} are not phases.` : '') +
72
+ unknown
73
+ .filter(x => Object.prototype.hasOwnProperty.call(RENAMED_PHASES, x))
74
+ .map(x => ` Rename '${x}' to '${RENAMED_PHASES[x]}'.`)
75
+ .join(''));
61
76
  }
62
77
  for (const key of keys) {
63
78
  if (typeof phases[key] !== 'function') {
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.7",
4
+ "version": "8.1.0-beta.8",
5
5
  "description": "Static Publisher for Fastly Compute JavaScript",
6
6
  "main": "build/server/server/index.js",
7
7
  "exports": {
@@ -4,8 +4,8 @@
4
4
  // the project file (or in static-publish.rc.js).
5
5
  //
6
6
  // defineExtension() gets a function for each phase that the module uses. The
7
- // app runs the middleware phase of all modules, then their beforeFiles phase,
8
- // then the published files, then their afterFiles phase. With only a function
7
+ // app runs the middleware phase of all modules, then their beforeFilesRoutes phase,
8
+ // then the published files, then their afterFilesRoutes phase. With only a function
9
9
  // in place of the object, the function is the middleware phase.
10
10
  import { defineExtension } from '@fastly/compute-js-static-publish/hono';
11
11
 
@@ -16,7 +16,7 @@ export default defineExtension({
16
16
  c.header(options?.header ?? 'x-example', 'from an extension');
17
17
  });
18
18
  },
19
- beforeFiles: (app) => {
19
+ beforeFilesRoutes: (app) => {
20
20
  app.get('/api/example', (c) => c.json({ hello: 'from an extension' }));
21
21
  },
22
22
  });
@@ -1243,9 +1243,9 @@
1243
1243
  }
1244
1244
  },
1245
1245
  "node_modules/@fastly/js-compute": {
1246
- "version": "4.0.1",
1247
- "resolved": "https://registry.npmjs.org/@fastly/js-compute/-/js-compute-4.0.1.tgz",
1248
- "integrity": "sha512-G5O9NxPaqbFBTjgMPXdyMI6NktUhFipEO8HLavRmF7QZ5cqlFfcdVfD4Fm13s8B5t2IrVROq0oNWueJyfxuFSQ==",
1246
+ "version": "4.3.0",
1247
+ "resolved": "https://registry.npmjs.org/@fastly/js-compute/-/js-compute-4.3.0.tgz",
1248
+ "integrity": "sha512-JaxynSbhhHIvfltdopeAv4Uw89t7J4Yxf/ImNzttUPs/9vV3nQXlLGyLuQddtp0SEHqW/x5MfTzmDp5J1UKyZw==",
1249
1249
  "bundleDependencies": [
1250
1250
  "@fastly/wasmtime"
1251
1251
  ],
@@ -38,8 +38,8 @@ app.use('*', logFastlyServiceVersion());
38
38
  app.use('*', selectCollection());
39
39
 
40
40
  // The extensions, in file-name order: first the middleware phase of all of
41
- // them, then the beforeFiles phase.
42
- for (const phase of [ 'middleware', 'beforeFiles' ] as const) {
41
+ // them, then the beforeFilesRoutes phase.
42
+ for (const phase of [ 'middleware', 'beforeFilesRoutes' ] as const) {
43
43
  for (const e of extensions) {
44
44
  e.module.phases[phase]?.(app, honoOptions?.extensions?.[e.name], helpers);
45
45
  }
@@ -51,10 +51,10 @@ for (const phase of [ 'middleware', 'beforeFiles' ] as const) {
51
51
  // Serve the published files. If no file matches, the request goes to the next handler.
52
52
  app.use('*', serveStatic());
53
53
 
54
- // The afterFiles phase of the extensions: only for the requests that no
54
+ // The afterFilesRoutes phase of the extensions: only for the requests that no
55
55
  // published file matches.
56
56
  for (const e of extensions) {
57
- e.module.phases.afterFiles?.(app, honoOptions?.extensions?.[e.name], helpers);
57
+ e.module.phases.afterFilesRoutes?.(app, honoOptions?.extensions?.[e.name], helpers);
58
58
  }
59
59
 
60
60
  // When nothing matches, serve the SPA file or the 404 page.
@@ -1217,9 +1217,9 @@
1217
1217
  }
1218
1218
  },
1219
1219
  "node_modules/@fastly/js-compute": {
1220
- "version": "4.0.1",
1221
- "resolved": "https://registry.npmjs.org/@fastly/js-compute/-/js-compute-4.0.1.tgz",
1222
- "integrity": "sha512-G5O9NxPaqbFBTjgMPXdyMI6NktUhFipEO8HLavRmF7QZ5cqlFfcdVfD4Fm13s8B5t2IrVROq0oNWueJyfxuFSQ==",
1220
+ "version": "4.3.0",
1221
+ "resolved": "https://registry.npmjs.org/@fastly/js-compute/-/js-compute-4.3.0.tgz",
1222
+ "integrity": "sha512-JaxynSbhhHIvfltdopeAv4Uw89t7J4Yxf/ImNzttUPs/9vV3nQXlLGyLuQddtp0SEHqW/x5MfTzmDp5J1UKyZw==",
1223
1223
  "bundleDependencies": [
1224
1224
  "@fastly/wasmtime"
1225
1225
  ],