@constructive-io/graphql-server 4.40.1 → 4.40.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/esm/middleware/api.js +25 -18
- package/middleware/api.js +25 -18
- package/package.json +2 -2
package/esm/middleware/api.js
CHANGED
|
@@ -111,6 +111,21 @@ const resolveModuleSettings = async (registry, ctx) => {
|
|
|
111
111
|
// =============================================================================
|
|
112
112
|
const isApiError = (result) => !!result && typeof result.errorHtml === 'string';
|
|
113
113
|
const parseCommaSeparatedHeader = (value) => value.split(',').map((s) => s.trim()).filter(Boolean);
|
|
114
|
+
const getPrivateHeaderMode = (headers) => {
|
|
115
|
+
if (headers.apiName)
|
|
116
|
+
return 'api-name-header';
|
|
117
|
+
if (headers.schemata)
|
|
118
|
+
return 'schemata-header';
|
|
119
|
+
if (headers.metaSchema)
|
|
120
|
+
return 'meta-schema-header';
|
|
121
|
+
return null;
|
|
122
|
+
};
|
|
123
|
+
const getRoutingHeaders = (req) => ({
|
|
124
|
+
schemata: req.get('X-Schemata'),
|
|
125
|
+
apiName: req.get('X-Api-Name'),
|
|
126
|
+
metaSchema: req.get('X-Meta-Schema'),
|
|
127
|
+
databaseId: req.get('X-Database-Id'),
|
|
128
|
+
});
|
|
114
129
|
const getUrlDomains = (req) => {
|
|
115
130
|
const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
|
116
131
|
const parsed = parseUrl(fullUrl);
|
|
@@ -127,14 +142,16 @@ export const getSvcKey = (opts, req) => {
|
|
|
127
142
|
const { domain, subdomains } = getUrlDomains(req);
|
|
128
143
|
const baseKey = subdomains.filter((n) => n !== 'www').concat(domain).join('.');
|
|
129
144
|
if (opts.api?.isPublic === false) {
|
|
130
|
-
|
|
131
|
-
|
|
145
|
+
const headers = getRoutingHeaders(req);
|
|
146
|
+
const mode = getPrivateHeaderMode(headers);
|
|
147
|
+
if (mode === 'api-name-header') {
|
|
148
|
+
return `api:${headers.databaseId}:${headers.apiName}`;
|
|
132
149
|
}
|
|
133
|
-
if (
|
|
134
|
-
return `schemata:${
|
|
150
|
+
if (mode === 'schemata-header') {
|
|
151
|
+
return `schemata:${headers.databaseId}:${headers.schemata}`;
|
|
135
152
|
}
|
|
136
|
-
if (
|
|
137
|
-
return `metaschema:api:${
|
|
153
|
+
if (mode === 'meta-schema-header') {
|
|
154
|
+
return `metaschema:api:${headers.databaseId}`;
|
|
138
155
|
}
|
|
139
156
|
}
|
|
140
157
|
return baseKey;
|
|
@@ -193,12 +210,7 @@ const determineMode = (ctx) => {
|
|
|
193
210
|
if (opts.api?.enableServicesApi === false)
|
|
194
211
|
return 'services-disabled';
|
|
195
212
|
if (opts.api?.isPublic === false) {
|
|
196
|
-
|
|
197
|
-
return 'schemata-header';
|
|
198
|
-
if (headers.apiName)
|
|
199
|
-
return 'api-name-header';
|
|
200
|
-
if (headers.metaSchema)
|
|
201
|
-
return 'meta-schema-header';
|
|
213
|
+
return getPrivateHeaderMode(headers) ?? 'domain-lookup';
|
|
202
214
|
}
|
|
203
215
|
return 'domain-lookup';
|
|
204
216
|
};
|
|
@@ -320,12 +332,7 @@ export const getApiConfig = async (opts, req) => {
|
|
|
320
332
|
domain,
|
|
321
333
|
subdomain,
|
|
322
334
|
cacheKey,
|
|
323
|
-
headers:
|
|
324
|
-
schemata: req.get('X-Schemata'),
|
|
325
|
-
apiName: req.get('X-Api-Name'),
|
|
326
|
-
metaSchema: req.get('X-Meta-Schema'),
|
|
327
|
-
databaseId: req.get('X-Database-Id'),
|
|
328
|
-
},
|
|
335
|
+
headers: getRoutingHeaders(req),
|
|
329
336
|
};
|
|
330
337
|
// Validate schemas upfront for modes that need them
|
|
331
338
|
const apiOpts = opts.api || {};
|
package/middleware/api.js
CHANGED
|
@@ -117,6 +117,21 @@ const resolveModuleSettings = async (registry, ctx) => {
|
|
|
117
117
|
// =============================================================================
|
|
118
118
|
const isApiError = (result) => !!result && typeof result.errorHtml === 'string';
|
|
119
119
|
const parseCommaSeparatedHeader = (value) => value.split(',').map((s) => s.trim()).filter(Boolean);
|
|
120
|
+
const getPrivateHeaderMode = (headers) => {
|
|
121
|
+
if (headers.apiName)
|
|
122
|
+
return 'api-name-header';
|
|
123
|
+
if (headers.schemata)
|
|
124
|
+
return 'schemata-header';
|
|
125
|
+
if (headers.metaSchema)
|
|
126
|
+
return 'meta-schema-header';
|
|
127
|
+
return null;
|
|
128
|
+
};
|
|
129
|
+
const getRoutingHeaders = (req) => ({
|
|
130
|
+
schemata: req.get('X-Schemata'),
|
|
131
|
+
apiName: req.get('X-Api-Name'),
|
|
132
|
+
metaSchema: req.get('X-Meta-Schema'),
|
|
133
|
+
databaseId: req.get('X-Database-Id'),
|
|
134
|
+
});
|
|
120
135
|
const getUrlDomains = (req) => {
|
|
121
136
|
const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
|
122
137
|
const parsed = (0, url_domains_1.parseUrl)(fullUrl);
|
|
@@ -134,14 +149,16 @@ const getSvcKey = (opts, req) => {
|
|
|
134
149
|
const { domain, subdomains } = getUrlDomains(req);
|
|
135
150
|
const baseKey = subdomains.filter((n) => n !== 'www').concat(domain).join('.');
|
|
136
151
|
if (opts.api?.isPublic === false) {
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
const headers = getRoutingHeaders(req);
|
|
153
|
+
const mode = getPrivateHeaderMode(headers);
|
|
154
|
+
if (mode === 'api-name-header') {
|
|
155
|
+
return `api:${headers.databaseId}:${headers.apiName}`;
|
|
139
156
|
}
|
|
140
|
-
if (
|
|
141
|
-
return `schemata:${
|
|
157
|
+
if (mode === 'schemata-header') {
|
|
158
|
+
return `schemata:${headers.databaseId}:${headers.schemata}`;
|
|
142
159
|
}
|
|
143
|
-
if (
|
|
144
|
-
return `metaschema:api:${
|
|
160
|
+
if (mode === 'meta-schema-header') {
|
|
161
|
+
return `metaschema:api:${headers.databaseId}`;
|
|
145
162
|
}
|
|
146
163
|
}
|
|
147
164
|
return baseKey;
|
|
@@ -201,12 +218,7 @@ const determineMode = (ctx) => {
|
|
|
201
218
|
if (opts.api?.enableServicesApi === false)
|
|
202
219
|
return 'services-disabled';
|
|
203
220
|
if (opts.api?.isPublic === false) {
|
|
204
|
-
|
|
205
|
-
return 'schemata-header';
|
|
206
|
-
if (headers.apiName)
|
|
207
|
-
return 'api-name-header';
|
|
208
|
-
if (headers.metaSchema)
|
|
209
|
-
return 'meta-schema-header';
|
|
221
|
+
return getPrivateHeaderMode(headers) ?? 'domain-lookup';
|
|
210
222
|
}
|
|
211
223
|
return 'domain-lookup';
|
|
212
224
|
};
|
|
@@ -328,12 +340,7 @@ const getApiConfig = async (opts, req) => {
|
|
|
328
340
|
domain,
|
|
329
341
|
subdomain,
|
|
330
342
|
cacheKey,
|
|
331
|
-
headers:
|
|
332
|
-
schemata: req.get('X-Schemata'),
|
|
333
|
-
apiName: req.get('X-Api-Name'),
|
|
334
|
-
metaSchema: req.get('X-Meta-Schema'),
|
|
335
|
-
databaseId: req.get('X-Database-Id'),
|
|
336
|
-
},
|
|
343
|
+
headers: getRoutingHeaders(req),
|
|
337
344
|
};
|
|
338
345
|
// Validate schemas upfront for modes that need them
|
|
339
346
|
const apiOpts = opts.api || {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/graphql-server",
|
|
3
|
-
"version": "4.40.
|
|
3
|
+
"version": "4.40.2",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "Constructive GraphQL Server",
|
|
6
6
|
"main": "index.js",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"nodemon": "^3.1.14",
|
|
91
91
|
"ts-node": "^10.9.2"
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "ed31ed2aa63fcd2d42acec6f27e672dd300a3959"
|
|
94
94
|
}
|