@okam/directus-next 1.2.0 → 1.2.1

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/{redirect → directus-next/src/redirect}/route.js +3 -2
  3. package/{redirect → directus-next/src/redirect}/route.mjs +2 -1
  4. package/directus-node/src/lib/redirection/fetchRedirectsData.js +92 -0
  5. package/directus-node/src/lib/redirection/fetchRedirectsData.mjs +92 -0
  6. package/directus-node/src/lib/redirection/utils/validateRedirects.js +22 -0
  7. package/directus-node/src/lib/redirection/utils/validateRedirects.mjs +22 -0
  8. package/package.json +2 -2
  9. package/redirect/utils/getRedirectsRoute.d.ts +1 -1
  10. /package/{draft → directus-next/src/draft}/env.js +0 -0
  11. /package/{draft → directus-next/src/draft}/env.mjs +0 -0
  12. /package/{draft → directus-next/src/draft}/route.js +0 -0
  13. /package/{draft → directus-next/src/draft}/route.mjs +0 -0
  14. /package/{index.js → directus-next/src/index.js} +0 -0
  15. /package/{index.mjs → directus-next/src/index.mjs} +0 -0
  16. /package/{lib → directus-next/src/lib}/directusRouteRouter.js +0 -0
  17. /package/{lib → directus-next/src/lib}/directusRouteRouter.mjs +0 -0
  18. /package/{logger.js → directus-next/src/logger.js} +0 -0
  19. /package/{logger.mjs → directus-next/src/logger.mjs} +0 -0
  20. /package/{pageSettings → directus-next/src/pageSettings}/context.js +0 -0
  21. /package/{pageSettings → directus-next/src/pageSettings}/context.mjs +0 -0
  22. /package/{pageSettings → directus-next/src/pageSettings}/usePageSettings.js +0 -0
  23. /package/{pageSettings → directus-next/src/pageSettings}/usePageSettings.mjs +0 -0
  24. /package/{redirect → directus-next/src/redirect}/env.js +0 -0
  25. /package/{redirect → directus-next/src/redirect}/env.mjs +0 -0
  26. /package/{redirect → directus-next/src/redirect}/utils/getRedirectsRoute.js +0 -0
  27. /package/{redirect → directus-next/src/redirect}/utils/getRedirectsRoute.mjs +0 -0
  28. /package/{redirect → directus-next/src/redirect}/utils/handleRedirect.js +0 -0
  29. /package/{redirect → directus-next/src/redirect}/utils/handleRedirect.mjs +0 -0
  30. /package/{response.js → directus-next/src/response.js} +0 -0
  31. /package/{response.mjs → directus-next/src/response.mjs} +0 -0
  32. /package/{server.js → directus-next/src/server.js} +0 -0
  33. /package/{server.mjs → directus-next/src/server.mjs} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 1.2.1 (2025-07-22)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - **directus-next:** import from direrctus-node/edge instead ([99d3bce](https://github.com/OKAMca/stack/commit/99d3bce))
6
+
7
+ ### 🧱 Updated Dependencies
8
+
9
+ - Updated directus-node to 0.6.0
10
+
11
+ ### ❤️ Thank You
12
+
13
+ - poclerson
14
+
1
15
  ## 1.2.0 (2025-07-22)
2
16
 
3
17
  ### 🚀 Features
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const directusNode = require("@okam/directus-node");
3
+ const fetchRedirectsData = require("../../../directus-node/src/lib/redirection/fetchRedirectsData.js");
4
+ require("@okam/core-lib");
4
5
  const response = require("../response.js");
5
6
  const env = require("./env.js");
6
7
  function parseRedirectParams(url) {
@@ -23,7 +24,7 @@ async function handleRedirectsRoute({
23
24
  }
24
25
  const graphqlEndpoint = getDirectusGraphqlUrl == null ? void 0 : getDirectusGraphqlUrl();
25
26
  const graphqlApiKey = getDirectusApiToken == null ? void 0 : getDirectusApiToken();
26
- const { redirects, rewrites } = await directusNode.fetchRedirectsData({ graphqlEndpoint, graphqlApiKey, limit }, init);
27
+ const { redirects, rewrites } = await fetchRedirectsData.fetchRedirectsData({ graphqlEndpoint, graphqlApiKey, limit }, init);
27
28
  return new Response(JSON.stringify({ redirects, rewrites }), { status: 200 });
28
29
  }
29
30
  exports.default = handleRedirectsRoute;
@@ -1,4 +1,5 @@
1
- import { fetchRedirectsData } from "@okam/directus-node";
1
+ import { fetchRedirectsData } from "../../../directus-node/src/lib/redirection/fetchRedirectsData.mjs";
2
+ import "@okam/core-lib";
2
3
  import { getJsonErrorResponse } from "../response.mjs";
3
4
  import { getRedirectSecretDefault } from "./env.mjs";
4
5
  function parseRedirectParams(url) {
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const logger = require("@okam/logger");
4
+ const validateRedirects = require("./utils/validateRedirects.js");
5
+ const redirectDefaultLimit = 2e3;
6
+ function getDefaultConfig() {
7
+ return {
8
+ graphqlEndpoint: process.env["NEXT_REDIRECT_GRAPHQL_URL"] || process.env["NEXT_PUBLIC_GRAPHQL_URL"] || "",
9
+ graphqlApiKey: process.env["NEXT_API_TOKEN_ADMIN"] || "",
10
+ redirectsFilename: "./redirect/redirects.json",
11
+ rewritesFilename: "./redirect/rewrites.json",
12
+ limit: redirectDefaultLimit
13
+ };
14
+ }
15
+ async function fetchRedirectsData(config, init) {
16
+ const {
17
+ graphqlApiKey: defaultGraphqlApiKey,
18
+ graphqlEndpoint: defaultGraphqlEndpoint,
19
+ limit: defaultLimit
20
+ } = getDefaultConfig();
21
+ const {
22
+ graphqlEndpoint = defaultGraphqlEndpoint,
23
+ graphqlApiKey = defaultGraphqlApiKey,
24
+ limit = defaultLimit
25
+ } = config;
26
+ if (!graphqlEndpoint) {
27
+ throw new Error(
28
+ "Missing fetchRedirects configuration `graphqlEndpoint`. Check environment variables NEXT_REDIRECT_GRAPHQL_URL or NEXT_PUBLIC_GRAPHQL_URL"
29
+ );
30
+ }
31
+ if (!graphqlApiKey) {
32
+ throw new Error(
33
+ "Missing fetchRedirects configuration `graphqlApiKey`. Check environment variable NEXT_API_TOKEN_ADMIN"
34
+ );
35
+ }
36
+ const query = `query fetchRedirects($limit: Int = 2000) {
37
+ redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:false}}, sort: "sort", limit: $limit) {
38
+ source
39
+ destination
40
+ permanent
41
+ locale
42
+ }
43
+ rewrites: redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:true}}, sort: "sort", limit: $limit) {
44
+ source
45
+ destination
46
+ permanent
47
+ locale
48
+ }
49
+ }`;
50
+ const graphqlBody = {
51
+ query,
52
+ // "operationName": "",
53
+ variables: {
54
+ limit: Number(limit) || redirectDefaultLimit
55
+ }
56
+ };
57
+ try {
58
+ const response = await fetch(graphqlEndpoint, {
59
+ ...init,
60
+ method: "POST",
61
+ headers: {
62
+ // eslint-disable-next-line @typescript-eslint/naming-convention
63
+ "Content-Type": "application/json",
64
+ Authorization: `Bearer ${graphqlApiKey}`
65
+ },
66
+ body: JSON.stringify(graphqlBody)
67
+ });
68
+ const { data } = await response.json();
69
+ const { redirects, rewrites } = data ?? {};
70
+ if (!(redirects == null ? void 0 : redirects.length) && !(rewrites == null ? void 0 : rewrites.length)) {
71
+ logger.logger.log("No redirects/rewrites found", "warn");
72
+ return {
73
+ redirects: [],
74
+ rewrites: []
75
+ };
76
+ }
77
+ logger.logger.log(`Fetch redirects count: ${(redirects == null ? void 0 : redirects.length) || 0}, rewrites count: ${(rewrites == null ? void 0 : rewrites.length) || 0}`);
78
+ return {
79
+ redirects: validateRedirects.normalizeRedirects(redirects),
80
+ rewrites: validateRedirects.normalizeRedirects(rewrites)
81
+ };
82
+ } catch (e) {
83
+ logger.logger.log(`Error fetching redirects: ${e.message}`, "error");
84
+ }
85
+ return {
86
+ redirects: [],
87
+ rewrites: []
88
+ };
89
+ }
90
+ exports.fetchRedirectsData = fetchRedirectsData;
91
+ exports.getDefaultConfig = getDefaultConfig;
92
+ exports.redirectDefaultLimit = redirectDefaultLimit;
@@ -0,0 +1,92 @@
1
+ import { logger } from "@okam/logger";
2
+ import { normalizeRedirects } from "./utils/validateRedirects.mjs";
3
+ const redirectDefaultLimit = 2e3;
4
+ function getDefaultConfig() {
5
+ return {
6
+ graphqlEndpoint: process.env["NEXT_REDIRECT_GRAPHQL_URL"] || process.env["NEXT_PUBLIC_GRAPHQL_URL"] || "",
7
+ graphqlApiKey: process.env["NEXT_API_TOKEN_ADMIN"] || "",
8
+ redirectsFilename: "./redirect/redirects.json",
9
+ rewritesFilename: "./redirect/rewrites.json",
10
+ limit: redirectDefaultLimit
11
+ };
12
+ }
13
+ async function fetchRedirectsData(config, init) {
14
+ const {
15
+ graphqlApiKey: defaultGraphqlApiKey,
16
+ graphqlEndpoint: defaultGraphqlEndpoint,
17
+ limit: defaultLimit
18
+ } = getDefaultConfig();
19
+ const {
20
+ graphqlEndpoint = defaultGraphqlEndpoint,
21
+ graphqlApiKey = defaultGraphqlApiKey,
22
+ limit = defaultLimit
23
+ } = config;
24
+ if (!graphqlEndpoint) {
25
+ throw new Error(
26
+ "Missing fetchRedirects configuration `graphqlEndpoint`. Check environment variables NEXT_REDIRECT_GRAPHQL_URL or NEXT_PUBLIC_GRAPHQL_URL"
27
+ );
28
+ }
29
+ if (!graphqlApiKey) {
30
+ throw new Error(
31
+ "Missing fetchRedirects configuration `graphqlApiKey`. Check environment variable NEXT_API_TOKEN_ADMIN"
32
+ );
33
+ }
34
+ const query = `query fetchRedirects($limit: Int = 2000) {
35
+ redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:false}}, sort: "sort", limit: $limit) {
36
+ source
37
+ destination
38
+ permanent
39
+ locale
40
+ }
41
+ rewrites: redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:true}}, sort: "sort", limit: $limit) {
42
+ source
43
+ destination
44
+ permanent
45
+ locale
46
+ }
47
+ }`;
48
+ const graphqlBody = {
49
+ query,
50
+ // "operationName": "",
51
+ variables: {
52
+ limit: Number(limit) || redirectDefaultLimit
53
+ }
54
+ };
55
+ try {
56
+ const response = await fetch(graphqlEndpoint, {
57
+ ...init,
58
+ method: "POST",
59
+ headers: {
60
+ // eslint-disable-next-line @typescript-eslint/naming-convention
61
+ "Content-Type": "application/json",
62
+ Authorization: `Bearer ${graphqlApiKey}`
63
+ },
64
+ body: JSON.stringify(graphqlBody)
65
+ });
66
+ const { data } = await response.json();
67
+ const { redirects, rewrites } = data ?? {};
68
+ if (!(redirects == null ? void 0 : redirects.length) && !(rewrites == null ? void 0 : rewrites.length)) {
69
+ logger.log("No redirects/rewrites found", "warn");
70
+ return {
71
+ redirects: [],
72
+ rewrites: []
73
+ };
74
+ }
75
+ logger.log(`Fetch redirects count: ${(redirects == null ? void 0 : redirects.length) || 0}, rewrites count: ${(rewrites == null ? void 0 : rewrites.length) || 0}`);
76
+ return {
77
+ redirects: normalizeRedirects(redirects),
78
+ rewrites: normalizeRedirects(rewrites)
79
+ };
80
+ } catch (e) {
81
+ logger.log(`Error fetching redirects: ${e.message}`, "error");
82
+ }
83
+ return {
84
+ redirects: [],
85
+ rewrites: []
86
+ };
87
+ }
88
+ export {
89
+ fetchRedirectsData,
90
+ getDefaultConfig,
91
+ redirectDefaultLimit
92
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const coreLib = require("@okam/core-lib");
4
+ function isRedirect(redirect) {
5
+ return !!redirect && typeof redirect === "object" && "source" in redirect && "destination" in redirect;
6
+ }
7
+ function normalizeRedirects(redirects) {
8
+ if (!redirects || !Array.isArray(redirects)) return [];
9
+ return redirects.flatMap((redirect) => {
10
+ const { source, destination, ...rest } = redirect ?? {};
11
+ if (!redirect || !source || !destination || !isRedirect(redirect)) return [];
12
+ return [
13
+ {
14
+ ...rest,
15
+ source: coreLib.normalizePath(source),
16
+ destination: coreLib.normalizePath(destination)
17
+ }
18
+ ];
19
+ });
20
+ }
21
+ exports.isRedirect = isRedirect;
22
+ exports.normalizeRedirects = normalizeRedirects;
@@ -0,0 +1,22 @@
1
+ import { normalizePath } from "@okam/core-lib";
2
+ function isRedirect(redirect) {
3
+ return !!redirect && typeof redirect === "object" && "source" in redirect && "destination" in redirect;
4
+ }
5
+ function normalizeRedirects(redirects) {
6
+ if (!redirects || !Array.isArray(redirects)) return [];
7
+ return redirects.flatMap((redirect) => {
8
+ const { source, destination, ...rest } = redirect ?? {};
9
+ if (!redirect || !source || !destination || !isRedirect(redirect)) return [];
10
+ return [
11
+ {
12
+ ...rest,
13
+ source: normalizePath(source),
14
+ destination: normalizePath(destination)
15
+ }
16
+ ];
17
+ });
18
+ }
19
+ export {
20
+ isRedirect,
21
+ normalizeRedirects
22
+ };
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.0",
4
+ "version": "1.2.1",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
7
7
  ".": {
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@okam/core-lib": "1.16.0",
36
- "@okam/directus-node": "0.5.0",
36
+ "@okam/directus-node": "0.6.0",
37
37
  "@okam/logger": "1.1.0",
38
38
  "next": "^14.1.1",
39
39
  "radashi": "^12.3.0",
@@ -1,4 +1,4 @@
1
- import type { TFetchRedirectsResponse } from '@okam/directus-node';
1
+ import type { TFetchRedirectsResponse } from '@okam/directus-node/edge';
2
2
  import type { DirectusRouteRedirectsModule } from '../../types/directusRouteConfig';
3
3
  /**
4
4
  * Gets a response from `options.apiRoute`
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes