@nest-boot/i18n 8.0.0-beta.0 → 8.0.0-beta.2

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.
@@ -1,3 +1,2 @@
1
1
  import { Inject } from "@nestjs/common";
2
- /** Decorator that injects the i18next instance into a constructor parameter or property. */
3
2
  export declare const InjectI18n: () => ReturnType<typeof Inject>;
@@ -1,5 +1,4 @@
1
1
  import { Inject } from "@nestjs/common";
2
2
  import { I18N } from "../i18n.constants.js";
3
- /** Decorator that injects the i18next instance into a constructor parameter or property. */
4
3
  export const InjectI18n = () => Inject(I18N);
5
4
  //# sourceMappingURL=inject-i18n.decorator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"inject-i18n.decorator.js","sourceRoot":"","sources":["../../src/decorators/inject-i18n.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,4FAA4F;AAC5F,MAAM,CAAC,MAAM,UAAU,GAAG,GAA8B,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC"}
1
+ {"version":3,"file":"inject-i18n.decorator.js","sourceRoot":"","sources":["../../src/decorators/inject-i18n.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAG5C,MAAM,CAAC,MAAM,UAAU,GAAG,GAA8B,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC"}
@@ -1,2 +1 @@
1
- /** Injection token for the i18next instance. */
2
1
  export declare const I18N: unique symbol;
@@ -1,3 +1,2 @@
1
- /** Injection token for the i18next instance. */
2
1
  export const I18N = Symbol("I18N");
3
2
  //# sourceMappingURL=i18n.constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.constants.js","sourceRoot":"","sources":["../src/i18n.constants.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"i18n.constants.js","sourceRoot":"","sources":["../src/i18n.constants.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC"}
@@ -1,27 +1,9 @@
1
1
  import { type NestMiddleware } from "@nestjs/common";
2
2
  import { type Request, type Response } from "express";
3
- import { type I18nModuleOptions } from "./interfaces/i18n-module-options.interface.js";
4
- /**
5
- * Middleware that detects the request language and stores the i18n instance in the request context.
6
- *
7
- * @remarks
8
- * Uses `i18next-http-middleware` for language detection from headers,
9
- * cookies, or query parameters, then makes the i18n instance available
10
- * via {@link RequestContext}.
11
- */
3
+ import type { I18nModuleOptions } from "./interfaces/i18n-module-options.interface.js";
12
4
  export declare class I18nMiddleware implements NestMiddleware {
13
5
  readonly options: I18nModuleOptions;
14
- /** i18next-http-middleware handler. @internal */
15
6
  private readonly handler;
16
- /** Creates a new I18nMiddleware instance.
17
- * @param options - i18next initialization and middleware options
18
- */
19
7
  constructor(options: I18nModuleOptions);
20
- /**
21
- * Handles language detection and stores the i18n instance in the request context.
22
- * @param req - Express request object
23
- * @param res - Express response object
24
- * @param next - Express next function
25
- */
26
8
  use(req: Request, res: Response, next: () => void): void;
27
9
  }
@@ -16,31 +16,13 @@ import i18next from "i18next";
16
16
  import * as middleware from "i18next-http-middleware";
17
17
  import { I18N } from "./i18n.constants.js";
18
18
  import { MODULE_OPTIONS_TOKEN } from "./i18n.module-definition.js";
19
- /**
20
- * Middleware that detects the request language and stores the i18n instance in the request context.
21
- *
22
- * @remarks
23
- * Uses `i18next-http-middleware` for language detection from headers,
24
- * cookies, or query parameters, then makes the i18n instance available
25
- * via {@link RequestContext}.
26
- */
27
19
  let I18nMiddleware = class I18nMiddleware {
28
20
  options;
29
- /** i18next-http-middleware handler. @internal */
30
21
  handler;
31
- /** Creates a new I18nMiddleware instance.
32
- * @param options - i18next initialization and middleware options
33
- */
34
22
  constructor(options) {
35
23
  this.options = options;
36
24
  this.handler = middleware.handle(i18next, options);
37
25
  }
38
- /**
39
- * Handles language detection and stores the i18n instance in the request context.
40
- * @param req - Express request object
41
- * @param res - Express response object
42
- * @param next - Express next function
43
- */
44
26
  use(req, res, next) {
45
27
  void this.handler(req, res, () => {
46
28
  RequestContext.set(I18N, req.i18n);
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.middleware.js","sourceRoot":"","sources":["../src/i18n.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAuB,MAAM,gBAAgB,CAAC;AAEzE,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,UAAU,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAGnE;;;;;;;GAOG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAc;IASd;IARX,iDAAiD;IAChC,OAAO,CAAU;IAElC;;OAEG;IACH,YAEW,OAA0B;QAA1B,YAAO,GAAP,OAAO,CAAmB;QAEnC,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,MAAM,CAC9B,OAAc,EACd,OAAO,CACc,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAgB;QAC/C,KAAK,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;YAC/B,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;YACnC,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA7BY,cAAc;IAD1B,UAAU,EAAE;IASR,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;;GARpB,cAAc,CA6B1B"}
1
+ {"version":3,"file":"i18n.middleware.js","sourceRoot":"","sources":["../src/i18n.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAuB,MAAM,gBAAgB,CAAC;AAEzE,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,UAAU,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAY5D,IAAM,cAAc,GAApB,MAAM,cAAc;IASd;IAPM,OAAO,CAAU;IAKlC,YAEW,OAA0B;QAA1B,YAAO,GAAP,OAAO,CAAmB;QAEnC,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,MAAM,CAC9B,OAAc,EACd,OAAO,CACc,CAAC;IAC1B,CAAC;IAQD,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAgB;QAC/C,KAAK,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;YAC/B,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;YACnC,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA7BY,cAAc;IAD1B,UAAU,EAAE;IASR,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;;GARpB,cAAc,CA6B1B"}
@@ -1,28 +1,10 @@
1
- import { type DynamicModule, type MiddlewareConsumer, type NestModule } from "@nestjs/common";
1
+ import { MiddlewareManager } from "@nest-boot/middleware";
2
+ import { type DynamicModule } from "@nestjs/common";
3
+ import { I18nMiddleware } from "./i18n.middleware.js";
2
4
  import { type ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, type OPTIONS_TYPE } from "./i18n.module-definition.js";
3
- /**
4
- * Module that provides i18n (internationalization) support via i18next.
5
- *
6
- * @remarks
7
- * Initializes i18next with file-system backend and HTTP language detection,
8
- * and makes the i18n instance available through dependency injection and
9
- * the request context.
10
- */
11
- export declare class I18nModule extends ConfigurableModuleClass implements NestModule {
12
- /**
13
- * Registers the I18nModule with synchronous options.
14
- * @param options - i18next configuration options
15
- * @returns Dynamic module configuration
16
- */
5
+ export declare class I18nModule extends ConfigurableModuleClass {
17
6
  static register(options: typeof OPTIONS_TYPE): DynamicModule;
18
- /**
19
- * Registers the I18nModule with asynchronous options.
20
- * @param options - Async configuration options
21
- * @returns Dynamic module configuration
22
- */
23
7
  static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
24
- /** Merges i18next init options with defaults. @internal */
25
8
  private static with;
26
- /** Configures i18n middleware for all routes. */
27
- configure(consumer: MiddlewareConsumer): void;
9
+ constructor(middlewareManager: MiddlewareManager, i18nMiddleware: I18nMiddleware);
28
10
  }
@@ -4,8 +4,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { RequestContextModule } from "@nest-boot/request-context";
8
- import { Module, } from "@nestjs/common";
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { MiddlewareManager, MiddlewareModule } from "@nest-boot/middleware";
11
+ import { RequestContextMiddleware, RequestContextModule, } from "@nest-boot/request-context";
12
+ import { Module } from "@nestjs/common";
9
13
  import i18next from "i18next";
10
14
  import Backend from "i18next-fs-backend";
11
15
  import { LanguageDetector } from "i18next-http-middleware";
@@ -14,36 +18,17 @@ import { I18N } from "./i18n.constants.js";
14
18
  import { I18nMiddleware } from "./i18n.middleware.js";
15
19
  import { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, } from "./i18n.module-definition.js";
16
20
  i18next.use(Backend).use(LanguageDetector);
17
- /**
18
- * Module that provides i18n (internationalization) support via i18next.
19
- *
20
- * @remarks
21
- * Initializes i18next with file-system backend and HTTP language detection,
22
- * and makes the i18n instance available through dependency injection and
23
- * the request context.
24
- */
25
21
  let I18nModule = class I18nModule extends ConfigurableModuleClass {
26
- /**
27
- * Registers the I18nModule with synchronous options.
28
- * @param options - i18next configuration options
29
- * @returns Dynamic module configuration
30
- */
31
22
  static register(options) {
32
23
  return {
33
24
  ...this.with(options, super.register(options)),
34
25
  };
35
26
  }
36
- /**
37
- * Registers the I18nModule with asynchronous options.
38
- * @param options - Async configuration options
39
- * @returns Dynamic module configuration
40
- */
41
27
  static registerAsync(options) {
42
28
  return {
43
29
  ...this.with(options, super.registerAsync(options)),
44
30
  };
45
31
  }
46
- /** Merges i18next init options with defaults. @internal */
47
32
  static with(options, dynamicModule) {
48
33
  const provider = {
49
34
  provide: I18N,
@@ -68,15 +53,21 @@ let I18nModule = class I18nModule extends ConfigurableModuleClass {
68
53
  exports: [...(dynamicModule.exports ?? []), provider],
69
54
  };
70
55
  }
71
- /** Configures i18n middleware for all routes. */
72
- configure(consumer) {
73
- consumer.apply(I18nMiddleware).forRoutes("*");
56
+ constructor(middlewareManager, i18nMiddleware) {
57
+ super();
58
+ middlewareManager
59
+ .apply(i18nMiddleware)
60
+ .dependencies(RequestContextMiddleware)
61
+ .forRoutes("*");
74
62
  }
75
63
  };
76
64
  I18nModule = __decorate([
77
65
  Module({
78
- imports: [RequestContextModule],
79
- })
66
+ imports: [RequestContextModule, MiddlewareModule],
67
+ providers: [I18nMiddleware],
68
+ }),
69
+ __metadata("design:paramtypes", [MiddlewareManager,
70
+ I18nMiddleware])
80
71
  ], I18nModule);
81
72
  export { I18nModule };
82
73
  //# sourceMappingURL=i18n.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.module.js","sourceRoot":"","sources":["../src/i18n.module.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAGL,MAAM,GAGP,MAAM,gBAAgB,CAAC;AACxB,OAAO,OAAsB,MAAM,SAAS,CAAC;AAC7C,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAEL,uBAAuB,EACvB,oBAAoB,GAErB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAE3C;;;;;;;GAOG;AAII,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,uBAAuB;IACrD;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,OAA4B;QAC1C,OAAO;YACL,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;SAC/C,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,OAAkC;QACrD,OAAO;YACL,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;SACpD,CAAC;IACJ,CAAC;IAED,2DAA2D;IACnD,MAAM,CAAC,IAAI,CACjB,OAAwD,EACxD,aAA4B;QAE5B,MAAM,QAAQ,GAAmB;YAC/B,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,CA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CAAC;qBACjE;oBACD,WAAW,EAAE,IAAI;oBACjB,YAAY,EAAE,KAAK;oBACnB,aAAa,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE;oBACrC,GAAG,aAAa;iBACjB,CAAC,CAAC;gBAEH,OAAO,OAAO,CAAC;YACjB,CAAC;SACF,CAAC;QAEF,OAAO;YACL,GAAG,aAAa;YAChB,SAAS,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC;YACzD,OAAO,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC;SACtD,CAAC;IACJ,CAAC;IAGD,YACE,iBAAoC,EACpC,cAA8B;QAE9B,KAAK,EAAE,CAAC;QAER,iBAAiB;aACd,KAAK,CAAC,cAAc,CAAC;aACrB,YAAY,CAAC,wBAAwB,CAAC;aACtC,SAAS,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;CACF,CAAA;AAlEY,UAAU;IAJtB,MAAM,CAAC;QACN,OAAO,EAAE,CAAC,oBAAoB,EAAE,gBAAgB,CAAC;QACjD,SAAS,EAAE,CAAC,cAAc,CAAC;KAC5B,CAAC;qCAyDqB,iBAAiB;QACpB,cAAc;GAzDrB,UAAU,CAkEtB"}
@@ -1,3 +1,2 @@
1
1
  import { type InitOptions } from "i18next";
2
- /** Configuration options for the I18nModule, extending i18next InitOptions. */
3
2
  export type I18nModuleOptions = InitOptions;
@@ -1,10 +1,3 @@
1
1
  import { type TOptions } from "i18next";
2
- /**
3
- * Translates the given key using the request-scoped i18n instance, or the global i18next fallback.
4
- * @param key - Translation key or array of keys
5
- * @param options - Optional i18next translation options
6
- * @returns The translated string
7
- */
8
2
  export declare const translation: (key: string | string[], options?: TOptions) => string;
9
- /** Alias for {@link translation}. */
10
3
  export declare const t: (key: string | string[], options?: TOptions) => string;
@@ -1,12 +1,6 @@
1
1
  import { RequestContext } from "@nest-boot/request-context";
2
2
  import i18next from "i18next";
3
3
  import { I18N } from "../i18n.constants.js";
4
- /**
5
- * Translates the given key using the request-scoped i18n instance, or the global i18next fallback.
6
- * @param key - Translation key or array of keys
7
- * @param options - Optional i18next translation options
8
- * @returns The translated string
9
- */
10
4
  export const translation = (key, options) => {
11
5
  const instance = RequestContext?.get(I18N) ?? i18next;
12
6
  if (typeof options !== "undefined") {
@@ -14,6 +8,5 @@ export const translation = (key, options) => {
14
8
  }
15
9
  return instance.t(key);
16
10
  };
17
- /** Alias for {@link translation}. */
18
11
  export const t = translation;
19
12
  //# sourceMappingURL=translation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"translation.js","sourceRoot":"","sources":["../../src/utils/translation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,OAAqC,MAAM,SAAS,CAAC;AAE5D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,GAAsB,EACtB,OAAkB,EACV,EAAE;IACV,MAAM,QAAQ,GAAG,cAAc,EAAE,GAAG,CAAO,IAAI,CAAC,IAAI,OAAO,CAAC;IAE5D,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACnC,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC,CAAC;AAEF,qCAAqC;AACrC,MAAM,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC"}
1
+ {"version":3,"file":"translation.js","sourceRoot":"","sources":["../../src/utils/translation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,OAAqC,MAAM,SAAS,CAAC;AAE5D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAQ5C,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,GAAsB,EACtB,OAAkB,EACV,EAAE;IACV,MAAM,QAAQ,GAAG,cAAc,EAAE,GAAG,CAAO,IAAI,CAAC,IAAI,OAAO,CAAC;IAE5D,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACnC,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC,CAAC;AAGF,MAAM,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-boot/i18n",
3
- "version": "8.0.0-beta.0",
3
+ "version": "8.0.0-beta.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/nest-boot/nest-boot.git",
@@ -14,8 +14,8 @@
14
14
  },
15
15
  "homepage": "",
16
16
  "license": "MIT",
17
- "main": "dist/index.js",
18
- "types": "dist/index.d.ts",
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
19
  "directories": {
20
20
  "lib": "dist"
21
21
  },
@@ -23,33 +23,42 @@
23
23
  "dist"
24
24
  ],
25
25
  "devDependencies": {
26
- "@nestjs/common": "next",
27
- "@nestjs/core": "next",
28
- "@types/express": "^5.0.3",
26
+ "@nestjs/common": "^12.0.1",
27
+ "@nestjs/core": "^12.0.1",
28
+ "@nestjs/platform-express": "^12.0.1",
29
+ "@nestjs/testing": "^12.0.1",
30
+ "@types/express": "^5.0.6",
29
31
  "@types/i18next-fs-backend": "^1.2.0",
30
32
  "@types/node": "^26.0.0",
33
+ "@types/supertest": "^7.2.1",
34
+ "@vitest/coverage-v8": "^4.1.11",
31
35
  "eslint": "^9.39.3",
32
- "express": "^5.1.0",
33
- "i18next": "^23.16.8",
34
- "i18next-fs-backend": "^2.6.0",
35
- "i18next-http-middleware": "^3.8.0",
36
+ "express": "^5.2.1",
37
+ "i18next": "^26.4.0",
38
+ "i18next-fs-backend": "^2.6.7",
39
+ "i18next-http-middleware": "^3.9.8",
36
40
  "reflect-metadata": "^0.2.2",
37
41
  "rxjs": "^7.8.2",
42
+ "supertest": "^7.2.2",
38
43
  "typescript": "^6.0.3",
39
- "@nest-boot/eslint-config": "^8.0.0-beta.0",
40
- "@nest-boot/eslint-plugin": "^8.0.0-beta.0",
41
- "@nest-boot/request-context": "^8.0.0-beta.0",
42
- "@nest-boot/tsconfig": "^8.0.0-beta.0"
44
+ "vite-tsconfig-paths": "^5.1.4",
45
+ "vitest": "^4.1.11",
46
+ "@nest-boot/eslint-config": "^8.0.0-beta.2",
47
+ "@nest-boot/eslint-plugin": "^8.0.0-beta.2",
48
+ "@nest-boot/middleware": "^8.0.0-beta.2",
49
+ "@nest-boot/request-context": "^8.0.0-beta.2",
50
+ "@nest-boot/tsconfig": "^8.0.0-beta.2"
43
51
  },
44
52
  "peerDependencies": {
45
- "@nestjs/common": "^12.0.0-alpha.5",
46
- "@nestjs/core": "^12.0.0-alpha.5",
47
- "i18next": "^23.0.0",
53
+ "@nestjs/common": "^12.0.0",
54
+ "@nestjs/core": "^12.0.0",
55
+ "i18next": "^23.0.0 || ^24.0.0 || ^25.0.0 || ^26.0.0",
48
56
  "i18next-fs-backend": "^2.0.0",
49
57
  "i18next-http-middleware": "^3.0.0",
50
58
  "reflect-metadata": "^0.2.2",
51
59
  "rxjs": "^7.0.0",
52
- "@nest-boot/request-context": "^8.0.0-beta.0"
60
+ "@nest-boot/middleware": "^8.0.0-beta.2",
61
+ "@nest-boot/request-context": "^8.0.0-beta.2"
53
62
  },
54
63
  "publishConfig": {
55
64
  "access": "public"
@@ -61,11 +70,26 @@
61
70
  ]
62
71
  },
63
72
  "type": "module",
73
+ "engines": {
74
+ "node": ">=26.0.0"
75
+ },
76
+ "exports": {
77
+ ".": {
78
+ "types": "./dist/index.d.ts",
79
+ "import": "./dist/index.js"
80
+ },
81
+ "./package.json": "./package.json"
82
+ },
64
83
  "scripts": {
65
84
  "build": "tsc -p tsconfig.build.json",
66
85
  "clean": "rm -rf .nx && rm -rf node_modules && rm -rf dist",
67
86
  "dev": "tsc -w -p tsconfig.build.json",
68
87
  "lint": "eslint \"{src,test}/**/*.ts\"",
69
- "lint:fix": "eslint \"{src,test}/**/*.ts\" --fix"
88
+ "lint:fix": "eslint \"{src,test}/**/*.ts\" --fix",
89
+ "test": "vitest run",
90
+ "test:cov": "vitest run --coverage",
91
+ "test:watch": "vitest",
92
+ "test:debug": "vitest --inspect-brk --no-file-parallelism",
93
+ "test:e2e": "vitest run --config ./vitest.config.e2e.ts"
70
94
  }
71
95
  }