@biorate/nestjs-tools 1.156.2 → 1.163.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biorate/nestjs-tools",
3
- "version": "1.156.2",
3
+ "version": "1.163.2",
4
4
  "description": "NestJS tools",
5
5
  "main": "dist",
6
6
  "scripts": {
@@ -37,7 +37,7 @@
37
37
  "@biorate/config": "1.156.2",
38
38
  "@biorate/errors": "1.102.0",
39
39
  "@biorate/inversion": "1.156.2",
40
- "@biorate/opentelemetry": "1.156.2",
40
+ "@biorate/opentelemetry": "1.163.0",
41
41
  "@biorate/prometheus": "1.156.2",
42
42
  "@biorate/tools": "1.102.1",
43
43
  "http-proxy": "1.18.1",
@@ -45,7 +45,7 @@
45
45
  "json-stringify-safe": "5.0.1",
46
46
  "on-headers": "1.0.2"
47
47
  },
48
- "gitHead": "99dfa1b6591c67b664f91d54f3ff5a5918fdeb3d",
48
+ "gitHead": "b69f39c6334ffa141f58f2594bc11a3eca5eab38",
49
49
  "devDependencies": {
50
50
  "@types/json-stringify-safe": "5.0.3"
51
51
  }
package/src/cors.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { container, Types } from '@biorate/inversion';
2
+ import { IConfig } from '@biorate/config';
3
+ import { CorsBadOriginError } from './errors';
4
+
5
+ export function corsOriginHandler(
6
+ origin: string,
7
+ callback: (error: null | Error, origin: string) => void,
8
+ ) {
9
+ if (!origin) return callback(null, origin);
10
+ const config = container.get<IConfig>(Types.Config);
11
+ const regexp = new RegExp(
12
+ config.get<string>(
13
+ 'allowedOrigin',
14
+ config.get<string>('package.name').replace('-server', ''),
15
+ ),
16
+ );
17
+ callback(regexp.test(origin) ? null : new CorsBadOriginError(origin), origin);
18
+ }
package/src/errors.ts CHANGED
@@ -11,3 +11,9 @@ export class AxiosRequestError extends BaseError {
11
11
  super(`Axios request error (%s) [%s]: %s`, [code, error, message]);
12
12
  }
13
13
  }
14
+
15
+ export class CorsBadOriginError extends BaseError {
16
+ public constructor(origin: string) {
17
+ super(`Cors bad origin error: [%s]`, [origin]);
18
+ }
19
+ }
package/src/index.ts CHANGED
@@ -7,3 +7,4 @@ export * from './providers';
7
7
  export * from './errors';
8
8
  export * from './http';
9
9
  export * from './app';
10
+ export * from './cors';