@wenlarge/communication 1.0.1 → 1.0.3

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.
@@ -0,0 +1,8 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+ export interface GrpcClientModuleOptions {
3
+ authServiceUrl: string;
4
+ projectServiceUrl: string;
5
+ }
6
+ export declare class GrpcClientModule {
7
+ static forRoot(options: GrpcClientModuleOptions): DynamicModule;
8
+ }
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.GrpcClientModule = void 0;
42
+ const common_1 = require("@nestjs/common");
43
+ const microservices_1 = require("@nestjs/microservices");
44
+ const path_1 = require("path");
45
+ const auth_1 = require("../generated/auth");
46
+ const project_1 = require("../generated/project");
47
+ const auth_config_1 = require("../config/auth-config");
48
+ const project_config_1 = require("../config/project-config");
49
+ let GrpcClientModule = (() => {
50
+ let _classDecorators = [(0, common_1.Module)({})];
51
+ let _classDescriptor;
52
+ let _classExtraInitializers = [];
53
+ let _classThis;
54
+ var GrpcClientModule = _classThis = class {
55
+ static forRoot(options) {
56
+ return {
57
+ module: GrpcClientModule,
58
+ global: true,
59
+ imports: [
60
+ microservices_1.ClientsModule.register([
61
+ {
62
+ name: auth_1.AUTH_PACKAGE_NAME,
63
+ transport: microservices_1.Transport.GRPC,
64
+ options: {
65
+ package: auth_1.AUTH_PACKAGE_NAME,
66
+ protoPath: auth_config_1.AUTH_PROTO_PATH.map((p) => (0, path_1.join)(__dirname, "../../" + p)),
67
+ url: options.authServiceUrl,
68
+ loader: {
69
+ keepCase: true,
70
+ longs: String,
71
+ enums: String,
72
+ defaults: true,
73
+ oneofs: true,
74
+ },
75
+ },
76
+ },
77
+ {
78
+ name: project_1.PROJECT_PACKAGE_NAME,
79
+ transport: microservices_1.Transport.GRPC,
80
+ options: {
81
+ package: project_1.PROJECT_PACKAGE_NAME,
82
+ protoPath: project_config_1.PROJECT_PROTO_PATH.map((p) => (0, path_1.join)(__dirname, "../../" + p)),
83
+ url: options.projectServiceUrl,
84
+ loader: {
85
+ keepCase: true,
86
+ longs: String,
87
+ enums: String,
88
+ defaults: true,
89
+ oneofs: true,
90
+ },
91
+ },
92
+ },
93
+ ]),
94
+ ],
95
+ exports: [microservices_1.ClientsModule],
96
+ };
97
+ }
98
+ };
99
+ __setFunctionName(_classThis, "GrpcClientModule");
100
+ (() => {
101
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
102
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
103
+ GrpcClientModule = _classThis = _classDescriptor.value;
104
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
105
+ __runInitializers(_classThis, _classExtraInitializers);
106
+ })();
107
+ return GrpcClientModule = _classThis;
108
+ })();
109
+ exports.GrpcClientModule = GrpcClientModule;
@@ -0,0 +1 @@
1
+ export * from "./grpc-client.module";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./grpc-client.module"), exports);
@@ -3,5 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseUserFromMetadata = parseUserFromMetadata;
4
4
  function parseUserFromMetadata(metadata) {
5
5
  const raw = metadata.get('user')[0];
6
- return typeof raw === 'string' ? JSON.parse(raw) : null;
6
+ if (!raw || typeof raw !== 'string')
7
+ return null;
8
+ try {
9
+ const decoded = Buffer.from(raw, 'base64').toString('utf8');
10
+ return JSON.parse(decoded);
11
+ }
12
+ catch (_a) {
13
+ return null;
14
+ }
7
15
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export * from './helpers/helper';
2
- export * as Auth from './generated/auth';
3
- export * from './config/auth-config';
4
- export * as Project from './generated/project';
5
- export * from './config/project-config';
1
+ export * from "./helpers/helper";
2
+ export * as Auth from "./generated/auth";
3
+ export * from "./config/auth-config";
4
+ export * as Project from "./generated/project";
5
+ export * from "./config/project-config";
6
+ export * from "./grpc-client";
package/dist/index.js CHANGED
@@ -42,3 +42,4 @@ exports.Auth = __importStar(require("./generated/auth"));
42
42
  __exportStar(require("./config/auth-config"), exports);
43
43
  exports.Project = __importStar(require("./generated/project"));
44
44
  __exportStar(require("./config/project-config"), exports);
45
+ __exportStar(require("./grpc-client"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wenlarge/communication",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Shared gRPC proto interfaces and generated clients for Wenlarge microservices.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -39,7 +39,8 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@nestjs/microservices": "^11.1.0",
42
+ "@types/node": "^24.9.1",
42
43
  "ts-proto": "^1.152.2",
43
44
  "typescript": "^5.0.0"
44
45
  }
45
- }
46
+ }