@bonsae/nrg 0.9.0 → 0.9.1
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/package.json +1 -1
- package/server/index.cjs +29 -37
- package/types/server.d.ts +2 -12
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<a href="https://www.npmjs.com/package/@bonsae/nrg"><img src="https://img.shields.io/npm/v/@bonsae/nrg.svg" alt="npm package"></a>
|
|
7
7
|
<a href="https://github.com/bonsaedev/nrg/actions/workflows/ci.yaml"><img src="https://github.com/bonsaedev/nrg/actions/workflows/ci.yaml/badge.svg?branch=main" alt="build status"></a>
|
|
8
|
+
<a href="https://socket.dev/npm/package/@bonsae/nrg"><img src="https://badge.socket.dev/npm/package/@bonsae/nrg" alt="Socket Badge"></a>
|
|
8
9
|
</p>
|
|
9
10
|
|
|
10
11
|
# nrg
|
package/package.json
CHANGED
package/server/index.cjs
CHANGED
|
@@ -750,45 +750,37 @@ function defineConfigNode(def) {
|
|
|
750
750
|
return NodeClass;
|
|
751
751
|
}
|
|
752
752
|
|
|
753
|
-
// src/core/server/api/
|
|
753
|
+
// src/core/server/api/nrg-assets.ts
|
|
754
754
|
var import_path = __toESM(require("path"), 1);
|
|
755
755
|
var import_fs = __toESM(require("fs"), 1);
|
|
756
|
-
var
|
|
757
|
-
|
|
758
|
-
".
|
|
759
|
-
".
|
|
760
|
-
".
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
756
|
+
var RESOURCES_DIR = import_path.default.resolve(__dirname, "./resources");
|
|
757
|
+
var ALLOWED_FILES = /* @__PURE__ */ new Set([
|
|
758
|
+
"nrg-client.js",
|
|
759
|
+
"vue.esm-browser.prod.js",
|
|
760
|
+
"vue.esm-browser.js"
|
|
761
|
+
]);
|
|
762
|
+
var handleNrgAsset = (req, res, next) => {
|
|
763
|
+
let fileName = req.params[0];
|
|
764
|
+
if (fileName === "vue.esm-browser.prod.js" && process.env.NODE_ENV !== "production") {
|
|
765
|
+
fileName = "vue.esm-browser.js";
|
|
766
|
+
}
|
|
767
|
+
if (!ALLOWED_FILES.has(fileName)) return next();
|
|
768
|
+
const filePath = import_path.default.join(RESOURCES_DIR, fileName);
|
|
769
|
+
if (!import_fs.default.existsSync(filePath)) return next();
|
|
770
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
771
|
+
import_fs.default.createReadStream(filePath).pipe(res);
|
|
764
772
|
};
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
let reqPath = req.path.slice(prefix.length);
|
|
777
|
-
if (reqPath === "vue.esm-browser.prod.js" && process.env.NODE_ENV !== "production") {
|
|
778
|
-
const devPath = import_path.default.resolve(clientDir, "vue.esm-browser.js");
|
|
779
|
-
if (import_fs.default.existsSync(devPath)) {
|
|
780
|
-
reqPath = "vue.esm-browser.js";
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
const filePath = import_path.default.resolve(clientDir, reqPath);
|
|
784
|
-
const rel = import_path.default.relative(clientDir, filePath);
|
|
785
|
-
if (rel.startsWith("..") || import_path.default.isAbsolute(rel)) return next();
|
|
786
|
-
if (!import_fs.default.existsSync(filePath) || !import_fs.default.statSync(filePath).isFile())
|
|
787
|
-
return next();
|
|
788
|
-
const ext = import_path.default.extname(filePath);
|
|
789
|
-
res.setHeader("Content-Type", MIME[ext] ?? "application/octet-stream");
|
|
790
|
-
import_fs.default.createReadStream(filePath).pipe(res);
|
|
791
|
-
});
|
|
773
|
+
function initNrgAssetsRoute(router) {
|
|
774
|
+
if (!import_fs.default.existsSync(RESOURCES_DIR)) return;
|
|
775
|
+
router.get("/nrg/assets/*", handleNrgAsset);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// src/core/server/api/routes.ts
|
|
779
|
+
var _initialized = false;
|
|
780
|
+
function initRoutes(RED) {
|
|
781
|
+
if (_initialized) return;
|
|
782
|
+
_initialized = true;
|
|
783
|
+
initNrgAssetsRoute(RED.httpAdmin);
|
|
792
784
|
}
|
|
793
785
|
|
|
794
786
|
// src/core/constants.ts
|
|
@@ -1022,7 +1014,7 @@ async function registerType(RED, NodeClass) {
|
|
|
1022
1014
|
function registerTypes(nodes) {
|
|
1023
1015
|
const fn = async function(RED) {
|
|
1024
1016
|
initValidator(RED);
|
|
1025
|
-
|
|
1017
|
+
initRoutes(RED);
|
|
1026
1018
|
try {
|
|
1027
1019
|
RED.log.info("Registering node types in series");
|
|
1028
1020
|
for (const NodeClass of nodes) {
|
package/types/server.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
|
+
import { Express as Express$1 } from 'express';
|
|
4
5
|
import { Http2ServerRequest } from 'http2';
|
|
5
6
|
|
|
6
7
|
declare const TransformKind: unique symbol;
|
|
@@ -2006,18 +2007,7 @@ export interface NodeRedHooks {
|
|
|
2006
2007
|
has(hookId: string): boolean;
|
|
2007
2008
|
clear(): void;
|
|
2008
2009
|
}
|
|
2009
|
-
export type
|
|
2010
|
-
export interface NodeRedExpressApp {
|
|
2011
|
-
get(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
2012
|
-
post(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
2013
|
-
put(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
2014
|
-
delete(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
2015
|
-
patch(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
2016
|
-
options(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
2017
|
-
head(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
2018
|
-
use(path: string | NodeRedRequestHandler, ...handlers: NodeRedRequestHandler[]): void;
|
|
2019
|
-
all(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
2020
|
-
}
|
|
2010
|
+
export type NodeRedExpressApp = Express;
|
|
2021
2011
|
export interface RED {
|
|
2022
2012
|
/** Internationalization function */
|
|
2023
2013
|
_(key: string, substitutions?: Record<string, string>): string;
|