@minesa-org/mini-interaction 0.0.1 → 0.0.3
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.
|
@@ -164,6 +164,14 @@ export declare class MiniInteraction {
|
|
|
164
164
|
* Resolves the absolute commands directory path from configuration.
|
|
165
165
|
*/
|
|
166
166
|
private resolveCommandsDirectory;
|
|
167
|
+
/**
|
|
168
|
+
* Resolves the absolute components directory path from configuration.
|
|
169
|
+
*/
|
|
170
|
+
private resolveComponentsDirectory;
|
|
171
|
+
/**
|
|
172
|
+
* Resolves a directory relative to the project "src" or "dist" folders with optional overrides.
|
|
173
|
+
*/
|
|
174
|
+
private resolveDirectory;
|
|
167
175
|
/**
|
|
168
176
|
* Handles execution of a message component interaction.
|
|
169
177
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import { readdir, stat } from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { pathToFileURL } from "node:url";
|
|
@@ -467,12 +468,70 @@ export class MiniInteraction {
|
|
|
467
468
|
* Resolves the absolute commands directory path from configuration.
|
|
468
469
|
*/
|
|
469
470
|
resolveCommandsDirectory(commandsDirectory) {
|
|
470
|
-
|
|
471
|
-
|
|
471
|
+
return this.resolveDirectory("commands", commandsDirectory);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Resolves the absolute components directory path from configuration.
|
|
475
|
+
*/
|
|
476
|
+
resolveComponentsDirectory(componentsDirectory) {
|
|
477
|
+
return this.resolveDirectory("components", componentsDirectory);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Resolves a directory relative to the project "src" or "dist" folders with optional overrides.
|
|
481
|
+
*/
|
|
482
|
+
resolveDirectory(defaultFolder, overrideDirectory) {
|
|
483
|
+
const projectRoot = process.cwd();
|
|
484
|
+
const allowedRoots = ["src", "dist"].map((folder) => path.resolve(projectRoot, folder));
|
|
485
|
+
const candidates = [];
|
|
486
|
+
const isWithin = (parent, child) => {
|
|
487
|
+
const relative = path.relative(parent, child);
|
|
488
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
489
|
+
};
|
|
490
|
+
const pushCandidate = (candidate) => {
|
|
491
|
+
if (!candidates.includes(candidate)) {
|
|
492
|
+
candidates.push(candidate);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
const ensureWithinAllowedRoots = (absolutePath) => {
|
|
496
|
+
if (!allowedRoots.some((root) => isWithin(root, absolutePath))) {
|
|
497
|
+
throw new Error(`[MiniInteraction] Directory overrides must be located within "${path.join(projectRoot, "src")}" or "${path.join(projectRoot, "dist")}". Received: ${absolutePath}`);
|
|
498
|
+
}
|
|
499
|
+
pushCandidate(absolutePath);
|
|
500
|
+
};
|
|
501
|
+
const addOverrideCandidates = (overridePath) => {
|
|
502
|
+
const trimmed = overridePath.trim();
|
|
503
|
+
if (!trimmed) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
if (path.isAbsolute(trimmed)) {
|
|
507
|
+
ensureWithinAllowedRoots(trimmed);
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
const normalised = trimmed.replace(/^[./\\]+/, "");
|
|
511
|
+
if (!normalised) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (normalised.startsWith("src") || normalised.startsWith("dist")) {
|
|
515
|
+
const absolutePath = path.resolve(projectRoot, normalised);
|
|
516
|
+
ensureWithinAllowedRoots(absolutePath);
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
for (const root of allowedRoots) {
|
|
520
|
+
ensureWithinAllowedRoots(path.resolve(root, normalised));
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
if (overrideDirectory) {
|
|
524
|
+
addOverrideCandidates(overrideDirectory);
|
|
525
|
+
}
|
|
526
|
+
for (const root of allowedRoots) {
|
|
527
|
+
pushCandidate(path.resolve(root, defaultFolder));
|
|
528
|
+
}
|
|
529
|
+
for (const candidate of candidates) {
|
|
530
|
+
if (existsSync(candidate)) {
|
|
531
|
+
return candidate;
|
|
532
|
+
}
|
|
472
533
|
}
|
|
473
|
-
return
|
|
474
|
-
? commandsDirectory
|
|
475
|
-
: path.resolve(process.cwd(), commandsDirectory);
|
|
534
|
+
return candidates[0];
|
|
476
535
|
}
|
|
477
536
|
/**
|
|
478
537
|
* Handles execution of a message component interaction.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minesa-org/mini-interaction",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Mini interaction, connecting your app with Discord via HTTP-interaction (Vercel support).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -47,4 +47,4 @@
|
|
|
47
47
|
"ts-node": "^10.9.2",
|
|
48
48
|
"typescript": "^5.9.3"
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
}
|