@gen3/toolsff 0.12.41 → 0.12.43
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/dist/scanSitePaths.esm.js +14 -14
- package/package.json +3 -3
- package/dist/gdcGqlToGuppyGql.esm.js +0 -148
|
@@ -37,7 +37,7 @@ function normalizeRoute(route) {
|
|
|
37
37
|
if (r.length > 1) r = r.replace(/\/$/, '');
|
|
38
38
|
return r;
|
|
39
39
|
}
|
|
40
|
-
// ✅ Convert Next.js pages-style dynamic segments to
|
|
40
|
+
// ✅ Convert Next.js pages-style dynamic segments to proxy matcher syntax
|
|
41
41
|
function routeToMiddlewareMatcher(route) {
|
|
42
42
|
// route examples:
|
|
43
43
|
// "/Explorer/[configId]" -> "/Explorer/:configId"
|
|
@@ -94,47 +94,47 @@ function getMatcherFromAuthConfig(authConfig) {
|
|
|
94
94
|
const excluded = new Set(DEFAULT_EXCLUDED_ROUTES.map(normalizeRoute));
|
|
95
95
|
return normalizedRoutes.filter((r)=>!excluded.has(r));
|
|
96
96
|
}
|
|
97
|
-
// ✅ Generates the actual Next
|
|
97
|
+
// ✅ Generates the actual Next proxy entry file with literal matcher
|
|
98
98
|
function writeGeneratedMiddlewareEntryTs(matcher, opts = {}) {
|
|
99
|
-
const outputFile = path.resolve(opts.outputFile || './src/
|
|
100
|
-
const body = `// @generated by tools/scanSitePaths.ts\n` + `// Do not edit manually. Edit src/
|
|
101
|
-
console.log(`Writing generated
|
|
99
|
+
const outputFile = path.resolve(opts.outputFile || './src/proxy.ts');
|
|
100
|
+
const body = `// @generated by tools/scanSitePaths.ts\n` + `// Do not edit manually. Edit src/proxy-impl.ts instead.\n` + `export { proxy } from './proxy-impl';\n\n` + `export const config = {\n` + ` matcher: ${JSON.stringify(matcher, null, 2)},\n` + `};\n`;
|
|
101
|
+
console.log(`Writing generated proxy entry to ${outputFile}`);
|
|
102
102
|
fs.mkdirSync(path.dirname(outputFile), {
|
|
103
103
|
recursive: true
|
|
104
104
|
});
|
|
105
105
|
fs.writeFileSync(outputFile, body);
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
-
* Configures and generates
|
|
108
|
+
* Configures and generates proxy route matchers based on authentication and routing requirements.
|
|
109
109
|
*
|
|
110
|
-
* The function determines the set of
|
|
111
|
-
* whether all pages require login. It generates appropriate route matchers for
|
|
110
|
+
* The function determines the set of proxy routes based on the authentication configuration and
|
|
111
|
+
* whether all pages require login. It generates appropriate route matchers for proxy processing
|
|
112
112
|
* and writes the resulting matchers to a TypeScript file for use in the application.
|
|
113
113
|
*
|
|
114
114
|
* @param {boolean} [useScanAllPaths=false] - A flag to determine whether to include all application routes
|
|
115
|
-
* in the
|
|
115
|
+
* in the proxy path matcher. If true, all application routes
|
|
116
116
|
* are scanned and included; otherwise, specific routes from the
|
|
117
117
|
* authentication configuration are considered.
|
|
118
|
-
* @param forceMatchAll - set to true to force all routes to be matched by the
|
|
118
|
+
* @param forceMatchAll - set to true to force all routes to be matched by the proxy.
|
|
119
119
|
*/ const createMiddlewareRoutes = (useScanAllPaths = false, forceMatchAll = false)=>{
|
|
120
120
|
const authConfig = loadAuthConfig();
|
|
121
121
|
const allPagesRequireLogin = authConfig?.routes?.['*']?.loginRequired;
|
|
122
122
|
let routes;
|
|
123
123
|
if (allPagesRequireLogin || forceMatchAll) {
|
|
124
|
-
console.log('All pages require login. Adding all routes to
|
|
124
|
+
console.log('All pages require login. Adding all routes to proxy path matcher.');
|
|
125
125
|
routes = useScanAllPaths ? getPagesRoutes() : []; // setting to [] will cause the matcher to be set below
|
|
126
126
|
} else {
|
|
127
|
-
console.log('Some pages require login. Adding authz routes to
|
|
127
|
+
console.log('Some pages require login. Adding authz routes to proxy path matcher.');
|
|
128
128
|
routes = getMatcherFromAuthConfig(authConfig);
|
|
129
129
|
}
|
|
130
|
-
// ✅ Convert to valid
|
|
130
|
+
// ✅ Convert to valid proxy matcher patterns
|
|
131
131
|
let matcher = (routes || []).map(routeToMiddlewareMatcher);
|
|
132
132
|
if (matcher.length === 0) {
|
|
133
133
|
matcher = [
|
|
134
134
|
'/((?!_next/static|_next/image|_next/data|Login|api|403|404|no-workspace-access|favicon.ico|.*\\.ico$|.*\\.png$|.*\\.jpg$|.*\\.svg$|.*\\.json$).*)'
|
|
135
135
|
];
|
|
136
136
|
}
|
|
137
|
-
console.log(`
|
|
137
|
+
console.log(`proxy matcher entries:\n${matcher.join('\n')}`);
|
|
138
138
|
writeGeneratedMiddlewareEntryTs(matcher);
|
|
139
139
|
};
|
|
140
140
|
function main() {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gen3/toolsff",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.43",
|
|
4
4
|
"description": "tools for processing Gen3 commons content: color theme, icons, sharedFilters",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
8
8
|
"npm": ">=11.9.0",
|
|
9
|
-
"node": ">=24.
|
|
9
|
+
"node": ">=24.15.0"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"lint": "eslint --ext .js,.ts src",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"axios": "^1.8.2"
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "8948283d154e2a56a7dbc0b4218cc187c293485e"
|
|
52
52
|
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
const getArgs = (defaults)=>{
|
|
2
|
-
const args = {
|
|
3
|
-
...defaults
|
|
4
|
-
};
|
|
5
|
-
process.argv.slice(2, process.argv.length).forEach((arg)=>{
|
|
6
|
-
// long arg
|
|
7
|
-
if (arg.slice(0, 2) === '--') {
|
|
8
|
-
const longArg = arg.split('=');
|
|
9
|
-
const longArgFlag = longArg[0].slice(2, longArg[0].length);
|
|
10
|
-
const longArgValue = longArg.length > 1 ? longArg[1] : true;
|
|
11
|
-
args[longArgFlag] = longArgValue;
|
|
12
|
-
} else if (arg[0] === '-') {
|
|
13
|
-
const flags = arg.slice(1, arg.length).split('');
|
|
14
|
-
flags.forEach((flag)=>{
|
|
15
|
-
args[flag] = true;
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return args;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const assertNever = (x)=>{
|
|
23
|
-
throw Error(`Exhaustive comparison did not handle: ${x}`);
|
|
24
|
-
};
|
|
25
|
-
const handleGqlOperation = (handler, op)=>{
|
|
26
|
-
switch(op.op){
|
|
27
|
-
case '=':
|
|
28
|
-
return handler.handleEquals(op);
|
|
29
|
-
case '!=':
|
|
30
|
-
return handler.handleNotEquals(op);
|
|
31
|
-
case '<':
|
|
32
|
-
return handler.handleLessThan(op);
|
|
33
|
-
case '<=':
|
|
34
|
-
return handler.handleLessThanOrEquals(op);
|
|
35
|
-
case '>':
|
|
36
|
-
return handler.handleGreaterThan(op);
|
|
37
|
-
case '>=':
|
|
38
|
-
return handler.handleGreaterThanOrEquals(op);
|
|
39
|
-
// case "is":
|
|
40
|
-
// return handler.handleMissing(op);
|
|
41
|
-
// case "not":
|
|
42
|
-
// return handler.handleExists(op);
|
|
43
|
-
case 'in':
|
|
44
|
-
return handler.handleIncludes(op);
|
|
45
|
-
case 'exclude':
|
|
46
|
-
return handler.handleExcludes(op);
|
|
47
|
-
case 'excludeifany':
|
|
48
|
-
return handler.handleExcludeIfAny(op);
|
|
49
|
-
case 'and':
|
|
50
|
-
return handler.handleIntersection(op);
|
|
51
|
-
case 'or':
|
|
52
|
-
return handler.handleUnion(op);
|
|
53
|
-
default:
|
|
54
|
-
return assertNever(op);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// a handler to convert from gql to guppy gql
|
|
59
|
-
class FromGDCToGen3 {
|
|
60
|
-
constructor(){
|
|
61
|
-
this.handleEquals = (op)=>({
|
|
62
|
-
"=": {
|
|
63
|
-
[op.content.field]: op.content.value
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
this.handleNotEquals = (op)=>({
|
|
67
|
-
"!=": {
|
|
68
|
-
[op.content.field]: op.content.value
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
this.handleLessThan = (op)=>({
|
|
72
|
-
"<": {
|
|
73
|
-
[op.content.field]: op.content.value
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
this.handleLessThanOrEquals = (op)=>({
|
|
77
|
-
"<=": {
|
|
78
|
-
[op.content.field]: op.content.value
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
this.handleGreaterThan = (op)=>({
|
|
82
|
-
">": {
|
|
83
|
-
[op.content.field]: op.content.value
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
this.handleGreaterThanOrEquals = (op)=>({
|
|
87
|
-
">=": {
|
|
88
|
-
[op.content.field]: op.content.value
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
// handleMissing = (op: GqlMissing): Missing => ({
|
|
92
|
-
// operator: "missing",
|
|
93
|
-
// field: op.content.field,
|
|
94
|
-
// });
|
|
95
|
-
// handleExists = (op: GqlExists): Exists => ({
|
|
96
|
-
// operator: "exists",
|
|
97
|
-
// field: op.content.field,
|
|
98
|
-
// });
|
|
99
|
-
this.handleIncludes = (op)=>({
|
|
100
|
-
"in": {
|
|
101
|
-
[op.content.field]: op.content.value
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
this.handleExcludes = (op)=>({
|
|
105
|
-
"exclude": {
|
|
106
|
-
[op.content.field]: op.content.value
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
this.handleExcludeIfAny = (op)=>({
|
|
110
|
-
"excludeifany": {
|
|
111
|
-
[op.content.field]: op.content.value instanceof Array ? op.content.value : [
|
|
112
|
-
op.content.value
|
|
113
|
-
]
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
this.handleIntersection = (op)=>({
|
|
117
|
-
and: op.content.map(convertGDCFilterToGen3Filter)
|
|
118
|
-
});
|
|
119
|
-
this.handleUnion = (op)=>({
|
|
120
|
-
or: op.content.map(convertGDCFilterToGen3Filter)
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const convertGDCFilterToGen3Filter = (gqlFilter)=>{
|
|
125
|
-
const handler = new FromGDCToGen3();
|
|
126
|
-
return handleGqlOperation(handler, gqlFilter);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const main = async ()=>{
|
|
130
|
-
console.log('Starting');
|
|
131
|
-
try {
|
|
132
|
-
const { query } = getArgs({
|
|
133
|
-
query: ''
|
|
134
|
-
});
|
|
135
|
-
if (!query) {
|
|
136
|
-
console.log('No query provided');
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
console.log('query', query);
|
|
140
|
-
const gdcQuery = JSON.parse(query);
|
|
141
|
-
console.log(gdcQuery);
|
|
142
|
-
const gen3Query = convertGDCFilterToGen3Filter(gdcQuery);
|
|
143
|
-
console.log(gen3Query);
|
|
144
|
-
} catch (e) {
|
|
145
|
-
console.log('Invalid query');
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
main();
|