@rebasepro/types 0.31.0-canary.g902a0ce → 0.32.0

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.
@@ -197,6 +197,62 @@ export interface RebaseStaticAppConfig {
197
197
  * @example "/admin" — the CMS is one route of a larger app
198
198
  */
199
199
  cms?: string;
200
+ /**
201
+ * Paths on this app's address that a custom function answers instead of
202
+ * the build: a sitemap, a feed, a server-rendered page.
203
+ *
204
+ * A static app cannot claim `/api`, so without this a function's response
205
+ * lives only at `/api/functions/<name>`, and `/sitemap.xml` or
206
+ * `/blog/<slug>` needs a custom runtime or a proxy in front. A route
207
+ * serves the function's response, whatever its content type, at the
208
+ * route's path, on this app's hostname when its `path` names one.
209
+ *
210
+ * The function sees the request as if it had been called at
211
+ * `/api/functions/<name>`, with the same auth, scopes and rate limit, and
212
+ * a wildcard route hands it the rest of the path: `/blog/*` sends
213
+ * `/blog/hello` to the function's `/hello` route. Query string, method,
214
+ * headers and body pass through, `Host` included.
215
+ *
216
+ * The most specific route wins: an exact path before a wildcard, and a
217
+ * longer wildcard before a shorter one. A route wins over a file of the
218
+ * same path in the build. The function's `Content-Security-Policy` is its
219
+ * own when it sends one; otherwise the response gets this app's, so
220
+ * {@link RebaseStaticAppConfig.frameAncestors} covers routed pages too.
221
+ *
222
+ * Served by the process that serves the project's functions, which is the
223
+ * backend this app is folded into. A static app deployed on its own has
224
+ * no functions to call, so `rebase cloud deploy` refuses one with routes.
225
+ */
226
+ routes?: RebaseStaticRoute[];
227
+ /**
228
+ * Origins allowed to frame this app, besides its own.
229
+ *
230
+ * A static app is served with `frame-ancestors 'self'`, so only a page on
231
+ * its own origin can put it in an iframe. A CMS on `admin.example.com`
232
+ * that previews the site on `www.example.com` needs the site to name it:
233
+ * `["https://admin.example.com"]`. Each entry is one origin: `https://`
234
+ * with a hostname and an optional port, or `http://` for `localhost`,
235
+ * `127.0.0.1` and `[::1]` while developing. No wildcards, no paths, no
236
+ * keywords — `'self'` is always included.
237
+ *
238
+ * Applies to every response this app serves, and to its routes' responses
239
+ * that carry no policy of their own.
240
+ */
241
+ frameAncestors?: string[];
242
+ }
243
+ /**
244
+ * A path on a static app's address answered by a custom function instead of
245
+ * the app's build. See {@link RebaseStaticAppConfig.routes}.
246
+ */
247
+ export interface RebaseStaticRoute {
248
+ /**
249
+ * The URL path, absolute — not relative to the app's `path` — and inside
250
+ * it. Either exact, `/sitemap.xml`, or a prefix ending in `/*`, `/blog/*`,
251
+ * which matches `/blog` itself and every path beneath it.
252
+ */
253
+ path: string;
254
+ /** The custom function that answers it, by name: `sitemap` for `/api/functions/sitemap`. */
255
+ function: string;
200
256
  }
201
257
  export type RebaseAppConfig = RebaseBackendAppConfig | RebaseStaticAppConfig;
202
258
  /**
@@ -260,6 +316,71 @@ export declare function parseAppAddress(value: string): AppAddressResult;
260
316
  * `localhost`. Internationalised names arrive here already in punycode.
261
317
  */
262
318
  export declare function isValidAppHost(host: string): boolean;
319
+ export type StaticRouteResult = {
320
+ ok: true;
321
+ route: RebaseStaticRoute;
322
+ } | {
323
+ ok: false;
324
+ field?: "path" | "function";
325
+ reason: string;
326
+ };
327
+ /**
328
+ * Validate one of a static app's routes against the app's own path (the path
329
+ * part of its address).
330
+ *
331
+ * Shared for the reason {@link parseAppAddress} is: the CLI checks a route
332
+ * while `rebase.json` is edited, and the runtime checks it again when it loads
333
+ * a bundle, which any program could have written. The rules:
334
+ *
335
+ * - `path` is absolute, with no `..`, empty segment or trailing slash, and
336
+ * ends in `/*` or holds no `*` at all.
337
+ * - No segment starts with a dot: `/.well-known` is the backend's, and a
338
+ * static app serves no dot-file.
339
+ * - It is not under a prefix the backend owns ({@link RESERVED_BACKEND_PREFIXES}),
340
+ * because the API answers there on every hostname.
341
+ * - It is inside the app's path, since the app is what answers there, and a
342
+ * wildcard does not cover the whole app, which would leave nothing of the
343
+ * build to serve.
344
+ * - `function` is one path segment, as a function's file name is.
345
+ */
346
+ export declare function validateStaticRoute(value: unknown, appPath: string): StaticRouteResult;
347
+ /**
348
+ * Whether `route` answers `requestPath`, and with what path under its
349
+ * function: `""` for the route's own path, `/rest` beneath a wildcard.
350
+ * `undefined` when it does not match.
351
+ *
352
+ * Compared as the path arrives, percent-encoding and all, and at segment
353
+ * boundaries: `/blog/*` matches `/blog` and `/blog/x`, not `/blogroll`.
354
+ */
355
+ export declare function matchStaticRoute(route: RebaseStaticRoute, requestPath: string): string | undefined;
356
+ /**
357
+ * Order routes so the first match is the most specific: exact paths first,
358
+ * then wildcards by the length of their prefix, longest first. Declaration
359
+ * order breaks ties, which only equal wildcards can have.
360
+ */
361
+ export declare function compareStaticRoutes(a: RebaseStaticRoute, b: RebaseStaticRoute): number;
362
+ export type FrameAncestorResult = {
363
+ ok: true;
364
+ origin: string;
365
+ } | {
366
+ ok: false;
367
+ reason: string;
368
+ };
369
+ /**
370
+ * Validate one entry of a static app's `frameAncestors`: a single origin that
371
+ * may frame the app.
372
+ *
373
+ * The value ends up inside a `Content-Security-Policy` header, so it is held
374
+ * to the exact serialisation of an origin — `new URL(value).origin` has to
375
+ * give it back unchanged. That leaves nothing that could close the directive
376
+ * or open another one, and turns every near miss (a trailing slash, a
377
+ * capital, a default port, a path) into a refusal that names the fix.
378
+ *
379
+ * `https://` with a public hostname, or `localhost`; plain `http://` only for
380
+ * a loopback host. Never a wildcard or a keyword: this is a list of the
381
+ * origins an operator chose, and `'self'` is always on it.
382
+ */
383
+ export declare function parseFrameAncestor(value: unknown): FrameAncestorResult;
263
384
  /**
264
385
  * One declared storage source, as authored in `rebase.json`.
265
386
  *
@@ -540,6 +661,22 @@ export interface RebaseBundleStatic {
540
661
  * for why a client-side route has to be declared to be knowable at all.
541
662
  */
542
663
  cms?: string;
664
+ /**
665
+ * Paths a custom function answers instead of the build, copied from the
666
+ * app's declaration — see {@link RebaseStaticAppConfig.routes}.
667
+ *
668
+ * A runtime that predates this field ignores it and answers each path from
669
+ * the build, which for an SPA is `index.html` with a 200. Nothing breaks
670
+ * that worked before, but the route is not served until the runtime reads
671
+ * it.
672
+ */
673
+ routes?: RebaseStaticRoute[];
674
+ /**
675
+ * Origins besides its own that may frame this app, copied from the app's
676
+ * declaration — see {@link RebaseStaticAppConfig.frameAncestors}. A runtime
677
+ * that predates this field serves `frame-ancestors 'self'`.
678
+ */
679
+ frameAncestors?: string[];
543
680
  }
544
681
  /**
545
682
  * A native module found in the dependency closure.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebasepro/types",
3
- "version": "0.31.0-canary.g902a0ce",
3
+ "version": "0.32.0",
4
4
  "description": "Rebase type definitions — shared interfaces and controller types",
5
5
  "keywords": [
6
6
  "rebase",