@crimson-education/replit-sdk 1.0.1-alpha-10 → 1.0.1-alpha-11
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expressRouter.d.ts","sourceRoot":"","sources":["../../src/api/expressRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"expressRouter.d.ts","sourceRoot":"","sources":["../../src/api/expressRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAkDvC,eAAO,MAAM,OAAO,GAAI,KAAK,OAAO,SAGnC,CAAC"}
|
package/lib/api/expressRouter.js
CHANGED
|
@@ -2,48 +2,50 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.bindApi = void 0;
|
|
4
4
|
const graphqlProxy_1 = require("./graphqlProxy");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
details: parsed.error.issues,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
const { query, variables, graphqlEndpoint, token, env = 'replit' } = parsed.data;
|
|
16
|
-
const authHeader = token ? `Bearer ${token}` : req.headers.authorization;
|
|
17
|
-
if (!authHeader && env !== 'replit') {
|
|
18
|
-
return res.status(401).json({ error: 'Authorization header is required' });
|
|
19
|
-
}
|
|
20
|
-
const response = await fetch(graphqlEndpoint, {
|
|
21
|
-
method: 'POST',
|
|
22
|
-
headers: {
|
|
23
|
-
'Content-Type': 'application/json',
|
|
24
|
-
...(env !== 'replit' && { Authorization: authHeader }),
|
|
25
|
-
...(env === 'replit' && { crimsonauthkey: 'THIS_IS_A_FAKE_KEY' }),
|
|
26
|
-
},
|
|
27
|
-
body: JSON.stringify({ query, variables }),
|
|
5
|
+
const handler = async (req, res) => {
|
|
6
|
+
try {
|
|
7
|
+
const parsed = graphqlProxy_1.graphqlProxySchema.safeParse(req.body);
|
|
8
|
+
if (!parsed.success) {
|
|
9
|
+
return res.status(400).json({
|
|
10
|
+
error: 'Invalid request body',
|
|
11
|
+
details: parsed.error.issues,
|
|
28
12
|
});
|
|
29
|
-
const contentType = response.headers.get('content-type') || '';
|
|
30
|
-
if (!contentType.includes('application/json')) {
|
|
31
|
-
const text = await response.text();
|
|
32
|
-
console.error('GraphQL endpoint returned non-JSON response:', response.status, text.substring(0, 200));
|
|
33
|
-
return res.status(response.status === 200 ? 502 : response.status).json({
|
|
34
|
-
error: 'GraphQL endpoint returned invalid response',
|
|
35
|
-
status: response.status,
|
|
36
|
-
message: response.status === 401 ? 'Authentication failed - invalid or expired token' : 'Unexpected response format',
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
const data = await response.json();
|
|
40
|
-
res.status(response.status).json(data);
|
|
41
13
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
14
|
+
const { query, variables, graphqlEndpoint, token, env = 'replit' } = parsed.data;
|
|
15
|
+
const authHeader = token ? `Bearer ${token}` : req.headers.authorization;
|
|
16
|
+
if (!authHeader && env !== 'replit') {
|
|
17
|
+
return res.status(401).json({ error: 'Authorization header is required' });
|
|
18
|
+
}
|
|
19
|
+
const response = await fetch(graphqlEndpoint, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
...(env !== 'replit' && { Authorization: authHeader }),
|
|
24
|
+
...(env === 'replit' && { crimsonauthkey: 'THIS_IS_A_FAKE_KEY' }),
|
|
25
|
+
},
|
|
26
|
+
body: JSON.stringify({ query, variables }),
|
|
27
|
+
});
|
|
28
|
+
const contentType = response.headers.get('content-type') || '';
|
|
29
|
+
if (!contentType.includes('application/json')) {
|
|
30
|
+
const text = await response.text();
|
|
31
|
+
console.error('GraphQL endpoint returned non-JSON response:', response.status, text.substring(0, 200));
|
|
32
|
+
return res.status(response.status === 200 ? 502 : response.status).json({
|
|
33
|
+
error: 'GraphQL endpoint returned invalid response',
|
|
34
|
+
status: response.status,
|
|
35
|
+
message: response.status === 401 ? 'Authentication failed - invalid or expired token' : 'Unexpected response format',
|
|
36
|
+
});
|
|
45
37
|
}
|
|
46
|
-
|
|
38
|
+
const data = await response.json();
|
|
39
|
+
res.status(response.status).json(data);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error('GraphQL proxy error:', error);
|
|
43
|
+
res.status(500).json({ error: 'Failed to execute GraphQL query' });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const bindApi = (app) => {
|
|
47
|
+
app.post('/api/function', handler);
|
|
48
|
+
app.post('/api/function/:operation', handler);
|
|
47
49
|
};
|
|
48
50
|
exports.bindApi = bindApi;
|
|
49
51
|
//# sourceMappingURL=expressRouter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expressRouter.js","sourceRoot":"","sources":["../../src/api/expressRouter.ts"],"names":[],"mappings":";;;AACA,iDAAoD;
|
|
1
|
+
{"version":3,"file":"expressRouter.js","sourceRoot":"","sources":["../../src/api/expressRouter.ts"],"names":[],"mappings":";;;AACA,iDAAoD;AAEpD,MAAM,OAAO,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IACjC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,iCAAkB,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC1B,KAAK,EAAE,sBAAsB;gBAC7B,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM;aAC7B,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE,KA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