From 80a6bb0acac44c451b0d5a7a0325d2d29e52a060 Mon Sep 17 00:00:00 2001 From: Tiago <70700766+tiagorangel1@users.noreply.github.com> Date: Fri, 25 Jul 2025 14:23:14 +0100 Subject: [PATCH] refactor: update import statements to use node built-ins --- checkpoints/elysia/index.js | 7 +++---- checkpoints/express/index.js | 7 +++---- checkpoints/hono/index.js | 7 +++---- demo/checkpoint/elysia/index.js | 15 ++++++++------- demo/checkpoint/express/index.js | 20 ++++++++++---------- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/checkpoints/elysia/index.js b/checkpoints/elysia/index.js index 4eef8f1..0aabe2a 100644 --- a/checkpoints/elysia/index.js +++ b/checkpoints/elysia/index.js @@ -1,11 +1,10 @@ +import crypto from "node:crypto"; import fs from "node:fs/promises"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; import Cap from "@cap.js/server"; -import crypto from "crypto"; import Elysia from "elysia"; -import { dirname, join } from "path"; -import { fileURLToPath } from "url"; - export const capMiddleware = (userOptions) => { const options = { token_validity_hours: 32, diff --git a/checkpoints/express/index.js b/checkpoints/express/index.js index 7a6016e..9589b6c 100644 --- a/checkpoints/express/index.js +++ b/checkpoints/express/index.js @@ -1,9 +1,8 @@ +import crypto from "node:crypto"; import fs from "node:fs/promises"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; import Cap from "@cap.js/server"; -import crypto from "crypto"; - -import { dirname, join } from "path"; -import { fileURLToPath } from "url"; export const capCheckpoint = (userOptions) => { const options = { diff --git a/checkpoints/hono/index.js b/checkpoints/hono/index.js index 676ecc4..063816f 100644 --- a/checkpoints/hono/index.js +++ b/checkpoints/hono/index.js @@ -1,12 +1,11 @@ +import crypto from "node:crypto"; import fs from "node:fs/promises"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; import Cap from "@cap.js/server"; -import crypto from "crypto"; import { getCookie, setCookie } from "hono/cookie"; import { createMiddleware } from "hono/factory"; -import { dirname, join } from "path"; -import { fileURLToPath } from "url"; - export const capCheckpoint = (userOptions) => { const options = { token_validity_hours: 32, diff --git a/demo/checkpoint/elysia/index.js b/demo/checkpoint/elysia/index.js index abf45a5..6a1a0ff 100644 --- a/demo/checkpoint/elysia/index.js +++ b/demo/checkpoint/elysia/index.js @@ -1,11 +1,12 @@ import { Elysia, file } from "elysia"; import { capMiddleware } from "../../../checkpoints/elysia/index"; + // import { capMiddleware } from "@cap.js/middleware-elysia"; new Elysia() - .use( - capMiddleware({ - /* + .use( + capMiddleware({ + /* token_validity_hours: 32, // how long the token is valid for tokens_store_path: ".data/tokensList.json", token_size: 16, // token size in bytes @@ -15,7 +16,7 @@ new Elysia() ), scoping: "scoped", // 'global' | 'scoped' */ - }) - ) - .get("/", () => file("success.html")) - .listen(3000); + }), + ) + .get("/", () => file("success.html")) + .listen(3000); diff --git a/demo/checkpoint/express/index.js b/demo/checkpoint/express/index.js index 5f94782..fcb6356 100644 --- a/demo/checkpoint/express/index.js +++ b/demo/checkpoint/express/index.js @@ -1,9 +1,9 @@ -import express from "express"; +import path, { dirname } from "node:path"; +import { fileURLToPath } from "node:url"; import cookieParser from "cookie-parser"; -import path from "path"; -import { dirname } from "path"; -import { fileURLToPath } from "url"; +import express from "express"; import { capCheckpoint } from "../../../checkpoints/express/index"; + // import { capCheckpoint } from "@cap.js/checkpoint-express"; const app = express(); @@ -13,20 +13,20 @@ app.use(express.json()); app.use(cookieParser()); app.use( - capCheckpoint({ - /* + capCheckpoint({ + /* token_validity_hours: 32, tokens_store_path: ".data/tokensList.json", token_size: 16, verification_template_path: join(__dirname, "./index.html"), */ - }) + }), ); -app.get("/", (req, res) => { - res.sendFile(path.join(__dirname, "success.html")); +app.get("/", (_, res) => { + res.sendFile(path.join(__dirname, "success.html")); }); app.listen(3000, () => { - console.log(`Server running on http://localhost:3000`); + console.log(`Server running on http://localhost:3000`); });