@okam/directus-node 0.7.0 → 0.7.3
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 +22 -0
- package/edge.d.ts +1 -1
- package/edge.js +1 -1
- package/edge.mjs +1 -1
- package/{fetchRedirectsData-DGLawlch.mjs → fetchRedirectsData-B8eRjr-j.mjs} +16 -13
- package/{fetchRedirectsData-nz-uddGa.js → fetchRedirectsData-DV3H4NVa.js} +16 -13
- package/index.d.ts +1 -1
- package/index.js +53 -58
- package/index.mjs +55 -60
- package/lib/codegen.d.ts +1 -2
- package/lib/redirection/fetchRedirectsData.d.ts +0 -1
- package/lib/redirection/index.d.ts +1 -1
- package/lib/redirection/redirectsFile.d.ts +2 -3
- package/lib/redirection/utils/validateRedirects.d.ts +1 -2
- package/logger.d.ts +1 -1
- package/package.json +14 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## 0.7.3 (2026-01-21)
|
|
2
|
+
|
|
3
|
+
### 🧱 Updated Dependencies
|
|
4
|
+
|
|
5
|
+
- Updated core-lib to 1.17.2
|
|
6
|
+
|
|
7
|
+
## 0.7.2 (2026-01-19)
|
|
8
|
+
|
|
9
|
+
### 🧱 Updated Dependencies
|
|
10
|
+
|
|
11
|
+
- Updated core-lib to 1.17.1
|
|
12
|
+
|
|
13
|
+
## 0.7.1 (2026-01-19)
|
|
14
|
+
|
|
15
|
+
### 🩹 Fixes
|
|
16
|
+
|
|
17
|
+
- cross-lib type imports are always absolute ([#392](https://github.com/OKAMca/stack/pull/392))
|
|
18
|
+
|
|
19
|
+
### ❤️ Thank You
|
|
20
|
+
|
|
21
|
+
- Pierre-Olivier Clerson @poclerson
|
|
22
|
+
|
|
1
23
|
## 0.7.0 (2026-01-16)
|
|
2
24
|
|
|
3
25
|
### 🚀 Features
|
package/edge.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Export file for functions that are used in edge functions (middleware-compatible)
|
|
3
3
|
*/
|
|
4
|
-
export type { TFetchRedirectsConfig, TFetchRedirectsResponse, TRedirectData, TRedirectType, } from './lib/redirection/interface';
|
|
5
4
|
export { fetchRedirectsData, getDefaultConfig } from './lib/redirection/fetchRedirectsData';
|
|
5
|
+
export type { TFetchRedirectsConfig, TFetchRedirectsResponse, TRedirectData, TRedirectType, } from './lib/redirection/interface';
|
|
6
6
|
export { isRedirect, normalizeRedirects } from './lib/redirection/utils/validateRedirects';
|
package/edge.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const fetchRedirectsData = require("./fetchRedirectsData-
|
|
3
|
+
const fetchRedirectsData = require("./fetchRedirectsData-DV3H4NVa.js");
|
|
4
4
|
exports.fetchRedirectsData = fetchRedirectsData.fetchRedirectsData;
|
|
5
5
|
exports.getDefaultConfig = fetchRedirectsData.getDefaultConfig;
|
|
6
6
|
exports.isRedirect = fetchRedirectsData.isRedirect;
|
package/edge.mjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { logger } from "@okam/logger";
|
|
2
2
|
import { normalizePath } from "@okam/core-lib";
|
|
3
3
|
function isRedirect(redirect) {
|
|
4
|
-
return
|
|
4
|
+
return redirect != null && typeof redirect === "object" && "source" in redirect && "destination" in redirect;
|
|
5
5
|
}
|
|
6
6
|
function normalizeRedirects(redirects) {
|
|
7
|
-
if (
|
|
7
|
+
if (redirects == null || !Array.isArray(redirects))
|
|
8
|
+
return [];
|
|
8
9
|
return redirects.flatMap((redirect) => {
|
|
9
10
|
const { source, destination, ...rest } = redirect ?? {};
|
|
10
|
-
if (
|
|
11
|
+
if (redirect == null || source == null || source === "" || destination == null || destination === "" || !isRedirect(redirect))
|
|
12
|
+
return [];
|
|
11
13
|
return [
|
|
12
14
|
{
|
|
13
15
|
...rest,
|
|
@@ -20,7 +22,9 @@ function normalizeRedirects(redirects) {
|
|
|
20
22
|
const redirectDefaultLimit = 2e3;
|
|
21
23
|
function getDefaultConfig() {
|
|
22
24
|
return {
|
|
25
|
+
// eslint-disable-next-line ts/prefer-nullish-coalescing, ts/strict-boolean-expressions -- empty string env var should fallback to next option
|
|
23
26
|
graphqlEndpoint: process.env["NEXT_REDIRECT_GRAPHQL_URL"] || process.env["NEXT_PUBLIC_GRAPHQL_URL"] || "",
|
|
27
|
+
// eslint-disable-next-line ts/prefer-nullish-coalescing, ts/strict-boolean-expressions -- empty string env var should fallback to default
|
|
24
28
|
graphqlApiKey: process.env["NEXT_API_TOKEN_ADMIN"] || "",
|
|
25
29
|
redirectsFilename: "./redirect/redirects.json",
|
|
26
30
|
rewritesFilename: "./redirect/rewrites.json",
|
|
@@ -38,12 +42,12 @@ async function fetchRedirectsData(config, init) {
|
|
|
38
42
|
graphqlApiKey = defaultGraphqlApiKey,
|
|
39
43
|
limit = defaultLimit
|
|
40
44
|
} = config;
|
|
41
|
-
if (
|
|
45
|
+
if (graphqlEndpoint == null || graphqlEndpoint === "") {
|
|
42
46
|
throw new Error(
|
|
43
47
|
"Missing fetchRedirects configuration `graphqlEndpoint`. Check environment variables NEXT_REDIRECT_GRAPHQL_URL or NEXT_PUBLIC_GRAPHQL_URL"
|
|
44
48
|
);
|
|
45
49
|
}
|
|
46
|
-
if (
|
|
50
|
+
if (graphqlApiKey == null || graphqlApiKey === "") {
|
|
47
51
|
throw new Error(
|
|
48
52
|
"Missing fetchRedirects configuration `graphqlApiKey`. Check environment variable NEXT_API_TOKEN_ADMIN"
|
|
49
53
|
);
|
|
@@ -74,25 +78,24 @@ async function fetchRedirectsData(config, init) {
|
|
|
74
78
|
...init,
|
|
75
79
|
method: "POST",
|
|
76
80
|
headers: {
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
78
81
|
"Content-Type": "application/json",
|
|
79
|
-
Authorization: `Bearer ${graphqlApiKey}`
|
|
82
|
+
"Authorization": `Bearer ${graphqlApiKey}`
|
|
80
83
|
},
|
|
81
84
|
body: JSON.stringify(graphqlBody)
|
|
82
85
|
});
|
|
83
|
-
const
|
|
84
|
-
const { redirects, rewrites } = data ?? {};
|
|
85
|
-
if (
|
|
86
|
+
const json = await response.json();
|
|
87
|
+
const { redirects, rewrites } = json.data ?? {};
|
|
88
|
+
if ((redirects == null || redirects.length === 0) && (rewrites == null || rewrites.length === 0)) {
|
|
86
89
|
logger.log("No redirects/rewrites found", "warn");
|
|
87
90
|
return {
|
|
88
91
|
redirects: [],
|
|
89
92
|
rewrites: []
|
|
90
93
|
};
|
|
91
94
|
}
|
|
92
|
-
logger.log(`Fetch redirects count: ${
|
|
95
|
+
logger.log(`Fetch redirects count: ${redirects?.length ?? 0}, rewrites count: ${rewrites?.length ?? 0}`);
|
|
93
96
|
return {
|
|
94
|
-
redirects: normalizeRedirects(redirects),
|
|
95
|
-
rewrites: normalizeRedirects(rewrites)
|
|
97
|
+
redirects: normalizeRedirects(redirects ?? null),
|
|
98
|
+
rewrites: normalizeRedirects(rewrites ?? null)
|
|
96
99
|
};
|
|
97
100
|
} catch (e) {
|
|
98
101
|
logger.log(`Error fetching redirects: ${e.message}`, "error");
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
const logger = require("@okam/logger");
|
|
3
3
|
const coreLib = require("@okam/core-lib");
|
|
4
4
|
function isRedirect(redirect) {
|
|
5
|
-
return
|
|
5
|
+
return redirect != null && typeof redirect === "object" && "source" in redirect && "destination" in redirect;
|
|
6
6
|
}
|
|
7
7
|
function normalizeRedirects(redirects) {
|
|
8
|
-
if (
|
|
8
|
+
if (redirects == null || !Array.isArray(redirects))
|
|
9
|
+
return [];
|
|
9
10
|
return redirects.flatMap((redirect) => {
|
|
10
11
|
const { source, destination, ...rest } = redirect ?? {};
|
|
11
|
-
if (
|
|
12
|
+
if (redirect == null || source == null || source === "" || destination == null || destination === "" || !isRedirect(redirect))
|
|
13
|
+
return [];
|
|
12
14
|
return [
|
|
13
15
|
{
|
|
14
16
|
...rest,
|
|
@@ -21,7 +23,9 @@ function normalizeRedirects(redirects) {
|
|
|
21
23
|
const redirectDefaultLimit = 2e3;
|
|
22
24
|
function getDefaultConfig() {
|
|
23
25
|
return {
|
|
26
|
+
// eslint-disable-next-line ts/prefer-nullish-coalescing, ts/strict-boolean-expressions -- empty string env var should fallback to next option
|
|
24
27
|
graphqlEndpoint: process.env["NEXT_REDIRECT_GRAPHQL_URL"] || process.env["NEXT_PUBLIC_GRAPHQL_URL"] || "",
|
|
28
|
+
// eslint-disable-next-line ts/prefer-nullish-coalescing, ts/strict-boolean-expressions -- empty string env var should fallback to default
|
|
25
29
|
graphqlApiKey: process.env["NEXT_API_TOKEN_ADMIN"] || "",
|
|
26
30
|
redirectsFilename: "./redirect/redirects.json",
|
|
27
31
|
rewritesFilename: "./redirect/rewrites.json",
|
|
@@ -39,12 +43,12 @@ async function fetchRedirectsData(config, init) {
|
|
|
39
43
|
graphqlApiKey = defaultGraphqlApiKey,
|
|
40
44
|
limit = defaultLimit
|
|
41
45
|
} = config;
|
|
42
|
-
if (
|
|
46
|
+
if (graphqlEndpoint == null || graphqlEndpoint === "") {
|
|
43
47
|
throw new Error(
|
|
44
48
|
"Missing fetchRedirects configuration `graphqlEndpoint`. Check environment variables NEXT_REDIRECT_GRAPHQL_URL or NEXT_PUBLIC_GRAPHQL_URL"
|
|
45
49
|
);
|
|
46
50
|
}
|
|
47
|
-
if (
|
|
51
|
+
if (graphqlApiKey == null || graphqlApiKey === "") {
|
|
48
52
|
throw new Error(
|
|
49
53
|
"Missing fetchRedirects configuration `graphqlApiKey`. Check environment variable NEXT_API_TOKEN_ADMIN"
|
|
50
54
|
);
|
|
@@ -75,25 +79,24 @@ async function fetchRedirectsData(config, init) {
|
|
|
75
79
|
...init,
|
|
76
80
|
method: "POST",
|
|
77
81
|
headers: {
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
79
82
|
"Content-Type": "application/json",
|
|
80
|
-
Authorization: `Bearer ${graphqlApiKey}`
|
|
83
|
+
"Authorization": `Bearer ${graphqlApiKey}`
|
|
81
84
|
},
|
|
82
85
|
body: JSON.stringify(graphqlBody)
|
|
83
86
|
});
|
|
84
|
-
const
|
|
85
|
-
const { redirects, rewrites } = data ?? {};
|
|
86
|
-
if (
|
|
87
|
+
const json = await response.json();
|
|
88
|
+
const { redirects, rewrites } = json.data ?? {};
|
|
89
|
+
if ((redirects == null || redirects.length === 0) && (rewrites == null || rewrites.length === 0)) {
|
|
87
90
|
logger.logger.log("No redirects/rewrites found", "warn");
|
|
88
91
|
return {
|
|
89
92
|
redirects: [],
|
|
90
93
|
rewrites: []
|
|
91
94
|
};
|
|
92
95
|
}
|
|
93
|
-
logger.logger.log(`Fetch redirects count: ${
|
|
96
|
+
logger.logger.log(`Fetch redirects count: ${redirects?.length ?? 0}, rewrites count: ${rewrites?.length ?? 0}`);
|
|
94
97
|
return {
|
|
95
|
-
redirects: normalizeRedirects(redirects),
|
|
96
|
-
rewrites: normalizeRedirects(rewrites)
|
|
98
|
+
redirects: normalizeRedirects(redirects ?? null),
|
|
99
|
+
rewrites: normalizeRedirects(rewrites ?? null)
|
|
97
100
|
};
|
|
98
101
|
} catch (e) {
|
|
99
102
|
logger.logger.log(`Error fetching redirects: ${e.message}`, "error");
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
require("@okam/core-lib");
|
|
5
|
-
const logger$1 = require("@okam/logger");
|
|
6
|
-
const path = require("path");
|
|
3
|
+
const path = require("node:path");
|
|
7
4
|
const dotenv = require("dotenv");
|
|
8
|
-
const
|
|
5
|
+
const logger$1 = require("@okam/logger");
|
|
6
|
+
const fetchRedirectsData$1 = require("./fetchRedirectsData-DV3H4NVa.js");
|
|
7
|
+
const promises = require("node:fs/promises");
|
|
9
8
|
function _interopNamespaceDefault(e) {
|
|
10
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
11
10
|
if (e) {
|
|
@@ -24,56 +23,7 @@ function _interopNamespaceDefault(e) {
|
|
|
24
23
|
}
|
|
25
24
|
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
26
25
|
const logger = logger$1.createLogger("[DirectusNode]");
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const writeData = JSON.stringify(data || []);
|
|
30
|
-
await promises.writeFile(filename, writeData);
|
|
31
|
-
return true;
|
|
32
|
-
} catch (e) {
|
|
33
|
-
logger.log(`Error writing redirect file ${filename}: ${e.message}`, "error");
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
async function readRedirectFileData(filename) {
|
|
38
|
-
try {
|
|
39
|
-
const file = await promises.readFile(filename, { encoding: "utf8" });
|
|
40
|
-
const data = JSON.parse(file);
|
|
41
|
-
return data;
|
|
42
|
-
} catch (e) {
|
|
43
|
-
logger.log(`Failed loading redirects JSON from ${filename}: ${e.message}`, "error");
|
|
44
|
-
}
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
async function readRedirectFile(filePath, type = "redirects") {
|
|
48
|
-
const absolutePath = path__namespace.resolve(process.cwd(), filePath);
|
|
49
|
-
const data = await readRedirectFileData(absolutePath);
|
|
50
|
-
if (Array.isArray(data)) {
|
|
51
|
-
const checkedData = data.filter((x) => {
|
|
52
|
-
return x && typeof (x == null ? void 0 : x.source) === "string" && typeof (x == null ? void 0 : x.destination) === "string";
|
|
53
|
-
});
|
|
54
|
-
logger.log(`Loading ${type} length: ${checkedData.length}`);
|
|
55
|
-
return checkedData;
|
|
56
|
-
}
|
|
57
|
-
logger.log(`Failed loading ${type}, not a valid array`, "error");
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
async function fetchRedirects(config) {
|
|
61
|
-
const { redirectsFilename, rewritesFilename } = config;
|
|
62
|
-
if (!redirectsFilename) {
|
|
63
|
-
throw new Error("Missing fetchRedirects configuration `redirectsFilename`");
|
|
64
|
-
}
|
|
65
|
-
if (!rewritesFilename) {
|
|
66
|
-
throw new Error("Missing fetchRedirects configuration `rewritesFilename`");
|
|
67
|
-
}
|
|
68
|
-
const data = await fetchRedirectsData$1.fetchRedirectsData(config);
|
|
69
|
-
await writeRedirectFile(redirectsFilename, data.redirects);
|
|
70
|
-
await writeRedirectFile(rewritesFilename, data.rewrites);
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
const fetchRedirectsData = fetchRedirectsData$1.fetchRedirectsData;
|
|
74
|
-
const getDefaultConfig = fetchRedirectsData$1.getDefaultConfig;
|
|
75
|
-
const redirectDefaultLimit = fetchRedirectsData$1.redirectDefaultLimit;
|
|
76
|
-
const graphqlCodegenConfig = (options) => {
|
|
26
|
+
function graphqlCodegenConfig(options) {
|
|
77
27
|
const {
|
|
78
28
|
schemaUrl: providedSchemaUrl,
|
|
79
29
|
authToken: providedAuthToken,
|
|
@@ -88,7 +38,7 @@ const graphqlCodegenConfig = (options) => {
|
|
|
88
38
|
dotenv.config({ path: localEnvPath, override: true });
|
|
89
39
|
const schemaUrl = providedSchemaUrl ?? process.env["NEXT_SERVER_GRAPHQL_URL"] ?? process.env["NEXT_PUBLIC_GRAPHQL_URL"];
|
|
90
40
|
const authToken = providedAuthToken ?? process.env["NEXT_PUBLIC_API_TOKEN"];
|
|
91
|
-
if (
|
|
41
|
+
if (schemaUrl == null || schemaUrl === "") {
|
|
92
42
|
const errorMsg = "GraphQL schema URL is not defined. Provide it as an option or set NEXT_SERVER_GRAPHQL_URL or NEXT_PUBLIC_GRAPHQL_URL environment variable.";
|
|
93
43
|
logger.log(errorMsg, "error");
|
|
94
44
|
throw new Error(errorMsg);
|
|
@@ -96,7 +46,7 @@ const graphqlCodegenConfig = (options) => {
|
|
|
96
46
|
const headers = {
|
|
97
47
|
...additionalHeaders
|
|
98
48
|
};
|
|
99
|
-
if (authToken) {
|
|
49
|
+
if (authToken != null && authToken !== "") {
|
|
100
50
|
headers["Authorization"] = `Bearer ${authToken}`;
|
|
101
51
|
}
|
|
102
52
|
const config = {
|
|
@@ -122,7 +72,52 @@ const graphqlCodegenConfig = (options) => {
|
|
|
122
72
|
logger.log("Error creating GraphQL codegen configuration:", "error", { error });
|
|
123
73
|
throw error;
|
|
124
74
|
}
|
|
125
|
-
}
|
|
75
|
+
}
|
|
76
|
+
async function writeRedirectFile(filename, data) {
|
|
77
|
+
try {
|
|
78
|
+
const writeData = JSON.stringify(data ?? []);
|
|
79
|
+
await promises.writeFile(filename, writeData);
|
|
80
|
+
return true;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
logger.log(`Error writing redirect file ${filename}: ${e.message}`, "error");
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
async function readRedirectFileData(filename) {
|
|
87
|
+
try {
|
|
88
|
+
const file = await promises.readFile(filename, { encoding: "utf8" });
|
|
89
|
+
const data = JSON.parse(file);
|
|
90
|
+
return data;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
logger.log(`Failed loading redirects JSON from ${filename}: ${e.message}`, "error");
|
|
93
|
+
}
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
async function readRedirectFile(filePath, type = "redirects") {
|
|
97
|
+
const absolutePath = path__namespace.resolve(process.cwd(), filePath);
|
|
98
|
+
const data = await readRedirectFileData(absolutePath);
|
|
99
|
+
const checkedData = data.filter((x) => {
|
|
100
|
+
return x != null && typeof x.source === "string" && typeof x.destination === "string";
|
|
101
|
+
});
|
|
102
|
+
logger.log(`Loading ${type} length: ${checkedData.length}`);
|
|
103
|
+
return checkedData;
|
|
104
|
+
}
|
|
105
|
+
async function fetchRedirects(config) {
|
|
106
|
+
const { redirectsFilename, rewritesFilename } = config;
|
|
107
|
+
if (redirectsFilename == null || redirectsFilename === "") {
|
|
108
|
+
throw new Error("Missing fetchRedirects configuration `redirectsFilename`");
|
|
109
|
+
}
|
|
110
|
+
if (rewritesFilename == null || rewritesFilename === "") {
|
|
111
|
+
throw new Error("Missing fetchRedirects configuration `rewritesFilename`");
|
|
112
|
+
}
|
|
113
|
+
const data = await fetchRedirectsData$1.fetchRedirectsData(config);
|
|
114
|
+
await writeRedirectFile(redirectsFilename, data.redirects);
|
|
115
|
+
await writeRedirectFile(rewritesFilename, data.rewrites);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
const fetchRedirectsData = fetchRedirectsData$1.fetchRedirectsData;
|
|
119
|
+
const getDefaultConfig = fetchRedirectsData$1.getDefaultConfig;
|
|
120
|
+
const redirectDefaultLimit = fetchRedirectsData$1.redirectDefaultLimit;
|
|
126
121
|
exports.isRedirect = fetchRedirectsData$1.isRedirect;
|
|
127
122
|
exports.normalizeRedirects = fetchRedirectsData$1.normalizeRedirects;
|
|
128
123
|
exports.DirectusNodeLogger = logger;
|
package/index.mjs
CHANGED
|
@@ -1,62 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import "@okam/core-lib";
|
|
4
|
-
import { createLogger } from "@okam/logger";
|
|
5
|
-
import * as path from "path";
|
|
6
|
-
import path__default from "path";
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import path__default from "node:path";
|
|
7
3
|
import { config } from "dotenv";
|
|
8
|
-
import {
|
|
4
|
+
import { createLogger } from "@okam/logger";
|
|
5
|
+
import { f as fetchRedirectsData$1, g as getDefaultConfig$1, r as redirectDefaultLimit$1 } from "./fetchRedirectsData-B8eRjr-j.mjs";
|
|
6
|
+
import { i, n } from "./fetchRedirectsData-B8eRjr-j.mjs";
|
|
7
|
+
import { writeFile, readFile } from "node:fs/promises";
|
|
9
8
|
const logger = createLogger("[DirectusNode]");
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
const writeData = JSON.stringify(data || []);
|
|
13
|
-
await writeFile(filename, writeData);
|
|
14
|
-
return true;
|
|
15
|
-
} catch (e) {
|
|
16
|
-
logger.log(`Error writing redirect file ${filename}: ${e.message}`, "error");
|
|
17
|
-
}
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
async function readRedirectFileData(filename) {
|
|
21
|
-
try {
|
|
22
|
-
const file = await readFile(filename, { encoding: "utf8" });
|
|
23
|
-
const data = JSON.parse(file);
|
|
24
|
-
return data;
|
|
25
|
-
} catch (e) {
|
|
26
|
-
logger.log(`Failed loading redirects JSON from ${filename}: ${e.message}`, "error");
|
|
27
|
-
}
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
async function readRedirectFile(filePath, type = "redirects") {
|
|
31
|
-
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
32
|
-
const data = await readRedirectFileData(absolutePath);
|
|
33
|
-
if (Array.isArray(data)) {
|
|
34
|
-
const checkedData = data.filter((x) => {
|
|
35
|
-
return x && typeof (x == null ? void 0 : x.source) === "string" && typeof (x == null ? void 0 : x.destination) === "string";
|
|
36
|
-
});
|
|
37
|
-
logger.log(`Loading ${type} length: ${checkedData.length}`);
|
|
38
|
-
return checkedData;
|
|
39
|
-
}
|
|
40
|
-
logger.log(`Failed loading ${type}, not a valid array`, "error");
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
async function fetchRedirects(config2) {
|
|
44
|
-
const { redirectsFilename, rewritesFilename } = config2;
|
|
45
|
-
if (!redirectsFilename) {
|
|
46
|
-
throw new Error("Missing fetchRedirects configuration `redirectsFilename`");
|
|
47
|
-
}
|
|
48
|
-
if (!rewritesFilename) {
|
|
49
|
-
throw new Error("Missing fetchRedirects configuration `rewritesFilename`");
|
|
50
|
-
}
|
|
51
|
-
const data = await fetchRedirectsData$1(config2);
|
|
52
|
-
await writeRedirectFile(redirectsFilename, data.redirects);
|
|
53
|
-
await writeRedirectFile(rewritesFilename, data.rewrites);
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
const fetchRedirectsData = fetchRedirectsData$1;
|
|
57
|
-
const getDefaultConfig = getDefaultConfig$1;
|
|
58
|
-
const redirectDefaultLimit = redirectDefaultLimit$1;
|
|
59
|
-
const graphqlCodegenConfig = (options) => {
|
|
9
|
+
function graphqlCodegenConfig(options) {
|
|
60
10
|
const {
|
|
61
11
|
schemaUrl: providedSchemaUrl,
|
|
62
12
|
authToken: providedAuthToken,
|
|
@@ -71,7 +21,7 @@ const graphqlCodegenConfig = (options) => {
|
|
|
71
21
|
config({ path: localEnvPath, override: true });
|
|
72
22
|
const schemaUrl = providedSchemaUrl ?? process.env["NEXT_SERVER_GRAPHQL_URL"] ?? process.env["NEXT_PUBLIC_GRAPHQL_URL"];
|
|
73
23
|
const authToken = providedAuthToken ?? process.env["NEXT_PUBLIC_API_TOKEN"];
|
|
74
|
-
if (
|
|
24
|
+
if (schemaUrl == null || schemaUrl === "") {
|
|
75
25
|
const errorMsg = "GraphQL schema URL is not defined. Provide it as an option or set NEXT_SERVER_GRAPHQL_URL or NEXT_PUBLIC_GRAPHQL_URL environment variable.";
|
|
76
26
|
logger.log(errorMsg, "error");
|
|
77
27
|
throw new Error(errorMsg);
|
|
@@ -79,7 +29,7 @@ const graphqlCodegenConfig = (options) => {
|
|
|
79
29
|
const headers = {
|
|
80
30
|
...additionalHeaders
|
|
81
31
|
};
|
|
82
|
-
if (authToken) {
|
|
32
|
+
if (authToken != null && authToken !== "") {
|
|
83
33
|
headers["Authorization"] = `Bearer ${authToken}`;
|
|
84
34
|
}
|
|
85
35
|
const config$1 = {
|
|
@@ -105,7 +55,52 @@ const graphqlCodegenConfig = (options) => {
|
|
|
105
55
|
logger.log("Error creating GraphQL codegen configuration:", "error", { error });
|
|
106
56
|
throw error;
|
|
107
57
|
}
|
|
108
|
-
}
|
|
58
|
+
}
|
|
59
|
+
async function writeRedirectFile(filename, data) {
|
|
60
|
+
try {
|
|
61
|
+
const writeData = JSON.stringify(data ?? []);
|
|
62
|
+
await writeFile(filename, writeData);
|
|
63
|
+
return true;
|
|
64
|
+
} catch (e) {
|
|
65
|
+
logger.log(`Error writing redirect file ${filename}: ${e.message}`, "error");
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
async function readRedirectFileData(filename) {
|
|
70
|
+
try {
|
|
71
|
+
const file = await readFile(filename, { encoding: "utf8" });
|
|
72
|
+
const data = JSON.parse(file);
|
|
73
|
+
return data;
|
|
74
|
+
} catch (e) {
|
|
75
|
+
logger.log(`Failed loading redirects JSON from ${filename}: ${e.message}`, "error");
|
|
76
|
+
}
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
async function readRedirectFile(filePath, type = "redirects") {
|
|
80
|
+
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
81
|
+
const data = await readRedirectFileData(absolutePath);
|
|
82
|
+
const checkedData = data.filter((x) => {
|
|
83
|
+
return x != null && typeof x.source === "string" && typeof x.destination === "string";
|
|
84
|
+
});
|
|
85
|
+
logger.log(`Loading ${type} length: ${checkedData.length}`);
|
|
86
|
+
return checkedData;
|
|
87
|
+
}
|
|
88
|
+
async function fetchRedirects(config2) {
|
|
89
|
+
const { redirectsFilename, rewritesFilename } = config2;
|
|
90
|
+
if (redirectsFilename == null || redirectsFilename === "") {
|
|
91
|
+
throw new Error("Missing fetchRedirects configuration `redirectsFilename`");
|
|
92
|
+
}
|
|
93
|
+
if (rewritesFilename == null || rewritesFilename === "") {
|
|
94
|
+
throw new Error("Missing fetchRedirects configuration `rewritesFilename`");
|
|
95
|
+
}
|
|
96
|
+
const data = await fetchRedirectsData$1(config2);
|
|
97
|
+
await writeRedirectFile(redirectsFilename, data.redirects);
|
|
98
|
+
await writeRedirectFile(rewritesFilename, data.rewrites);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
const fetchRedirectsData = fetchRedirectsData$1;
|
|
102
|
+
const getDefaultConfig = getDefaultConfig$1;
|
|
103
|
+
const redirectDefaultLimit = redirectDefaultLimit$1;
|
|
109
104
|
export {
|
|
110
105
|
logger as DirectusNodeLogger,
|
|
111
106
|
fetchRedirects,
|
package/lib/codegen.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CodegenConfig } from '@graphql-codegen/cli';
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Configuration options for GraphQL code generation.
|
|
5
4
|
* This interface defines all the options that can be passed to the graphqlCodegenConfig function
|
|
@@ -74,5 +73,5 @@ export interface CodegenOptions {
|
|
|
74
73
|
* @param options - Configuration options for the codegen
|
|
75
74
|
* @returns GraphQL codegen configuration object that can be used with the GraphQL Code Generator
|
|
76
75
|
*/
|
|
77
|
-
declare
|
|
76
|
+
declare function graphqlCodegenConfig(options: CodegenOptions): CodegenConfig;
|
|
78
77
|
export default graphqlCodegenConfig;
|
|
@@ -12,5 +12,5 @@ export declare const getDefaultConfig: typeof fetchRedirectsDataFile.getDefaultC
|
|
|
12
12
|
*/
|
|
13
13
|
export declare const redirectDefaultLimit = 2000;
|
|
14
14
|
export type { TFetchRedirectsConfig, TFetchRedirectsResponse, TRedirectData, TRedirectType } from './interface';
|
|
15
|
-
export * from './utils/validateRedirects';
|
|
16
15
|
export * from './redirectsFile';
|
|
16
|
+
export * from './utils/validateRedirects';
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { TFetchRedirectsConfig,
|
|
2
|
-
|
|
1
|
+
import { TFetchRedirectsConfig, TRedirectData, TRedirectType } from './interface';
|
|
3
2
|
/**
|
|
4
3
|
* Write Redirect Data
|
|
5
4
|
* @param {string} filename filename
|
|
6
5
|
* @param {unknown} data redirects data (rewrites or redirects)
|
|
7
6
|
*/
|
|
8
7
|
export declare function writeRedirectFile(filename: string, data: unknown): Promise<boolean>;
|
|
9
|
-
export declare function readRedirectFileData(filename: string): Promise<
|
|
8
|
+
export declare function readRedirectFileData(filename: string): Promise<TRedirectData[]>;
|
|
10
9
|
/**
|
|
11
10
|
* Read one redirects or rewrites file
|
|
12
11
|
* @param {string} filePath relative file path like './redirect/redirects.json' to the current working dir
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { TRedirectData } from '../interface';
|
|
2
|
-
|
|
3
|
-
export declare function isRedirect(redirect: unknown): boolean;
|
|
2
|
+
export declare function isRedirect(redirect: unknown): redirect is TRedirectData;
|
|
4
3
|
export declare function normalizeRedirects(redirects: (TRedirectData | null)[] | null): TRedirectData[];
|
package/logger.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const logger: import('
|
|
1
|
+
export declare const logger: import('@okam/logger').Logger;
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okam/directus-node",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
3
|
+
"version": "0.7.3",
|
|
4
|
+
"repository": {
|
|
5
|
+
"url": "https://github.com/OKAMca/stack.git"
|
|
8
6
|
},
|
|
7
|
+
"sideEffects": false,
|
|
9
8
|
"exports": {
|
|
10
9
|
".": {
|
|
11
10
|
"import": {
|
|
@@ -28,13 +27,18 @@
|
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
},
|
|
31
|
-
"
|
|
32
|
-
|
|
30
|
+
"main": "./src/index.js",
|
|
31
|
+
"types": "./src/index.d.ts",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20.19.0"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
33
37
|
},
|
|
34
38
|
"dependencies": {
|
|
35
|
-
"@graphql-codegen/cli": "^
|
|
39
|
+
"@graphql-codegen/cli": "^6.1.1",
|
|
40
|
+
"@okam/core-lib": "1.17.2",
|
|
36
41
|
"@okam/logger": "1.1.0",
|
|
37
|
-
"dotenv": "^16.4.7"
|
|
38
|
-
"@okam/core-lib": "1.17.0"
|
|
42
|
+
"dotenv": "^16.4.7"
|
|
39
43
|
}
|
|
40
44
|
}
|