@vita-mojo/auth 0.0.3-rc.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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # auth
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test auth` to execute the unit tests via [Jest](https://jestjs.io).
8
+
9
+ ## Running lint
10
+
11
+ Run `nx lint auth` to execute the lint via [ESLint](https://eslint.org/).
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@vita-mojo/auth",
3
+ "version": "0.0.3-rc.0",
4
+ "main": "./src/index.js",
5
+ "types": "./src/index.d.ts",
6
+ "dependencies": {},
7
+ "peerDependencies": {
8
+ "jsonwebtoken": "9.0.0",
9
+ "passport-jwt": "4.0.1",
10
+ "tslib": "2.4.1"
11
+ }
12
+ }
package/src/auth.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Request } from 'express';
2
+ import * as jwt from 'jsonwebtoken';
3
+ export declare const extractTokenFromRequest: (request: Request) => Promise<string | null>;
4
+ export declare const checkToken: (token: string, secretOrKey: string) => Promise<string | jwt.JwtPayload>;
5
+ export declare const isAllowedRole: (role: {
6
+ slug: string;
7
+ }, allowedRoles: string[]) => boolean;
8
+ export declare const isAllowedPermission: (permissions: string[], allowedPermissions: string[]) => boolean;
package/src/auth.js ADDED
@@ -0,0 +1,8 @@
1
+ import { __awaiter } from "tslib";
2
+ import * as jwt from 'jsonwebtoken';
3
+ import { ExtractJwt } from 'passport-jwt';
4
+ export const extractTokenFromRequest = (request) => __awaiter(void 0, void 0, void 0, function* () { return ExtractJwt.fromAuthHeaderAsBearerToken()(request); });
5
+ export const checkToken = (token, secretOrKey) => __awaiter(void 0, void 0, void 0, function* () { return jwt.verify(token, secretOrKey, { algorithms: ['HS256', 'RS256'] }); });
6
+ export const isAllowedRole = (role, allowedRoles) => allowedRoles.includes(role.slug);
7
+ export const isAllowedPermission = (permissions, allowedPermissions) => permissions.some((permission) => allowedPermissions.includes(permission));
8
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../../packages/auth/src/auth.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAO,OAAgB,EAAE,EAAE,kDAChE,OAAA,UAAU,CAAC,2BAA2B,EAAE,CAAC,OAAO,CAAC,CAAA,GAAA,CAAC;AAEpD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAO,KAAa,EAAE,WAAmB,EAAE,EAAE,kDACrE,OAAA,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAA,GAAA,CAAC;AAErE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAsB,EAAE,YAAsB,EAAE,EAAE,CAC9E,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEnC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,WAAqB,EACrB,kBAA4B,EAC5B,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC"}
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './auth';
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './auth';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/auth/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}