@flusys/nestjs-auth 6.4.1 → 7.0.0-beta.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/cjs/config/event-actions.js +45 -0
- package/cjs/config/index.js +1 -0
- package/cjs/config/message-keys.js +12 -0
- package/cjs/modules/auth.module.js +2 -1
- package/cjs/services/auth-email.service.js +21 -0
- package/cjs/services/auth-email.service.spec.js +52 -0
- package/cjs/services/authentication.service.js +62 -4
- package/cjs/services/authentication.service.spec.js +58 -0
- package/cjs/services/branch.service.js +20 -0
- package/cjs/services/branch.service.spec.js +15 -0
- package/cjs/services/company.service.js +20 -0
- package/cjs/services/company.service.spec.js +14 -0
- package/cjs/services/user-permission.service.js +20 -0
- package/cjs/services/user-permission.service.spec.js +52 -0
- package/config/event-actions.d.ts +21 -0
- package/config/index.d.ts +1 -0
- package/config/message-keys.d.ts +6 -0
- package/fesm/config/event-actions.js +24 -0
- package/fesm/config/index.js +1 -0
- package/fesm/config/message-keys.js +6 -0
- package/fesm/modules/auth.module.js +3 -2
- package/fesm/services/auth-email.service.js +22 -1
- package/fesm/services/auth-email.service.spec.js +52 -0
- package/fesm/services/authentication.service.js +64 -6
- package/fesm/services/authentication.service.spec.js +58 -0
- package/fesm/services/branch.service.js +22 -2
- package/fesm/services/branch.service.spec.js +15 -0
- package/fesm/services/company.service.js +22 -2
- package/fesm/services/company.service.spec.js +14 -0
- package/fesm/services/user-permission.service.js +21 -1
- package/fesm/services/user-permission.service.spec.js +52 -0
- package/interfaces/auth-module-options.interface.d.ts +2 -0
- package/package.json +3 -3
- package/services/auth-email.service.d.ts +1 -0
- package/services/authentication.service.d.ts +3 -0
- package/services/user-permission.service.d.ts +1 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ConflictException, NotFoundException } from '@nestjs/common';
|
|
2
|
+
import { EventBusRegistry } from '@flusys/nestjs-shared/classes';
|
|
2
3
|
import { createMockDataSourceProvider, createMockRepository } from '@test-utils/mocks/repository.mock';
|
|
3
4
|
import { UserPermissionService } from './user-permission.service';
|
|
4
5
|
import { PermissionType } from '../entities/user-company-permission.entity';
|
|
@@ -195,4 +196,55 @@ describe('UserPermissionService', ()=>{
|
|
|
195
196
|
});
|
|
196
197
|
});
|
|
197
198
|
});
|
|
199
|
+
describe('domain events', ()=>{
|
|
200
|
+
let publish;
|
|
201
|
+
beforeEach(()=>{
|
|
202
|
+
publish = jest.fn().mockResolvedValue(undefined);
|
|
203
|
+
EventBusRegistry.reset();
|
|
204
|
+
EventBusRegistry.setBus({
|
|
205
|
+
publish,
|
|
206
|
+
subscribe: jest.fn(),
|
|
207
|
+
close: jest.fn()
|
|
208
|
+
});
|
|
209
|
+
EventBusRegistry.configureModule('auth', {
|
|
210
|
+
enabled: true
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
afterEach(()=>{
|
|
214
|
+
EventBusRegistry.reset();
|
|
215
|
+
});
|
|
216
|
+
it('publishes permission-granted after a new assignment', async ()=>{
|
|
217
|
+
mockRepo.findOne.mockResolvedValue(null);
|
|
218
|
+
mockRepo.create.mockReturnValue(buildPermission());
|
|
219
|
+
mockRepo.save.mockResolvedValue(buildPermission());
|
|
220
|
+
await service.assignPermission('user-1', 'company-1', PermissionType.COMPANY);
|
|
221
|
+
expect(publish).toHaveBeenCalledWith(expect.objectContaining({
|
|
222
|
+
name: 'auth.user_company_permission.permission-granted',
|
|
223
|
+
payload: expect.objectContaining({
|
|
224
|
+
ids: [
|
|
225
|
+
'company-1'
|
|
226
|
+
],
|
|
227
|
+
metadata: expect.objectContaining({
|
|
228
|
+
targetUserId: 'user-1',
|
|
229
|
+
permissionType: PermissionType.COMPANY
|
|
230
|
+
})
|
|
231
|
+
})
|
|
232
|
+
}));
|
|
233
|
+
});
|
|
234
|
+
it('does not publish when the assignment is rejected as a duplicate', async ()=>{
|
|
235
|
+
mockRepo.findOne.mockResolvedValue(buildPermission());
|
|
236
|
+
await expect(service.assignPermission('user-1', 'company-1', PermissionType.COMPANY)).rejects.toThrow(ConflictException);
|
|
237
|
+
expect(publish).not.toHaveBeenCalled();
|
|
238
|
+
});
|
|
239
|
+
it('does not publish when the auth module has events disabled', async ()=>{
|
|
240
|
+
EventBusRegistry.configureModule('auth', {
|
|
241
|
+
enabled: false
|
|
242
|
+
});
|
|
243
|
+
mockRepo.findOne.mockResolvedValue(null);
|
|
244
|
+
mockRepo.create.mockReturnValue(buildPermission());
|
|
245
|
+
mockRepo.save.mockResolvedValue(buildPermission());
|
|
246
|
+
await service.assignPermission('user-1', 'company-1', PermissionType.COMPANY);
|
|
247
|
+
expect(publish).not.toHaveBeenCalled();
|
|
248
|
+
});
|
|
249
|
+
});
|
|
198
250
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IBootstrapAppConfig, IDataSourceServiceOptions, IDynamicModuleConfig, IModuleOptionsFactory } from '@flusys/nestjs-core';
|
|
2
|
+
import { IModuleEventsConfig } from '@flusys/nestjs-shared/interfaces';
|
|
2
3
|
import { ModuleMetadata, Provider, Type } from '@nestjs/common';
|
|
3
4
|
export interface IAuthModuleConfig extends IDataSourceServiceOptions {
|
|
4
5
|
jwtSecret?: string;
|
|
@@ -6,6 +7,7 @@ export interface IAuthModuleConfig extends IDataSourceServiceOptions {
|
|
|
6
7
|
refreshTokenSecret?: string;
|
|
7
8
|
refreshTokenExpiration?: string;
|
|
8
9
|
refreshTokenCookieName?: string;
|
|
10
|
+
events?: IModuleEventsConfig;
|
|
9
11
|
}
|
|
10
12
|
export interface AuthModuleOptions extends IDynamicModuleConfig {
|
|
11
13
|
bootstrapAppConfig?: IBootstrapAppConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flusys/nestjs-auth",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-beta.1",
|
|
4
4
|
"description": "Authentication and authorization infrastructure for NestJS applications",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "fesm/index.js",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"rxjs": "^7.8.0"
|
|
99
99
|
},
|
|
100
100
|
"dependencies": {
|
|
101
|
-
"@flusys/nestjs-core": "
|
|
102
|
-
"@flusys/nestjs-shared": "
|
|
101
|
+
"@flusys/nestjs-core": "7.0.0-beta.1",
|
|
102
|
+
"@flusys/nestjs-shared": "7.0.0-beta.1"
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -61,4 +61,7 @@ export declare class AuthenticationService {
|
|
|
61
61
|
private generateCompanySelectionResponse;
|
|
62
62
|
private generateRegistrationResponse;
|
|
63
63
|
private generateRegistrationResponseWithCompany;
|
|
64
|
+
private publishSessionEvent;
|
|
65
|
+
private publishUserEvent;
|
|
66
|
+
private publishAuthEvent;
|
|
64
67
|
}
|
|
@@ -10,6 +10,7 @@ export declare class UserPermissionService {
|
|
|
10
10
|
findUserPermissions(userId: string, type: PermissionType): Promise<UserCompanyPermission[]>;
|
|
11
11
|
assignPermission(userId: string, targetId: string, type: PermissionType): Promise<void>;
|
|
12
12
|
revokePermission(userId: string, targetId: string, type: PermissionType): Promise<void>;
|
|
13
|
+
private publishPermissionEvent;
|
|
13
14
|
private revokeBranchPermissionsForCompany;
|
|
14
15
|
findUserCompanies: (userId: string) => Promise<UserCompanyPermission[]>;
|
|
15
16
|
findUserBranches(userId: string, companyId?: string): Promise<UserCompanyPermission[]>;
|