@okam/directus-next 1.2.1 → 1.2.2
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 +14 -0
- package/{directus-next/src/lib/directusRouteRouter.mjs → directusRouteRouter-Bt3bEq4S.mjs} +93 -3
- package/directusRouteRouter-CfK0xrh0.js +191 -0
- package/index.js +291 -0
- package/index.mjs +292 -0
- package/package.json +2 -2
- package/{directus-next/src/pageSettings/usePageSettings.js → server.js} +22 -9
- package/{directus-next/src/pageSettings/usePageSettings.mjs → server.mjs} +16 -2
- package/directus-next/src/draft/env.js +0 -6
- package/directus-next/src/draft/env.mjs +0 -6
- package/directus-next/src/draft/route.js +0 -141
- package/directus-next/src/draft/route.mjs +0 -141
- package/directus-next/src/index.js +0 -24
- package/directus-next/src/index.mjs +0 -24
- package/directus-next/src/lib/directusRouteRouter.js +0 -102
- package/directus-next/src/logger.js +0 -11
- package/directus-next/src/logger.mjs +0 -11
- package/directus-next/src/pageSettings/context.js +0 -14
- package/directus-next/src/pageSettings/context.mjs +0 -14
- package/directus-next/src/redirect/env.js +0 -20
- package/directus-next/src/redirect/env.mjs +0 -20
- package/directus-next/src/redirect/route.js +0 -31
- package/directus-next/src/redirect/route.mjs +0 -31
- package/directus-next/src/redirect/utils/getRedirectsRoute.js +0 -27
- package/directus-next/src/redirect/utils/getRedirectsRoute.mjs +0 -27
- package/directus-next/src/redirect/utils/handleRedirect.js +0 -48
- package/directus-next/src/redirect/utils/handleRedirect.mjs +0 -48
- package/directus-next/src/response.js +0 -14
- package/directus-next/src/response.mjs +0 -14
- package/directus-next/src/server.js +0 -9
- package/directus-next/src/server.mjs +0 -9
- package/directus-node/src/lib/redirection/fetchRedirectsData.js +0 -92
- package/directus-node/src/lib/redirection/fetchRedirectsData.mjs +0 -92
- package/directus-node/src/lib/redirection/utils/validateRedirects.js +0 -22
- package/directus-node/src/lib/redirection/utils/validateRedirects.mjs +0 -22
|
@@ -1,92 +0,0 @@
|
|
|
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;
|
|
@@ -1,92 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
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;
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
};
|