@okam/directus-next 1.2.11 → 1.2.12

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,29 @@
1
+ ## 1.2.12 (2026-01-15)
2
+
3
+ ### 🚀 Features
4
+
5
+ - ⚠️ React 19 + Next.js 15 upgrade for all @okam/* packages ([#369](https://github.com/OKAMca/stack/pull/369))
6
+
7
+ ### 🩹 Fixes
8
+
9
+ - **directus-next:** remove server-only ([ecd8d1b](https://github.com/OKAMca/stack/commit/ecd8d1b))
10
+ - **directus-next:** draft route handler uses zod, returns draft isEnabled whenever possible ([#376](https://github.com/OKAMca/stack/pull/376))
11
+ - ⚠️ functions starting with "use" should be reserved to react hooks ([68f1f8f](https://github.com/OKAMca/stack/commit/68f1f8f))
12
+
13
+ ### ⚠️ Breaking Changes
14
+
15
+ - Consumers must now have react and react-dom in their own
16
+
17
+ ### 🧱 Updated Dependencies
18
+
19
+ - Updated next-component to 1.3.0
20
+
21
+ ### ❤️ Thank You
22
+
23
+ - Marie-Maxime Tanguay @marie-maxime
24
+ - Pierre-Olivier Clerson @poclerson
25
+ - poclerson
26
+
1
27
  ## 1.2.11 (2026-01-14)
2
28
 
3
29
  ### 🚀 Features
@@ -0,0 +1,14 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { isEqual } from "radashi";
3
+ import { memo } from "react";
4
+ const SvgComponent = (props) => /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "16 14 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_73015_2388)", children: /* @__PURE__ */ jsx(
5
+ "path",
6
+ {
7
+ d: "M32 22C32 24.1217 31.1571 26.1566 29.6569 27.6569C28.1566 29.1571 26.1217 30 24 30C21.8783 30 19.8434 29.1571 18.3431 27.6569C16.8429 26.1566 16 24.1217 16 22C16 19.8783 16.8429 17.8434 18.3431 16.3431C19.8434 14.8429 21.8783 14 24 14C26.1217 14 28.1566 14.8429 29.6569 16.3431C31.1571 17.8434 32 19.8783 32 22ZM24 18C23.8736 18.0001 23.7486 18.0266 23.6331 18.0779C23.5176 18.1292 23.4141 18.2042 23.3293 18.2979C23.2446 18.3916 23.1803 18.5021 23.1408 18.6222C23.1013 18.7422 23.0874 18.8692 23.1 18.995L23.45 22.502C23.4618 22.6398 23.5248 22.7681 23.6266 22.8616C23.7285 22.9552 23.8617 23.0071 24 23.0071C24.1383 23.0071 24.2715 22.9552 24.3734 22.8616C24.4752 22.7681 24.5382 22.6398 24.55 22.502L24.9 18.995C24.9126 18.8692 24.8987 18.7422 24.8592 18.6222C24.8197 18.5021 24.7554 18.3916 24.6707 18.2979C24.5859 18.2042 24.4824 18.1292 24.3669 18.0779C24.2514 18.0266 24.1264 18.0001 24 18ZM24.002 24C23.7368 24 23.4824 24.1054 23.2949 24.2929C23.1074 24.4804 23.002 24.7348 23.002 25C23.002 25.2652 23.1074 25.5196 23.2949 25.7071C23.4824 25.8946 23.7368 26 24.002 26C24.2672 26 24.5216 25.8946 24.7091 25.7071C24.8966 25.5196 25.002 25.2652 25.002 25C25.002 24.7348 24.8966 24.4804 24.7091 24.2929C24.5216 24.1054 24.2672 24 24.002 24Z",
8
+ fill: "currentColor"
9
+ }
10
+ ) }) });
11
+ const ErrorIcon = memo(SvgComponent, isEqual);
12
+ export {
13
+ ErrorIcon as default
14
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const radashi = require("radashi");
5
+ const React = require("react");
6
+ const SvgComponent = (props) => /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "16 14 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_73015_2388)", children: /* @__PURE__ */ jsxRuntime.jsx(
7
+ "path",
8
+ {
9
+ d: "M32 22C32 24.1217 31.1571 26.1566 29.6569 27.6569C28.1566 29.1571 26.1217 30 24 30C21.8783 30 19.8434 29.1571 18.3431 27.6569C16.8429 26.1566 16 24.1217 16 22C16 19.8783 16.8429 17.8434 18.3431 16.3431C19.8434 14.8429 21.8783 14 24 14C26.1217 14 28.1566 14.8429 29.6569 16.3431C31.1571 17.8434 32 19.8783 32 22ZM24 18C23.8736 18.0001 23.7486 18.0266 23.6331 18.0779C23.5176 18.1292 23.4141 18.2042 23.3293 18.2979C23.2446 18.3916 23.1803 18.5021 23.1408 18.6222C23.1013 18.7422 23.0874 18.8692 23.1 18.995L23.45 22.502C23.4618 22.6398 23.5248 22.7681 23.6266 22.8616C23.7285 22.9552 23.8617 23.0071 24 23.0071C24.1383 23.0071 24.2715 22.9552 24.3734 22.8616C24.4752 22.7681 24.5382 22.6398 24.55 22.502L24.9 18.995C24.9126 18.8692 24.8987 18.7422 24.8592 18.6222C24.8197 18.5021 24.7554 18.3916 24.6707 18.2979C24.5859 18.2042 24.4824 18.1292 24.3669 18.0779C24.2514 18.0266 24.1264 18.0001 24 18ZM24.002 24C23.7368 24 23.4824 24.1054 23.2949 24.2929C23.1074 24.4804 23.002 24.7348 23.002 25C23.002 25.2652 23.1074 25.5196 23.2949 25.7071C23.4824 25.8946 23.7368 26 24.002 26C24.2672 26 24.5216 25.8946 24.7091 25.7071C24.8966 25.5196 25.002 25.2652 25.002 25C25.002 24.7348 24.8966 24.4804 24.7091 24.2929C24.5216 24.1054 24.2672 24 24.002 24Z",
10
+ fill: "currentColor"
11
+ }
12
+ ) }) });
13
+ const ErrorIcon = React.memo(SvgComponent, radashi.isEqual);
14
+ exports.default = ErrorIcon;
package/draft/route.d.ts CHANGED
@@ -1,20 +1,25 @@
1
- export declare function parseDraftParams(url: string): {
2
- secret: string;
3
- languages: any;
4
- paths: never[];
5
- routes: any;
6
- type: string;
7
- pk: string;
8
- version: string;
1
+ import * as zod from 'zod';
2
+ export declare function parseDraftParams(url: string, expectedSecret: string): zod.ZodSafeParseError<string> | zod.ZodSafeParseResult<{
3
+ type: "path";
4
+ urls: string[];
5
+ languages: string[];
6
+ version?: string | undefined;
7
+ enable?: boolean | undefined;
8
+ pk?: string | undefined;
9
9
  } | {
10
- secret: string;
11
- languages: any;
12
- paths: any;
13
- routes: never[];
14
- type: string;
15
- pk: string;
16
- version: string;
17
- };
10
+ type: "route";
11
+ routes: string[];
12
+ languages: string[];
13
+ version?: string | undefined;
14
+ enable?: boolean | undefined;
15
+ pk?: string | undefined;
16
+ } | {
17
+ type: undefined;
18
+ languages?: string[] | undefined;
19
+ version?: string | undefined;
20
+ enable?: boolean | undefined;
21
+ pk?: string | undefined;
22
+ }>;
18
23
  /**
19
24
  * Parse route to find argument, then check in url search part to find the value
20
25
  * Example {{slug}} will match slug=abc or slugs=["abc"] (if index = 0)
package/index.js CHANGED
@@ -3,9 +3,27 @@ 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 zod = require("zod");
6
7
  const router = require("./router-DTZYUtal.js");
7
8
  const logger = require("@okam/logger");
8
9
  const coreLib = require("@okam/core-lib");
10
+ function _interopNamespaceDefault(e) {
11
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
12
+ if (e) {
13
+ for (const k in e) {
14
+ if (k !== "default") {
15
+ const d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: () => e[k]
19
+ });
20
+ }
21
+ }
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+ const zod__namespace = /* @__PURE__ */ _interopNamespaceDefault(zod);
9
27
  function getJsonErrorResponse(data, status) {
10
28
  const headers2 = {
11
29
  // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -20,58 +38,60 @@ function getJsonErrorResponse(data, status) {
20
38
  function getDraftSecretDefault() {
21
39
  return process.env.NEXT_API_DRAFT_SECRET || "";
22
40
  }
23
- function parseDraftParams(url) {
24
- const { searchParams } = new URL(url);
25
- const secret = searchParams.get("secret") || "";
26
- const languagesParam = searchParams.get("languages");
27
- const pathsParam = searchParams.get("urls");
28
- const routesParam = searchParams.get("routes");
29
- const pkParam = searchParams.get("pk");
30
- const versionParam = searchParams.get("version");
31
- const emptyReturn = {
32
- secret: "",
33
- languages: [],
34
- paths: [],
35
- routes: [],
36
- type: "",
37
- pk: "",
38
- version: ""
39
- };
40
- if (!secret || !languagesParam || !(pathsParam || routesParam)) {
41
- return emptyReturn;
42
- }
43
- const pk = typeof pkParam === "string" ? pkParam : "";
44
- const version = typeof versionParam === "string" ? versionParam : "";
41
+ const jsonStringsArraySchema = (message, code) => zod__namespace.string().transform((val, ctx) => {
45
42
  try {
46
- const languages = JSON.parse(languagesParam);
47
- if (routesParam) {
48
- const routes = JSON.parse(routesParam);
49
- return {
50
- secret,
51
- languages,
52
- paths: [],
53
- routes,
54
- type: "route",
55
- pk,
56
- version
57
- };
58
- }
59
- if (!pathsParam) {
60
- return emptyReturn;
61
- }
62
- const paths = JSON.parse(pathsParam);
63
- return {
64
- secret,
65
- languages,
66
- paths,
67
- routes: [],
68
- type: "path",
69
- pk,
70
- version
71
- };
72
- } catch (e) {
73
- return emptyReturn;
43
+ const decodedVal = decodeURIComponent(decodeURIComponent(val));
44
+ return JSON.parse(decodedVal);
45
+ } catch (error) {
46
+ ctx.addIssue({
47
+ code: zod__namespace.ZodIssueCode.custom,
48
+ message: "Invalid JSON string",
49
+ params: { code }
50
+ });
51
+ return zod__namespace.NEVER;
52
+ }
53
+ }).pipe(zod__namespace.array(zod__namespace.string(), { error: () => ({ message }) }));
54
+ const languagesSchema = jsonStringsArraySchema("Invalid languages argument", 400);
55
+ const commonSchema = zod__namespace.object({
56
+ version: zod__namespace.string().optional(),
57
+ enable: zod__namespace.enum(["true", "false"]).transform((val) => val === "true").optional(),
58
+ pk: zod__namespace.string().optional()
59
+ });
60
+ const createSecretSchema = (expectedSecret) => zod__namespace.string({ error: () => ({ message: "Invalid secret argument" }) }).refine((val) => val === expectedSecret, {
61
+ message: "Invalid secret argument",
62
+ params: { code: 401 }
63
+ });
64
+ const draftParamsSchema = zod__namespace.discriminatedUnion(
65
+ "type",
66
+ [
67
+ // When type is 'path', urls is required
68
+ zod__namespace.object({
69
+ type: zod__namespace.literal("path"),
70
+ urls: jsonStringsArraySchema("Invalid urls argument", 400),
71
+ languages: languagesSchema
72
+ }).extend(commonSchema.shape),
73
+ // When type is 'route', routes is required
74
+ zod__namespace.object({
75
+ type: zod__namespace.literal("route"),
76
+ routes: jsonStringsArraySchema("Invalid routes argument", 400),
77
+ languages: languagesSchema
78
+ }).extend(commonSchema.shape),
79
+ zod__namespace.object({
80
+ type: zod__namespace.undefined(),
81
+ languages: languagesSchema.optional()
82
+ }).extend(commonSchema.shape)
83
+ ],
84
+ { error: () => ({ message: `Invalid type/urls/routes arguments combination` }) }
85
+ );
86
+ function parseDraftParams(url, expectedSecret) {
87
+ const { searchParams } = new URL(url);
88
+ const searchParamsObject = Object.fromEntries(searchParams.entries());
89
+ const secretResult = createSecretSchema(expectedSecret).safeParse(searchParamsObject.secret);
90
+ if (!secretResult.success) {
91
+ return secretResult;
74
92
  }
93
+ const result = draftParamsSchema.safeParse(searchParamsObject);
94
+ return result;
75
95
  }
76
96
  function getPathFromRoute(routeUrl, url, index = 0) {
77
97
  const { searchParams } = new URL(url);
@@ -104,52 +124,57 @@ async function handleDraftRoute({
104
124
  getDraftSecret,
105
125
  getJsonError
106
126
  }) {
127
+ var _a, _b, _c;
107
128
  const getSecretFunction = getDraftSecret || getDraftSecretDefault;
108
129
  const getJsonErrorResponseFunction = getJsonError || getJsonErrorResponse;
109
- const { secret, languages, paths, routes, type, version } = parseDraftParams(url);
110
- if (secret !== getSecretFunction()) {
111
- return getJsonErrorResponseFunction({ error: "Invalid argument" }, 401);
112
- }
113
- if (type === "") {
114
- return getJsonErrorResponseFunction({ error: "Invalid argument" }, 400);
130
+ const { success, error, data } = parseDraftParams(url, getSecretFunction());
131
+ if (!success) {
132
+ return getJsonErrorResponseFunction(
133
+ { error: error.issues },
134
+ ((_a = error.issues[0]) == null ? void 0 : _a.code) === "custom" ? (_c = (_b = error.issues[0]) == null ? void 0 : _b.params) == null ? void 0 : _c.code : 400
135
+ );
115
136
  }
116
- if (!Array.isArray(languages) || languages.length <= 0) {
117
- return getJsonErrorResponseFunction({ error: "Invalid languages argument" }, 400);
137
+ const { type, languages, version, enable } = data;
138
+ let redirectUrl;
139
+ if (type) {
140
+ const directusLang = getDirectusLanguage();
141
+ const indexDefault = languages.indexOf(directusLang);
142
+ const index = indexDefault !== -1 ? indexDefault : 0;
143
+ if (type === "path") {
144
+ const { urls } = data;
145
+ const path = urls[index] || "";
146
+ if (!path) {
147
+ return getJsonErrorResponseFunction({ error: "Invalid path" }, 400);
148
+ }
149
+ redirectUrl = path;
150
+ } else if (type === "route") {
151
+ const { routes } = data;
152
+ const route = (routes == null ? void 0 : routes[index]) || "";
153
+ if (!route) {
154
+ return getJsonErrorResponseFunction({ error: "Invalid route" }, 400);
155
+ }
156
+ const pathFromRoute = getPathFromRoute(route, url, index);
157
+ if (!pathFromRoute) {
158
+ return getJsonErrorResponseFunction({ error: "Invalid route" }, 400);
159
+ }
160
+ redirectUrl = pathFromRoute;
161
+ }
118
162
  }
119
- if (type === "path" && (!Array.isArray(paths) || paths.length <= 0)) {
120
- return getJsonErrorResponseFunction({ error: "Invalid paths argument" }, 400);
163
+ const draft = await headers.draftMode();
164
+ if (enable === true) {
165
+ draft.enable();
121
166
  }
122
- if (type === "route" && (!Array.isArray(routes) || routes.length <= 0)) {
123
- return getJsonErrorResponseFunction({ error: "Invalid routes argument" }, 400);
167
+ if (enable === false) {
168
+ draft.disable();
124
169
  }
125
- const directusLang = getDirectusLanguage();
126
- const indexDefault = languages.indexOf(directusLang);
127
- const index = indexDefault !== -1 ? indexDefault : 0;
128
- let redirectUrl = "";
129
- if (type === "path") {
130
- const path = paths[index] || "";
131
- if (!path) {
132
- return getJsonErrorResponse({ error: "Invalid path" }, 400);
170
+ if (redirectUrl) {
171
+ if (version) {
172
+ const withParams = redirectUrl.indexOf("?") !== -1;
173
+ redirectUrl = `${redirectUrl}${withParams ? "&" : "?"}version=${encodeURIComponent(version)}`;
133
174
  }
134
- redirectUrl = path;
135
- } else if (type === "route") {
136
- const route = routes[index] || "";
137
- if (!route) {
138
- return getJsonErrorResponse({ error: "Invalid route" }, 400);
139
- }
140
- const pathFromRoute = getPathFromRoute(route, url, index);
141
- if (!pathFromRoute) {
142
- return getJsonErrorResponse({ error: "Invalid route" }, 400);
143
- }
144
- redirectUrl = pathFromRoute;
145
- }
146
- if (redirectUrl && version) {
147
- const withParams = redirectUrl.indexOf("?") !== -1;
148
- redirectUrl = `${redirectUrl}${withParams ? "&" : "?"}version=${encodeURIComponent(version)}`;
175
+ navigation.redirect(redirectUrl);
149
176
  }
150
- (await headers.draftMode()).enable();
151
- navigation.redirect(redirectUrl);
152
- return void 0;
177
+ return new Response(JSON.stringify({ isEnabled: draft.isEnabled }), { status: 200 });
153
178
  }
154
179
  function isRedirect(redirect) {
155
180
  return !!redirect && typeof redirect === "object" && "source" in redirect && "destination" in redirect;
package/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { draftMode } from "next/headers";
2
2
  import { redirect } from "next/navigation";
3
3
  import { template } from "radashi";
4
+ import * as zod from "zod";
4
5
  import { g as getRedirectSecretDefault } from "./router-CA4ItnAc.mjs";
5
6
  import { l, d, b, a, h } from "./router-CA4ItnAc.mjs";
6
7
  import { logger } from "@okam/logger";
@@ -19,58 +20,60 @@ function getJsonErrorResponse(data, status) {
19
20
  function getDraftSecretDefault() {
20
21
  return process.env.NEXT_API_DRAFT_SECRET || "";
21
22
  }
22
- function parseDraftParams(url) {
23
- const { searchParams } = new URL(url);
24
- const secret = searchParams.get("secret") || "";
25
- const languagesParam = searchParams.get("languages");
26
- const pathsParam = searchParams.get("urls");
27
- const routesParam = searchParams.get("routes");
28
- const pkParam = searchParams.get("pk");
29
- const versionParam = searchParams.get("version");
30
- const emptyReturn = {
31
- secret: "",
32
- languages: [],
33
- paths: [],
34
- routes: [],
35
- type: "",
36
- pk: "",
37
- version: ""
38
- };
39
- if (!secret || !languagesParam || !(pathsParam || routesParam)) {
40
- return emptyReturn;
41
- }
42
- const pk = typeof pkParam === "string" ? pkParam : "";
43
- const version = typeof versionParam === "string" ? versionParam : "";
23
+ const jsonStringsArraySchema = (message, code) => zod.string().transform((val, ctx) => {
44
24
  try {
45
- const languages = JSON.parse(languagesParam);
46
- if (routesParam) {
47
- const routes = JSON.parse(routesParam);
48
- return {
49
- secret,
50
- languages,
51
- paths: [],
52
- routes,
53
- type: "route",
54
- pk,
55
- version
56
- };
57
- }
58
- if (!pathsParam) {
59
- return emptyReturn;
60
- }
61
- const paths = JSON.parse(pathsParam);
62
- return {
63
- secret,
64
- languages,
65
- paths,
66
- routes: [],
67
- type: "path",
68
- pk,
69
- version
70
- };
71
- } catch (e) {
72
- return emptyReturn;
25
+ const decodedVal = decodeURIComponent(decodeURIComponent(val));
26
+ return JSON.parse(decodedVal);
27
+ } catch (error) {
28
+ ctx.addIssue({
29
+ code: zod.ZodIssueCode.custom,
30
+ message: "Invalid JSON string",
31
+ params: { code }
32
+ });
33
+ return zod.NEVER;
73
34
  }
35
+ }).pipe(zod.array(zod.string(), { error: () => ({ message }) }));
36
+ const languagesSchema = jsonStringsArraySchema("Invalid languages argument", 400);
37
+ const commonSchema = zod.object({
38
+ version: zod.string().optional(),
39
+ enable: zod.enum(["true", "false"]).transform((val) => val === "true").optional(),
40
+ pk: zod.string().optional()
41
+ });
42
+ const createSecretSchema = (expectedSecret) => zod.string({ error: () => ({ message: "Invalid secret argument" }) }).refine((val) => val === expectedSecret, {
43
+ message: "Invalid secret argument",
44
+ params: { code: 401 }
45
+ });
46
+ const draftParamsSchema = zod.discriminatedUnion(
47
+ "type",
48
+ [
49
+ // When type is 'path', urls is required
50
+ zod.object({
51
+ type: zod.literal("path"),
52
+ urls: jsonStringsArraySchema("Invalid urls argument", 400),
53
+ languages: languagesSchema
54
+ }).extend(commonSchema.shape),
55
+ // When type is 'route', routes is required
56
+ zod.object({
57
+ type: zod.literal("route"),
58
+ routes: jsonStringsArraySchema("Invalid routes argument", 400),
59
+ languages: languagesSchema
60
+ }).extend(commonSchema.shape),
61
+ zod.object({
62
+ type: zod.undefined(),
63
+ languages: languagesSchema.optional()
64
+ }).extend(commonSchema.shape)
65
+ ],
66
+ { error: () => ({ message: `Invalid type/urls/routes arguments combination` }) }
67
+ );
68
+ function parseDraftParams(url, expectedSecret) {
69
+ const { searchParams } = new URL(url);
70
+ const searchParamsObject = Object.fromEntries(searchParams.entries());
71
+ const secretResult = createSecretSchema(expectedSecret).safeParse(searchParamsObject.secret);
72
+ if (!secretResult.success) {
73
+ return secretResult;
74
+ }
75
+ const result = draftParamsSchema.safeParse(searchParamsObject);
76
+ return result;
74
77
  }
75
78
  function getPathFromRoute(routeUrl, url, index = 0) {
76
79
  const { searchParams } = new URL(url);
@@ -103,52 +106,57 @@ async function handleDraftRoute({
103
106
  getDraftSecret,
104
107
  getJsonError
105
108
  }) {
109
+ var _a, _b, _c;
106
110
  const getSecretFunction = getDraftSecret || getDraftSecretDefault;
107
111
  const getJsonErrorResponseFunction = getJsonError || getJsonErrorResponse;
108
- const { secret, languages, paths, routes, type, version } = parseDraftParams(url);
109
- if (secret !== getSecretFunction()) {
110
- return getJsonErrorResponseFunction({ error: "Invalid argument" }, 401);
111
- }
112
- if (type === "") {
113
- return getJsonErrorResponseFunction({ error: "Invalid argument" }, 400);
112
+ const { success, error, data } = parseDraftParams(url, getSecretFunction());
113
+ if (!success) {
114
+ return getJsonErrorResponseFunction(
115
+ { error: error.issues },
116
+ ((_a = error.issues[0]) == null ? void 0 : _a.code) === "custom" ? (_c = (_b = error.issues[0]) == null ? void 0 : _b.params) == null ? void 0 : _c.code : 400
117
+ );
114
118
  }
115
- if (!Array.isArray(languages) || languages.length <= 0) {
116
- return getJsonErrorResponseFunction({ error: "Invalid languages argument" }, 400);
119
+ const { type, languages, version, enable } = data;
120
+ let redirectUrl;
121
+ if (type) {
122
+ const directusLang = getDirectusLanguage();
123
+ const indexDefault = languages.indexOf(directusLang);
124
+ const index = indexDefault !== -1 ? indexDefault : 0;
125
+ if (type === "path") {
126
+ const { urls } = data;
127
+ const path = urls[index] || "";
128
+ if (!path) {
129
+ return getJsonErrorResponseFunction({ error: "Invalid path" }, 400);
130
+ }
131
+ redirectUrl = path;
132
+ } else if (type === "route") {
133
+ const { routes } = data;
134
+ const route = (routes == null ? void 0 : routes[index]) || "";
135
+ if (!route) {
136
+ return getJsonErrorResponseFunction({ error: "Invalid route" }, 400);
137
+ }
138
+ const pathFromRoute = getPathFromRoute(route, url, index);
139
+ if (!pathFromRoute) {
140
+ return getJsonErrorResponseFunction({ error: "Invalid route" }, 400);
141
+ }
142
+ redirectUrl = pathFromRoute;
143
+ }
117
144
  }
118
- if (type === "path" && (!Array.isArray(paths) || paths.length <= 0)) {
119
- return getJsonErrorResponseFunction({ error: "Invalid paths argument" }, 400);
145
+ const draft = await draftMode();
146
+ if (enable === true) {
147
+ draft.enable();
120
148
  }
121
- if (type === "route" && (!Array.isArray(routes) || routes.length <= 0)) {
122
- return getJsonErrorResponseFunction({ error: "Invalid routes argument" }, 400);
149
+ if (enable === false) {
150
+ draft.disable();
123
151
  }
124
- const directusLang = getDirectusLanguage();
125
- const indexDefault = languages.indexOf(directusLang);
126
- const index = indexDefault !== -1 ? indexDefault : 0;
127
- let redirectUrl = "";
128
- if (type === "path") {
129
- const path = paths[index] || "";
130
- if (!path) {
131
- return getJsonErrorResponse({ error: "Invalid path" }, 400);
132
- }
133
- redirectUrl = path;
134
- } else if (type === "route") {
135
- const route = routes[index] || "";
136
- if (!route) {
137
- return getJsonErrorResponse({ error: "Invalid route" }, 400);
152
+ if (redirectUrl) {
153
+ if (version) {
154
+ const withParams = redirectUrl.indexOf("?") !== -1;
155
+ redirectUrl = `${redirectUrl}${withParams ? "&" : "?"}version=${encodeURIComponent(version)}`;
138
156
  }
139
- const pathFromRoute = getPathFromRoute(route, url, index);
140
- if (!pathFromRoute) {
141
- return getJsonErrorResponse({ error: "Invalid route" }, 400);
142
- }
143
- redirectUrl = pathFromRoute;
144
- }
145
- if (redirectUrl && version) {
146
- const withParams = redirectUrl.indexOf("?") !== -1;
147
- redirectUrl = `${redirectUrl}${withParams ? "&" : "?"}version=${encodeURIComponent(version)}`;
157
+ redirect(redirectUrl);
148
158
  }
149
- (await draftMode()).enable();
150
- redirect(redirectUrl);
151
- return void 0;
159
+ return new Response(JSON.stringify({ isEnabled: draft.isEnabled }), { status: 200 });
152
160
  }
153
161
  function isRedirect(redirect2) {
154
162
  return !!redirect2 && typeof redirect2 === "object" && "source" in redirect2 && "destination" in redirect2;
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.11",
4
+ "version": "1.2.12",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
7
7
  ".": {
@@ -36,12 +36,12 @@
36
36
  "@okam/directus-node": "0.6.2",
37
37
  "@okam/stack-ui": "1.44.0",
38
38
  "@okam/logger": "1.1.0",
39
- "@okam/next-component": "1.2.4",
39
+ "@okam/next-component": "1.3.0",
40
40
  "next": "^15.0.0",
41
41
  "radashi": "^12.3.0",
42
42
  "@okam/directus-query": "1.4.2",
43
- "server-only": "0.0.1",
44
- "graphql-request": "7.1.2",
45
- "@graphql-typed-document-node/core": "3.2.0"
43
+ "graphql-request": "^7.1.2",
44
+ "@graphql-typed-document-node/core": "3.2.0",
45
+ "zod": "^4.3.5"
46
46
  }
47
47
  }