badmfck-api-server 4.1.45 → 4.1.47
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.
|
@@ -67,6 +67,7 @@ async function Deploy(opt) {
|
|
|
67
67
|
var execResult = run("npm run build");
|
|
68
68
|
console.log(execResult);
|
|
69
69
|
const items = [];
|
|
70
|
+
let spaMode = false;
|
|
70
71
|
const binExists = fs_1.default.existsSync("./bin");
|
|
71
72
|
if (binExists) {
|
|
72
73
|
items.push("./bin");
|
|
@@ -78,8 +79,8 @@ async function Deploy(opt) {
|
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
else if (fs_1.default.existsSync("./dist") && fs_1.default.existsSync(path_1.default.resolve("dist", "index.html"))) {
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
spaMode = true;
|
|
83
|
+
console.log("No ./bin found — using entire ./dist contents as distribution");
|
|
83
84
|
}
|
|
84
85
|
if (Array.isArray(opt.includes)) {
|
|
85
86
|
for (const inc of opt.includes) {
|
|
@@ -95,8 +96,8 @@ async function Deploy(opt) {
|
|
|
95
96
|
items.push(inc);
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
|
-
if (items.length === 0) {
|
|
99
|
-
throw new Error("Nothing to archive (no ./bin
|
|
99
|
+
if (items.length === 0 && !spaMode) {
|
|
100
|
+
throw new Error("Nothing to archive (no ./bin, no ./dist/index.html, no valid includes)");
|
|
100
101
|
}
|
|
101
102
|
const excludes = new Set();
|
|
102
103
|
const addExclude = (raw, source) => {
|
|
@@ -122,11 +123,28 @@ async function Deploy(opt) {
|
|
|
122
123
|
addExclude(ex, "config.excludes");
|
|
123
124
|
}
|
|
124
125
|
const excludeArgs = Array.from(excludes).map(p => `--exclude=${p}`);
|
|
125
|
-
|
|
126
|
+
const tarArgs = ["-czvf", archiveName, ...excludeArgs];
|
|
127
|
+
if (spaMode) {
|
|
128
|
+
tarArgs.push("-C", "./dist", ".");
|
|
129
|
+
if (items.length > 0) {
|
|
130
|
+
tarArgs.push("-C", process.cwd(), ...items);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
tarArgs.push(...items);
|
|
135
|
+
}
|
|
136
|
+
if (spaMode) {
|
|
137
|
+
console.log("Archiving: contents of ./dist (recursively, at archive root)");
|
|
138
|
+
if (items.length > 0)
|
|
139
|
+
console.log("Also archiving from cwd:", items.join(", "));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
console.log("Archiving:", items.join(", "));
|
|
143
|
+
}
|
|
126
144
|
if (excludeArgs.length > 0)
|
|
127
145
|
console.log("Excluding:", Array.from(excludes).join(", "));
|
|
128
146
|
try {
|
|
129
|
-
(0, child_process_1.execFileSync)("tar",
|
|
147
|
+
(0, child_process_1.execFileSync)("tar", tarArgs, { encoding: "utf-8", stdio: "inherit" });
|
|
130
148
|
}
|
|
131
149
|
catch (err) {
|
|
132
150
|
console.error(`\ntar failed while creating ${archiveName}\n`);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IInterceptor } from "../APIService";
|
|
2
|
+
import { HTTPRequestVO } from "../structures/Interfaces";
|
|
3
|
+
export declare class InterceptorPayAuth implements IInterceptor<any> {
|
|
4
|
+
intercept(req: HTTPRequestVO, authorizations: {
|
|
5
|
+
key: string;
|
|
6
|
+
kid: string;
|
|
7
|
+
}[]): Promise<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.InterceptorPayAuth = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const Validator_1 = require("../helper/Validator");
|
|
9
|
+
const DefaultErrors_1 = __importDefault(require("../structures/DefaultErrors"));
|
|
10
|
+
const _TAuthParams = {
|
|
11
|
+
v: 0,
|
|
12
|
+
ts: "",
|
|
13
|
+
nonce: "",
|
|
14
|
+
kid: "",
|
|
15
|
+
alg: "",
|
|
16
|
+
$__alg_optional: true,
|
|
17
|
+
sig: ""
|
|
18
|
+
};
|
|
19
|
+
class InterceptorPayAuth {
|
|
20
|
+
async intercept(req, authorizations) {
|
|
21
|
+
const authScheme = "payauth ";
|
|
22
|
+
let headerData = req.headers["authorization"];
|
|
23
|
+
if (!headerData)
|
|
24
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "No authorization header" };
|
|
25
|
+
if (!headerData.toLowerCase().startsWith(authScheme))
|
|
26
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "wrong authorization scheme" };
|
|
27
|
+
const b64 = req.data.b64;
|
|
28
|
+
if (req.data.b64) {
|
|
29
|
+
let json = null;
|
|
30
|
+
try {
|
|
31
|
+
json = Buffer.from(req.data.b64, "base64").toString("utf-8");
|
|
32
|
+
json = JSON.parse(json);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
throw { ...DefaultErrors_1.default.BAD_REQUEST, details: "JSON malformed" };
|
|
36
|
+
}
|
|
37
|
+
req.data = json;
|
|
38
|
+
}
|
|
39
|
+
const params = {};
|
|
40
|
+
headerData.substring(authScheme.length).trim().split(",").forEach(v => {
|
|
41
|
+
v = v.trim();
|
|
42
|
+
const tmp = v.split("=");
|
|
43
|
+
if (tmp.length === 2) {
|
|
44
|
+
const key = tmp[0].trim().toLowerCase();
|
|
45
|
+
let value = tmp[1].trim();
|
|
46
|
+
if (value.startsWith("'") && value.endsWith("'")) {
|
|
47
|
+
value = value.substring(1, value.length - 1);
|
|
48
|
+
}
|
|
49
|
+
params[key] = value;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const errors = await Validator_1.Validator.validateStructure(_TAuthParams, params);
|
|
53
|
+
if (errors)
|
|
54
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "Malformed authorization header", stack: errors };
|
|
55
|
+
for (let i of authorizations) {
|
|
56
|
+
if (i.kid === params.kid) {
|
|
57
|
+
if (params.alg.toLowerCase() === "hmac-sha256") {
|
|
58
|
+
if (b64) {
|
|
59
|
+
const key = Buffer.from(i.key, "hex");
|
|
60
|
+
const sig = crypto_1.default.createHmac("sha256", key).update(b64 + params.ts + params.nonce).digest("hex");
|
|
61
|
+
if (sig === params.sig)
|
|
62
|
+
return i;
|
|
63
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "Signature mismatch, calc:" + sig + ", got:" + params.sig, stack: params };
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "Can't calc signature, no b64" };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "Unsupported alg" };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
throw { ...DefaultErrors_1.default.UNAUTHORIZED, details: "Key not found" };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.InterceptorPayAuth = InterceptorPayAuth;
|
package/dist/index.d.ts
CHANGED
|
@@ -18,4 +18,5 @@ import { MicroserviceHost } from "./apiServer/external/MicroserviceHost";
|
|
|
18
18
|
import { MicroserviceClient } from "./apiServer/external/MicroserviceClient";
|
|
19
19
|
import { Deploy } from "./apiServer/deployment/Deploy";
|
|
20
20
|
import { Activate } from "./apiServer/deployment/Activate";
|
|
21
|
-
|
|
21
|
+
import { InterceptorPayAuth } from "./apiServer/interceptors/InterceptorPayAuth";
|
|
22
|
+
export { MicroserviceHost, MicroserviceClient, Http, ZipUtils, UID, YYYYMMDDHH, JSONStableStringify, APIService, Initializer, LocalRequest, ValidationModel, MysqlService, TimeframeService, Validator, LogService, DataProvider, ErrorUtils, ExternalService, DBService, Deploy, Activate, InterceptorPayAuth, S_MONITOR_REGISTRATE_ACTION };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.S_MONITOR_REGISTRATE_ACTION = exports.Activate = exports.Deploy = exports.DBService = exports.ExternalService = exports.ErrorUtils = exports.DataProvider = exports.LogService = exports.Validator = exports.TimeframeService = exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = exports.JSONStableStringify = exports.YYYYMMDDHH = exports.UID = exports.ZipUtils = exports.Http = exports.MicroserviceClient = exports.MicroserviceHost = void 0;
|
|
3
|
+
exports.S_MONITOR_REGISTRATE_ACTION = exports.InterceptorPayAuth = exports.Activate = exports.Deploy = exports.DBService = exports.ExternalService = exports.ErrorUtils = exports.DataProvider = exports.LogService = exports.Validator = exports.TimeframeService = exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = exports.JSONStableStringify = exports.YYYYMMDDHH = exports.UID = exports.ZipUtils = exports.Http = exports.MicroserviceClient = exports.MicroserviceHost = void 0;
|
|
4
4
|
const APIService_1 = require("./apiServer/APIService");
|
|
5
5
|
Object.defineProperty(exports, "APIService", { enumerable: true, get: function () { return APIService_1.APIService; } });
|
|
6
6
|
Object.defineProperty(exports, "Initializer", { enumerable: true, get: function () { return APIService_1.Initializer; } });
|
|
@@ -42,3 +42,5 @@ const Deploy_1 = require("./apiServer/deployment/Deploy");
|
|
|
42
42
|
Object.defineProperty(exports, "Deploy", { enumerable: true, get: function () { return Deploy_1.Deploy; } });
|
|
43
43
|
const Activate_1 = require("./apiServer/deployment/Activate");
|
|
44
44
|
Object.defineProperty(exports, "Activate", { enumerable: true, get: function () { return Activate_1.Activate; } });
|
|
45
|
+
const InterceptorPayAuth_1 = require("./apiServer/interceptors/InterceptorPayAuth");
|
|
46
|
+
Object.defineProperty(exports, "InterceptorPayAuth", { enumerable: true, get: function () { return InterceptorPayAuth_1.InterceptorPayAuth; } });
|