@mr-aftab-ahmad-khan/guardpress 0.1.0

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 ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Initial public release.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aftab Ahmad Khan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # guardpress
2
+
3
+ **Topics:** `auth` · `express` · `guardpress` · `mern-packages` · `merndev` · `nodejs` · `npm-pm` · `observability` · `typescript`
4
+
5
+ guardpress — Route guard composer for Express (role + custom predicates). See `src/index.ts` for the public API surface.
6
+
7
+ ## License
8
+
9
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ guardRole: () => guardRole,
24
+ guardpress: () => guardpress
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+ function guardpress(...g) {
28
+ return async (req, res, next) => {
29
+ for (const x of g) {
30
+ if (!await x(req)) {
31
+ res.status(403).json({ error: "forbidden" });
32
+ return;
33
+ }
34
+ }
35
+ next();
36
+ };
37
+ }
38
+ var guardRole = (get, ok) => (req) => {
39
+ const r = get(req);
40
+ return !!r && ok.has(r);
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ guardRole,
45
+ guardpress
46
+ });
47
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Request, RequestHandler } from \"express\";\nexport type GF = (req: Request)=>boolean|Promise<boolean>;\nexport function guardpress(...g: GF[]): RequestHandler { return async (req,res,next)=>{ for(const x of g){ if(!(await x(req))){ res.status(403).json({error:\"forbidden\"}); return; } } next(); }; }\nexport const guardRole = (get:(req:Request)=>string|undefined, ok: Set<string>): GF => (req) => { const r=get(req); return !!r&&ok.has(r); };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,SAAS,cAAc,GAAyB;AAAE,SAAO,OAAO,KAAI,KAAI,SAAO;AAAE,eAAU,KAAK,GAAE;AAAE,UAAG,CAAE,MAAM,EAAE,GAAG,GAAG;AAAE,YAAI,OAAO,GAAG,EAAE,KAAK,EAAC,OAAM,YAAW,CAAC;AAAG;AAAA,MAAQ;AAAA,IAAE;AAAE,SAAK;AAAA,EAAG;AAAG;AAC3L,IAAM,YAAY,CAAC,KAAqC,OAAwB,CAAC,QAAQ;AAAE,QAAM,IAAE,IAAI,GAAG;AAAG,SAAO,CAAC,CAAC,KAAG,GAAG,IAAI,CAAC;AAAG;","names":[]}
@@ -0,0 +1,7 @@
1
+ import { Request, RequestHandler } from 'express';
2
+
3
+ type GF = (req: Request) => boolean | Promise<boolean>;
4
+ declare function guardpress(...g: GF[]): RequestHandler;
5
+ declare const guardRole: (get: (req: Request) => string | undefined, ok: Set<string>) => GF;
6
+
7
+ export { type GF, guardRole, guardpress };
@@ -0,0 +1,7 @@
1
+ import { Request, RequestHandler } from 'express';
2
+
3
+ type GF = (req: Request) => boolean | Promise<boolean>;
4
+ declare function guardpress(...g: GF[]): RequestHandler;
5
+ declare const guardRole: (get: (req: Request) => string | undefined, ok: Set<string>) => GF;
6
+
7
+ export { type GF, guardRole, guardpress };
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ // src/index.ts
2
+ function guardpress(...g) {
3
+ return async (req, res, next) => {
4
+ for (const x of g) {
5
+ if (!await x(req)) {
6
+ res.status(403).json({ error: "forbidden" });
7
+ return;
8
+ }
9
+ }
10
+ next();
11
+ };
12
+ }
13
+ var guardRole = (get, ok) => (req) => {
14
+ const r = get(req);
15
+ return !!r && ok.has(r);
16
+ };
17
+ export {
18
+ guardRole,
19
+ guardpress
20
+ };
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Request, RequestHandler } from \"express\";\nexport type GF = (req: Request)=>boolean|Promise<boolean>;\nexport function guardpress(...g: GF[]): RequestHandler { return async (req,res,next)=>{ for(const x of g){ if(!(await x(req))){ res.status(403).json({error:\"forbidden\"}); return; } } next(); }; }\nexport const guardRole = (get:(req:Request)=>string|undefined, ok: Set<string>): GF => (req) => { const r=get(req); return !!r&&ok.has(r); };\n"],"mappings":";AAEO,SAAS,cAAc,GAAyB;AAAE,SAAO,OAAO,KAAI,KAAI,SAAO;AAAE,eAAU,KAAK,GAAE;AAAE,UAAG,CAAE,MAAM,EAAE,GAAG,GAAG;AAAE,YAAI,OAAO,GAAG,EAAE,KAAK,EAAC,OAAM,YAAW,CAAC;AAAG;AAAA,MAAQ;AAAA,IAAE;AAAE,SAAK;AAAA,EAAG;AAAG;AAC3L,IAAM,YAAY,CAAC,KAAqC,OAAwB,CAAC,QAAQ;AAAE,QAAM,IAAE,IAAI,GAAG;AAAG,SAAO,CAAC,CAAC,KAAG,GAAG,IAAI,CAAC;AAAG;","names":[]}
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@mr-aftab-ahmad-khan/guardpress",
3
+ "version": "0.1.0",
4
+ "description": "guardpress — Route guard composer for Express (role + custom predicates).",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE",
21
+ "CHANGELOG.md"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsup",
25
+ "test": "vitest run",
26
+ "typecheck": "tsc --noEmit",
27
+ "prepublishOnly": "npm run build"
28
+ },
29
+ "keywords": [
30
+ "auth",
31
+ "express",
32
+ "guardpress",
33
+ "mern-packages",
34
+ "merndev",
35
+ "nodejs",
36
+ "npm-pm",
37
+ "observability",
38
+ "typescript"
39
+ ],
40
+ "devDependencies": {
41
+ "@types/node": "^20.11.0",
42
+ "tsup": "^8.0.0",
43
+ "typescript": "^5.4.0",
44
+ "vitest": "^1.4.0",
45
+ "@types/express": "^4.17.21",
46
+ "express": "^4.19.2",
47
+ "@types/supertest": "^6.0.2",
48
+ "supertest": "^7.0.0"
49
+ },
50
+ "engines": {
51
+ "node": ">=18"
52
+ },
53
+ "author": "Aftab Ahmad Khan (https://github.com/aftab-ahmad-khan-dev)",
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "git+https://github.com/NPM-Packages-Modules/mern.git",
57
+ "directory": "guardpress"
58
+ },
59
+ "bugs": {
60
+ "url": "https://github.com/NPM-Packages-Modules/mern/issues"
61
+ },
62
+ "homepage": "https://github.com/NPM-Packages-Modules/mern/tree/main/guardpress",
63
+ "publishConfig": {
64
+ "access": "public"
65
+ },
66
+ "peerDependencies": {
67
+ "express": "^4.0.0 || ^5.0.0"
68
+ },
69
+ "peerDependenciesMeta": {
70
+ "express": {
71
+ "optional": true
72
+ }
73
+ }
74
+ }