@okam/directus-node 0.6.2 → 0.7.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 +31 -0
- package/index.js +49 -19
- package/index.mjs +53 -22
- package/lib/codegen.d.ts +77 -1
- package/lib/redirection/fetchRedirectsData.d.ts +2 -1
- package/lib/redirection/redirectsFile.d.ts +2 -1
- package/lib/redirection/utils/validateRedirects.d.ts +2 -1
- package/logger.d.ts +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
## 0.7.2 (2026-01-19)
|
|
2
|
+
|
|
3
|
+
### 🧱 Updated Dependencies
|
|
4
|
+
|
|
5
|
+
- Updated core-lib to 1.17.1
|
|
6
|
+
|
|
7
|
+
## 0.7.1 (2026-01-19)
|
|
8
|
+
|
|
9
|
+
### 🩹 Fixes
|
|
10
|
+
|
|
11
|
+
- cross-lib type imports are always absolute ([#392](https://github.com/OKAMca/stack/pull/392))
|
|
12
|
+
|
|
13
|
+
### ❤️ Thank You
|
|
14
|
+
|
|
15
|
+
- Pierre-Olivier Clerson @poclerson
|
|
16
|
+
|
|
17
|
+
## 0.7.0 (2026-01-16)
|
|
18
|
+
|
|
19
|
+
### 🚀 Features
|
|
20
|
+
|
|
21
|
+
- **directus-query:** codegen file update ([82811eb](https://github.com/OKAMca/stack/commit/82811eb))
|
|
22
|
+
|
|
23
|
+
### 🩹 Fixes
|
|
24
|
+
|
|
25
|
+
- **directus-node:** stop bundling okam libs ([38cada6](https://github.com/OKAMca/stack/commit/38cada6))
|
|
26
|
+
|
|
27
|
+
### ❤️ Thank You
|
|
28
|
+
|
|
29
|
+
- Jérôme Trottier @JeromeTrottier
|
|
30
|
+
- poclerson
|
|
31
|
+
|
|
1
32
|
## 0.6.2 (2025-07-24)
|
|
2
33
|
|
|
3
34
|
### 🧱 Updated Dependencies
|
package/index.js
CHANGED
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const fetchRedirectsData$1 = require("./fetchRedirectsData-nz-uddGa.js");
|
|
4
4
|
require("@okam/core-lib");
|
|
5
5
|
const logger$1 = require("@okam/logger");
|
|
6
|
-
const promises = require("fs/promises");
|
|
7
6
|
const path = require("path");
|
|
7
|
+
const dotenv = require("dotenv");
|
|
8
|
+
const promises = require("fs/promises");
|
|
8
9
|
function _interopNamespaceDefault(e) {
|
|
9
10
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
11
|
if (e) {
|
|
@@ -72,26 +73,55 @@ async function fetchRedirects(config) {
|
|
|
72
73
|
const fetchRedirectsData = fetchRedirectsData$1.fetchRedirectsData;
|
|
73
74
|
const getDefaultConfig = fetchRedirectsData$1.getDefaultConfig;
|
|
74
75
|
const redirectDefaultLimit = fetchRedirectsData$1.redirectDefaultLimit;
|
|
75
|
-
const graphqlCodegenConfig = (
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
const graphqlCodegenConfig = (options) => {
|
|
77
|
+
const {
|
|
78
|
+
schemaUrl: providedSchemaUrl,
|
|
79
|
+
authToken: providedAuthToken,
|
|
80
|
+
documentsGlob,
|
|
81
|
+
outputPath,
|
|
82
|
+
projectRoot = process.cwd(),
|
|
83
|
+
additionalHeaders = {}
|
|
84
|
+
} = options;
|
|
85
|
+
try {
|
|
86
|
+
dotenv.config({ path: path.resolve(projectRoot, ".env") });
|
|
87
|
+
const localEnvPath = path.resolve(projectRoot, ".env.local");
|
|
88
|
+
dotenv.config({ path: localEnvPath, override: true });
|
|
89
|
+
const schemaUrl = providedSchemaUrl ?? process.env["NEXT_SERVER_GRAPHQL_URL"] ?? process.env["NEXT_PUBLIC_GRAPHQL_URL"];
|
|
90
|
+
const authToken = providedAuthToken ?? process.env["NEXT_PUBLIC_API_TOKEN"];
|
|
91
|
+
if (!schemaUrl) {
|
|
92
|
+
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
|
+
logger.log(errorMsg, "error");
|
|
94
|
+
throw new Error(errorMsg);
|
|
95
|
+
}
|
|
96
|
+
const headers = {
|
|
97
|
+
...additionalHeaders
|
|
98
|
+
};
|
|
99
|
+
if (authToken) {
|
|
100
|
+
headers["Authorization"] = `Bearer ${authToken}`;
|
|
101
|
+
}
|
|
102
|
+
const config = {
|
|
103
|
+
overwrite: true,
|
|
104
|
+
schema: [
|
|
105
|
+
{
|
|
106
|
+
[schemaUrl]: {
|
|
107
|
+
headers
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
documents: [path.resolve(projectRoot, documentsGlob)],
|
|
112
|
+
ignoreNoDocuments: true,
|
|
113
|
+
// for better experience with the watcher
|
|
114
|
+
generates: {
|
|
115
|
+
[path.resolve(projectRoot, outputPath)]: {
|
|
116
|
+
preset: "client"
|
|
82
117
|
}
|
|
83
118
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
preset: "client"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
return config;
|
|
119
|
+
};
|
|
120
|
+
return config;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
logger.log("Error creating GraphQL codegen configuration:", "error", { error });
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
95
125
|
};
|
|
96
126
|
exports.isRedirect = fetchRedirectsData$1.isRedirect;
|
|
97
127
|
exports.normalizeRedirects = fetchRedirectsData$1.normalizeRedirects;
|
package/index.mjs
CHANGED
|
@@ -2,8 +2,10 @@ import { f as fetchRedirectsData$1, g as getDefaultConfig$1, r as redirectDefaul
|
|
|
2
2
|
import { i, n } from "./fetchRedirectsData-DGLawlch.mjs";
|
|
3
3
|
import "@okam/core-lib";
|
|
4
4
|
import { createLogger } from "@okam/logger";
|
|
5
|
-
import { writeFile, readFile } from "fs/promises";
|
|
6
5
|
import * as path from "path";
|
|
6
|
+
import path__default from "path";
|
|
7
|
+
import { config } from "dotenv";
|
|
8
|
+
import { writeFile, readFile } from "fs/promises";
|
|
7
9
|
const logger = createLogger("[DirectusNode]");
|
|
8
10
|
async function writeRedirectFile(filename, data) {
|
|
9
11
|
try {
|
|
@@ -38,15 +40,15 @@ async function readRedirectFile(filePath, type = "redirects") {
|
|
|
38
40
|
logger.log(`Failed loading ${type}, not a valid array`, "error");
|
|
39
41
|
return [];
|
|
40
42
|
}
|
|
41
|
-
async function fetchRedirects(
|
|
42
|
-
const { redirectsFilename, rewritesFilename } =
|
|
43
|
+
async function fetchRedirects(config2) {
|
|
44
|
+
const { redirectsFilename, rewritesFilename } = config2;
|
|
43
45
|
if (!redirectsFilename) {
|
|
44
46
|
throw new Error("Missing fetchRedirects configuration `redirectsFilename`");
|
|
45
47
|
}
|
|
46
48
|
if (!rewritesFilename) {
|
|
47
49
|
throw new Error("Missing fetchRedirects configuration `rewritesFilename`");
|
|
48
50
|
}
|
|
49
|
-
const data = await fetchRedirectsData$1(
|
|
51
|
+
const data = await fetchRedirectsData$1(config2);
|
|
50
52
|
await writeRedirectFile(redirectsFilename, data.redirects);
|
|
51
53
|
await writeRedirectFile(rewritesFilename, data.rewrites);
|
|
52
54
|
return true;
|
|
@@ -54,26 +56,55 @@ async function fetchRedirects(config) {
|
|
|
54
56
|
const fetchRedirectsData = fetchRedirectsData$1;
|
|
55
57
|
const getDefaultConfig = getDefaultConfig$1;
|
|
56
58
|
const redirectDefaultLimit = redirectDefaultLimit$1;
|
|
57
|
-
const graphqlCodegenConfig = (
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
const graphqlCodegenConfig = (options) => {
|
|
60
|
+
const {
|
|
61
|
+
schemaUrl: providedSchemaUrl,
|
|
62
|
+
authToken: providedAuthToken,
|
|
63
|
+
documentsGlob,
|
|
64
|
+
outputPath,
|
|
65
|
+
projectRoot = process.cwd(),
|
|
66
|
+
additionalHeaders = {}
|
|
67
|
+
} = options;
|
|
68
|
+
try {
|
|
69
|
+
config({ path: path__default.resolve(projectRoot, ".env") });
|
|
70
|
+
const localEnvPath = path__default.resolve(projectRoot, ".env.local");
|
|
71
|
+
config({ path: localEnvPath, override: true });
|
|
72
|
+
const schemaUrl = providedSchemaUrl ?? process.env["NEXT_SERVER_GRAPHQL_URL"] ?? process.env["NEXT_PUBLIC_GRAPHQL_URL"];
|
|
73
|
+
const authToken = providedAuthToken ?? process.env["NEXT_PUBLIC_API_TOKEN"];
|
|
74
|
+
if (!schemaUrl) {
|
|
75
|
+
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
|
+
logger.log(errorMsg, "error");
|
|
77
|
+
throw new Error(errorMsg);
|
|
78
|
+
}
|
|
79
|
+
const headers = {
|
|
80
|
+
...additionalHeaders
|
|
81
|
+
};
|
|
82
|
+
if (authToken) {
|
|
83
|
+
headers["Authorization"] = `Bearer ${authToken}`;
|
|
84
|
+
}
|
|
85
|
+
const config$1 = {
|
|
86
|
+
overwrite: true,
|
|
87
|
+
schema: [
|
|
88
|
+
{
|
|
89
|
+
[schemaUrl]: {
|
|
90
|
+
headers
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
documents: [path__default.resolve(projectRoot, documentsGlob)],
|
|
95
|
+
ignoreNoDocuments: true,
|
|
96
|
+
// for better experience with the watcher
|
|
97
|
+
generates: {
|
|
98
|
+
[path__default.resolve(projectRoot, outputPath)]: {
|
|
99
|
+
preset: "client"
|
|
64
100
|
}
|
|
65
101
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
preset: "client"
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
return config;
|
|
102
|
+
};
|
|
103
|
+
return config$1;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
logger.log("Error creating GraphQL codegen configuration:", "error", { error });
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
77
108
|
};
|
|
78
109
|
export {
|
|
79
110
|
logger as DirectusNodeLogger,
|
package/lib/codegen.d.ts
CHANGED
|
@@ -1,2 +1,78 @@
|
|
|
1
|
-
|
|
1
|
+
import { CodegenConfig } from '@graphql-codegen/cli';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for GraphQL code generation.
|
|
5
|
+
* This interface defines all the options that can be passed to the graphqlCodegenConfig function
|
|
6
|
+
* to customize the GraphQL code generation process.
|
|
7
|
+
*/
|
|
8
|
+
export interface CodegenOptions {
|
|
9
|
+
/**
|
|
10
|
+
* URL of the GraphQL schema.
|
|
11
|
+
* If not provided, the function will try to use the NEXT_PUBLIC_GRAPHQL_URL environment variable.
|
|
12
|
+
* Example: 'https://api.example.com/graphql'
|
|
13
|
+
*/
|
|
14
|
+
schemaUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Authentication token for the GraphQL API.
|
|
17
|
+
* If not provided, the function will try to use the NEXT_PUBLIC_API_TOKEN environment variable.
|
|
18
|
+
* This token will be used to create an Authorization header with the format: "Bearer {token}".
|
|
19
|
+
*/
|
|
20
|
+
authToken?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Glob pattern for GraphQL documents.
|
|
23
|
+
* This pattern is used to find all GraphQL documents (queries, mutations, etc.) in your project.
|
|
24
|
+
* The pattern is relative to the projectRoot.
|
|
25
|
+
* Example: 'src/*.graphql'
|
|
26
|
+
*/
|
|
27
|
+
documentsGlob: string;
|
|
28
|
+
/**
|
|
29
|
+
* Path where generated files should be saved.
|
|
30
|
+
* This path is used as the output directory for the generated GraphQL client code.
|
|
31
|
+
* Example: 'src/lib/gql/generated/'
|
|
32
|
+
*/
|
|
33
|
+
outputPath: string;
|
|
34
|
+
/**
|
|
35
|
+
* Root directory of the project.
|
|
36
|
+
* This is used as the base directory for resolving relative paths.
|
|
37
|
+
* If not provided, the current working directory (process.cwd()) will be used.
|
|
38
|
+
*/
|
|
39
|
+
projectRoot?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Additional headers to include in GraphQL requests.
|
|
42
|
+
* These headers will be included in all requests to the GraphQL API.
|
|
43
|
+
* Example: { 'X-API-Key': 'your-api-key' }
|
|
44
|
+
*/
|
|
45
|
+
additionalHeaders?: Record<string, string>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a GraphQL codegen configuration that can be used across different projects.
|
|
49
|
+
*
|
|
50
|
+
* This function generates a configuration object for the GraphQL Code Generator based on the provided options.
|
|
51
|
+
* It handles environment variable loading, authentication, and path resolution to make the configuration
|
|
52
|
+
* reusable across different projects.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // Basic usage with minimal configuration
|
|
56
|
+
* const config = graphqlCodegenConfig({
|
|
57
|
+
* documentsGlob: 'src/*.graphql',
|
|
58
|
+
* outputPath: 'src/lib/gql/generated/'
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // Advanced usage with all options
|
|
63
|
+
* const config = graphqlCodegenConfig({
|
|
64
|
+
* schemaUrl: 'https://api.example.com/graphql',
|
|
65
|
+
* authToken: 'your-auth-token',
|
|
66
|
+
* documentsGlob: 'src/*.graphql',
|
|
67
|
+
* outputPath: 'src/lib/gql/generated/',
|
|
68
|
+
* projectRoot: '/path/to/your/project',
|
|
69
|
+
* additionalHeaders: {
|
|
70
|
+
* 'X-API-Key': 'your-api-key'
|
|
71
|
+
* }
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* @param options - Configuration options for the codegen
|
|
75
|
+
* @returns GraphQL codegen configuration object that can be used with the GraphQL Code Generator
|
|
76
|
+
*/
|
|
77
|
+
declare const graphqlCodegenConfig: (options: CodegenOptions) => CodegenConfig;
|
|
2
78
|
export default graphqlCodegenConfig;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { TRedirectData } from '../interface';
|
|
2
|
+
|
|
2
3
|
export declare function isRedirect(redirect: unknown): boolean;
|
|
3
4
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okam/directus-node",
|
|
3
3
|
"main": "./src/index.js",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.2",
|
|
5
5
|
"types": "./src/index.d.ts",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@graphql-codegen/cli": "^5.0.3",
|
|
36
36
|
"@okam/logger": "1.1.0",
|
|
37
|
-
"
|
|
37
|
+
"dotenv": "^16.4.7",
|
|
38
|
+
"@okam/core-lib": "1.17.1"
|
|
38
39
|
}
|
|
39
40
|
}
|