@flink-app/generic-request-plugin 0.12.1-alpha.9 → 0.13.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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +66 -3
- package/package.json +25 -27
- package/readme.md +582 -18
- package/spec/GenericRequestPlugin.spec.ts +459 -0
- package/spec/helpers/reporter.ts +22 -0
- package/spec/support/jasmine.json +7 -0
- package/src/index.ts +52 -29
- package/tsconfig.dist.json +4 -0
- package/tsconfig.json +5 -3
package/CHANGELOG.md
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -18,5 +18,11 @@ export type GenericRequestOptions = {
|
|
|
18
18
|
* Http method for this request
|
|
19
19
|
*/
|
|
20
20
|
method: HttpMethod;
|
|
21
|
+
/**
|
|
22
|
+
* Optional permission(s) required to access this route.
|
|
23
|
+
* If set, the auth plugin will validate the request before calling the handler.
|
|
24
|
+
* Requires an auth plugin (e.g., jwt-auth-plugin) to be configured in FlinkApp.
|
|
25
|
+
*/
|
|
26
|
+
permissions?: string | string[];
|
|
21
27
|
};
|
|
22
28
|
export declare const genericRequestPlugin: (options: GenericRequestOptions) => FlinkPlugin;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
40
|
};
|
|
@@ -20,12 +56,39 @@ var genericRequestPlugin = function (options) {
|
|
|
20
56
|
};
|
|
21
57
|
exports.genericRequestPlugin = genericRequestPlugin;
|
|
22
58
|
function init(app, options) {
|
|
59
|
+
var _this = this;
|
|
23
60
|
var expressApp = app.expressApp;
|
|
24
61
|
if (!expressApp) {
|
|
25
62
|
throw new Error("Express app not initialized");
|
|
26
63
|
}
|
|
27
|
-
expressApp[options.method](options.path, function (req, res) {
|
|
28
|
-
|
|
29
|
-
|
|
64
|
+
expressApp[options.method](options.path, function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
65
|
+
var authenticated;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
if (!options.permissions) return [3 /*break*/, 2];
|
|
70
|
+
if (!app.auth) {
|
|
71
|
+
throw new Error("Route ".concat(options.method.toUpperCase(), " ").concat(options.path, " requires permissions but no auth plugin is configured"));
|
|
72
|
+
}
|
|
73
|
+
return [4 /*yield*/, app.auth.authenticateRequest(req, options.permissions)];
|
|
74
|
+
case 1:
|
|
75
|
+
authenticated = _a.sent();
|
|
76
|
+
if (!authenticated) {
|
|
77
|
+
return [2 /*return*/, res.status(401).json({
|
|
78
|
+
status: 401,
|
|
79
|
+
error: {
|
|
80
|
+
title: "Unauthorized",
|
|
81
|
+
detail: "Authentication required or insufficient permissions",
|
|
82
|
+
},
|
|
83
|
+
})];
|
|
84
|
+
}
|
|
85
|
+
_a.label = 2;
|
|
86
|
+
case 2:
|
|
87
|
+
// Call the handler
|
|
88
|
+
options.handler(req, res, app);
|
|
89
|
+
return [2 /*return*/];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}); });
|
|
30
93
|
node_color_log_1.default.info("Registered genericRequest route ".concat(options.method, " ").concat(options.path));
|
|
31
94
|
}
|
package/package.json
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"gitHead": "3007ad036607014176930446fde56203bde8d6f5"
|
|
28
|
-
}
|
|
2
|
+
"name": "@flink-app/generic-request-plugin",
|
|
3
|
+
"version": "0.13.1",
|
|
4
|
+
"description": "Flink plugin that makes it possible to override default request handlers and handle specific requests manually",
|
|
5
|
+
"author": "johan@frost.se",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"node-color-log": "^5.3.1",
|
|
14
|
+
"@flink-app/flink": "0.13.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/jasmine": "^3.7.1",
|
|
18
|
+
"@types/node": "22.13.10"
|
|
19
|
+
},
|
|
20
|
+
"gitHead": "4243e3b3cd6d4e1ca001a61baa8436bf2bbe4113",
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "jasmine-ts --config=./spec/support/jasmine.json",
|
|
23
|
+
"build": "tsc --project tsconfig.dist.json",
|
|
24
|
+
"clean": "rimraf dist .flink"
|
|
25
|
+
}
|
|
26
|
+
}
|