@okam/directus-node 0.6.0 → 0.6.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 +16 -0
- package/edge.js +7 -0
- package/edge.mjs +7 -0
- package/fetchRedirectsData-DGLawlch.mjs +111 -0
- package/fetchRedirectsData-nz-uddGa.js +110 -0
- package/index.js +106 -0
- package/index.mjs +90 -0
- package/package.json +26 -6
- package/src/edge.js +0 -13
- package/src/edge.js.map +0 -1
- package/src/index.js +0 -10
- package/src/index.js.map +0 -1
- package/src/lib/codegen.js +0 -24
- package/src/lib/codegen.js.map +0 -1
- package/src/lib/redirection/fetchRedirectsData.js +0 -85
- package/src/lib/redirection/fetchRedirectsData.js.map +0 -1
- package/src/lib/redirection/index.js +0 -22
- package/src/lib/redirection/index.js.map +0 -1
- package/src/lib/redirection/interface.js +0 -3
- package/src/lib/redirection/interface.js.map +0 -1
- package/src/lib/redirection/redirectsFile.js +0 -88
- package/src/lib/redirection/redirectsFile.js.map +0 -1
- package/src/lib/redirection/utils/validateRedirects.js +0 -22
- package/src/lib/redirection/utils/validateRedirects.js.map +0 -1
- package/src/logger.js +0 -6
- package/src/logger.js.map +0 -1
- /package/{src/edge.d.ts → edge.d.ts} +0 -0
- /package/{src/index.d.ts → index.d.ts} +0 -0
- /package/{src/lib → lib}/codegen.d.ts +0 -0
- /package/{src/lib → lib}/redirection/fetchRedirectsData.d.ts +0 -0
- /package/{src/lib → lib}/redirection/index.d.ts +0 -0
- /package/{src/lib → lib}/redirection/interface.d.ts +0 -0
- /package/{src/lib → lib}/redirection/redirectsFile.d.ts +0 -0
- /package/{src/lib → lib}/redirection/utils/validateRedirects.d.ts +0 -0
- /package/{src/logger.d.ts → logger.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## 0.6.2 (2025-07-24)
|
|
2
|
+
|
|
3
|
+
### 🧱 Updated Dependencies
|
|
4
|
+
|
|
5
|
+
- Updated core-lib to 1.17.0
|
|
6
|
+
|
|
7
|
+
## 0.6.1 (2025-07-23)
|
|
8
|
+
|
|
9
|
+
### 🩹 Fixes
|
|
10
|
+
|
|
11
|
+
- directus next directus node builds ([#317](https://github.com/OKAMca/stack/pull/317))
|
|
12
|
+
|
|
13
|
+
### ❤️ Thank You
|
|
14
|
+
|
|
15
|
+
- Pierre-Olivier Clerson @poclerson
|
|
16
|
+
|
|
1
17
|
## 0.6.0 (2025-07-22)
|
|
2
18
|
|
|
3
19
|
### 🚀 Features
|
package/edge.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const fetchRedirectsData = require("./fetchRedirectsData-nz-uddGa.js");
|
|
4
|
+
exports.fetchRedirectsData = fetchRedirectsData.fetchRedirectsData;
|
|
5
|
+
exports.getDefaultConfig = fetchRedirectsData.getDefaultConfig;
|
|
6
|
+
exports.isRedirect = fetchRedirectsData.isRedirect;
|
|
7
|
+
exports.normalizeRedirects = fetchRedirectsData.normalizeRedirects;
|
package/edge.mjs
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { logger } from "@okam/logger";
|
|
2
|
+
import { normalizePath } from "@okam/core-lib";
|
|
3
|
+
function isRedirect(redirect) {
|
|
4
|
+
return !!redirect && typeof redirect === "object" && "source" in redirect && "destination" in redirect;
|
|
5
|
+
}
|
|
6
|
+
function normalizeRedirects(redirects) {
|
|
7
|
+
if (!redirects || !Array.isArray(redirects)) return [];
|
|
8
|
+
return redirects.flatMap((redirect) => {
|
|
9
|
+
const { source, destination, ...rest } = redirect ?? {};
|
|
10
|
+
if (!redirect || !source || !destination || !isRedirect(redirect)) return [];
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
...rest,
|
|
14
|
+
source: normalizePath(source),
|
|
15
|
+
destination: normalizePath(destination)
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const redirectDefaultLimit = 2e3;
|
|
21
|
+
function getDefaultConfig() {
|
|
22
|
+
return {
|
|
23
|
+
graphqlEndpoint: process.env["NEXT_REDIRECT_GRAPHQL_URL"] || process.env["NEXT_PUBLIC_GRAPHQL_URL"] || "",
|
|
24
|
+
graphqlApiKey: process.env["NEXT_API_TOKEN_ADMIN"] || "",
|
|
25
|
+
redirectsFilename: "./redirect/redirects.json",
|
|
26
|
+
rewritesFilename: "./redirect/rewrites.json",
|
|
27
|
+
limit: redirectDefaultLimit
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async function fetchRedirectsData(config, init) {
|
|
31
|
+
const {
|
|
32
|
+
graphqlApiKey: defaultGraphqlApiKey,
|
|
33
|
+
graphqlEndpoint: defaultGraphqlEndpoint,
|
|
34
|
+
limit: defaultLimit
|
|
35
|
+
} = getDefaultConfig();
|
|
36
|
+
const {
|
|
37
|
+
graphqlEndpoint = defaultGraphqlEndpoint,
|
|
38
|
+
graphqlApiKey = defaultGraphqlApiKey,
|
|
39
|
+
limit = defaultLimit
|
|
40
|
+
} = config;
|
|
41
|
+
if (!graphqlEndpoint) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
"Missing fetchRedirects configuration `graphqlEndpoint`. Check environment variables NEXT_REDIRECT_GRAPHQL_URL or NEXT_PUBLIC_GRAPHQL_URL"
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (!graphqlApiKey) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
"Missing fetchRedirects configuration `graphqlApiKey`. Check environment variable NEXT_API_TOKEN_ADMIN"
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
const query = `query fetchRedirects($limit: Int = 2000) {
|
|
52
|
+
redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:false}}, sort: "sort", limit: $limit) {
|
|
53
|
+
source
|
|
54
|
+
destination
|
|
55
|
+
permanent
|
|
56
|
+
locale
|
|
57
|
+
}
|
|
58
|
+
rewrites: redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:true}}, sort: "sort", limit: $limit) {
|
|
59
|
+
source
|
|
60
|
+
destination
|
|
61
|
+
permanent
|
|
62
|
+
locale
|
|
63
|
+
}
|
|
64
|
+
}`;
|
|
65
|
+
const graphqlBody = {
|
|
66
|
+
query,
|
|
67
|
+
// "operationName": "",
|
|
68
|
+
variables: {
|
|
69
|
+
limit: Number(limit) || redirectDefaultLimit
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
try {
|
|
73
|
+
const response = await fetch(graphqlEndpoint, {
|
|
74
|
+
...init,
|
|
75
|
+
method: "POST",
|
|
76
|
+
headers: {
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
78
|
+
"Content-Type": "application/json",
|
|
79
|
+
Authorization: `Bearer ${graphqlApiKey}`
|
|
80
|
+
},
|
|
81
|
+
body: JSON.stringify(graphqlBody)
|
|
82
|
+
});
|
|
83
|
+
const { data } = await response.json();
|
|
84
|
+
const { redirects, rewrites } = data ?? {};
|
|
85
|
+
if (!(redirects == null ? void 0 : redirects.length) && !(rewrites == null ? void 0 : rewrites.length)) {
|
|
86
|
+
logger.log("No redirects/rewrites found", "warn");
|
|
87
|
+
return {
|
|
88
|
+
redirects: [],
|
|
89
|
+
rewrites: []
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
logger.log(`Fetch redirects count: ${(redirects == null ? void 0 : redirects.length) || 0}, rewrites count: ${(rewrites == null ? void 0 : rewrites.length) || 0}`);
|
|
93
|
+
return {
|
|
94
|
+
redirects: normalizeRedirects(redirects),
|
|
95
|
+
rewrites: normalizeRedirects(rewrites)
|
|
96
|
+
};
|
|
97
|
+
} catch (e) {
|
|
98
|
+
logger.log(`Error fetching redirects: ${e.message}`, "error");
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
redirects: [],
|
|
102
|
+
rewrites: []
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
fetchRedirectsData as f,
|
|
107
|
+
getDefaultConfig as g,
|
|
108
|
+
isRedirect as i,
|
|
109
|
+
normalizeRedirects as n,
|
|
110
|
+
redirectDefaultLimit as r
|
|
111
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const logger = require("@okam/logger");
|
|
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
|
+
const redirectDefaultLimit = 2e3;
|
|
22
|
+
function getDefaultConfig() {
|
|
23
|
+
return {
|
|
24
|
+
graphqlEndpoint: process.env["NEXT_REDIRECT_GRAPHQL_URL"] || process.env["NEXT_PUBLIC_GRAPHQL_URL"] || "",
|
|
25
|
+
graphqlApiKey: process.env["NEXT_API_TOKEN_ADMIN"] || "",
|
|
26
|
+
redirectsFilename: "./redirect/redirects.json",
|
|
27
|
+
rewritesFilename: "./redirect/rewrites.json",
|
|
28
|
+
limit: redirectDefaultLimit
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async function fetchRedirectsData(config, init) {
|
|
32
|
+
const {
|
|
33
|
+
graphqlApiKey: defaultGraphqlApiKey,
|
|
34
|
+
graphqlEndpoint: defaultGraphqlEndpoint,
|
|
35
|
+
limit: defaultLimit
|
|
36
|
+
} = getDefaultConfig();
|
|
37
|
+
const {
|
|
38
|
+
graphqlEndpoint = defaultGraphqlEndpoint,
|
|
39
|
+
graphqlApiKey = defaultGraphqlApiKey,
|
|
40
|
+
limit = defaultLimit
|
|
41
|
+
} = config;
|
|
42
|
+
if (!graphqlEndpoint) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"Missing fetchRedirects configuration `graphqlEndpoint`. Check environment variables NEXT_REDIRECT_GRAPHQL_URL or NEXT_PUBLIC_GRAPHQL_URL"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
if (!graphqlApiKey) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
"Missing fetchRedirects configuration `graphqlApiKey`. Check environment variable NEXT_API_TOKEN_ADMIN"
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const query = `query fetchRedirects($limit: Int = 2000) {
|
|
53
|
+
redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:false}}, sort: "sort", limit: $limit) {
|
|
54
|
+
source
|
|
55
|
+
destination
|
|
56
|
+
permanent
|
|
57
|
+
locale
|
|
58
|
+
}
|
|
59
|
+
rewrites: redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:true}}, sort: "sort", limit: $limit) {
|
|
60
|
+
source
|
|
61
|
+
destination
|
|
62
|
+
permanent
|
|
63
|
+
locale
|
|
64
|
+
}
|
|
65
|
+
}`;
|
|
66
|
+
const graphqlBody = {
|
|
67
|
+
query,
|
|
68
|
+
// "operationName": "",
|
|
69
|
+
variables: {
|
|
70
|
+
limit: Number(limit) || redirectDefaultLimit
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
const response = await fetch(graphqlEndpoint, {
|
|
75
|
+
...init,
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers: {
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
Authorization: `Bearer ${graphqlApiKey}`
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify(graphqlBody)
|
|
83
|
+
});
|
|
84
|
+
const { data } = await response.json();
|
|
85
|
+
const { redirects, rewrites } = data ?? {};
|
|
86
|
+
if (!(redirects == null ? void 0 : redirects.length) && !(rewrites == null ? void 0 : rewrites.length)) {
|
|
87
|
+
logger.logger.log("No redirects/rewrites found", "warn");
|
|
88
|
+
return {
|
|
89
|
+
redirects: [],
|
|
90
|
+
rewrites: []
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
logger.logger.log(`Fetch redirects count: ${(redirects == null ? void 0 : redirects.length) || 0}, rewrites count: ${(rewrites == null ? void 0 : rewrites.length) || 0}`);
|
|
94
|
+
return {
|
|
95
|
+
redirects: normalizeRedirects(redirects),
|
|
96
|
+
rewrites: normalizeRedirects(rewrites)
|
|
97
|
+
};
|
|
98
|
+
} catch (e) {
|
|
99
|
+
logger.logger.log(`Error fetching redirects: ${e.message}`, "error");
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
redirects: [],
|
|
103
|
+
rewrites: []
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
exports.fetchRedirectsData = fetchRedirectsData;
|
|
107
|
+
exports.getDefaultConfig = getDefaultConfig;
|
|
108
|
+
exports.isRedirect = isRedirect;
|
|
109
|
+
exports.normalizeRedirects = normalizeRedirects;
|
|
110
|
+
exports.redirectDefaultLimit = redirectDefaultLimit;
|
package/index.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const fetchRedirectsData$1 = require("./fetchRedirectsData-nz-uddGa.js");
|
|
4
|
+
require("@okam/core-lib");
|
|
5
|
+
const logger$1 = require("@okam/logger");
|
|
6
|
+
const promises = require("fs/promises");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
9
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
|
+
if (e) {
|
|
11
|
+
for (const k in e) {
|
|
12
|
+
if (k !== "default") {
|
|
13
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: () => e[k]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
25
|
+
const logger = logger$1.createLogger("[DirectusNode]");
|
|
26
|
+
async function writeRedirectFile(filename, data) {
|
|
27
|
+
try {
|
|
28
|
+
const writeData = JSON.stringify(data || []);
|
|
29
|
+
await promises.writeFile(filename, writeData);
|
|
30
|
+
return true;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
logger.log(`Error writing redirect file ${filename}: ${e.message}`, "error");
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
async function readRedirectFileData(filename) {
|
|
37
|
+
try {
|
|
38
|
+
const file = await promises.readFile(filename, { encoding: "utf8" });
|
|
39
|
+
const data = JSON.parse(file);
|
|
40
|
+
return data;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
logger.log(`Failed loading redirects JSON from ${filename}: ${e.message}`, "error");
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
async function readRedirectFile(filePath, type = "redirects") {
|
|
47
|
+
const absolutePath = path__namespace.resolve(process.cwd(), filePath);
|
|
48
|
+
const data = await readRedirectFileData(absolutePath);
|
|
49
|
+
if (Array.isArray(data)) {
|
|
50
|
+
const checkedData = data.filter((x) => {
|
|
51
|
+
return x && typeof (x == null ? void 0 : x.source) === "string" && typeof (x == null ? void 0 : x.destination) === "string";
|
|
52
|
+
});
|
|
53
|
+
logger.log(`Loading ${type} length: ${checkedData.length}`);
|
|
54
|
+
return checkedData;
|
|
55
|
+
}
|
|
56
|
+
logger.log(`Failed loading ${type}, not a valid array`, "error");
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
async function fetchRedirects(config) {
|
|
60
|
+
const { redirectsFilename, rewritesFilename } = config;
|
|
61
|
+
if (!redirectsFilename) {
|
|
62
|
+
throw new Error("Missing fetchRedirects configuration `redirectsFilename`");
|
|
63
|
+
}
|
|
64
|
+
if (!rewritesFilename) {
|
|
65
|
+
throw new Error("Missing fetchRedirects configuration `rewritesFilename`");
|
|
66
|
+
}
|
|
67
|
+
const data = await fetchRedirectsData$1.fetchRedirectsData(config);
|
|
68
|
+
await writeRedirectFile(redirectsFilename, data.redirects);
|
|
69
|
+
await writeRedirectFile(rewritesFilename, data.rewrites);
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
const fetchRedirectsData = fetchRedirectsData$1.fetchRedirectsData;
|
|
73
|
+
const getDefaultConfig = fetchRedirectsData$1.getDefaultConfig;
|
|
74
|
+
const redirectDefaultLimit = fetchRedirectsData$1.redirectDefaultLimit;
|
|
75
|
+
const graphqlCodegenConfig = (schemaUrl, generatePath, headers) => {
|
|
76
|
+
const config = {
|
|
77
|
+
overwrite: true,
|
|
78
|
+
schema: [
|
|
79
|
+
{
|
|
80
|
+
[schemaUrl]: {
|
|
81
|
+
headers
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
documents: [`${__dirname}/apps/demo/**/*.graphql`],
|
|
86
|
+
ignoreNoDocuments: true,
|
|
87
|
+
// for better experience with the watcher
|
|
88
|
+
generates: {
|
|
89
|
+
[generatePath]: {
|
|
90
|
+
preset: "client"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
return config;
|
|
95
|
+
};
|
|
96
|
+
exports.isRedirect = fetchRedirectsData$1.isRedirect;
|
|
97
|
+
exports.normalizeRedirects = fetchRedirectsData$1.normalizeRedirects;
|
|
98
|
+
exports.DirectusNodeLogger = logger;
|
|
99
|
+
exports.fetchRedirects = fetchRedirects;
|
|
100
|
+
exports.fetchRedirectsData = fetchRedirectsData;
|
|
101
|
+
exports.getDefaultConfig = getDefaultConfig;
|
|
102
|
+
exports.graphqlCodegenConfig = graphqlCodegenConfig;
|
|
103
|
+
exports.readRedirectFile = readRedirectFile;
|
|
104
|
+
exports.readRedirectFileData = readRedirectFileData;
|
|
105
|
+
exports.redirectDefaultLimit = redirectDefaultLimit;
|
|
106
|
+
exports.writeRedirectFile = writeRedirectFile;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { f as fetchRedirectsData$1, g as getDefaultConfig$1, r as redirectDefaultLimit$1 } from "./fetchRedirectsData-DGLawlch.mjs";
|
|
2
|
+
import { i, n } from "./fetchRedirectsData-DGLawlch.mjs";
|
|
3
|
+
import "@okam/core-lib";
|
|
4
|
+
import { createLogger } from "@okam/logger";
|
|
5
|
+
import { writeFile, readFile } from "fs/promises";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
const logger = createLogger("[DirectusNode]");
|
|
8
|
+
async function writeRedirectFile(filename, data) {
|
|
9
|
+
try {
|
|
10
|
+
const writeData = JSON.stringify(data || []);
|
|
11
|
+
await writeFile(filename, writeData);
|
|
12
|
+
return true;
|
|
13
|
+
} catch (e) {
|
|
14
|
+
logger.log(`Error writing redirect file ${filename}: ${e.message}`, "error");
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
async function readRedirectFileData(filename) {
|
|
19
|
+
try {
|
|
20
|
+
const file = await readFile(filename, { encoding: "utf8" });
|
|
21
|
+
const data = JSON.parse(file);
|
|
22
|
+
return data;
|
|
23
|
+
} catch (e) {
|
|
24
|
+
logger.log(`Failed loading redirects JSON from ${filename}: ${e.message}`, "error");
|
|
25
|
+
}
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
async function readRedirectFile(filePath, type = "redirects") {
|
|
29
|
+
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
30
|
+
const data = await readRedirectFileData(absolutePath);
|
|
31
|
+
if (Array.isArray(data)) {
|
|
32
|
+
const checkedData = data.filter((x) => {
|
|
33
|
+
return x && typeof (x == null ? void 0 : x.source) === "string" && typeof (x == null ? void 0 : x.destination) === "string";
|
|
34
|
+
});
|
|
35
|
+
logger.log(`Loading ${type} length: ${checkedData.length}`);
|
|
36
|
+
return checkedData;
|
|
37
|
+
}
|
|
38
|
+
logger.log(`Failed loading ${type}, not a valid array`, "error");
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
async function fetchRedirects(config) {
|
|
42
|
+
const { redirectsFilename, rewritesFilename } = config;
|
|
43
|
+
if (!redirectsFilename) {
|
|
44
|
+
throw new Error("Missing fetchRedirects configuration `redirectsFilename`");
|
|
45
|
+
}
|
|
46
|
+
if (!rewritesFilename) {
|
|
47
|
+
throw new Error("Missing fetchRedirects configuration `rewritesFilename`");
|
|
48
|
+
}
|
|
49
|
+
const data = await fetchRedirectsData$1(config);
|
|
50
|
+
await writeRedirectFile(redirectsFilename, data.redirects);
|
|
51
|
+
await writeRedirectFile(rewritesFilename, data.rewrites);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
const fetchRedirectsData = fetchRedirectsData$1;
|
|
55
|
+
const getDefaultConfig = getDefaultConfig$1;
|
|
56
|
+
const redirectDefaultLimit = redirectDefaultLimit$1;
|
|
57
|
+
const graphqlCodegenConfig = (schemaUrl, generatePath, headers) => {
|
|
58
|
+
const config = {
|
|
59
|
+
overwrite: true,
|
|
60
|
+
schema: [
|
|
61
|
+
{
|
|
62
|
+
[schemaUrl]: {
|
|
63
|
+
headers
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
documents: [`${__dirname}/apps/demo/**/*.graphql`],
|
|
68
|
+
ignoreNoDocuments: true,
|
|
69
|
+
// for better experience with the watcher
|
|
70
|
+
generates: {
|
|
71
|
+
[generatePath]: {
|
|
72
|
+
preset: "client"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
return config;
|
|
77
|
+
};
|
|
78
|
+
export {
|
|
79
|
+
logger as DirectusNodeLogger,
|
|
80
|
+
fetchRedirects,
|
|
81
|
+
fetchRedirectsData,
|
|
82
|
+
getDefaultConfig,
|
|
83
|
+
graphqlCodegenConfig,
|
|
84
|
+
i as isRedirect,
|
|
85
|
+
n as normalizeRedirects,
|
|
86
|
+
readRedirectFile,
|
|
87
|
+
readRedirectFileData,
|
|
88
|
+
redirectDefaultLimit,
|
|
89
|
+
writeRedirectFile
|
|
90
|
+
};
|
package/package.json
CHANGED
|
@@ -1,19 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okam/directus-node",
|
|
3
3
|
"main": "./src/index.js",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.2",
|
|
5
5
|
"types": "./src/index.d.ts",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"default": "./index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./index.d.ts",
|
|
17
|
+
"default": "./index.mjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./edge": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./edge.d.ts",
|
|
23
|
+
"default": "./edge.mjs"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./edge.d.ts",
|
|
27
|
+
"default": "./edge.mjs"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
9
31
|
"repository": {
|
|
10
32
|
"url": "https://github.com/OKAMca/stack.git"
|
|
11
33
|
},
|
|
12
34
|
"dependencies": {
|
|
13
35
|
"@graphql-codegen/cli": "^5.0.3",
|
|
14
36
|
"@okam/logger": "1.1.0",
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"type": "commonjs"
|
|
19
|
-
}
|
|
37
|
+
"@okam/core-lib": "1.17.0"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/edge.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Export file for functions that are used in edge functions (middleware-compatible)
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.normalizeRedirects = exports.isRedirect = exports.getDefaultConfig = exports.fetchRedirectsData = void 0;
|
|
7
|
-
var fetchRedirectsData_1 = require("./lib/redirection/fetchRedirectsData");
|
|
8
|
-
Object.defineProperty(exports, "fetchRedirectsData", { enumerable: true, get: function () { return fetchRedirectsData_1.fetchRedirectsData; } });
|
|
9
|
-
Object.defineProperty(exports, "getDefaultConfig", { enumerable: true, get: function () { return fetchRedirectsData_1.getDefaultConfig; } });
|
|
10
|
-
var validateRedirects_1 = require("./lib/redirection/utils/validateRedirects");
|
|
11
|
-
Object.defineProperty(exports, "isRedirect", { enumerable: true, get: function () { return validateRedirects_1.isRedirect; } });
|
|
12
|
-
Object.defineProperty(exports, "normalizeRedirects", { enumerable: true, get: function () { return validateRedirects_1.normalizeRedirects; } });
|
|
13
|
-
//# sourceMappingURL=edge.js.map
|
package/src/edge.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"edge.js","sourceRoot":"","sources":["../../../../../libs/directus/directus-node/src/edge.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AASH,2EAA2F;AAAlF,wHAAA,kBAAkB,OAAA;AAAE,sHAAA,gBAAgB,OAAA;AAC7C,+EAA0F;AAAjF,+GAAA,UAAU,OAAA;AAAE,uHAAA,kBAAkB,OAAA"}
|
package/src/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DirectusNodeLogger = exports.graphqlCodegenConfig = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
tslib_1.__exportStar(require("./lib/redirection"), exports);
|
|
6
|
-
var codegen_1 = require("./lib/codegen");
|
|
7
|
-
Object.defineProperty(exports, "graphqlCodegenConfig", { enumerable: true, get: function () { return tslib_1.__importDefault(codegen_1).default; } });
|
|
8
|
-
var logger_1 = require("./logger");
|
|
9
|
-
Object.defineProperty(exports, "DirectusNodeLogger", { enumerable: true, get: function () { return logger_1.logger; } });
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/directus/directus-node/src/index.ts"],"names":[],"mappings":";;;;AAAA,4DAAiC;AACjC,yCAA+D;AAAtD,wIAAA,OAAO,OAAwB;AACxC,mCAAuD;AAA9C,4GAAA,MAAM,OAAsB"}
|
package/src/lib/codegen.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const graphqlCodegenConfig = (schemaUrl, generatePath, headers) => {
|
|
4
|
-
const config = {
|
|
5
|
-
overwrite: true,
|
|
6
|
-
schema: [
|
|
7
|
-
{
|
|
8
|
-
[schemaUrl]: {
|
|
9
|
-
headers,
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
],
|
|
13
|
-
documents: [`${__dirname}/apps/demo/**/*.graphql`],
|
|
14
|
-
ignoreNoDocuments: true, // for better experience with the watcher
|
|
15
|
-
generates: {
|
|
16
|
-
[generatePath]: {
|
|
17
|
-
preset: 'client',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
return config;
|
|
22
|
-
};
|
|
23
|
-
exports.default = graphqlCodegenConfig;
|
|
24
|
-
//# sourceMappingURL=codegen.js.map
|
package/src/lib/codegen.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../../../../libs/directus/directus-node/src/lib/codegen.ts"],"names":[],"mappings":";;AAEA,MAAM,oBAAoB,GAAG,CAAC,SAAiB,EAAE,YAAoB,EAAE,OAA+B,EAAE,EAAE;IACxG,MAAM,MAAM,GAAkB;QAC5B,SAAS,EAAE,IAAI;QACf,MAAM,EAAE;YACN;gBACE,CAAC,SAAS,CAAC,EAAE;oBACX,OAAO;iBACR;aACF;SACF;QACD,SAAS,EAAE,CAAC,GAAG,SAAS,yBAAyB,CAAC;QAClD,iBAAiB,EAAE,IAAI,EAAE,yCAAyC;QAClE,SAAS,EAAE;YACT,CAAC,YAAY,CAAC,EAAE;gBACd,MAAM,EAAE,QAAQ;aACjB;SACF;KACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,kBAAe,oBAAoB,CAAA"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.redirectDefaultLimit = void 0;
|
|
4
|
-
exports.getDefaultConfig = getDefaultConfig;
|
|
5
|
-
exports.fetchRedirectsData = fetchRedirectsData;
|
|
6
|
-
const tslib_1 = require("tslib");
|
|
7
|
-
const logger_1 = require("@okam/logger");
|
|
8
|
-
const validateRedirects_1 = require("./utils/validateRedirects");
|
|
9
|
-
exports.redirectDefaultLimit = 2000;
|
|
10
|
-
/**
|
|
11
|
-
* Get Fetch Redirects Configuration
|
|
12
|
-
* @returns {object}
|
|
13
|
-
*/
|
|
14
|
-
function getDefaultConfig() {
|
|
15
|
-
return {
|
|
16
|
-
graphqlEndpoint: process.env['NEXT_REDIRECT_GRAPHQL_URL'] || process.env['NEXT_PUBLIC_GRAPHQL_URL'] || '',
|
|
17
|
-
graphqlApiKey: process.env['NEXT_API_TOKEN_ADMIN'] || '',
|
|
18
|
-
redirectsFilename: './redirect/redirects.json',
|
|
19
|
-
rewritesFilename: './redirect/rewrites.json',
|
|
20
|
-
limit: exports.redirectDefaultLimit,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function fetchRedirectsData(config, init) {
|
|
24
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
const { graphqlApiKey: defaultGraphqlApiKey, graphqlEndpoint: defaultGraphqlEndpoint, limit: defaultLimit, } = getDefaultConfig();
|
|
26
|
-
const { graphqlEndpoint = defaultGraphqlEndpoint, graphqlApiKey = defaultGraphqlApiKey, limit = defaultLimit, } = config;
|
|
27
|
-
if (!graphqlEndpoint) {
|
|
28
|
-
throw new Error('Missing fetchRedirects configuration `graphqlEndpoint`. Check environment variables NEXT_REDIRECT_GRAPHQL_URL or NEXT_PUBLIC_GRAPHQL_URL');
|
|
29
|
-
}
|
|
30
|
-
if (!graphqlApiKey) {
|
|
31
|
-
throw new Error('Missing fetchRedirects configuration `graphqlApiKey`. Check environment variable NEXT_API_TOKEN_ADMIN');
|
|
32
|
-
}
|
|
33
|
-
const query = `query fetchRedirects($limit: Int = 2000) {
|
|
34
|
-
redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:false}}, sort: "sort", limit: $limit) {
|
|
35
|
-
source
|
|
36
|
-
destination
|
|
37
|
-
permanent
|
|
38
|
-
locale
|
|
39
|
-
}
|
|
40
|
-
rewrites: redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:true}}, sort: "sort", limit: $limit) {
|
|
41
|
-
source
|
|
42
|
-
destination
|
|
43
|
-
permanent
|
|
44
|
-
locale
|
|
45
|
-
}
|
|
46
|
-
}`;
|
|
47
|
-
const graphqlBody = {
|
|
48
|
-
query,
|
|
49
|
-
// "operationName": "",
|
|
50
|
-
variables: {
|
|
51
|
-
limit: Number(limit) || exports.redirectDefaultLimit,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
try {
|
|
55
|
-
// console.info(`Fetching redirects on ${graphqlEndpoint}`)
|
|
56
|
-
const response = yield fetch(graphqlEndpoint, Object.assign(Object.assign({}, init), { method: 'POST', headers: {
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
58
|
-
'Content-Type': 'application/json',
|
|
59
|
-
Authorization: `Bearer ${graphqlApiKey}`,
|
|
60
|
-
}, body: JSON.stringify(graphqlBody) }));
|
|
61
|
-
const { data } = yield response.json();
|
|
62
|
-
const { redirects, rewrites } = data !== null && data !== void 0 ? data : {};
|
|
63
|
-
if (!(redirects === null || redirects === void 0 ? void 0 : redirects.length) && !(rewrites === null || rewrites === void 0 ? void 0 : rewrites.length)) {
|
|
64
|
-
logger_1.logger.log('No redirects/rewrites found', 'warn');
|
|
65
|
-
return {
|
|
66
|
-
redirects: [],
|
|
67
|
-
rewrites: [],
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
logger_1.logger.log(`Fetch redirects count: ${(redirects === null || redirects === void 0 ? void 0 : redirects.length) || 0}, rewrites count: ${(rewrites === null || rewrites === void 0 ? void 0 : rewrites.length) || 0}`);
|
|
71
|
-
return {
|
|
72
|
-
redirects: (0, validateRedirects_1.normalizeRedirects)(redirects),
|
|
73
|
-
rewrites: (0, validateRedirects_1.normalizeRedirects)(rewrites),
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
logger_1.logger.log(`Error fetching redirects: ${e.message}`, 'error');
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
redirects: [],
|
|
81
|
-
rewrites: [],
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
//# sourceMappingURL=fetchRedirectsData.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchRedirectsData.js","sourceRoot":"","sources":["../../../../../../../libs/directus/directus-node/src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@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable prefer-destructuring */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.redirectDefaultLimit = exports.getDefaultConfig = exports.fetchRedirectsData = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const fetchRedirectsDataFile = tslib_1.__importStar(require("./fetchRedirectsData"));
|
|
7
|
-
// Re-export with deprecation warnings
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated Import from `@okam/directus-node/edge` instead
|
|
10
|
-
*/
|
|
11
|
-
exports.fetchRedirectsData = fetchRedirectsDataFile.fetchRedirectsData;
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated Import from `@okam/directus-node/edge` instead
|
|
14
|
-
*/
|
|
15
|
-
exports.getDefaultConfig = fetchRedirectsDataFile.getDefaultConfig;
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated Import from `@okam/directus-node/edge` instead
|
|
18
|
-
*/
|
|
19
|
-
exports.redirectDefaultLimit = fetchRedirectsDataFile.redirectDefaultLimit;
|
|
20
|
-
tslib_1.__exportStar(require("./utils/validateRedirects"), exports);
|
|
21
|
-
tslib_1.__exportStar(require("./redirectsFile"), exports);
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/directus/directus-node/src/lib/redirection/index.ts"],"names":[],"mappings":";AAAA,yCAAyC;;;;AAEzC,qFAA8D;AAC9D,sCAAsC;AACtC;;GAEG;AACU,QAAA,kBAAkB,GAAG,sBAAsB,CAAC,kBAAkB,CAAA;AAC3E;;GAEG;AACU,QAAA,gBAAgB,GAAG,sBAAsB,CAAC,gBAAgB,CAAA;AACvE;;GAEG;AACU,QAAA,oBAAoB,GAAG,sBAAsB,CAAC,oBAAoB,CAAA;AAG/E,oEAAyC;AACzC,0DAA+B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../../../../../libs/directus/directus-node/src/lib/redirection/interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeRedirectFile = writeRedirectFile;
|
|
4
|
-
exports.readRedirectFileData = readRedirectFileData;
|
|
5
|
-
exports.readRedirectFile = readRedirectFile;
|
|
6
|
-
exports.fetchRedirects = fetchRedirects;
|
|
7
|
-
const tslib_1 = require("tslib");
|
|
8
|
-
const promises_1 = require("fs/promises");
|
|
9
|
-
const path = tslib_1.__importStar(require("path"));
|
|
10
|
-
const logger_1 = require("../../logger");
|
|
11
|
-
const fetchRedirectsData_1 = require("./fetchRedirectsData");
|
|
12
|
-
/**
|
|
13
|
-
* Write Redirect Data
|
|
14
|
-
* @param {string} filename filename
|
|
15
|
-
* @param {unknown} data redirects data (rewrites or redirects)
|
|
16
|
-
*/
|
|
17
|
-
function writeRedirectFile(filename, data) {
|
|
18
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
try {
|
|
20
|
-
const writeData = JSON.stringify(data || []);
|
|
21
|
-
yield (0, promises_1.writeFile)(filename, writeData);
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
logger_1.logger.log(`Error writing redirect file ${filename}: ${e.message}`, 'error');
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
function readRedirectFileData(filename) {
|
|
31
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
try {
|
|
33
|
-
const file = yield (0, promises_1.readFile)(filename, { encoding: 'utf8' });
|
|
34
|
-
const data = JSON.parse(file);
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
logger_1.logger.log(`Failed loading redirects JSON from ${filename}: ${e.message}`, 'error');
|
|
39
|
-
}
|
|
40
|
-
return [];
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Read one redirects or rewrites file
|
|
45
|
-
* @param {string} filePath relative file path like './redirect/redirects.json' to the current working dir
|
|
46
|
-
* @param {TRedirectType} type redirects or rewrites
|
|
47
|
-
* @returns {Promise<TRedirectData[]>} an array of redirect information
|
|
48
|
-
*/
|
|
49
|
-
function readRedirectFile(filePath_1) {
|
|
50
|
-
return tslib_1.__awaiter(this, arguments, void 0, function* (filePath, type = 'redirects') {
|
|
51
|
-
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
52
|
-
const data = yield readRedirectFileData(absolutePath);
|
|
53
|
-
if (Array.isArray(data)) {
|
|
54
|
-
// check data integrity
|
|
55
|
-
const checkedData = data.filter((x) => {
|
|
56
|
-
return x && typeof (x === null || x === void 0 ? void 0 : x.source) === 'string' && typeof (x === null || x === void 0 ? void 0 : x.destination) === 'string';
|
|
57
|
-
});
|
|
58
|
-
logger_1.logger.log(`Loading ${type} length: ${checkedData.length}`);
|
|
59
|
-
return checkedData;
|
|
60
|
-
}
|
|
61
|
-
logger_1.logger.log(`Failed loading ${type}, not a valid array`, 'error');
|
|
62
|
-
return [];
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Fetch and write redirects and rewrites files
|
|
67
|
-
* @param {TFetchRedirectsConfig} config fetch redirects configuration
|
|
68
|
-
* @returns {Promise<boolean>} true
|
|
69
|
-
* @throws {Error}
|
|
70
|
-
*/
|
|
71
|
-
function fetchRedirects(config) {
|
|
72
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
const { redirectsFilename, rewritesFilename } = config;
|
|
74
|
-
if (!redirectsFilename) {
|
|
75
|
-
throw new Error('Missing fetchRedirects configuration `redirectsFilename`');
|
|
76
|
-
}
|
|
77
|
-
if (!rewritesFilename) {
|
|
78
|
-
throw new Error('Missing fetchRedirects configuration `rewritesFilename`');
|
|
79
|
-
}
|
|
80
|
-
// fetch can throw
|
|
81
|
-
const data = yield (0, fetchRedirectsData_1.fetchRedirectsData)(config);
|
|
82
|
-
// should not throw
|
|
83
|
-
yield writeRedirectFile(redirectsFilename, data.redirects);
|
|
84
|
-
yield writeRedirectFile(rewritesFilename, data.rewrites);
|
|
85
|
-
return true;
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=redirectsFile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redirectsFile.js","sourceRoot":"","sources":["../../../../../../../libs/directus/directus-node/src/lib/redirection/redirectsFile.ts"],"names":[],"mappings":";;AAWA,8CASC;AAED,oDASC;AAQD,4CAaC;AAQD,wCAkBC;;AA9ED,0CAAiD;AACjD,mDAA4B;AAC5B,yCAAqC;AACrC,6DAAyD;AAGzD;;;;GAIG;AACH,SAAsB,iBAAiB,CAAC,QAAgB,EAAE,IAAa;;QACrE,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAAC,CAAA;YAC5C,MAAM,IAAA,oBAAS,EAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;YACpC,OAAO,IAAI,CAAA;QACb,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,eAAM,CAAC,GAAG,CAAC,+BAA+B,QAAQ,KAAM,CAAW,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAA;QACzF,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;CAAA;AAED,SAAsB,oBAAoB,CAAC,QAAgB;;QACzD,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAA;YAC3D,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;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A0D,CAAC,CAAA;QAC7E,CAAC;QAED,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAA;QAC5E,CAAC;QAED,kBAAkB;QAClB,MAAM,IAAI,GAAG,MAAM,IAAA,uCAAkB,EAAC,MAAM,CAAC,CAAA;QAE7C,mBAAmB;QACnB,MAAM,iBAAiB,CAAC,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;QAC1D,MAAM,iBAAiB,CAAC,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QACxD,OAAO,IAAI,CAAA;IACb,CAAC;CAAA"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isRedirect = isRedirect;
|
|
4
|
-
exports.normalizeRedirects = normalizeRedirects;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const core_lib_1 = require("@okam/core-lib");
|
|
7
|
-
function isRedirect(redirect) {
|
|
8
|
-
return !!redirect && typeof redirect === 'object' && 'source' in redirect && 'destination' in redirect;
|
|
9
|
-
}
|
|
10
|
-
function normalizeRedirects(redirects) {
|
|
11
|
-
if (!redirects || !Array.isArray(redirects))
|
|
12
|
-
return [];
|
|
13
|
-
return redirects.flatMap((redirect) => {
|
|
14
|
-
const _a = redirect !== null && redirect !== void 0 ? redirect : {}, { source, destination } = _a, rest = tslib_1.__rest(_a, ["source", "destination"]);
|
|
15
|
-
if (!redirect || !source || !destination || !isRedirect(redirect))
|
|
16
|
-
return [];
|
|
17
|
-
return [
|
|
18
|
-
Object.assign(Object.assign({}, rest), { source: (0, core_lib_1.normalizePath)(source), destination: (0, core_lib_1.normalizePath)(destination) }),
|
|
19
|
-
];
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=validateRedirects.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateRedirects.js","sourceRoot":"","sources":["../../../../../../../../libs/directus/directus-node/src/lib/redirection/utils/validateRedirects.ts"],"names":[],"mappings":";;AAGA,gCAEC;AAED,gDAaC;;AApBD,6CAA8C;AAG9C,SAAgB,UAAU,CAAC,QAAiB;IAC1C,OAAO,CAAC,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,IAAI,QAAQ,IAAI,aAAa,IAAI,QAAQ,CAAA;AACxG,CAAC;AAED,SAAgB,kBAAkB,CAAC,SAA0C;IAC3E,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;QAAE,OAAO,EAAE,CAAA;IACtD,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QACpC,MAAM,KAAmC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,EAAjD,EAAE,MAAM,EAAE,WAAW,OAA4B,EAAvB,IAAI,sBAA9B,yBAAgC,CAAiB,CAAA;QACvD,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;YAAE,OAAO,EAAE,CAAA;QAC5E,OAAO;4CAEA,IAAI,KACP,MAAM,EAAE,IAAA,wBAAa,EAAC,MAAM,CAAC,EAC7B,WAAW,EAAE,IAAA,wBAAa,EAAC,WAAW,CAAC;SAE1C,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/src/logger.js
DELETED
package/src/logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../../libs/directus/directus-node/src/logger.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAE9B,QAAA,MAAM,GAAG,IAAA,qBAAY,EAAC,gBAAgB,CAAC,CAAA"}
|
|
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
|