@okam/directus-next 1.2.7 → 1.2.9

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
@@ -1,3 +1,9 @@
1
+ ## 1.2.8 (2025-11-01)
2
+
3
+ ### 🧱 Updated Dependencies
4
+
5
+ - Updated next-component to 1.2.1
6
+
1
7
  ## 1.2.7 (2025-11-01)
2
8
 
3
9
  ### 🧱 Updated Dependencies
package/index.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const headers = require("next/headers");
4
4
  const navigation = require("next/navigation");
5
5
  const radashi = require("radashi");
6
- const router = require("./router-XhYR_hlg.js");
6
+ const router = require("./router-DTZYUtal.js");
7
7
  const logger = require("@okam/logger");
8
8
  const coreLib = require("@okam/core-lib");
9
9
  function getJsonErrorResponse(data, status) {
package/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { draftMode } from "next/headers";
2
2
  import { redirect } from "next/navigation";
3
3
  import { template } from "radashi";
4
- import { g as getRedirectSecretDefault } from "./router-BdkmiPvg.mjs";
5
- import { l, d, b, a, h } from "./router-BdkmiPvg.mjs";
4
+ import { g as getRedirectSecretDefault } from "./router-CA4ItnAc.mjs";
5
+ import { l, d, b, a, h } from "./router-CA4ItnAc.mjs";
6
6
  import { logger } from "@okam/logger";
7
7
  import { normalizePath } from "@okam/core-lib";
8
8
  function getJsonErrorResponse(data, status) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@okam/directus-next",
3
3
  "main": "./index.js",
4
- "version": "1.2.7",
4
+ "version": "1.2.9",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
7
7
  ".": {
@@ -35,7 +35,7 @@
35
35
  "@okam/core-lib": "1.17.0",
36
36
  "@okam/directus-node": "0.6.2",
37
37
  "@okam/logger": "1.1.0",
38
- "@okam/next-component": "1.2.0",
38
+ "@okam/next-component": "1.2.2",
39
39
  "next": "^14.1.1",
40
40
  "radashi": "^12.3.0",
41
41
  "@okam/directus-query": "1.4.2",
@@ -1,5 +1,32 @@
1
1
  import type { NextRequest, NextResponse as NextResponseType } from 'next/server';
2
2
  import type { DirectusRouteConfig } from '../types/directusRouteConfig';
3
+ /**
4
+ * Handles incoming middleware requests and rewrites the path to the new format according to fetched page settings.
5
+ * @param request - The NextRequest object
6
+ * @param config - The DirectusRouteConfig object
7
+ * @deprecated Use `directusRouteRouter(request, config)` instead. NextResponse is now directly imported in this file.
8
+ * @param NextResponse - The NextResponse object
9
+ * @returns NextResponse
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * export const directusConfig: DirectusRouteConfig = {
14
+ * localeMap: {
15
+ * 'fr-CA': 'fr',
16
+ * 'en-CA': 'en',
17
+ * },
18
+ * collectionSettings: {
19
+ * default: {
20
+ * idField: 'id',
21
+ * },
22
+ * },
23
+ * }
24
+ *
25
+ * export async function middleware(request: NextRequest) {
26
+ * return directusRouteRouter(request, directusConfig)
27
+ * }
28
+ * ```
29
+ */
3
30
  export declare function directusRouteRouter(request: NextRequest, config: DirectusRouteConfig,
4
31
  /**
5
32
  * @deprecated Use `directusRouteRouter(request, config)` instead. NextResponse is now directly imported in this file.
@@ -0,0 +1,21 @@
1
+ import type { DirectusRouteConfig } from '../../types';
2
+ /**
3
+ * Validates if a given string is a valid locale from the directus route configuration.
4
+ * @param maybeLocale The string to validate as a locale
5
+ * @param config The Directus route configuration containing the locale map
6
+ * @returns The validated locale string, or undefined if invalid
7
+ */
8
+ export declare function getValidLocale(maybeLocale: string | null | undefined, config: DirectusRouteConfig): string | undefined;
9
+ /**
10
+ * Splits the locale from the pathname and returns the locale and the pathname without the locale.
11
+ * @param pathname The pathname to split the locale from
12
+ * @param config The Directus route configuration containing the locale map
13
+ * @returns The locale and the pathname without the locale
14
+ */
15
+ export declare function splitLocaleFromPathname(pathname: string, config: DirectusRouteConfig): {
16
+ locale: string;
17
+ pathname: string;
18
+ } | {
19
+ locale: undefined;
20
+ pathname: string;
21
+ };
@@ -137,9 +137,18 @@ async function fetchPageSettingsTranslation(path) {
137
137
  return null;
138
138
  }
139
139
  }
140
- function removeLocaleFromPathname(pathname, config) {
141
- const currentLocale = Object.values(config.localeMap ?? {}).find((locale) => pathname.startsWith(`/${locale}/`));
142
- return { locale: currentLocale, pathname: currentLocale ? pathname.replace(`/${currentLocale}/`, "/") : pathname };
140
+ function getValidLocale(maybeLocale, config) {
141
+ const locale = Object.values(config.localeMap ?? {}).find((l) => l === maybeLocale);
142
+ return locale;
143
+ }
144
+ function splitLocaleFromPathname(pathname, config) {
145
+ const [, maybeLocale, ...parts] = pathname.split("/");
146
+ const locale = getValidLocale(maybeLocale, config);
147
+ if (locale) {
148
+ const newPathname = parts.length > 0 ? `/${parts.join("/")}` : "/";
149
+ return { locale, pathname: newPathname };
150
+ }
151
+ return { locale: void 0, pathname };
143
152
  }
144
153
  function getValidTranslation(translations, locale) {
145
154
  const translation = translations[0];
@@ -155,7 +164,7 @@ function getValidTranslation(translations, locale) {
155
164
  async function directusRouteRouter(request, config, NextResponse$1 = NextResponse) {
156
165
  var _a, _b, _c;
157
166
  const { pathname: localizedPathname } = request.nextUrl;
158
- const { locale, pathname } = removeLocaleFromPathname(localizedPathname, config);
167
+ const { locale, pathname } = splitLocaleFromPathname(localizedPathname, config);
159
168
  log("Processing request for pathname:", { locale, pathname });
160
169
  const redirect = await handleRedirect(request, (_a = config.modules) == null ? void 0 : _a.redirects);
161
170
  if (redirect) {
@@ -138,9 +138,18 @@ async function fetchPageSettingsTranslation(path) {
138
138
  return null;
139
139
  }
140
140
  }
141
- function removeLocaleFromPathname(pathname, config) {
142
- const currentLocale = Object.values(config.localeMap ?? {}).find((locale) => pathname.startsWith(`/${locale}/`));
143
- return { locale: currentLocale, pathname: currentLocale ? pathname.replace(`/${currentLocale}/`, "/") : pathname };
141
+ function getValidLocale(maybeLocale, config) {
142
+ const locale = Object.values(config.localeMap ?? {}).find((l) => l === maybeLocale);
143
+ return locale;
144
+ }
145
+ function splitLocaleFromPathname(pathname, config) {
146
+ const [, maybeLocale, ...parts] = pathname.split("/");
147
+ const locale = getValidLocale(maybeLocale, config);
148
+ if (locale) {
149
+ const newPathname = parts.length > 0 ? `/${parts.join("/")}` : "/";
150
+ return { locale, pathname: newPathname };
151
+ }
152
+ return { locale: void 0, pathname };
144
153
  }
145
154
  function getValidTranslation(translations, locale) {
146
155
  const translation = translations[0];
@@ -156,7 +165,7 @@ function getValidTranslation(translations, locale) {
156
165
  async function directusRouteRouter(request, config, NextResponse = server.NextResponse) {
157
166
  var _a, _b, _c;
158
167
  const { pathname: localizedPathname } = request.nextUrl;
159
- const { locale, pathname } = removeLocaleFromPathname(localizedPathname, config);
168
+ const { locale, pathname } = splitLocaleFromPathname(localizedPathname, config);
160
169
  log("Processing request for pathname:", { locale, pathname });
161
170
  const redirect = await handleRedirect(request, (_a = config.modules) == null ? void 0 : _a.redirects);
162
171
  if (redirect) {
package/server.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use server";
2
2
  "use strict";
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
- const router = require("./router-XhYR_hlg.js");
4
+ const router = require("./router-DTZYUtal.js");
5
5
  require("server-only");
6
6
  const react = require("react");
7
7
  const directusQuery = require("@okam/directus-query");
package/server.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use server";
2
- import { c as log } from "./router-BdkmiPvg.mjs";
3
- import { d } from "./router-BdkmiPvg.mjs";
2
+ import { c as log } from "./router-CA4ItnAc.mjs";
3
+ import { d } from "./router-CA4ItnAc.mjs";
4
4
  import "server-only";
5
5
  import { cache } from "react";
6
6
  import { queryGql } from "@okam/directus-query";