sprint-es 0.0.42 ā 0.0.43
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/dist/cjs/cli.cjs +4 -6
- package/dist/cjs/index.cjs +8 -6
- package/dist/cjs/modules/jwt/index.cjs +4 -2
- package/dist/esm/cli.js +4 -6
- package/dist/esm/index.js +8 -6
- package/dist/esm/modules/jwt/index.js +4 -2
- package/dist/types/modules/jwt/index.d.ts.map +1 -1
- package/dist/types/sprint.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/cli.cjs
CHANGED
|
@@ -59,9 +59,7 @@ function getProjectRoot() {
|
|
|
59
59
|
function loadEnv() {
|
|
60
60
|
const projectRoot2 = getProjectRoot();
|
|
61
61
|
const envFile = fs.existsSync(path.join(projectRoot2, ".env")) ? ".env" : fs.existsSync(path.join(projectRoot2, ".env.development")) ? ".env.development" : fs.existsSync(path.join(projectRoot2, ".env.production")) ? ".env.production" : null;
|
|
62
|
-
if (envFile) {
|
|
63
|
-
dotenv.config({ path: path.join(projectRoot2, envFile) });
|
|
64
|
-
}
|
|
62
|
+
if (envFile) dotenv.config({ path: path.join(projectRoot2, envFile), quiet: true });
|
|
65
63
|
}
|
|
66
64
|
function checkJwtKeys() {
|
|
67
65
|
loadEnv();
|
|
@@ -113,9 +111,9 @@ switch (command) {
|
|
|
113
111
|
privateKeyEncoding: { type: "pkcs8", format: "pem" }
|
|
114
112
|
});
|
|
115
113
|
console.log("\nš Generating JWT keys...\n");
|
|
116
|
-
console.log("JWT_PUBLIC_KEY=" + publicKey
|
|
117
|
-
console.log("\nJWT_PRIVATE_KEY=" + privateKey
|
|
118
|
-
console.log("\nš Add these to your .env file:\n");
|
|
114
|
+
console.log("JWT_PUBLIC_KEY='" + publicKey + "'");
|
|
115
|
+
console.log("\nJWT_PRIVATE_KEY='" + privateKey + "'");
|
|
116
|
+
console.log("\nš Add these to your .env file (use single quotes for multiline values):\n");
|
|
119
117
|
process.exit(0);
|
|
120
118
|
break;
|
|
121
119
|
default:
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -43,9 +43,9 @@ function stripRouteGroups(routePath) {
|
|
|
43
43
|
const nodeEnv = process.env.NODE_ENV?.toLowerCase();
|
|
44
44
|
const isDev = nodeEnv === "development";
|
|
45
45
|
const isProd = nodeEnv === "production";
|
|
46
|
-
if (isDev) dotenv.config({ path: ".env.development" });
|
|
47
|
-
else if (isProd) dotenv.config({ path: ".env.production" });
|
|
48
|
-
else dotenv.config();
|
|
46
|
+
if (isDev) dotenv.config({ path: ".env.development", quiet: true });
|
|
47
|
+
else if (isProd) dotenv.config({ path: ".env.production", quiet: true });
|
|
48
|
+
else dotenv.config({ quiet: true });
|
|
49
49
|
const limiter = new rateLimit.RateLimiter({
|
|
50
50
|
logs: isDev || isVerbose
|
|
51
51
|
});
|
|
@@ -131,7 +131,7 @@ class Sprint {
|
|
|
131
131
|
res.setHeader("X-Powered-By", "Sprint");
|
|
132
132
|
return next();
|
|
133
133
|
});
|
|
134
|
-
this.app.set("port", this.port || 5e3);
|
|
134
|
+
this.app.set("port", this.port || process.env.PORT || 5e3);
|
|
135
135
|
this.app.set("json spaces", 2);
|
|
136
136
|
this.app.enable("trust proxy");
|
|
137
137
|
this.app.set("trust proxy", true);
|
|
@@ -315,9 +315,11 @@ class Sprint {
|
|
|
315
315
|
const isDev2 = process.env.NODE_ENV === "development";
|
|
316
316
|
const basePort = this.app.get("port") || 5e3;
|
|
317
317
|
const triedPorts = [];
|
|
318
|
+
let serverStarted = false;
|
|
318
319
|
const tryListen = (port) => {
|
|
319
320
|
triedPorts.push(port);
|
|
320
321
|
this.server.listen(port, () => {
|
|
322
|
+
serverStarted = true;
|
|
321
323
|
const prefixInfo = this.prefix ? this.prefix : "/";
|
|
322
324
|
const reset = "\x1B[0m";
|
|
323
325
|
const bold = "\x1B[1m";
|
|
@@ -335,7 +337,7 @@ class Sprint {
|
|
|
335
337
|
console.log("");
|
|
336
338
|
});
|
|
337
339
|
this.server.on("error", (err) => {
|
|
338
|
-
if (err.code === "EADDRINUSE" && isDev2) {
|
|
340
|
+
if (err.code === "EADDRINUSE" && isDev2 && !serverStarted) {
|
|
339
341
|
const nextPort = triedPorts.length === 1 ? 3e3 : triedPorts[triedPorts.length - 1] + 1;
|
|
340
342
|
if (nextPort > 1e4) {
|
|
341
343
|
console.error(`ā No available ports found after trying: ${triedPorts.join(", ")}`);
|
|
@@ -344,7 +346,7 @@ class Sprint {
|
|
|
344
346
|
console.log(`ā ļø Port ${port} in use, trying ${nextPort}...`);
|
|
345
347
|
this.server.close();
|
|
346
348
|
tryListen(nextPort);
|
|
347
|
-
} else {
|
|
349
|
+
} else if (!serverStarted) {
|
|
348
350
|
console.error(`ā Server error:`, err.message);
|
|
349
351
|
process.exit(1);
|
|
350
352
|
}
|
|
@@ -81,11 +81,13 @@ function verifyTokenPair(token, publicKey) {
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
function getJwtFromEnv() {
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
let publicKey = process.env.JWT_PUBLIC_KEY;
|
|
85
|
+
let privateKey = process.env.JWT_PRIVATE_KEY;
|
|
86
86
|
if (!publicKey || !privateKey) {
|
|
87
87
|
throw new Error("JWT keys not configured. Run 'npm run generate:keys' and add the keys to your .env file.");
|
|
88
88
|
}
|
|
89
|
+
publicKey = publicKey.replace(/^['"]|['"]$/g, "").replace(/\\n/g, "\n");
|
|
90
|
+
privateKey = privateKey.replace(/^['"]|['"]$/g, "").replace(/\\n/g, "\n");
|
|
89
91
|
return { publicKey, privateKey };
|
|
90
92
|
}
|
|
91
93
|
exports.createTokenPair = createTokenPair;
|
package/dist/esm/cli.js
CHANGED
|
@@ -41,9 +41,7 @@ function getProjectRoot() {
|
|
|
41
41
|
function loadEnv() {
|
|
42
42
|
const projectRoot2 = getProjectRoot();
|
|
43
43
|
const envFile = existsSync(join(projectRoot2, ".env")) ? ".env" : existsSync(join(projectRoot2, ".env.development")) ? ".env.development" : existsSync(join(projectRoot2, ".env.production")) ? ".env.production" : null;
|
|
44
|
-
if (envFile) {
|
|
45
|
-
dotenv.config({ path: join(projectRoot2, envFile) });
|
|
46
|
-
}
|
|
44
|
+
if (envFile) dotenv.config({ path: join(projectRoot2, envFile), quiet: true });
|
|
47
45
|
}
|
|
48
46
|
function checkJwtKeys() {
|
|
49
47
|
loadEnv();
|
|
@@ -95,9 +93,9 @@ switch (command) {
|
|
|
95
93
|
privateKeyEncoding: { type: "pkcs8", format: "pem" }
|
|
96
94
|
});
|
|
97
95
|
console.log("\nš Generating JWT keys...\n");
|
|
98
|
-
console.log("JWT_PUBLIC_KEY=" + publicKey
|
|
99
|
-
console.log("\nJWT_PRIVATE_KEY=" + privateKey
|
|
100
|
-
console.log("\nš Add these to your .env file:\n");
|
|
96
|
+
console.log("JWT_PUBLIC_KEY='" + publicKey + "'");
|
|
97
|
+
console.log("\nJWT_PRIVATE_KEY='" + privateKey + "'");
|
|
98
|
+
console.log("\nš Add these to your .env file (use single quotes for multiline values):\n");
|
|
101
99
|
process.exit(0);
|
|
102
100
|
break;
|
|
103
101
|
default:
|
package/dist/esm/index.js
CHANGED
|
@@ -40,9 +40,9 @@ function stripRouteGroups(routePath) {
|
|
|
40
40
|
const nodeEnv = process.env.NODE_ENV?.toLowerCase();
|
|
41
41
|
const isDev = nodeEnv === "development";
|
|
42
42
|
const isProd = nodeEnv === "production";
|
|
43
|
-
if (isDev) dotenv.config({ path: ".env.development" });
|
|
44
|
-
else if (isProd) dotenv.config({ path: ".env.production" });
|
|
45
|
-
else dotenv.config();
|
|
43
|
+
if (isDev) dotenv.config({ path: ".env.development", quiet: true });
|
|
44
|
+
else if (isProd) dotenv.config({ path: ".env.production", quiet: true });
|
|
45
|
+
else dotenv.config({ quiet: true });
|
|
46
46
|
const limiter = new RateLimiter({
|
|
47
47
|
logs: isDev || isVerbose
|
|
48
48
|
});
|
|
@@ -128,7 +128,7 @@ class Sprint {
|
|
|
128
128
|
res.setHeader("X-Powered-By", "Sprint");
|
|
129
129
|
return next();
|
|
130
130
|
});
|
|
131
|
-
this.app.set("port", this.port || 5e3);
|
|
131
|
+
this.app.set("port", this.port || process.env.PORT || 5e3);
|
|
132
132
|
this.app.set("json spaces", 2);
|
|
133
133
|
this.app.enable("trust proxy");
|
|
134
134
|
this.app.set("trust proxy", true);
|
|
@@ -312,9 +312,11 @@ class Sprint {
|
|
|
312
312
|
const isDev2 = process.env.NODE_ENV === "development";
|
|
313
313
|
const basePort = this.app.get("port") || 5e3;
|
|
314
314
|
const triedPorts = [];
|
|
315
|
+
let serverStarted = false;
|
|
315
316
|
const tryListen = (port) => {
|
|
316
317
|
triedPorts.push(port);
|
|
317
318
|
this.server.listen(port, () => {
|
|
319
|
+
serverStarted = true;
|
|
318
320
|
const prefixInfo = this.prefix ? this.prefix : "/";
|
|
319
321
|
const reset = "\x1B[0m";
|
|
320
322
|
const bold = "\x1B[1m";
|
|
@@ -332,7 +334,7 @@ class Sprint {
|
|
|
332
334
|
console.log("");
|
|
333
335
|
});
|
|
334
336
|
this.server.on("error", (err) => {
|
|
335
|
-
if (err.code === "EADDRINUSE" && isDev2) {
|
|
337
|
+
if (err.code === "EADDRINUSE" && isDev2 && !serverStarted) {
|
|
336
338
|
const nextPort = triedPorts.length === 1 ? 3e3 : triedPorts[triedPorts.length - 1] + 1;
|
|
337
339
|
if (nextPort > 1e4) {
|
|
338
340
|
console.error(`ā No available ports found after trying: ${triedPorts.join(", ")}`);
|
|
@@ -341,7 +343,7 @@ class Sprint {
|
|
|
341
343
|
console.log(`ā ļø Port ${port} in use, trying ${nextPort}...`);
|
|
342
344
|
this.server.close();
|
|
343
345
|
tryListen(nextPort);
|
|
344
|
-
} else {
|
|
346
|
+
} else if (!serverStarted) {
|
|
345
347
|
console.error(`ā Server error:`, err.message);
|
|
346
348
|
process.exit(1);
|
|
347
349
|
}
|
|
@@ -79,11 +79,13 @@ function verifyTokenPair(token, publicKey) {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
function getJwtFromEnv() {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
let publicKey = process.env.JWT_PUBLIC_KEY;
|
|
83
|
+
let privateKey = process.env.JWT_PRIVATE_KEY;
|
|
84
84
|
if (!publicKey || !privateKey) {
|
|
85
85
|
throw new Error("JWT keys not configured. Run 'npm run generate:keys' and add the keys to your .env file.");
|
|
86
86
|
}
|
|
87
|
+
publicKey = publicKey.replace(/^['"]|['"]$/g, "").replace(/\\n/g, "\n");
|
|
88
|
+
privateKey = privateKey.replace(/^['"]|['"]$/g, "").replace(/\\n/g, "\n");
|
|
87
89
|
return { publicKey, privateKey };
|
|
88
90
|
}
|
|
89
91
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/jwt/index.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,UAAU;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACvB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,OAAO;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAkB,GAAG,OAAO,CActE;AAED,wBAAgB,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,MAAM,CAqB9F;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAqB1E;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,U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