@okam/directus-node 0.2.0 → 0.3.0
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 +37 -0
- package/README.md +6 -0
- package/package.json +1 -1
- package/src/lib/redirection.d.ts +2 -0
- package/src/lib/redirection.js +14 -8
- package/src/lib/redirection.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
## 0.3.0 (2024-09-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🚀 Features
|
|
5
|
+
|
|
6
|
+
- Add console log for redirects and rewrites count ([2ae2d19](https://github.com/OKAMca/stack/commit/2ae2d19))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### 🩹 Fixes
|
|
10
|
+
|
|
11
|
+
- add console.warn with error in catch block ([865cd5e](https://github.com/OKAMca/stack/commit/865cd5e))
|
|
12
|
+
|
|
13
|
+
- return true on error when fetching redirects ([54c34c6](https://github.com/OKAMca/stack/commit/54c34c6))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### ❤️ Thank You
|
|
17
|
+
|
|
18
|
+
- David Paquet Pitts
|
|
19
|
+
- David Paquet Pitts (aider)
|
|
20
|
+
|
|
21
|
+
## 0.2.1 (2024-09-06)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### 🩹 Fixes
|
|
25
|
+
|
|
26
|
+
- **directus-node:** adding limit = 200 for graphql redirects queries ([#192](https://github.com/OKAMca/stack/pull/192))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### ❤️ Thank You
|
|
30
|
+
|
|
31
|
+
- Marie-Maxime Tanguay @marie-maxime
|
|
32
|
+
- mykimd @mykimd
|
|
33
|
+
- Pierre-Olivier Clerson @poclerson
|
|
34
|
+
- poclerson
|
|
35
|
+
- Yan Morin
|
|
36
|
+
- yanmorinokamca @yanmorinokamca
|
|
37
|
+
|
|
1
38
|
## 0.2.0 (2024-07-25)
|
|
2
39
|
|
|
3
40
|
|
package/README.md
CHANGED
|
@@ -22,6 +22,12 @@ Run `nx test directus-node` to execute the unit tests via [Jest](https://jestjs.
|
|
|
22
22
|
*/
|
|
23
23
|
const { fetchRedirects, getDefaultConfig } = require('@okam/directus-node')
|
|
24
24
|
|
|
25
|
+
// getDefaultConfig() will return an object with
|
|
26
|
+
// graphqlEndpoint: use environment variable NEXT_PUBLIC_GRAPHQL_URL
|
|
27
|
+
// graphqlApiKey: use environment variable NEXT_API_TOKEN_ADMIN
|
|
28
|
+
// redirectsFilename
|
|
29
|
+
// rewritesFilename
|
|
30
|
+
// limit: 2000 (number of redirect or rewrite rules fetched by graphql)
|
|
25
31
|
fetchRedirects(getDefaultConfig())
|
|
26
32
|
```
|
|
27
33
|
|
package/package.json
CHANGED
package/src/lib/redirection.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ interface TFetchRedirectsConfig {
|
|
|
3
3
|
graphqlApiKey: string;
|
|
4
4
|
redirectsFilename: string;
|
|
5
5
|
rewritesFilename: string;
|
|
6
|
+
limit: number | undefined;
|
|
6
7
|
}
|
|
8
|
+
export declare const redirectDefaultLimit = 2000;
|
|
7
9
|
/**
|
|
8
10
|
* Get Fetch Redirects Configuration
|
|
9
11
|
* @returns {object}
|
package/src/lib/redirection.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchRedirects = exports.getDefaultConfig = void 0;
|
|
3
|
+
exports.fetchRedirects = exports.getDefaultConfig = exports.redirectDefaultLimit = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const promises_1 = require("node:fs/promises");
|
|
6
|
+
exports.redirectDefaultLimit = 2000;
|
|
6
7
|
/**
|
|
7
8
|
* Get Fetch Redirects Configuration
|
|
8
9
|
* @returns {object}
|
|
@@ -13,26 +14,28 @@ function getDefaultConfig() {
|
|
|
13
14
|
graphqlApiKey: process.env['NEXT_API_TOKEN_ADMIN'] || '',
|
|
14
15
|
redirectsFilename: './redirect/redirects.json',
|
|
15
16
|
rewritesFilename: './redirect/rewrites.json',
|
|
17
|
+
limit: exports.redirectDefaultLimit,
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
20
|
exports.getDefaultConfig = getDefaultConfig;
|
|
19
21
|
function fetchRedirects(config) {
|
|
20
22
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const { graphqlEndpoint, graphqlApiKey, redirectsFilename, rewritesFilename, limit } = config;
|
|
22
25
|
if (!graphqlEndpoint || !graphqlApiKey) {
|
|
23
26
|
throw new Error('Missing graphql configuration: NEXT_PUBLIC_GRAPHQL_URL or NEXT_API_TOKEN_ADMIN');
|
|
24
27
|
}
|
|
25
28
|
if (!redirectsFilename || !rewritesFilename) {
|
|
26
29
|
throw new Error('Missing filename');
|
|
27
30
|
}
|
|
28
|
-
const query = `query fetchRedirects {
|
|
29
|
-
redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:false}}, sort: "sort") {
|
|
31
|
+
const query = `query fetchRedirects($limit: Int = 2000) {
|
|
32
|
+
redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:false}}, sort: "sort", limit: $limit) {
|
|
30
33
|
source
|
|
31
34
|
destination
|
|
32
35
|
permanent
|
|
33
36
|
locale
|
|
34
37
|
}
|
|
35
|
-
rewrites: redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:true}}, sort: "sort") {
|
|
38
|
+
rewrites: redirects(filter: {status:{_eq:"published"},isrewrite:{_eq:true}}, sort: "sort", limit: $limit) {
|
|
36
39
|
source
|
|
37
40
|
destination
|
|
38
41
|
permanent
|
|
@@ -42,7 +45,9 @@ function fetchRedirects(config) {
|
|
|
42
45
|
const graphqlBody = {
|
|
43
46
|
query,
|
|
44
47
|
// "operationName": "",
|
|
45
|
-
variables: {
|
|
48
|
+
variables: {
|
|
49
|
+
limit: Number(limit) || exports.redirectDefaultLimit,
|
|
50
|
+
},
|
|
46
51
|
};
|
|
47
52
|
try {
|
|
48
53
|
// console.info(`Fetching redirects on ${graphqlEndpoint}`)
|
|
@@ -60,10 +65,11 @@ function fetchRedirects(config) {
|
|
|
60
65
|
yield (0, promises_1.writeFile)(redirectsFilename, writeDataRedirects);
|
|
61
66
|
const writeDataRewrites = JSON.stringify(data.rewrites || []);
|
|
62
67
|
yield (0, promises_1.writeFile)(rewritesFilename, writeDataRewrites);
|
|
68
|
+
console.log(`Redirects count: ${((_a = data.redirects) === null || _a === void 0 ? void 0 : _a.length) || 0}, Rewrites count: ${((_b = data.rewrites) === null || _b === void 0 ? void 0 : _b.length) || 0}`);
|
|
63
69
|
}
|
|
64
70
|
catch (e) {
|
|
65
|
-
|
|
66
|
-
//
|
|
71
|
+
console.warn('Error fetching redirects:', e.message);
|
|
72
|
+
return true; // still want build to pass
|
|
67
73
|
}
|
|
68
74
|
return true;
|
|
69
75
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirection.js","sourceRoot":"","sources":["../../../../../../libs/directus/directus-node/src/lib/redirection.ts"],"names":[],"mappings":";;;;AAAA,+CAA4C;
|
|
1
|
+
{"version":3,"file":"redirection.js","sourceRoot":"","sources":["../../../../../../libs/directus/directus-node/src/lib/redirection.ts"],"names":[],"mappings":";;;;AAAA,+CAA4C;AAU/B,QAAA,oBAAoB,GAAG,IAAI,CAAA;AAExC;;;GAGG;AACH,SAAgB,gBAAgB;IAC9B,OAAO;QACL,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,IAAI,EAAE;QAC7D,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,EAAE;QACxD,iBAAiB,EAAE,2BAA2B;QAC9C,gBAAgB,EAAE,0BAA0B;QAC5C,KAAK,EAAE,4BAAoB;KAC5B,CAAA;AACH,CAAC;AARD,4CAQC;AAED,SAAsB,cAAc,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