@terreno/api 0.23.1 → 0.25.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/README.md +1 -0
- package/dist/__tests__/versionCheckPlugin.test.js +47 -2
- package/dist/api.query.test.js +99 -0
- package/dist/auth.compile.test.d.ts +1 -0
- package/dist/auth.compile.test.js +201 -0
- package/dist/auth.js +38 -7
- package/dist/auth.test.js +249 -0
- package/dist/betterAuthSetup.test.js +76 -0
- package/dist/docLoader.test.js +0 -1
- package/dist/expressServer.d.ts +25 -1
- package/dist/expressServer.js +1 -3
- package/dist/expressServer.test.js +15 -8
- package/dist/githubAuth.d.ts +1 -1
- package/dist/httpClient.d.ts +119 -0
- package/dist/httpClient.js +412 -0
- package/dist/httpClient.test.d.ts +1 -0
- package/dist/httpClient.test.js +1470 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/notifiers/googleChatNotifier.test.js +0 -1
- package/dist/populate.test.js +30 -0
- package/dist/realtime/queryStore.d.ts +3 -3
- package/dist/realtime/queryStore.js +0 -1
- package/dist/realtime/realtime.test.js +22 -0
- package/dist/tests/fixtures/compileAuthEntry.d.ts +1 -0
- package/dist/tests/fixtures/compileAuthEntry.js +37 -0
- package/dist/transformers.test.js +0 -1
- package/package.json +2 -2
- package/src/__tests__/versionCheckPlugin.test.ts +37 -2
- package/src/api.query.test.ts +59 -0
- package/src/auth.compile.test.ts +106 -0
- package/src/auth.test.ts +177 -0
- package/src/auth.ts +49 -7
- package/src/betterAuthSetup.test.ts +65 -0
- package/src/docLoader.test.ts +4 -4
- package/src/expressServer.test.ts +17 -8
- package/src/expressServer.ts +30 -6
- package/src/githubAuth.ts +2 -4
- package/src/httpClient.test.ts +979 -0
- package/src/httpClient.ts +464 -0
- package/src/index.ts +1 -0
- package/src/notifiers/googleChatNotifier.test.ts +5 -4
- package/src/populate.test.ts +32 -0
- package/src/realtime/queryStore.ts +6 -7
- package/src/realtime/realtime.test.ts +28 -2
- package/src/realtime/realtimeApp.ts +3 -3
- package/src/tests/fixtures/compileAuthEntry.ts +43 -0
- package/src/transformers.test.ts +15 -8
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Minimal server for the bun-compile auth regression test
|
|
2
|
+
// (src/auth.compile.test.ts). Registers a real passport JWT strategy and
|
|
3
|
+
// guards one route with authenticateMiddleware, using the same error
|
|
4
|
+
// middleware chain as expressServer. Compiled with `bun build --compile`, an
|
|
5
|
+
// unauthenticated request must produce a 401 — not a 500 from passport's
|
|
6
|
+
// strict-mode-illegal AuthenticationError (`arguments.callee`).
|
|
7
|
+
|
|
8
|
+
import express from "express";
|
|
9
|
+
import passport from "passport";
|
|
10
|
+
import {ExtractJwt, Strategy as JwtStrategy} from "passport-jwt";
|
|
11
|
+
import {authenticateMiddleware} from "../../auth";
|
|
12
|
+
import {apiErrorMiddleware, apiUnauthorizedMiddleware} from "../../errors";
|
|
13
|
+
|
|
14
|
+
passport.use(
|
|
15
|
+
"jwt",
|
|
16
|
+
new JwtStrategy(
|
|
17
|
+
{
|
|
18
|
+
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
19
|
+
secretOrKey: "compile-test-secret",
|
|
20
|
+
},
|
|
21
|
+
(payload, done) => done(null, payload)
|
|
22
|
+
)
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const app = express();
|
|
26
|
+
app.use(passport.initialize());
|
|
27
|
+
|
|
28
|
+
app.get("/secure", authenticateMiddleware(), (_req, res) => {
|
|
29
|
+
res.json({data: "ok"});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
app.use(apiUnauthorizedMiddleware);
|
|
33
|
+
app.use(apiErrorMiddleware);
|
|
34
|
+
// Terreno's fallthrough: anything reaching here surfaces as a 500. The
|
|
35
|
+
// regression turns auth failures into exactly this kind of error.
|
|
36
|
+
app.use((err: Error, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
|
|
37
|
+
res.status(500).json({status: 500, title: `Fallthrough error: ${err.message}`});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const port = Number(process.env.PORT ?? 0);
|
|
41
|
+
app.listen(port, () => {
|
|
42
|
+
console.info(`LISTENING ${port}`);
|
|
43
|
+
});
|
package/src/transformers.test.ts
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
1
|
import {beforeEach, describe, expect, it} from "bun:test";
|
|
3
2
|
import type express from "express";
|
|
4
|
-
import type {Document, ObjectId} from "mongoose";
|
|
3
|
+
import type {Document, HydratedDocument, ObjectId} from "mongoose";
|
|
5
4
|
import supertest from "supertest";
|
|
6
5
|
import type TestAgent from "supertest/lib/agent";
|
|
7
6
|
|
|
8
7
|
import type {ModelRouterOptions} from "./api";
|
|
9
8
|
import {modelRouter} from "./api";
|
|
10
|
-
import {addAuthRoutes, setupAuth} from "./auth";
|
|
9
|
+
import {type UserModel as AuthUserModel, addAuthRoutes, setupAuth} from "./auth";
|
|
11
10
|
import {APIError} from "./errors";
|
|
12
11
|
import {Permissions} from "./permissions";
|
|
13
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
authAsUser,
|
|
14
|
+
type Food,
|
|
15
|
+
FoodModel,
|
|
16
|
+
getBaseServer,
|
|
17
|
+
setupTestData,
|
|
18
|
+
type User,
|
|
19
|
+
UserModel,
|
|
20
|
+
} from "./tests";
|
|
14
21
|
import {AdminOwnerTransformer, defaultResponseHandler, transform} from "./transformers";
|
|
15
22
|
|
|
16
23
|
describe("query and transform", () => {
|
|
17
|
-
let notAdmin:
|
|
18
|
-
let admin:
|
|
24
|
+
let notAdmin: HydratedDocument<User>;
|
|
25
|
+
let admin: HydratedDocument<User>;
|
|
19
26
|
let server: TestAgent;
|
|
20
27
|
let app: express.Application;
|
|
21
28
|
|
|
@@ -26,8 +33,8 @@ describe("query and transform", () => {
|
|
|
26
33
|
admin = testData.users.admin;
|
|
27
34
|
notAdmin = testData.users.notAdmin;
|
|
28
35
|
app = getBaseServer();
|
|
29
|
-
setupAuth(app, UserModel as
|
|
30
|
-
addAuthRoutes(app, UserModel as
|
|
36
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
37
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
31
38
|
app.use(
|
|
32
39
|
"/food",
|
|
33
40
|
modelRouter(FoodModel, {
|