@smartsoft001/auth-shell-app-services 1.1.91 → 2.69.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/.eslintrc.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "extends": "../../../../.eslintrc.json",
3
+ "ignorePatterns": ["!**/*"],
4
+ "rules": {
5
+ "import/order": "off"
6
+ },
7
+ "overrides": [
8
+ {
9
+ "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
10
+ "rules": {}
11
+ },
12
+ {
13
+ "files": ["*.ts", "*.tsx"],
14
+ "rules": {}
15
+ },
16
+ {
17
+ "files": ["*.js", "*.jsx"],
18
+ "rules": {}
19
+ },
20
+ {
21
+ "files": "package.json",
22
+ "parser": "jsonc-eslint-parser",
23
+ "rules": {}
24
+ }
25
+ ]
26
+ }
package/README.md CHANGED
@@ -1,6 +1,25 @@
1
- # auth-shell-app-services
1
+ # @smartsoft001/auth-shell-app-services
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ ## Installation
4
+
5
+ `npm i @smartsoft001/auth-shell-app-services`
6
+
7
+ ## Services
8
+
9
+ ### AuthService
10
+
11
+ <table>
12
+ <thead>
13
+ <tr>
14
+ <td>Method</td>
15
+ <td>Description</td>
16
+ </tr>
17
+ </thead>
18
+ <tr>
19
+ <td>create(req: IAuthTokenRequest, httpReq?: Request)</td>
20
+ <td>Creates authentication token using the domain TokenFactory with automatic provider resolution</td>
21
+ </tr>
22
+ </table>
4
23
 
5
24
  ## Running unit tests
6
25
 
package/jest.config.ts ADDED
@@ -0,0 +1,26 @@
1
+ /* eslint-disable */
2
+ export default {
3
+ displayName: 'auth-shell-app-services',
4
+ preset: '../../../../jest.preset.js',
5
+ testEnvironment: 'node',
6
+ transform: {
7
+ '^.+\\.[tj]sx?$': [
8
+ 'ts-jest',
9
+ {
10
+ tsConfig: '<rootDir>/tsconfig.spec.json',
11
+ },
12
+ ],
13
+ },
14
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
15
+ coverageDirectory: '../../../../coverage/packages/auth/shell/app-services',
16
+ /* TODO: Update to latest Jest snapshotFormat
17
+ * By default Nx has kept the older style of Jest Snapshot formats
18
+ * to prevent breaking of any existing tests with snapshots.
19
+ * It's recommend you update to the latest format.
20
+ * You can do this by removing snapshotFormat property
21
+ * and running tests with --update-snapshot flag.
22
+ * Example: From within the project directory, run "nx test --update-snapshot"
23
+ * More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
24
+ */
25
+ snapshotFormat: { escapeString: true, printBasicPrototype: true },
26
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartsoft001/auth-shell-app-services",
3
- "version": "1.1.91",
3
+ "version": "2.69.0",
4
4
  "description": "Utils to authorization",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,36 +12,5 @@
12
12
  "nestjs"
13
13
  ],
14
14
  "author": "Emil Juchnikowski",
15
- "license": "MIT",
16
- "dependencies": {
17
- "@angular/common": "16.1.3",
18
- "@angular/core": "16.1.3",
19
- "@angular/platform-browser-dynamic": "16.1.3",
20
- "@nestjs/axios": "3.0.0",
21
- "@nestjs/common": "^10.0.5",
22
- "@nestjs/core": "^10.0.5",
23
- "@nestjs/jwt": "^10.1.0",
24
- "@nestjs/typeorm": "^10.0.0",
25
- "express": "4.18.2",
26
- "flatted": "^3.2.4",
27
- "guid-typescript": "1.0.9",
28
- "lodash": "^4.17.20",
29
- "md5": "2.3.0",
30
- "reflect-metadata": "0.1.13",
31
- "rxjs": "7.8.1",
32
- "typeorm": "0.3.17"
33
- },
34
- "peerDependencies": {
35
- "@smartsoft001/auth-domain": "1.1.91",
36
- "@smartsoft001/domain-core": "1.1.91",
37
- "@smartsoft001/fb": "1.1.91",
38
- "@smartsoft001/google": "1.1.91",
39
- "@smartsoft001/models": "1.1.91",
40
- "@smartsoft001/users": "1.1.91",
41
- "@smartsoft001/utils": "1.1.91",
42
- "util": "0.12.5",
43
- "tslib": "2.5.3"
44
- },
45
- "main": "./src/index.js",
46
- "types": "./src/index.d.ts"
15
+ "license": "MIT"
47
16
  }
package/project.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "auth-shell-app-services",
3
+ "$schema": "../../../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "packages/auth/shell/app-services/src",
5
+ "projectType": "library",
6
+ "targets": {
7
+ "lint": {
8
+ "executor": "@nx/eslint:lint",
9
+ "outputs": ["{options.outputFile}"],
10
+ "options": {
11
+ "lintFilePatterns": [
12
+ "packages/auth/shell/app-services/**/*.{ts,tsx,js,jsx}",
13
+ "packages/auth/shell/app-services/package.json"
14
+ ]
15
+ }
16
+ },
17
+ "test": {
18
+ "executor": "@nx/jest:jest",
19
+ "outputs": ["{workspaceRoot}/coverage/packages/auth/shell/app-services"],
20
+ "options": {
21
+ "jestConfig": "packages/auth/shell/app-services/jest.config.ts"
22
+ }
23
+ },
24
+ "build": {
25
+ "executor": "@nx/esbuild:esbuild",
26
+ "outputs": ["{options.outputPath}"],
27
+ "options": {
28
+ "outputPath": "dist/packages/auth/shell/app-services",
29
+ "tsConfig": "packages/auth/shell/app-services/tsconfig.lib.json",
30
+ "packageJson": "packages/auth/shell/app-services/package.json",
31
+ "main": "packages/auth/shell/app-services/src/index.ts",
32
+ "assets": ["packages/auth/shell/app-services/*.md"]
33
+ }
34
+ },
35
+ "deploy": {
36
+ "executor": "ngx-deploy-npm:deploy",
37
+ "options": {
38
+ "access": "public",
39
+ "distFolderPath": "dist/packages/auth/shell/app-services"
40
+ },
41
+ "dependsOn": ["build"]
42
+ }
43
+ }
44
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/services/auth/auth.service';
@@ -0,0 +1,114 @@
1
+ import { ModuleRef } from '@nestjs/core';
2
+ import { Test, TestingModule } from '@nestjs/testing';
3
+ import { Request } from 'express';
4
+
5
+ import {
6
+ AUTH_TOKEN_PAYLOAD_PROVIDER,
7
+ AUTH_TOKEN_USER_PROVIDER,
8
+ AUTH_TOKEN_VALIDATION_PROVIDER,
9
+ IAuthToken,
10
+ TokenFactory,
11
+ } from '@smartsoft001/auth-domain';
12
+
13
+ import { AuthService } from './auth.service';
14
+
15
+ describe('auth-shell-app-services: AuthService', () => {
16
+ let service: AuthService;
17
+ let moduleRef: ModuleRef;
18
+ let tokenFactory: TokenFactory;
19
+
20
+ beforeEach(async () => {
21
+ const module: TestingModule = await Test.createTestingModule({
22
+ providers: [
23
+ AuthService,
24
+ {
25
+ provide: TokenFactory,
26
+ useValue: {
27
+ create: jest.fn(),
28
+ },
29
+ },
30
+ {
31
+ provide: ModuleRef,
32
+ useValue: {
33
+ get: jest.fn(),
34
+ },
35
+ },
36
+ ],
37
+ }).compile();
38
+
39
+ service = module.get<AuthService>(AuthService);
40
+ moduleRef = module.get<ModuleRef>(ModuleRef);
41
+ tokenFactory = module.get<TokenFactory>(TokenFactory);
42
+ });
43
+
44
+ describe('create', () => {
45
+ it('should call TokenFactory.create with correct parameters when no providers are available', async () => {
46
+ const request = { grant_type: 'password' };
47
+ const httpReq = {} as Request;
48
+ const expectedToken = { token_type: 'bearer' } as IAuthToken;
49
+
50
+ (moduleRef.get as jest.Mock).mockImplementation(() => {
51
+ throw new Error('Not found');
52
+ });
53
+ (tokenFactory.create as jest.Mock).mockResolvedValue(expectedToken);
54
+
55
+ const result = await service.create(request, httpReq);
56
+
57
+ expect(result).toEqual(expectedToken);
58
+ });
59
+
60
+ it('should include payload provider when available', async () => {
61
+ const request = { grant_type: 'password' };
62
+ const payloadProvider = { change: jest.fn() };
63
+
64
+ (moduleRef.get as jest.Mock).mockImplementation((token) => {
65
+ if (token === AUTH_TOKEN_PAYLOAD_PROVIDER) {
66
+ return payloadProvider;
67
+ }
68
+ throw new Error('Not found');
69
+ });
70
+
71
+ await service.create(request);
72
+
73
+ expect(
74
+ (tokenFactory.create as jest.Mock).mock.calls[0][0].payloadProvider,
75
+ ).toBe(payloadProvider);
76
+ });
77
+
78
+ it('should include validation provider when available', async () => {
79
+ const request = { grant_type: 'password' };
80
+ const validationProvider = { check: jest.fn() };
81
+
82
+ (moduleRef.get as jest.Mock).mockImplementation((token) => {
83
+ if (token === AUTH_TOKEN_VALIDATION_PROVIDER) {
84
+ return validationProvider;
85
+ }
86
+ throw new Error('Not found');
87
+ });
88
+
89
+ await service.create(request);
90
+
91
+ expect(
92
+ (tokenFactory.create as jest.Mock).mock.calls[0][0].validationProvider,
93
+ ).toBe(validationProvider);
94
+ });
95
+
96
+ it('should include user provider when available', async () => {
97
+ const request = { grant_type: 'password' };
98
+ const userProvider = { get: jest.fn() };
99
+
100
+ (moduleRef.get as jest.Mock).mockImplementation((token) => {
101
+ if (token === AUTH_TOKEN_USER_PROVIDER) {
102
+ return userProvider;
103
+ }
104
+ throw new Error('Not found');
105
+ });
106
+
107
+ await service.create(request);
108
+
109
+ expect(
110
+ (tokenFactory.create as jest.Mock).mock.calls[0][0].userProvider,
111
+ ).toBe(userProvider);
112
+ });
113
+ });
114
+ });
@@ -0,0 +1,66 @@
1
+ import { Injectable, Logger } from '@nestjs/common';
2
+ import { ModuleRef } from '@nestjs/core';
3
+ import { Request } from 'express';
4
+
5
+ import {
6
+ AUTH_TOKEN_PAYLOAD_PROVIDER,
7
+ AUTH_TOKEN_USER_PROVIDER,
8
+ AUTH_TOKEN_VALIDATION_PROVIDER,
9
+ IAuthToken,
10
+ IAuthTokenRequest,
11
+ ITokenPayloadProvider,
12
+ ITokenUserProvider,
13
+ ITokenValidationProvider,
14
+ TokenFactory,
15
+ } from '@smartsoft001/auth-domain';
16
+
17
+ @Injectable()
18
+ export class AuthService {
19
+ constructor(
20
+ private factory: TokenFactory,
21
+ private moduleRef: ModuleRef,
22
+ ) {}
23
+
24
+ create(req: IAuthTokenRequest, httpReq?: Request): Promise<IAuthToken> {
25
+ return this.factory.create({
26
+ httpReq: httpReq,
27
+ request: req,
28
+ payloadProvider: this.getPayloadProvider(),
29
+ validationProvider: this.getValidationProvider(),
30
+ userProvider: this.getUserProvider(),
31
+ }) as Promise<IAuthToken>;
32
+ }
33
+
34
+ private getPayloadProvider(): ITokenPayloadProvider {
35
+ try {
36
+ return this.moduleRef.get(AUTH_TOKEN_PAYLOAD_PROVIDER, {
37
+ strict: false,
38
+ });
39
+ } catch (e) {
40
+ Logger.debug(e.message, AuthService.name);
41
+ }
42
+ return null;
43
+ }
44
+
45
+ private getValidationProvider(): ITokenValidationProvider {
46
+ try {
47
+ return this.moduleRef.get(AUTH_TOKEN_VALIDATION_PROVIDER, {
48
+ strict: false,
49
+ });
50
+ } catch (e) {
51
+ Logger.debug(e.message, AuthService.name);
52
+ }
53
+ return null;
54
+ }
55
+
56
+ private getUserProvider(): ITokenUserProvider {
57
+ try {
58
+ return this.moduleRef.get(AUTH_TOKEN_USER_PROVIDER, {
59
+ strict: false,
60
+ });
61
+ } catch (e) {
62
+ Logger.debug(e.message, AuthService.name);
63
+ }
64
+ return null;
65
+ }
66
+ }
@@ -0,0 +1,5 @@
1
+ import { AuthService } from './auth/auth.service';
2
+
3
+ export * from './auth/auth.service';
4
+
5
+ export const SERVICES = [AuthService];
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../../../tsconfig.base.json",
3
+ "files": [],
4
+ "include": [],
5
+ "references": [
6
+ {
7
+ "path": "./tsconfig.lib.json"
8
+ },
9
+ {
10
+ "path": "./tsconfig.spec.json"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "outDir": "../../../../dist/out-tsc",
6
+ "declaration": true,
7
+ "types": ["node"]
8
+ },
9
+ "exclude": ["**/*.spec.ts", "**/*.test.ts", "jest.config.ts"],
10
+ "include": ["**/*.ts"]
11
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"]
7
+ },
8
+ "include": [
9
+ "**/*.spec.ts",
10
+ "**/*.test.ts",
11
+ "**/*.spec.tsx",
12
+ "**/*.test.tsx",
13
+ "**/*.spec.js",
14
+ "**/*.test.js",
15
+ "**/*.spec.jsx",
16
+ "**/*.test.jsx",
17
+ "**/*.d.ts",
18
+ "jest.config.ts"
19
+ ]
20
+ }
package/src/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./lib/services/auth/auth.service";
package/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./lib/services/auth/auth.service"), exports);
5
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/shell/app-services/src/index.ts"],"names":[],"mappings":";;;AAAA,2EAAiD"}
@@ -1,12 +0,0 @@
1
- import { ModuleRef } from "@nestjs/core";
2
- import { Request } from "express";
3
- import { IAuthToken, IAuthTokenRequest, TokenFactory } from "@smartsoft001/auth-domain";
4
- export declare class AuthService {
5
- private factory;
6
- private moduleRef;
7
- constructor(factory: TokenFactory, moduleRef: ModuleRef);
8
- create(req: IAuthTokenRequest, httpReq?: Request): Promise<IAuthToken>;
9
- private getPayloadProvider;
10
- private getValidationProvider;
11
- private getUserProvider;
12
- }
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var AuthService_1;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.AuthService = void 0;
5
- const tslib_1 = require("tslib");
6
- const common_1 = require("@nestjs/common");
7
- const core_1 = require("@nestjs/core");
8
- const auth_domain_1 = require("@smartsoft001/auth-domain");
9
- let AuthService = exports.AuthService = AuthService_1 = class AuthService {
10
- constructor(factory, moduleRef) {
11
- this.factory = factory;
12
- this.moduleRef = moduleRef;
13
- }
14
- create(req, httpReq) {
15
- return this.factory.create({
16
- httpReq: httpReq,
17
- request: req,
18
- payloadProvider: this.getPayloadProvider(),
19
- validationProvider: this.getValidationProvider(),
20
- userProvider: this.getUserProvider()
21
- });
22
- }
23
- getPayloadProvider() {
24
- try {
25
- return this.moduleRef.get(auth_domain_1.AUTH_TOKEN_PAYLOAD_PROVIDER, {
26
- strict: false,
27
- });
28
- }
29
- catch (e) {
30
- common_1.Logger.debug(e.message, AuthService_1.name);
31
- }
32
- return null;
33
- }
34
- getValidationProvider() {
35
- try {
36
- return this.moduleRef.get(auth_domain_1.AUTH_TOKEN_VALIDATION_PROVIDER, {
37
- strict: false,
38
- });
39
- }
40
- catch (e) {
41
- common_1.Logger.debug(e.message, AuthService_1.name);
42
- }
43
- return null;
44
- }
45
- getUserProvider() {
46
- try {
47
- return this.moduleRef.get(auth_domain_1.AUTH_TOKEN_USER_PROVIDER, {
48
- strict: false,
49
- });
50
- }
51
- catch (e) {
52
- common_1.Logger.debug(e.message, AuthService_1.name);
53
- }
54
- return null;
55
- }
56
- };
57
- exports.AuthService = AuthService = AuthService_1 = tslib_1.__decorate([
58
- (0, common_1.Injectable)(),
59
- tslib_1.__metadata("design:paramtypes", [auth_domain_1.TokenFactory,
60
- core_1.ModuleRef])
61
- ], AuthService);
62
- //# sourceMappingURL=auth.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../../../../../../../../libs/auth/shell/app-services/src/lib/services/auth/auth.service.ts"],"names":[],"mappings":";;;;;AAAA,2CAAkD;AAClD,uCAAyC;AAGzC,2DAQmC;AAG5B,IAAM,WAAW,yCAAjB,MAAM,WAAW;IACtB,YACY,OAAqB,EACrB,SAAoB;QADpB,YAAO,GAAP,OAAO,CAAc;QACrB,cAAS,GAAT,SAAS,CAAW;IAC7B,CAAC;IAEF,MAAM,CAAC,GAAsB,EAAE,OAAiB;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;YACzB,OAA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ERVICES: (typeof AuthService)[];
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SERVICES = void 0;
4
- const tslib_1 = require("tslib");
5
- const auth_service_1 = require("./auth/auth.service");
6
- tslib_1.__exportStar(require("./auth/auth.service"), exports);
7
- exports.SERVICES = [
8
- auth_service_1.AuthService
9
- ];
10
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/shell/app-services/src/lib/services/index.ts"],"names":[],"mappings":";;;;AAAA,sDAAgD;AAEhD,8DAAoC;AAEvB,QAAA,QAAQ,GAAG;IACpB,0BAAW;CACd,CAAC"}
package/test-setup.js DELETED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=test-setup.js.map
package/test-setup.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-setup.js","sourceRoot":"","sources":["../../../../../libs/auth/shell/app-services/test-setup.ts"],"names":[],"mappings":""}
File without changes