@atls/nestjs-grpc-http-proxy 0.0.2 → 0.0.5

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.
@@ -28,8 +28,8 @@ let AuthenticationService = class AuthenticationService {
28
28
  }
29
29
  };
30
30
  AuthenticationService = __decorate([
31
- common_1.Injectable(),
32
- __param(0, common_2.Inject(grpc_http_proxy_constants_1.GRPC_HTTP_PROXY_MODULE_OPTIONS)),
31
+ (0, common_1.Injectable)(),
32
+ __param(0, (0, common_2.Inject)(grpc_http_proxy_constants_1.GRPC_HTTP_PROXY_MODULE_OPTIONS)),
33
33
  __metadata("design:paramtypes", [Object])
34
34
  ], AuthenticationService);
35
35
  exports.AuthenticationService = AuthenticationService;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HeaderAuthenticator = void 0;
4
+ class HeaderAuthenticator {
5
+ async execute(req) {
6
+ return req.headers.authorization || null;
7
+ }
8
+ }
9
+ exports.HeaderAuthenticator = HeaderAuthenticator;
@@ -13,3 +13,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./authenticator.interface"), exports);
14
14
  __exportStar(require("./authentication.service"), exports);
15
15
  __exportStar(require("./private-key.authenticator"), exports);
16
+ __exportStar(require("./header.authenticator"), exports);
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PrivateKeyAuthenticator = void 0;
7
- const jsonwebtoken_1 = require("jsonwebtoken");
7
+ const cookie_1 = __importDefault(require("cookie"));
8
8
  const fs_1 = require("fs");
9
+ const jsonwebtoken_1 = require("jsonwebtoken");
9
10
  const uuid_1 = require("uuid");
10
- const cookie_1 = __importDefault(require("cookie"));
11
11
  class PrivateKeyAuthenticator {
12
12
  constructor(privateKey) {
13
13
  this.privateKey = privateKey;
@@ -18,7 +18,7 @@ class PrivateKeyAuthenticator {
18
18
  async execute(req, res) {
19
19
  if (this.privateKey) {
20
20
  const cookies = cookie_1.default.parse(req.headers.cookie || '');
21
- const subject = cookies.subject || uuid_1.v4();
21
+ const subject = cookies.subject || (0, uuid_1.v4)();
22
22
  if (!cookies.subject) {
23
23
  res.setHeader('Set-Cookie', cookie_1.default.serialize('subject', String(subject), {
24
24
  maxAge: 60 * 60 * 24 * 7,
@@ -27,7 +27,7 @@ class PrivateKeyAuthenticator {
27
27
  }));
28
28
  }
29
29
  const privateKey = await fs_1.promises.readFile(this.privateKey, 'utf-8');
30
- const token = jsonwebtoken_1.sign({ sub: subject }, privateKey, { algorithm: 'RS256' });
30
+ const token = (0, jsonwebtoken_1.sign)({ sub: subject }, privateKey, { algorithm: 'RS256' });
31
31
  return `Bearer ${token}`;
32
32
  }
33
33
  return null;
@@ -16,6 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.GrpcHttpProxyController = void 0;
19
+ const grpc_error_status_1 = require("@atls/grpc-error-status");
19
20
  const common_1 = require("@nestjs/common");
20
21
  const common_2 = require("@nestjs/common");
21
22
  const common_3 = require("@nestjs/common");
@@ -24,7 +25,6 @@ const common_5 = require("@nestjs/common");
24
25
  const common_6 = require("@nestjs/common");
25
26
  const common_7 = require("@nestjs/common");
26
27
  const common_8 = require("@nestjs/common");
27
- const grpc_error_status_1 = require("@atls/grpc-error-status");
28
28
  const buffer_json_1 = __importDefault(require("buffer-json"));
29
29
  const authenticators_1 = require("../authenticators");
30
30
  const proto_1 = require("../proto");
@@ -45,20 +45,20 @@ let GrpcHttpProxyController = class GrpcHttpProxyController {
45
45
  }
46
46
  };
47
47
  __decorate([
48
- common_4.HttpCode(200),
49
- common_3.Post('/:service/:method'),
50
- common_6.Header('Content-Type', 'application/json'),
51
- __param(0, common_5.Param('service')),
52
- __param(1, common_5.Param('method')),
53
- __param(2, common_2.Body()),
54
- __param(3, common_7.Req()),
55
- __param(4, common_8.Res()),
48
+ (0, common_4.HttpCode)(200),
49
+ (0, common_3.Post)('/:service/:method'),
50
+ (0, common_6.Header)('Content-Type', 'application/json'),
51
+ __param(0, (0, common_5.Param)('service')),
52
+ __param(1, (0, common_5.Param)('method')),
53
+ __param(2, (0, common_2.Body)()),
54
+ __param(3, (0, common_7.Req)()),
55
+ __param(4, (0, common_8.Res)()),
56
56
  __metadata("design:type", Function),
57
57
  __metadata("design:paramtypes", [Object, Object, Object, Object, Object]),
58
58
  __metadata("design:returntype", Promise)
59
59
  ], GrpcHttpProxyController.prototype, "call", null);
60
60
  GrpcHttpProxyController = __decorate([
61
- common_1.Controller('grpc-proxy'),
61
+ (0, common_1.Controller)('grpc-proxy'),
62
62
  __metadata("design:paramtypes", [proto_1.ProtoRegistry,
63
63
  authenticators_1.AuthenticationService])
64
64
  ], GrpcHttpProxyController);
@@ -9,16 +9,16 @@ var GrpcHttpProxyModule_1;
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.GrpcHttpProxyModule = void 0;
11
11
  const common_1 = require("@nestjs/common");
12
+ const controllers_1 = require("../controllers");
12
13
  const grpc_http_proxy_constants_1 = require("./grpc-http-proxy.constants");
13
14
  const grpc_http_proxy_providers_1 = require("./grpc-http-proxy.providers");
14
15
  const grpc_http_proxy_providers_2 = require("./grpc-http-proxy.providers");
15
16
  const grpc_http_proxy_providers_3 = require("./grpc-http-proxy.providers");
16
- const controllers_1 = require("../controllers");
17
17
  let GrpcHttpProxyModule = GrpcHttpProxyModule_1 = class GrpcHttpProxyModule {
18
18
  static register(options) {
19
- const optionsProviders = grpc_http_proxy_providers_3.createGrpcHttpProxyOptionsProvider(options);
20
- const exportsProviders = grpc_http_proxy_providers_1.createGrpcHttpProxyExportsProvider();
21
- const providers = grpc_http_proxy_providers_2.createGrpcHttpProxyProvider();
19
+ const optionsProviders = (0, grpc_http_proxy_providers_3.createGrpcHttpProxyOptionsProvider)(options);
20
+ const exportsProviders = (0, grpc_http_proxy_providers_1.createGrpcHttpProxyExportsProvider)();
21
+ const providers = (0, grpc_http_proxy_providers_2.createGrpcHttpProxyProvider)();
22
22
  return {
23
23
  module: GrpcHttpProxyModule_1,
24
24
  providers: [...optionsProviders, ...providers, ...exportsProviders],
@@ -27,8 +27,8 @@ let GrpcHttpProxyModule = GrpcHttpProxyModule_1 = class GrpcHttpProxyModule {
27
27
  };
28
28
  }
29
29
  static registerAsync(options) {
30
- const exportsProviders = grpc_http_proxy_providers_1.createGrpcHttpProxyExportsProvider();
31
- const providers = grpc_http_proxy_providers_2.createGrpcHttpProxyProvider();
30
+ const exportsProviders = (0, grpc_http_proxy_providers_1.createGrpcHttpProxyExportsProvider)();
31
+ const providers = (0, grpc_http_proxy_providers_2.createGrpcHttpProxyProvider)();
32
32
  return {
33
33
  module: GrpcHttpProxyModule_1,
34
34
  imports: options.imports || [],
@@ -65,6 +65,6 @@ let GrpcHttpProxyModule = GrpcHttpProxyModule_1 = class GrpcHttpProxyModule {
65
65
  }
66
66
  };
67
67
  GrpcHttpProxyModule = GrpcHttpProxyModule_1 = __decorate([
68
- common_1.Module({})
68
+ (0, common_1.Module)({})
69
69
  ], GrpcHttpProxyModule);
70
70
  exports.GrpcHttpProxyModule = GrpcHttpProxyModule;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createGrpcHttpProxyExportsProvider = exports.createGrpcHttpProxyProvider = exports.createGrpcHttpProxyOptionsProvider = void 0;
4
- const grpc_http_proxy_constants_1 = require("./grpc-http-proxy.constants");
5
4
  const authenticators_1 = require("../authenticators");
6
5
  const proto_1 = require("../proto");
6
+ const grpc_http_proxy_constants_1 = require("./grpc-http-proxy.constants");
7
7
  const createGrpcHttpProxyOptionsProvider = (options) => [
8
8
  {
9
9
  provide: grpc_http_proxy_constants_1.GRPC_HTTP_PROXY_MODULE_OPTIONS,
@@ -8,10 +8,10 @@ class ProtoClient {
8
8
  this.client = client;
9
9
  }
10
10
  static create(url = '0.0.0.0:50051', ServiceClient) {
11
- return new ProtoClient(new ServiceClient(url, grpc_js_1.credentials.createInsecure(), {}));
11
+ return new ProtoClient(new ServiceClient(url, grpc_js_2.credentials.createInsecure(), {}));
12
12
  }
13
13
  call(method, request, meta = {}) {
14
- const metadata = new grpc_js_2.Metadata();
14
+ const metadata = new grpc_js_1.Metadata();
15
15
  Object.keys(meta).forEach((key) => {
16
16
  if (meta[key]) {
17
17
  metadata.add(key, meta[key]);
@@ -17,8 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.ProtoRegistry = void 0;
19
19
  const common_1 = require("@nestjs/common");
20
- const proto_loader_1 = require("@grpc/proto-loader");
20
+ const common_2 = require("@nestjs/common");
21
21
  const grpc_js_1 = require("@grpc/grpc-js");
22
+ const proto_loader_1 = require("@grpc/proto-loader");
22
23
  const lodash_get_1 = __importDefault(require("lodash.get"));
23
24
  const module_1 = require("../module");
24
25
  const proto_client_1 = require("./proto.client");
@@ -32,8 +33,8 @@ let ProtoRegistry = class ProtoRegistry {
32
33
  ? this.options.options.protoPath
33
34
  : [this.options.options.protoPath];
34
35
  this.definitions = await Promise.all(protoPaths.map(async (protoPath) => {
35
- const packageDefinition = await proto_loader_1.load(protoPath, this.options.options.loader);
36
- return grpc_js_1.loadPackageDefinition(packageDefinition);
36
+ const packageDefinition = await (0, proto_loader_1.load)(protoPath, this.options.options.loader);
37
+ return (0, grpc_js_1.loadPackageDefinition)(packageDefinition);
37
38
  }));
38
39
  }
39
40
  getClient(serviceName) {
@@ -41,7 +42,7 @@ let ProtoRegistry = class ProtoRegistry {
41
42
  if (serviceClient) {
42
43
  return serviceClient;
43
44
  }
44
- return lodash_get_1.default(definition, serviceName);
45
+ return (0, lodash_get_1.default)(definition, serviceName);
45
46
  }, undefined);
46
47
  if (!client) {
47
48
  throw new Error('GRPC service not found');
@@ -50,8 +51,8 @@ let ProtoRegistry = class ProtoRegistry {
50
51
  }
51
52
  };
52
53
  ProtoRegistry = __decorate([
53
- common_1.Injectable(),
54
- __param(0, common_1.Inject(module_1.GRPC_HTTP_PROXY_MODULE_OPTIONS)),
54
+ (0, common_2.Injectable)(),
55
+ __param(0, (0, common_1.Inject)(module_1.GRPC_HTTP_PROXY_MODULE_OPTIONS)),
55
56
  __metadata("design:paramtypes", [Object])
56
57
  ], ProtoRegistry);
57
58
  exports.ProtoRegistry = ProtoRegistry;
package/package.json CHANGED
@@ -1,32 +1,43 @@
1
1
  {
2
2
  "name": "@atls/nestjs-grpc-http-proxy",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "license": "BSD-3-Clause",
5
5
  "main": "dist/index.js",
6
6
  "files": [
7
7
  "dist"
8
8
  ],
9
9
  "scripts": {
10
- "build": "yarn app library build",
11
- "postpack": "rm -rf dist",
12
- "prepack": "yarn run build"
10
+ "build": "yarn library build",
11
+ "prepack": "yarn run build",
12
+ "postpack": "rm -rf dist"
13
+ },
14
+ "dependencies": {
15
+ "@atls/grpc-error-status": "^0.0.3",
16
+ "@grpc/grpc-js": "^1.3.7",
17
+ "@grpc/proto-loader": "^0.6.4",
18
+ "buffer-json": "^2.0.0",
19
+ "class-transformer": "^0.4.0",
20
+ "cookie": "^0.4.1",
21
+ "jsonwebtoken": "^8.5.1",
22
+ "lodash.get": "^4.4.2",
23
+ "uuid": "^8.3.2"
13
24
  },
14
25
  "devDependencies": {
15
- "@nestjs/common": "^8.0.4",
16
- "@nestjs/core": "^8.0.4",
17
- "@nestjs/microservices": "^8.0.4",
18
- "@nestjs/testing": "^8.0.4",
26
+ "@nestjs/common": "^8.0.5",
27
+ "@nestjs/core": "^8.0.5",
28
+ "@nestjs/microservices": "^8.0.5",
29
+ "@nestjs/testing": "^8.0.5",
19
30
  "@types/cookie": "^0.4.1",
20
31
  "@types/express": "^4.17.13",
21
- "@types/jsonwebtoken": "^8.5.4",
32
+ "@types/jsonwebtoken": "^8.5.8",
22
33
  "@types/lodash.get": "^4.4.6",
23
- "@types/uuid": "^8.3.1",
24
- "express": "^4.17.1",
34
+ "@types/uuid": "^8.3.4",
35
+ "express": "^4.17.3",
25
36
  "get-port": "^5.1.1",
26
37
  "protobufjs": "^6.11.2",
27
38
  "reflect-metadata": "0.1.13",
28
- "rxjs": "7.2.0",
29
- "supertest": "^6.1.3"
39
+ "rxjs": "7.5.4",
40
+ "supertest": "^6.2.2"
30
41
  },
31
42
  "peerDependencies": {
32
43
  "@nestjs/common": "^8.0.0",
@@ -39,16 +50,5 @@
39
50
  "main": "dist/index.js",
40
51
  "typings": "dist/index.d.ts"
41
52
  },
42
- "dependencies": {
43
- "@atls/grpc-error-status": "^0.0.3",
44
- "@grpc/grpc-js": "^1.3.5",
45
- "@grpc/proto-loader": "^0.6.4",
46
- "buffer-json": "^2.0.0",
47
- "class-transformer": "^0.4.0",
48
- "cookie": "^0.4.1",
49
- "jsonwebtoken": "^8.5.1",
50
- "lodash.get": "^4.4.2",
51
- "uuid": "^8.3.2"
52
- },
53
53
  "typings": "dist/index.d.ts"
54
54
  }
@@ -1,8 +0,0 @@
1
- import { Request } from 'express';
2
- import { Response } from 'express';
3
- import { GrpcHttpProxyModuleOptions } from '../module/grpc-http-proxy-module-options.interface';
4
- export declare class AuthenticationService {
5
- private readonly options;
6
- constructor(options: GrpcHttpProxyModuleOptions);
7
- authenticate(req: Request, res: Response): Promise<string | null> | null;
8
- }
@@ -1,5 +0,0 @@
1
- import { Request } from 'express';
2
- import { Response } from 'express';
3
- export interface Authenticator {
4
- execute(req: Request, res: Response): Promise<string | null>;
5
- }
@@ -1,3 +0,0 @@
1
- export * from './authenticator.interface';
2
- export * from './authentication.service';
3
- export * from './private-key.authenticator';
@@ -1,8 +0,0 @@
1
- import { Request } from 'express';
2
- import { Response } from 'express';
3
- import { Authenticator } from './authenticator.interface';
4
- export declare class PrivateKeyAuthenticator implements Authenticator {
5
- private readonly privateKey?;
6
- constructor(privateKey?: string | undefined);
7
- execute(req: Request, res: Response): Promise<string | null>;
8
- }
@@ -1,8 +0,0 @@
1
- import { AuthenticationService } from '../authenticators';
2
- import { ProtoRegistry } from '../proto';
3
- export declare class GrpcHttpProxyController {
4
- private readonly protoRegistry;
5
- private readonly authenticator;
6
- constructor(protoRegistry: ProtoRegistry, authenticator: AuthenticationService);
7
- call(service: any, method: any, body: any, req: any, res: any): Promise<void>;
8
- }
@@ -1 +0,0 @@
1
- export * from './grpc-http-proxy.controller';
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './authenticators';
2
- export * from './module';
@@ -1,16 +0,0 @@
1
- import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
2
- import { GrpcOptions } from '@nestjs/microservices';
3
- import { Authenticator } from '../authenticators';
4
- export interface GrpcHttpProxyModuleOptions {
5
- options: GrpcOptions['options'];
6
- authenticator?: Authenticator;
7
- }
8
- export interface GrpcHttpProxyOptionsFactory {
9
- createGrpcHttpProxyOptions(): Promise<GrpcHttpProxyModuleOptions> | GrpcHttpProxyModuleOptions;
10
- }
11
- export interface GrpcHttpProxyModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
12
- useExisting?: Type<GrpcHttpProxyOptionsFactory>;
13
- useClass?: Type<GrpcHttpProxyOptionsFactory>;
14
- useFactory?: (...args: any[]) => Promise<GrpcHttpProxyModuleOptions> | GrpcHttpProxyModuleOptions;
15
- inject?: any[];
16
- }
@@ -1 +0,0 @@
1
- export declare const GRPC_HTTP_PROXY_MODULE_OPTIONS = "GRPC_HTTP_PROXY_MODULE_OPTIONS";
@@ -1,9 +0,0 @@
1
- import { DynamicModule } from '@nestjs/common';
2
- import { GrpcHttpProxyModuleAsyncOptions } from './grpc-http-proxy-module-options.interface';
3
- import { GrpcHttpProxyModuleOptions } from './grpc-http-proxy-module-options.interface';
4
- export declare class GrpcHttpProxyModule {
5
- static register(options: GrpcHttpProxyModuleOptions): DynamicModule;
6
- static registerAsync(options: GrpcHttpProxyModuleAsyncOptions): DynamicModule;
7
- private static createAsyncProviders;
8
- private static createAsyncOptionsProvider;
9
- }
@@ -1,5 +0,0 @@
1
- import { Provider } from '@nestjs/common';
2
- import { GrpcHttpProxyModuleOptions } from './grpc-http-proxy-module-options.interface';
3
- export declare const createGrpcHttpProxyOptionsProvider: (options: GrpcHttpProxyModuleOptions) => Provider[];
4
- export declare const createGrpcHttpProxyProvider: () => Provider[];
5
- export declare const createGrpcHttpProxyExportsProvider: () => Provider[];
@@ -1,3 +0,0 @@
1
- export * from './grpc-http-proxy-module-options.interface';
2
- export * from './grpc-http-proxy.constants';
3
- export * from './grpc-http-proxy.module';
@@ -1 +0,0 @@
1
- export * from './proto.registry';
@@ -1,7 +0,0 @@
1
- import { Client } from '@grpc/grpc-js';
2
- export declare class ProtoClient {
3
- private readonly client;
4
- constructor(client: Client);
5
- static create(url: string | undefined, ServiceClient: any): ProtoClient;
6
- call(method: string, request: any, meta?: {}): Promise<unknown>;
7
- }
@@ -1,10 +0,0 @@
1
- import { OnApplicationBootstrap } from '@nestjs/common';
2
- import { GrpcHttpProxyModuleOptions } from '../module';
3
- import { ProtoClient } from './proto.client';
4
- export declare class ProtoRegistry implements OnApplicationBootstrap {
5
- private readonly options;
6
- private definitions;
7
- constructor(options: GrpcHttpProxyModuleOptions);
8
- onApplicationBootstrap(): Promise<void>;
9
- getClient(serviceName: string): ProtoClient;
10
- }