@contello/astro 2.1.0 → 2.2.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.
package/dist/index.cjs CHANGED
@@ -156,7 +156,7 @@ function customHeaders(headers) {
156
156
  }
157
157
  return result;
158
158
  }
159
- function createBoundRoutingMiddleware(contello, routes, exclude) {
159
+ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePath) {
160
160
  return (0, import_middleware2.defineMiddleware)((ctx, next) => {
161
161
  if ((0, import_excludes.shouldExclude)(ctx, exclude ?? import_excludes.RECOMMENDED_EXCLUDES)) {
162
162
  return next();
@@ -169,7 +169,8 @@ function createBoundRoutingMiddleware(contello, routes, exclude) {
169
169
  if (url.pathname.startsWith("/contello/entities/")) {
170
170
  return contello[runRequest]({ url, route: void 0, rewritten: false }, () => next());
171
171
  }
172
- const lookup = routes.getByPath(url.pathname);
172
+ const path = resolveRoutePath ? resolveRoutePath(ctx) : url.pathname;
173
+ const lookup = routes.getByPath(path);
173
174
  return (0, import_store.maybeThen)(lookup, (route) => {
174
175
  if (!route) {
175
176
  return contello[runRequest]({ url, route: void 0, rewritten: false }, () => next());
@@ -414,7 +415,7 @@ var Contello = class {
414
415
  } else {
415
416
  routes = routesOption;
416
417
  }
417
- return createBoundRoutingMiddleware(this, routes, options?.exclude);
418
+ return createBoundRoutingMiddleware(this, routes, options?.exclude, options?.resolveRoutePath);
418
419
  };
419
420
  createAssetsMiddleware = (options) => {
420
421
  return createBoundAssetsMiddleware(this, options);
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as astro from 'astro';
2
+ import { APIContext } from 'astro';
2
3
  import { Schema, ContelloClient, SourceDef } from '@contello/client';
3
4
  import { MediaResolverOptions, MediaResolver, ImageDef } from '@contello/media';
4
5
  import { Routes, RoutesSync, LazyRoutes, CreateStoreOptions, SyncCacheOptions, Loadable, I18nMessages, ReadonlyDeep, StoreRoute, SourceKeysOf, ExtractSourceResult, ResolveSource, SingletonOptions, Singleton, SingletonSyncOptions, SingletonSync, CollectionOptions, Collection, CollectionSyncOptions, CollectionSync, LazyCollectionOptions, LazyCollection, RoutesOptions, RoutesSyncOptions, LazyRoutesOptions, AssetsOptions, Assets, AssetsSyncOptions, AssetsSync, LazyAssetsOptions, LazyAssets } from '@contello/store';
@@ -18,6 +19,16 @@ type ContelloAssetsMiddlewareOptions = {
18
19
  };
19
20
 
20
21
  type AnyRoutes = Routes | RoutesSync | LazyRoutes;
22
+ /**
23
+ * Derives the path used to look up a Contello route from the request context.
24
+ *
25
+ * @default `(ctx) => ctx.url.pathname`
26
+ *
27
+ * ```ts
28
+ * resolveRoutePath: (ctx) => `/${ctx.url.hostname}${ctx.url.pathname}`
29
+ * ```
30
+ */
31
+ type RoutePathResolver = (ctx: APIContext) => string;
21
32
  type ContelloRoutingMiddlewareOptions = {
22
33
  /**
23
34
  * - `'eager'` (default) — use a `RoutesSync` instance managed by contello (auto-loaded by `contello.init()`)
@@ -26,6 +37,7 @@ type ContelloRoutingMiddlewareOptions = {
26
37
  */
27
38
  routes?: 'eager' | 'lazy' | AnyRoutes | undefined;
28
39
  exclude?: ExcludePattern[] | undefined;
40
+ resolveRoutePath?: RoutePathResolver | undefined;
29
41
  };
30
42
 
31
43
  type ContelloRequestContext = {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as astro from 'astro';
2
+ import { APIContext } from 'astro';
2
3
  import { Schema, ContelloClient, SourceDef } from '@contello/client';
3
4
  import { MediaResolverOptions, MediaResolver, ImageDef } from '@contello/media';
4
5
  import { Routes, RoutesSync, LazyRoutes, CreateStoreOptions, SyncCacheOptions, Loadable, I18nMessages, ReadonlyDeep, StoreRoute, SourceKeysOf, ExtractSourceResult, ResolveSource, SingletonOptions, Singleton, SingletonSyncOptions, SingletonSync, CollectionOptions, Collection, CollectionSyncOptions, CollectionSync, LazyCollectionOptions, LazyCollection, RoutesOptions, RoutesSyncOptions, LazyRoutesOptions, AssetsOptions, Assets, AssetsSyncOptions, AssetsSync, LazyAssetsOptions, LazyAssets } from '@contello/store';
@@ -18,6 +19,16 @@ type ContelloAssetsMiddlewareOptions = {
18
19
  };
19
20
 
20
21
  type AnyRoutes = Routes | RoutesSync | LazyRoutes;
22
+ /**
23
+ * Derives the path used to look up a Contello route from the request context.
24
+ *
25
+ * @default `(ctx) => ctx.url.pathname`
26
+ *
27
+ * ```ts
28
+ * resolveRoutePath: (ctx) => `/${ctx.url.hostname}${ctx.url.pathname}`
29
+ * ```
30
+ */
31
+ type RoutePathResolver = (ctx: APIContext) => string;
21
32
  type ContelloRoutingMiddlewareOptions = {
22
33
  /**
23
34
  * - `'eager'` (default) — use a `RoutesSync` instance managed by contello (auto-loaded by `contello.init()`)
@@ -26,6 +37,7 @@ type ContelloRoutingMiddlewareOptions = {
26
37
  */
27
38
  routes?: 'eager' | 'lazy' | AnyRoutes | undefined;
28
39
  exclude?: ExcludePattern[] | undefined;
40
+ resolveRoutePath?: RoutePathResolver | undefined;
29
41
  };
30
42
 
31
43
  type ContelloRequestContext = {
package/dist/index.js CHANGED
@@ -123,7 +123,7 @@ function customHeaders(headers) {
123
123
  }
124
124
  return result;
125
125
  }
126
- function createBoundRoutingMiddleware(contello, routes, exclude) {
126
+ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePath) {
127
127
  return defineMiddleware2((ctx, next) => {
128
128
  if (shouldExclude(ctx, exclude ?? RECOMMENDED_EXCLUDES)) {
129
129
  return next();
@@ -136,7 +136,8 @@ function createBoundRoutingMiddleware(contello, routes, exclude) {
136
136
  if (url.pathname.startsWith("/contello/entities/")) {
137
137
  return contello[runRequest]({ url, route: void 0, rewritten: false }, () => next());
138
138
  }
139
- const lookup = routes.getByPath(url.pathname);
139
+ const path = resolveRoutePath ? resolveRoutePath(ctx) : url.pathname;
140
+ const lookup = routes.getByPath(path);
140
141
  return maybeThen(lookup, (route) => {
141
142
  if (!route) {
142
143
  return contello[runRequest]({ url, route: void 0, rewritten: false }, () => next());
@@ -381,7 +382,7 @@ var Contello = class {
381
382
  } else {
382
383
  routes = routesOption;
383
384
  }
384
- return createBoundRoutingMiddleware(this, routes, options?.exclude);
385
+ return createBoundRoutingMiddleware(this, routes, options?.exclude, options?.resolveRoutePath);
385
386
  };
386
387
  createAssetsMiddleware = (options) => {
387
388
  return createBoundAssetsMiddleware(this, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contello/astro",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Astro integration for Contello CMS — route middleware and i18n bridge",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -15,8 +15,8 @@
15
15
  "@astroscope/i18n": ">=0.3.0",
16
16
  "astro": "^6.0.0",
17
17
  "@contello/client": "^2.2.0",
18
- "@contello/media": "^1.0.1",
19
- "@contello/store": "^2.1.0"
18
+ "@contello/store": "^2.1.0",
19
+ "@contello/media": "^1.0.1"
20
20
  },
21
21
  "peerDependenciesMeta": {
22
22
  "@astroscope/i18n": {
@@ -28,8 +28,8 @@
28
28
  "@astroscope/i18n": "^0.4.5",
29
29
  "astro": "^6.1.8",
30
30
  "@contello/client": "^2.2.0",
31
- "@contello/media": "^1.0.1",
32
- "@contello/store": "^2.1.0"
31
+ "@contello/store": "^2.1.0",
32
+ "@contello/media": "^1.0.1"
33
33
  },
34
34
  "files": [
35
35
  "dist"