@proteinjs/user-auth 1.0.6 → 1.0.8

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/.eslintrc.js ADDED
@@ -0,0 +1,20 @@
1
+ module.exports = {
2
+ extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', 'prettier'],
3
+ parser: '@typescript-eslint/parser',
4
+ plugins: ['@typescript-eslint', 'prettier'],
5
+ root: true,
6
+ ignorePatterns: ['**/dist/*', '**/node_modules/*'],
7
+
8
+ rules: {
9
+ 'prettier/prettier': ['warn'],
10
+ curly: ['warn'],
11
+ 'eol-last': ['warn', 'always'],
12
+ 'keyword-spacing': ['warn', { before: true }],
13
+ 'no-undef': 'off',
14
+ '@typescript-eslint/no-unused-vars': 'off',
15
+ '@typescript-eslint/no-var-requires': 'off',
16
+ '@typescript-eslint/no-explicit-any': 'off',
17
+ '@typescript-eslint/prefer-as-const': 'off',
18
+ '@typescript-eslint/ban-types': 'off',
19
+ },
20
+ };
@@ -0,0 +1,3 @@
1
+ node_modules/
2
+ dist/
3
+ .DS_Store
package/.prettierrc ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "trailingComma": "es5",
3
+ "tabWidth": 2,
4
+ "semi": true,
5
+ "singleQuote": true,
6
+ "jsxSingleQuote": true,
7
+ "printWidth": 120
8
+ }
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.0.8](https://github.com/proteinjs/user/compare/@proteinjs/user-auth@1.0.7...@proteinjs/user-auth@1.0.8) (2024-05-10)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * add linting and lint all files ([71defcd](https://github.com/proteinjs/user/commit/71defcd78dc479d2eef1f624c746c879f4e31daa))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 1.0.1 (2024-04-19)
7
18
 
8
19
  **Note:** Version bump only for package @proteinjs/user-auth
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Brent Bahry
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.
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  require("@proteinjs/reflection");
19
19
  require("moment");
20
20
  /** Generate Source Graph */
21
- var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"value\":{\"packageName\":\"@proteinjs/user-auth\",\"name\":\"AuthenticatedUserRepo\",\"filePath\":\"/Users/brentbahry/workspaces/n3xa/packages/proteinjs/packages/user/packages/auth/src/UserAuth.ts\",\"qualifiedName\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"properties\":[],\"methods\":[{\"name\":\"getUser\",\"returnType\":{\"packageName\":\"@proteinjs/user-auth\",\"name\":\"AuthenticatedUser\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user-auth/AuthenticatedUser\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"}],\"edges\":[{\"v\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"}]}";
21
+ var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"value\":{\"packageName\":\"@proteinjs/user-auth\",\"name\":\"AuthenticatedUserRepo\",\"filePath\":\"/home/runner/work/user/user/packages/auth/src/UserAuth.ts\",\"qualifiedName\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"properties\":[],\"methods\":[{\"name\":\"getUser\",\"returnType\":{\"packageName\":\"@proteinjs/user-auth\",\"name\":\"AuthenticatedUser\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user-auth/AuthenticatedUser\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"}],\"edges\":[{\"v\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"}]}";
22
22
  /** Generate Source Links */
23
23
  var sourceLinks = {};
24
24
  /** Load Source Graph and Links */
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,iCAA+B;AAC/B,kBAAgB;AAGhB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,wuCAAwuC,CAAC;AAG7vC,4BAA4B;AAG5B,IAAM,WAAW,GAAG,EACnB,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,iCAA+B;AAC/B,kBAAgB;AAGhB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,isCAAisC,CAAC;AAGttC,4BAA4B;AAG5B,IAAM,WAAW,GAAG,EACnB,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,kDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,kDAAgC"}
@@ -1 +1 @@
1
- {"version":3,"file":"UserAuth.d.ts","sourceRoot":"","sources":["../../src/UserAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,uBAAuB,CAAA;AAGlE,MAAM,WAAW,iBAAiB;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,qBAAsB,SAAQ,QAAQ;IACnD,OAAO,IAAI,iBAAiB,CAAC;CAChC;AAED,eAAO,MAAM,wBAAwB,yCAAqH,CAAC;AAE3J,qBAAa,QAAQ;IACjB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAwB;IAEhD,OAAO,CAAC,MAAM,CAAC,WAAW;IAO1B,MAAM,CAAC,UAAU,IAAI,OAAO;IAS5B;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAYrC;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,GAAE,KAAK,GAAC,cAAsB,GAAG,OAAO;CAiB/E"}
1
+ {"version":3,"file":"UserAuth.d.ts","sourceRoot":"","sources":["../../src/UserAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,uBAAuB,CAAC;AAGnE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,qBAAsB,SAAQ,QAAQ;IACrD,OAAO,IAAI,iBAAiB,CAAC;CAC9B;AAED,eAAO,MAAM,wBAAwB,yCAC2E,CAAC;AAEjH,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAwB;IAEhD,OAAO,CAAC,MAAM,CAAC,WAAW;IAQ1B,MAAM,CAAC,UAAU,IAAI,OAAO;IAU5B;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAcrC;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,GAAE,KAAK,GAAG,cAAsB,GAAG,OAAO;CAoB/E"}
@@ -3,20 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserAuth = exports.getAuthenticatedUserRepo = void 0;
4
4
  var reflection_1 = require("@proteinjs/reflection");
5
5
  var guestUser_1 = require("./guestUser");
6
- var getAuthenticatedUserRepo = function () { return reflection_1.SourceRepository.get().object('@proteinjs/user-auth/AuthenticatedUserRepo'); };
6
+ var getAuthenticatedUserRepo = function () {
7
+ return reflection_1.SourceRepository.get().object('@proteinjs/user-auth/AuthenticatedUserRepo');
8
+ };
7
9
  exports.getAuthenticatedUserRepo = getAuthenticatedUserRepo;
8
10
  var UserAuth = /** @class */ (function () {
9
11
  function UserAuth() {
10
12
  }
11
13
  UserAuth.getUserRepo = function () {
12
- if (!UserAuth.userRepo)
14
+ if (!UserAuth.userRepo) {
13
15
  UserAuth.userRepo = (0, exports.getAuthenticatedUserRepo)();
16
+ }
14
17
  return UserAuth.userRepo;
15
18
  };
16
19
  UserAuth.isLoggedIn = function () {
17
20
  var userRepo = UserAuth.getUserRepo();
18
- if (!userRepo)
21
+ if (!userRepo) {
19
22
  return true;
23
+ }
20
24
  var user = userRepo.getUser();
21
25
  return user.email != guestUser_1.guestUser.email;
22
26
  };
@@ -25,11 +29,13 @@ var UserAuth = /** @class */ (function () {
25
29
  */
26
30
  UserAuth.hasRole = function (role) {
27
31
  var userRepo = UserAuth.getUserRepo();
28
- if (!userRepo)
32
+ if (!userRepo) {
29
33
  return true;
34
+ }
30
35
  var user = userRepo.getUser();
31
- if (user.roles.includes('admin'))
36
+ if (user.roles.includes('admin')) {
32
37
  return true;
38
+ }
33
39
  return user.roles.includes(role);
34
40
  };
35
41
  /**
@@ -39,17 +45,20 @@ var UserAuth = /** @class */ (function () {
39
45
  UserAuth.hasRoles = function (roles, has) {
40
46
  if (has === void 0) { has = 'all'; }
41
47
  var userRepo = UserAuth.getUserRepo();
42
- if (!userRepo)
48
+ if (!userRepo) {
43
49
  return true;
50
+ }
44
51
  for (var _i = 0, roles_1 = roles; _i < roles_1.length; _i++) {
45
52
  var role = roles_1[_i];
46
53
  if (!UserAuth.hasRole(role)) {
47
- if (has === 'all')
54
+ if (has === 'all') {
48
55
  return false;
56
+ }
49
57
  }
50
58
  else {
51
- if (has === 'at least one')
59
+ if (has === 'at least one') {
52
60
  return true;
61
+ }
53
62
  }
54
63
  }
55
64
  return has === 'all';
@@ -1 +1 @@
1
- {"version":3,"file":"UserAuth.js","sourceRoot":"","sources":["../../src/UserAuth.ts"],"names":[],"mappings":";;;AAAA,oDAAkE;AAClE,yCAAuC;AAWhC,IAAM,wBAAwB,GAAG,cAAM,OAAA,6BAAgB,CAAC,GAAG,EAAE,CAAC,MAAM,CAAkC,4CAA4C,CAAC,EAA5G,CAA4G,CAAC;AAA9I,QAAA,wBAAwB,4BAAsH;AAE3J;IAAA;IAuDA,CAAC;IApDkB,oBAAW,GAA1B;QACI,IAAI,CAAC,QAAQ,CAAC,QAAQ;YAClB,QAAQ,CAAC,QAAQ,GAAG,IAAA,gCAAwB,GAAE,CAAC;QAEnD,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAEM,mBAAU,GAAjB;QACI,IAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;QACxC,IAAI,CAAC,QAAQ;YACT,OAAO,IAAI,CAAC;QAEhB,IAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC,KAAK,IAAI,qBAAS,CAAC,KAAK,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,gBA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AM;gBACL,IAAI,GAAG,KAAK,cAAc,EAAE;oBAC1B,OAAO,IAAI,CAAC;iBACb;aACF;SACF;QAED,OAAO,GAAG,KAAK,KAAK,CAAC;IACvB,CAAC;IACH,eAAC;AAAD,CAAC,AA9DD,IA8DC;AA9DY,4BAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"guestUser.d.ts","sourceRoot":"","sources":["../../src/guestUser.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,eAAO,MAAM,SAAS;;;;;;;;;CASrB,CAAC"}
1
+ {"version":3,"file":"guestUser.d.ts","sourceRoot":"","sources":["../../src/guestUser.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,eAAO,MAAM,SAAS;;;;;;;;;CASrB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"guestUser.js","sourceRoot":"","sources":["../../src/guestUser.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA2B;AAEd,QAAA,SAAS,GAAG;IACrB,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,OAAO;IACjB,aAAa,EAAE,KAAK;IACpB,KAAK,EAAE,EAAE;IACT,OAAO,EAAE,IAAA,gBAAM,GAAE;IACjB,OAAO,EAAE,IAAA,gBAAM,GAAE;IACjB,EAAE,EAAE,OAAO;CACd,CAAC"}
1
+ {"version":3,"file":"guestUser.js","sourceRoot":"","sources":["../../src/guestUser.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA4B;AAEf,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,OAAO;IACjB,aAAa,EAAE,KAAK;IACpB,KAAK,EAAE,EAAE;IACT,OAAO,EAAE,IAAA,gBAAM,GAAE;IACjB,OAAO,EAAE,IAAA,gBAAM,GAAE;IACjB,EAAE,EAAE,OAAO;CACZ,CAAC"}
@@ -3,23 +3,18 @@
3
3
  import '@proteinjs/reflection';
4
4
  import 'moment';
5
5
 
6
-
7
6
  /** Generate Source Graph */
8
7
 
9
- const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"value\":{\"packageName\":\"@proteinjs/user-auth\",\"name\":\"AuthenticatedUserRepo\",\"filePath\":\"/Users/brentbahry/workspaces/n3xa/packages/proteinjs/packages/user/packages/auth/src/UserAuth.ts\",\"qualifiedName\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"properties\":[],\"methods\":[{\"name\":\"getUser\",\"returnType\":{\"packageName\":\"@proteinjs/user-auth\",\"name\":\"AuthenticatedUser\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user-auth/AuthenticatedUser\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"}],\"edges\":[{\"v\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"}]}";
10
-
8
+ const sourceGraph =
9
+ '{"options":{"directed":true,"multigraph":false,"compound":false},"nodes":[{"v":"@proteinjs/user-auth/AuthenticatedUserRepo","value":{"packageName":"@proteinjs/user-auth","name":"AuthenticatedUserRepo","filePath":"/home/runner/work/user/user/packages/auth/src/UserAuth.ts","qualifiedName":"@proteinjs/user-auth/AuthenticatedUserRepo","properties":[],"methods":[{"name":"getUser","returnType":{"packageName":"@proteinjs/user-auth","name":"AuthenticatedUser","filePath":null,"qualifiedName":"@proteinjs/user-auth/AuthenticatedUser","typeParameters":null,"directParents":null},"isAsync":false,"isOptional":false,"isAbstract":true,"isStatic":false,"visibility":"public","parameters":[]}],"typeParameters":[],"directParents":[{"packageName":"@proteinjs/reflection","name":"Loadable","filePath":null,"qualifiedName":"@proteinjs/reflection/Loadable","properties":[],"methods":[],"typeParameters":[],"directParents":[]}],"sourceType":3}},{"v":"@proteinjs/reflection/Loadable"}],"edges":[{"v":"@proteinjs/user-auth/AuthenticatedUserRepo","w":"@proteinjs/reflection/Loadable","value":"extends interface"}]}';
11
10
 
12
11
  /** Generate Source Links */
13
12
 
14
-
15
- const sourceLinks = {
16
- };
17
-
13
+ const sourceLinks = {};
18
14
 
19
15
  /** Load Source Graph and Links */
20
16
 
21
17
  import { SourceRepository } from '@proteinjs/reflection';
22
18
  SourceRepository.merge(sourceGraph, sourceLinks);
23
19
 
24
-
25
- export * from '../index';
20
+ export * from '../index';
package/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './src/UserAuth'
2
- export * from './src/guestUser'
1
+ export * from './src/UserAuth';
2
+ export * from './src/guestUser';
package/jest.config.js CHANGED
@@ -1,18 +1,9 @@
1
1
  module.exports = {
2
- "roots": [
3
- "<rootDir>/test"
4
- ],
5
- "transform": {
6
- "^.+\\.tsx?$": "ts-jest"
7
- },
8
- "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
9
- "moduleFileExtensions": [
10
- "ts",
11
- "tsx",
12
- "js",
13
- "jsx",
14
- "json",
15
- "node"
16
- ],
17
- "testEnvironment": "node"
18
- }
2
+ roots: ['<rootDir>/test'],
3
+ transform: {
4
+ '^.+\\.tsx?$': 'ts-jest',
5
+ },
6
+ testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
7
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
8
+ testEnvironment: 'node',
9
+ };
package/package.json CHANGED
@@ -1,37 +1,43 @@
1
1
  {
2
- "name": "@proteinjs/user-auth",
3
- "version": "1.0.6",
4
- "description": "User auth",
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/proteinjs/user.git"
11
- },
12
- "bugs": {
13
- "url": "https://github.com/proteinjs/user/issues"
14
- },
15
- "homepage": "https://github.com/proteinjs/user#readme",
16
- "author": "Brent Bahry",
17
- "license": "ISC",
18
- "scripts": {
19
- "clean": "rm -rf dist/ generated/ node_modules/",
20
- "build": "reflection-build && tsc",
21
- "watch": "reflection-watch"
22
- },
23
- "dependencies": {
24
- "@proteinjs/reflection": "1.0.7",
25
- "moment": "2.29.4"
26
- },
27
- "devDependencies": {
28
- "@proteinjs/reflection-build": "1.0.13",
29
- "@types/jest": "29.5.5",
30
- "@types/node": "14.0.13",
31
- "jest": "29.7.0",
32
- "ts-jest": "29.1.1",
33
- "typescript": "5.2.2"
34
- },
35
- "main": "./dist/generated/index.js",
36
- "types": "./dist/generated/index.d.ts"
37
- }
2
+ "name": "@proteinjs/user-auth",
3
+ "version": "1.0.8",
4
+ "description": "User auth",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/proteinjs/user.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/proteinjs/user/issues"
14
+ },
15
+ "homepage": "https://github.com/proteinjs/user#readme",
16
+ "author": "Brent Bahry",
17
+ "license": "ISC",
18
+ "scripts": {
19
+ "clean": "rm -rf dist/ generated/ node_modules/",
20
+ "build": "reflection-build && tsc",
21
+ "watch": "reflection-watch"
22
+ },
23
+ "dependencies": {
24
+ "@proteinjs/reflection": "1.1.1",
25
+ "moment": "2.29.4"
26
+ },
27
+ "devDependencies": {
28
+ "@proteinjs/reflection-build": "1.0.16",
29
+ "@types/jest": "29.5.5",
30
+ "@types/node": "14.0.13",
31
+ "@typescript-eslint/eslint-plugin": "7.8.0",
32
+ "@typescript-eslint/parser": "7.8.0",
33
+ "eslint": "8.57.0",
34
+ "eslint-config-prettier": "9.1.0",
35
+ "eslint-plugin-prettier": "5.1.3",
36
+ "jest": "29.7.0",
37
+ "ts-jest": "29.1.1",
38
+ "typescript": "5.2.2"
39
+ },
40
+ "main": "./dist/generated/index.js",
41
+ "types": "./dist/generated/index.d.ts",
42
+ "gitHead": "2fd5a5ee7f68e33bf8b6ba045fd5bbd043b36e3b"
43
+ }
package/src/UserAuth.ts CHANGED
@@ -1,70 +1,78 @@
1
- import { Loadable, SourceRepository } from '@proteinjs/reflection'
2
- import { guestUser } from './guestUser'
1
+ import { Loadable, SourceRepository } from '@proteinjs/reflection';
2
+ import { guestUser } from './guestUser';
3
3
 
4
4
  export interface AuthenticatedUser {
5
- email: string;
6
- roles: string[];
5
+ email: string;
6
+ roles: string[];
7
7
  }
8
8
 
9
9
  export interface AuthenticatedUserRepo extends Loadable {
10
- getUser(): AuthenticatedUser;
10
+ getUser(): AuthenticatedUser;
11
11
  }
12
12
 
13
- export const getAuthenticatedUserRepo = () => SourceRepository.get().object<AuthenticatedUserRepo|undefined>('@proteinjs/user-auth/AuthenticatedUserRepo');
13
+ export const getAuthenticatedUserRepo = () =>
14
+ SourceRepository.get().object<AuthenticatedUserRepo | undefined>('@proteinjs/user-auth/AuthenticatedUserRepo');
14
15
 
15
16
  export class UserAuth {
16
- private static userRepo?: AuthenticatedUserRepo;
17
+ private static userRepo?: AuthenticatedUserRepo;
17
18
 
18
- private static getUserRepo() {
19
- if (!UserAuth.userRepo)
20
- UserAuth.userRepo = getAuthenticatedUserRepo();
21
-
22
- return UserAuth.userRepo;
19
+ private static getUserRepo() {
20
+ if (!UserAuth.userRepo) {
21
+ UserAuth.userRepo = getAuthenticatedUserRepo();
23
22
  }
24
23
 
25
- static isLoggedIn(): boolean {
26
- const userRepo = UserAuth.getUserRepo();
27
- if (!userRepo)
28
- return true;
24
+ return UserAuth.userRepo;
25
+ }
29
26
 
30
- const user = userRepo.getUser();
31
- return user.email != guestUser.email;
27
+ static isLoggedIn(): boolean {
28
+ const userRepo = UserAuth.getUserRepo();
29
+ if (!userRepo) {
30
+ return true;
32
31
  }
33
32
 
34
- /**
35
- * @return true if user has role or user has role 'admin'
36
- */
37
- static hasRole(role: string): boolean {
38
- const userRepo = UserAuth.getUserRepo();
39
- if (!userRepo)
40
- return true;
33
+ const user = userRepo.getUser();
34
+ return user.email != guestUser.email;
35
+ }
41
36
 
42
- const user = userRepo.getUser();
43
- if (user.roles.includes('admin'))
44
- return true;
37
+ /**
38
+ * @return true if user has role or user has role 'admin'
39
+ */
40
+ static hasRole(role: string): boolean {
41
+ const userRepo = UserAuth.getUserRepo();
42
+ if (!userRepo) {
43
+ return true;
44
+ }
45
45
 
46
- return user.roles.includes(role);
46
+ const user = userRepo.getUser();
47
+ if (user.roles.includes('admin')) {
48
+ return true;
47
49
  }
48
50
 
49
- /**
50
- * @param has (default) `all` - return true if user has all roles
51
- * @param has `at least one` - return true if user has at least one role
52
- */
53
- static hasRoles(roles: string[], has: 'all'|'at least one' = 'all'): boolean {
54
- const userRepo = UserAuth.getUserRepo();
55
- if (!userRepo)
56
- return true;
51
+ return user.roles.includes(role);
52
+ }
57
53
 
58
- for (const role of roles) {
59
- if (!UserAuth.hasRole(role)) {
60
- if (has === 'all')
61
- return false;
62
- } else {
63
- if (has === 'at least one')
64
- return true;
65
- }
66
- }
54
+ /**
55
+ * @param has (default) `all` - return true if user has all roles
56
+ * @param has `at least one` - return true if user has at least one role
57
+ */
58
+ static hasRoles(roles: string[], has: 'all' | 'at least one' = 'all'): boolean {
59
+ const userRepo = UserAuth.getUserRepo();
60
+ if (!userRepo) {
61
+ return true;
62
+ }
67
63
 
68
- return has === 'all';
64
+ for (const role of roles) {
65
+ if (!UserAuth.hasRole(role)) {
66
+ if (has === 'all') {
67
+ return false;
68
+ }
69
+ } else {
70
+ if (has === 'at least one') {
71
+ return true;
72
+ }
73
+ }
69
74
  }
70
- }
75
+
76
+ return has === 'all';
77
+ }
78
+ }
package/src/guestUser.ts CHANGED
@@ -1,12 +1,12 @@
1
- import moment from 'moment'
1
+ import moment from 'moment';
2
2
 
3
3
  export const guestUser = {
4
- name: 'Guest',
5
- email: 'guest',
6
- password: 'guest',
7
- emailVerified: false,
8
- roles: '',
9
- created: moment(),
10
- updated: moment(),
11
- id: 'guest',
12
- };
4
+ name: 'Guest',
5
+ email: 'guest',
6
+ password: 'guest',
7
+ emailVerified: false,
8
+ roles: '',
9
+ created: moment(),
10
+ updated: moment(),
11
+ id: 'guest',
12
+ };
package/tsconfig.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
- "compilerOptions": {
3
- "rootDir": "./",
4
- "target": "es5",
5
- "module": "commonjs",
6
- "declaration": true,
7
- "declarationMap": true,
8
- "sourceMap": true,
9
- "outDir": "./dist/",
10
- "strict": true,
11
- "noImplicitAny": true,
12
- "esModuleInterop": true,
13
- "skipLibCheck": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "resolveJsonModule": true,
16
- "jsx": "react"
17
- }
18
- }
2
+ "compilerOptions": {
3
+ "rootDir": "./",
4
+ "target": "es5",
5
+ "module": "commonjs",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "sourceMap": true,
9
+ "outDir": "./dist/",
10
+ "strict": true,
11
+ "noImplicitAny": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "resolveJsonModule": true,
16
+ "jsx": "react"
17
+ }
18
+ }