@okam/directus-next 1.2.8 → 1.2.10

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/draft/route.d.ts CHANGED
@@ -44,4 +44,4 @@ export type HandleDraftOptions = {
44
44
  * })
45
45
  * }
46
46
  */
47
- export default function handleDraftRoute({ url, getDirectusLanguage, getDraftSecret, getJsonError, }: HandleDraftOptions): Response | undefined;
47
+ export default function handleDraftRoute({ url, getDirectusLanguage, getDraftSecret, getJsonError, }: HandleDraftOptions): Promise<Response | undefined>;
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) {
@@ -98,7 +98,7 @@ function getPathFromRoute(routeUrl, url, index = 0) {
98
98
  });
99
99
  return radashi.template(routeUrl, map);
100
100
  }
101
- function handleDraftRoute({
101
+ async function handleDraftRoute({
102
102
  url,
103
103
  getDirectusLanguage,
104
104
  getDraftSecret,
@@ -147,7 +147,7 @@ function handleDraftRoute({
147
147
  const withParams = redirectUrl.indexOf("?") !== -1;
148
148
  redirectUrl = `${redirectUrl}${withParams ? "&" : "?"}version=${encodeURIComponent(version)}`;
149
149
  }
150
- headers.draftMode().enable();
150
+ (await headers.draftMode()).enable();
151
151
  navigation.redirect(redirectUrl);
152
152
  return void 0;
153
153
  }
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) {
@@ -97,7 +97,7 @@ function getPathFromRoute(routeUrl, url, index = 0) {
97
97
  });
98
98
  return template(routeUrl, map);
99
99
  }
100
- function handleDraftRoute({
100
+ async function handleDraftRoute({
101
101
  url,
102
102
  getDirectusLanguage,
103
103
  getDraftSecret,
@@ -146,7 +146,7 @@ function handleDraftRoute({
146
146
  const withParams = redirectUrl.indexOf("?") !== -1;
147
147
  redirectUrl = `${redirectUrl}${withParams ? "&" : "?"}version=${encodeURIComponent(version)}`;
148
148
  }
149
- draftMode().enable();
149
+ (await draftMode()).enable();
150
150
  redirect(redirectUrl);
151
151
  return void 0;
152
152
  }
package/logger.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import type { LogSeverity } from '@okam/logger';
2
- export declare const logger: import("@okam/logger").Logger;
1
+ import { LogSeverity } from '../../../stack/logger/src/index.ts';
2
+
3
+ export declare const logger: import('../../../stack/logger/src/index.ts').Logger;
3
4
  export declare function log(msg: string, context?: unknown, severity?: LogSeverity): void;
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.8",
4
+ "version": "1.2.10",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
7
7
  ".": {
@@ -35,8 +35,8 @@
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.1",
39
- "next": "^14.1.1",
38
+ "@okam/next-component": "1.2.3",
39
+ "next": "^15.0.0",
40
40
  "radashi": "^12.3.0",
41
41
  "@okam/directus-query": "1.4.2",
42
42
  "server-only": "0.0.1",
@@ -1,4 +1,5 @@
1
- import type { Variables } from 'graphql-request';
2
- import type { TPageSettingsQueryItem, TUsePageSettingsReturn } from './interface';
1
+ import { Variables } from 'graphql-request';
2
+ import { TPageSettingsQueryItem, TUsePageSettingsReturn } from './interface';
3
+
3
4
  export declare function pageSettingsContext<Item extends TPageSettingsQueryItem>(defaultValue?: TUsePageSettingsReturn<Item>): readonly [() => TUsePageSettingsReturn<Item> | undefined, (value: TUsePageSettingsReturn<Item> | undefined) => void];
4
5
  export declare function pageSettingsVariablesContext(variables?: Variables): readonly [() => object | undefined, (value: object | undefined) => void];
@@ -1,7 +1,8 @@
1
- import { type TypedDocumentNode } from '@graphql-typed-document-node/core';
2
- import type { Variables } from 'graphql-request';
3
- import type { TFiles } from '../files/interface';
4
- import type { DirectusRouteConfig } from '../types/directusRouteConfig';
1
+ import { TypedDocumentNode } from '@graphql-typed-document-node/core';
2
+ import { Variables } from 'graphql-request';
3
+ import { TFiles } from '../files/interface';
4
+ import { DirectusRouteConfig } from '../types/directusRouteConfig';
5
+
5
6
  export type Fragmentize<FragmentData, FragmentName extends string = string> = {
6
7
  ' $fragmentRefs'?: {
7
8
  [FragmentKey in FragmentName]?: FragmentData | null | undefined;
@@ -1,5 +1,6 @@
1
- import type { Variables } from 'graphql-request';
2
- import type { TUsePageSettingsProps, TPageSettingsQueryItem, TUsePageSettingsReturn } from './interface';
1
+ import { Variables } from 'graphql-request';
2
+ import { TUsePageSettingsProps, TPageSettingsQueryItem, TUsePageSettingsReturn } from './interface';
3
+
3
4
  /**
4
5
  * @param props Optional props. Passing new props will trigger a new query if the variables have changed compared to the value of the variables in the cache. Omitting props will return the cached value.
5
6
  * @param itemKey Required if the query has more than a single root field
@@ -1,4 +1,5 @@
1
- import type { HandleRedirectOptions } from './interface';
1
+ import { HandleRedirectOptions } from './interface';
2
+
2
3
  export declare function parseRedirectParams(url: string): {
3
4
  secret: string;
4
5
  };
@@ -1,5 +1,6 @@
1
- import type { TFetchRedirectsResponse } from '@okam/directus-node/edge';
2
- import type { DirectusRouteRedirectsModule } from '../../types/directusRouteConfig';
1
+ import { TFetchRedirectsResponse } from '../../../../directus-node/src/edge.ts';
2
+ import { DirectusRouteRedirectsModule } from '../../types/directusRouteConfig';
3
+
3
4
  /**
4
5
  * Gets a response from `options.apiRoute`
5
6
  * @param {DirectusRouteRedirectsModule} options
@@ -1,6 +1,6 @@
1
- import type { NextRequest } from 'next/server';
2
- import { NextResponse } from 'next/server';
3
- import type { DirectusRouteRedirectsModule } from '../../types/directusRouteConfig';
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+ import { DirectusRouteRedirectsModule } from '../../types/directusRouteConfig';
3
+
4
4
  /**
5
5
  * Handles next redirection using directus redirects
6
6
  */
@@ -1,5 +1,33 @@
1
- import type { NextRequest, NextResponse as NextResponseType } from 'next/server';
2
- import type { DirectusRouteConfig } from '../types/directusRouteConfig';
1
+ import { NextRequest, NextResponse as NextResponseType } from 'next/server';
2
+ import { DirectusRouteConfig } from '../types/directusRouteConfig';
3
+
4
+ /**
5
+ * Handles incoming middleware requests and rewrites the path to the new format according to fetched page settings.
6
+ * @param request - The NextRequest object
7
+ * @param config - The DirectusRouteConfig object
8
+ * @deprecated Use `directusRouteRouter(request, config)` instead. NextResponse is now directly imported in this file.
9
+ * @param NextResponse - The NextResponse object
10
+ * @returns NextResponse
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * export const directusConfig: DirectusRouteConfig = {
15
+ * localeMap: {
16
+ * 'fr-CA': 'fr',
17
+ * 'en-CA': 'en',
18
+ * },
19
+ * collectionSettings: {
20
+ * default: {
21
+ * idField: 'id',
22
+ * },
23
+ * },
24
+ * }
25
+ *
26
+ * export async function middleware(request: NextRequest) {
27
+ * return directusRouteRouter(request, directusConfig)
28
+ * }
29
+ * ```
30
+ */
3
31
  export declare function directusRouteRouter(request: NextRequest, config: DirectusRouteConfig,
4
32
  /**
5
33
  * @deprecated Use `directusRouteRouter(request, config)` instead. NextResponse is now directly imported in this file.
@@ -1,2 +1,3 @@
1
- import type { PageSettingsTranslation } from '../../types';
1
+ import { PageSettingsTranslation } from '../../types';
2
+
2
3
  export declare function fetchPageSettingsTranslation(path: string): Promise<PageSettingsTranslation[] | null>;
@@ -0,0 +1,22 @@
1
+ import { DirectusRouteConfig } from '../../types';
2
+
3
+ /**
4
+ * Validates if a given string is a valid locale from the directus route configuration.
5
+ * @param maybeLocale The string to validate as a locale
6
+ * @param config The Directus route configuration containing the locale map
7
+ * @returns The validated locale string, or undefined if invalid
8
+ */
9
+ export declare function getValidLocale(maybeLocale: string | null | undefined, config: DirectusRouteConfig): string | undefined;
10
+ /**
11
+ * Splits the locale from the pathname and returns the locale and the pathname without the locale.
12
+ * @param pathname The pathname to split the locale from
13
+ * @param config The Directus route configuration containing the locale map
14
+ * @returns The locale and the pathname without the locale
15
+ */
16
+ export declare function splitLocaleFromPathname(pathname: string, config: DirectusRouteConfig): {
17
+ locale: string;
18
+ pathname: string;
19
+ } | {
20
+ locale: undefined;
21
+ pathname: string;
22
+ };
@@ -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";