@wopr-network/platform-core 0.1.0 → 1.0.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/.github/workflows/ci.yml +43 -0
- package/.github/workflows/dependabot-auto-merge.yml +11 -0
- package/.github/workflows/publish.yml +12 -0
- package/.pr_agent.toml +10 -0
- package/package.json +9 -1
- package/dist/email/require-verified.test.d.ts +0 -1
- package/dist/email/require-verified.test.js +0 -62
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
merge_group:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: [main]
|
|
9
|
+
|
|
10
|
+
permissions: {}
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
ci:
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
pull-requests: write
|
|
17
|
+
runs-on: [self-hosted, Linux, X64]
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- uses: pnpm/action-setup@v4
|
|
22
|
+
|
|
23
|
+
- uses: actions/setup-node@v4
|
|
24
|
+
with:
|
|
25
|
+
node-version: "24"
|
|
26
|
+
cache: "pnpm"
|
|
27
|
+
|
|
28
|
+
- run: pnpm install --frozen-lockfile
|
|
29
|
+
|
|
30
|
+
- name: Lint and Type Check
|
|
31
|
+
run: pnpm check
|
|
32
|
+
|
|
33
|
+
- name: Build
|
|
34
|
+
run: pnpm build
|
|
35
|
+
|
|
36
|
+
- name: Test
|
|
37
|
+
run: pnpm test -- --coverage
|
|
38
|
+
|
|
39
|
+
- name: Coverage Report
|
|
40
|
+
if: github.event_name == 'pull_request'
|
|
41
|
+
uses: davelosert/vitest-coverage-report-action@v2
|
|
42
|
+
with:
|
|
43
|
+
json-summary-path: coverage/coverage-summary.json
|
package/.pr_agent.toml
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wopr-network/platform-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"@trpc/server": "^11.12.0",
|
|
46
46
|
"@types/node": "^25.4.0",
|
|
47
47
|
"@types/pg": "^8.18.0",
|
|
48
|
+
"@wopr-network/semantic-release-config": "^1.0.0",
|
|
48
49
|
"better-auth": "^1.5.4",
|
|
49
50
|
"drizzle-kit": "^0.31.9",
|
|
50
51
|
"drizzle-orm": "^0.45.1",
|
|
@@ -60,5 +61,12 @@
|
|
|
60
61
|
"winston": "^3.19.0",
|
|
61
62
|
"zod": "^4.3.6"
|
|
62
63
|
},
|
|
64
|
+
"release": {
|
|
65
|
+
"extends": "@wopr-network/semantic-release-config"
|
|
66
|
+
},
|
|
67
|
+
"repository": {
|
|
68
|
+
"type": "git",
|
|
69
|
+
"url": "https://github.com/wopr-network/platform-core.git"
|
|
70
|
+
},
|
|
63
71
|
"packageManager": "pnpm@10.31.0"
|
|
64
72
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Hono } from "hono";
|
|
2
|
-
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
|
-
import { requireEmailVerified } from "./require-verified.js";
|
|
4
|
-
describe("requireEmailVerified middleware", () => {
|
|
5
|
-
let verifiedUsers;
|
|
6
|
-
let app;
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
verifiedUsers = new Set();
|
|
9
|
-
const middleware = requireEmailVerified({
|
|
10
|
-
isVerified: async (userId) => verifiedUsers.has(userId),
|
|
11
|
-
});
|
|
12
|
-
app = new Hono();
|
|
13
|
-
// Simulate session auth middleware setting user context
|
|
14
|
-
app.use("/test/*", async (c, next) => {
|
|
15
|
-
const authMethod = (c.req.header("X-Auth-Method") || "session");
|
|
16
|
-
const userId = c.req.header("X-User-Id") || "user-1";
|
|
17
|
-
c.set("authMethod", authMethod);
|
|
18
|
-
c.set("user", { id: userId, roles: ["user"] });
|
|
19
|
-
return next();
|
|
20
|
-
});
|
|
21
|
-
app.use("/test/*", middleware);
|
|
22
|
-
app.post("/test/create", (c) => c.json({ ok: true }));
|
|
23
|
-
// Route without auth context — use a plain Hono app for this
|
|
24
|
-
const noauthApp = new Hono();
|
|
25
|
-
noauthApp.use("/noauth/*", middleware);
|
|
26
|
-
noauthApp.post("/noauth/create", (c) => c.json({ ok: true }));
|
|
27
|
-
// Mount the noauth app into the main app
|
|
28
|
-
app.route("/", noauthApp);
|
|
29
|
-
});
|
|
30
|
-
it("should block session-authenticated users without verified email", async () => {
|
|
31
|
-
const res = await app.request("/test/create", {
|
|
32
|
-
method: "POST",
|
|
33
|
-
headers: { "X-Auth-Method": "session", "X-User-Id": "user-1" },
|
|
34
|
-
});
|
|
35
|
-
expect(res.status).toBe(403);
|
|
36
|
-
const body = await res.json();
|
|
37
|
-
expect(body.code).toBe("EMAIL_NOT_VERIFIED");
|
|
38
|
-
});
|
|
39
|
-
it("should allow session-authenticated users with verified email", async () => {
|
|
40
|
-
verifiedUsers.add("user-1");
|
|
41
|
-
const res = await app.request("/test/create", {
|
|
42
|
-
method: "POST",
|
|
43
|
-
headers: { "X-Auth-Method": "session", "X-User-Id": "user-1" },
|
|
44
|
-
});
|
|
45
|
-
expect(res.status).toBe(200);
|
|
46
|
-
const body = await res.json();
|
|
47
|
-
expect(body.ok).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
it("should always allow API token auth", async () => {
|
|
50
|
-
const res = await app.request("/test/create", {
|
|
51
|
-
method: "POST",
|
|
52
|
-
headers: { "X-Auth-Method": "api_key", "X-User-Id": "token:write" },
|
|
53
|
-
});
|
|
54
|
-
expect(res.status).toBe(200);
|
|
55
|
-
const body = await res.json();
|
|
56
|
-
expect(body.ok).toBe(true);
|
|
57
|
-
});
|
|
58
|
-
it("should pass through when no auth context is set", async () => {
|
|
59
|
-
const res = await app.request("/noauth/create", { method: "POST" });
|
|
60
|
-
expect(res.status).toBe(200);
|
|
61
|
-
});
|
|
62
|
-
});
|