Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,109 changes: 1,080 additions & 1,029 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@
"devDependencies": {
"@angular-devkit/core": "20.3.23",
"@angular-devkit/schematics": "20.3.23",
"@apollo/server": "5.5.0",
"@as-integrations/express5": "1.1.2",
"@azure/abort-controller": "1.1.0",
"@azure/service-bus": "7.9.5",
"@azure/storage-blob": "12.30.0",
"@commitlint/cli": "20.4.1",
"@commitlint/config-conventional": "19.5.0",
"@commitlint/prompt-cli": "19.5.0",
"@nestjs/apollo": "12.2.2",
"@nestjs/common": "10.4.22",
"@nestjs/core": "10.4.22",
"@nestjs/jwt": "10.2.0",
"@nestjs/passport": "10.0.3",
"@nestjs/platform-express": "10.4.22",
"@nestjs/testing": "10.4.22",
"@nestjs/apollo": "13.2.5",
"@nestjs/common": "11.1.18",
"@nestjs/core": "11.1.18",
"@nestjs/graphql": "13.2.5",
"@nestjs/jwt": "11.0.2",
"@nestjs/passport": "11.0.5",
"@nestjs/platform-express": "11.1.18",
"@nestjs/testing": "11.1.18",
"@types/eslint": "8.56.3",
"@types/fs-extra": "11.0.4",
"@types/jest": "29.5.13",
Expand All @@ -64,6 +67,7 @@
"@types/pluralize": "0.0.33",
"@types/supertest": "6.0.2",
"@types/uuid": "10.0.0",
"uuid": "11.1.0",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"amqp-ts": "1.8.0",
Expand All @@ -75,6 +79,7 @@
"eslint-plugin-prettier": "4.2.1",
"glob": "8.1.0",
"glob-promise": "6.0.5",
"graphql": "16.13.2",
"husky": "9.1.7",
"jest": "29.7.0",
"json-schema-to-typescript": "13.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/async-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"peerDependencies": {
"@nestjs/common": ">=6.11.11"
"@nestjs/common": ">=11.0.0"
},
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"uuid": "^11.1.0"
},
"peerDependencies": {
"@nestjs/common": ">=6.11.11",
"@nestjs/jwt": ">=6.1.2",
"@nestjs/passport": ">=6.2.0"
"@nestjs/common": ">=11.0.0",
"@nestjs/jwt": ">=11.0.0",
"@nestjs/passport": ">=11.0.0"
},
"contributors": [
"Norbert Lehotzky <norbert.lehotzky@sclable.com>",
Expand Down
23 changes: 10 additions & 13 deletions packages/auth/src/decorators/user.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { createParamDecorator } from '@nestjs/common'
import { ExecutionContext, createParamDecorator } from '@nestjs/common'

export const RequestUser = createParamDecorator((_, req) => {
if (Array.isArray(req)) {
const [
,
,
{
req: { user },
},
] = req

return user
export const RequestUser = createParamDecorator((_data: unknown, ctx: ExecutionContext) => {
const type = ctx.getType<'http' | 'graphql' | 'ws'>()
if (type === 'http') {
return ctx.switchToHttp().getRequest<{ user?: unknown }>().user
}

return req.user
// GraphQL context: args[2] is { req, res, ... }
const [, , gqlCtx] =
ctx.getArgs<[unknown, unknown, { req?: { user?: unknown }; user?: unknown }]>()

return gqlCtx?.req?.user ?? gqlCtx?.user
})
5 changes: 4 additions & 1 deletion packages/auth/src/modules/local-auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export class LocalAuthModule extends AuthModule {
inject: [AUTH_MODULE_OPTIONS],
useFactory: (options: AuthModuleOptions) => ({
secret: options.config.jwtSecret,
signOptions: { expiresIn: options.config.jwtExpiresIn },
// jwtExpiresIn is a valid ms-compatible string at runtime; cast to satisfy stricter type
signOptions: {
expiresIn: options.config.jwtExpiresIn as import('ms').StringValue,
},
}),
}),
...(asyncOptions.imports || []),
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/strategies/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class JwtStrategy<UserType extends ApplicationUserContract> extends Passp
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: authModuleOptions.config.jwtSecret,
secretOrKey: authModuleOptions.config.jwtSecret ?? '',
})
}

Expand Down
10 changes: 7 additions & 3 deletions packages/auth/src/strategies/keycloak.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ export class KeycloakStrategy<
@Inject(ExternalAuthService) private readonly authService: ExternalAuthService<UserType>,
) {
super({
realm: authModuleOptions.config.providerRealm,
url: authModuleOptions.config.providerUrl,
loggingLevel: authModuleOptions.config.loglevel || 'error',
realm: authModuleOptions.config.providerRealm ?? '',
url: authModuleOptions.config.providerUrl ?? '',
loggingLevel: (authModuleOptions.config.loglevel || 'error') as
| 'error'
| 'debug'
| 'info'
| 'warn',
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/strategies/local.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class LocalStrategy<UserType extends ApplicationUserContract> extends Pas
super()
}

protected async validate(username: string, password: string): Promise<UserType> {
public async validate(username: string, password: string): Promise<UserType> {
const user = await this.authService.validateUser(username, password)
if (!user) {
throw new UnauthorizedException()
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/strategies/mock.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class MockStrategy<UserType extends ApplicationUserContract> extends Pass
super()
}

protected async validate(): Promise<UserType | null> {
public async validate(): Promise<UserType | null> {
const user = await this.userService.getTestUser()

this.logger.debug(`MOCK user successfully authenticated (ID: ${user.id})`)
Expand Down
6 changes: 3 additions & 3 deletions packages/es-cqrs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
},
"dependencies": {
"@babel/runtime": "^7.9.2",
"@nestjs/cqrs": "10.2.7",
"@nestjs/cqrs": "^11.0.3",
"lodash": "^4.17.12",
"p-limit": "^3.1.0",
"uuid": "^11.1.0"
},
"peerDependencies": {
"@nestjs/common": "^10",
"@nestjs/core": "^10"
"@nestjs/common": "^11",
"@nestjs/core": "^11"
}
}
29 changes: 14 additions & 15 deletions packages/es-cqrs/src/explorer.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Inject, Injectable, Type } from '@nestjs/common'
import { Inject, Injectable } from '@nestjs/common'
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper'
import { Module } from '@nestjs/core/injector/module'
import { ModulesContainer } from '@nestjs/core/injector/modules-container'
Expand All @@ -10,8 +10,8 @@ import {
} from '@nestjs/cqrs/dist/decorators/constants'

export interface CqrsOptions {
events?: Type<IEventHandler>[]
commands?: Type<ICommandHandler>[]
events?: InstanceWrapper<IEventHandler>[]
commands?: InstanceWrapper<ICommandHandler>[]
}

@Injectable()
Expand All @@ -35,33 +35,32 @@ export class ExplorerService {

public flatMap<T>(
modules: Module[],
callback: (instance: InstanceWrapper) => Type<any> | undefined,
): Type<T>[] {
callback: (instance: InstanceWrapper) => InstanceWrapper<T> | undefined,
): InstanceWrapper<T>[] {
const items = modules
.map(module => [...module.providers.values()].map(callback))
.reduce((all, prvs) => all.concat(prvs), [])

return items.filter(element => !!element) as Type<T>[]
return items.filter(element => !!element) as InstanceWrapper<T>[]
}

public filterProvider(wrapper: InstanceWrapper, metadataKey: string): Type<any> | undefined {
public filterProvider(
wrapper: InstanceWrapper,
metadataKey: string,
): InstanceWrapper | undefined {
const { instance } = wrapper
if (!instance) {
return undefined
}

return this.extractMetadata(instance, metadataKey)
return this.extractMetadata(instance, metadataKey) ? wrapper : undefined
}

public extractMetadata(
instance: Record<string, unknown>,
metadataKey: string,
): Type<any> | undefined {
public extractMetadata(instance: Record<string, unknown>, metadataKey: string): boolean {
if (!instance.constructor) {
return undefined
return false
}
const metadata = Reflect.getMetadata(metadataKey, instance.constructor)

return metadata ? (instance.constructor as Type<any>) : undefined
return !!Reflect.getMetadata(metadataKey, instance.constructor)
}
}
20 changes: 14 additions & 6 deletions packages/es-cqrs/src/rate-limited-event-bus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@nestjs/common'
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper'
import { EventBus, IEventHandler } from '@nestjs/cqrs'
import pLimit, { Limit } from 'p-limit'

Expand All @@ -18,24 +19,31 @@ import { Event } from './interfaces'
export class RateLimitedEventBus extends EventBus<Event> {
private limits: { [key: string]: Limit } = {}

public bind(handler: IEventHandler<Event>, id: string): void {
public bind(handler: InstanceWrapper<IEventHandler<Event>>, id: string): void {
if (!handler.isDependencyTreeStatic()) {
// Fall back to default behavior for request-scoped handlers
super.bind(handler, id)

return
}

const stream$ = id ? this.ofEventId(id) : this.subject$
stream$.subscribe(event => {
if (event.customOptions && event.customOptions.skipQueue) {
handler.handle(event)
handler.instance.handle(event)

return
}
const id =
const queueId =
event.customOptions && event.customOptions.queueById
? event.customOptions.queueById
: event.aggregateId

if (!this.limits[id]) {
this.limits[id] = pLimit(1)
if (!this.limits[queueId]) {
this.limits[queueId] = pLimit(1)
}

this.limits[id](() => handler.handle(event))
this.limits[queueId](() => handler.instance.handle(event))
})
}
}
17 changes: 16 additions & 1 deletion packages/es-cqrs/test/rate-limited-event-bus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const mockedLimit = jest.fn().mockImplementation((cb: () => void) => cb())
const mockedPLimit = jest.fn().mockImplementation(() => mockedLimit)
jest.mock('p-limit', () => mockedPLimit)

import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper'
import { Test, TestingModule } from '@nestjs/testing'

import {
Expand Down Expand Up @@ -87,7 +88,21 @@ describe('RateLimitedEventBus', () => {
})

it('should register and use handler', done => {
eventBus.register([TestEvent1Handler, CombinedEventHandler, TestEndHandler])
const wrap = <T>(
instance: T,
metatype: new (...args: unknown[]) => T,
): InstanceWrapper<T> =>
({
instance,
metatype,
isDependencyTreeStatic: () => true,
} as unknown as InstanceWrapper<T>)

eventBus.register([
wrap(mockedHandler, TestEvent1Handler),
wrap(mockedCombinedHandler, CombinedEventHandler),
wrap(testEndHandler, TestEndHandler),
])
eventBus.publish(new TestEvent1('id', TEST_AGGREGATE_NAME, 1, new Date(), 'user', {}))
eventBus.publish(new TestEvent1('id', TEST_AGGREGATE_NAME, 2, new Date(), 'user', {}))
eventBus.publish(new TestEvent1('id', TEST_AGGREGATE_NAME, 3, new Date(), 'user', {}))
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-scalar-uuid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
"graphql": "^16.8.1"
},
"peerDependencies": {
"@nestjs/graphql": ">=6.6.2"
"@nestjs/graphql": ">=13.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/queue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"peerDependencies": {
"@azure/service-bus": "^7.4.0",
"@nestjs/common": ">=6.11.11",
"@nestjs/common": ">=11.0.0",
"amqp-ts": "^1.8.0",
"rxjs": ">=6.6.7"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"peerDependencies": {
"@azure/abort-controller": "^1.0.1",
"@azure/storage-blob": "^12.1.1",
"@nestjs/common": ">=6.11.11",
"@nestjs/common": ">=11.0.0",
"@sclable/nestjs-queue": "^1.0.11",
"minio": "^7.0.14"
},
Expand Down