@mamindom/common 1.0.120 → 1.0.122

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.
@@ -6,6 +6,7 @@ export declare class GrpcClientFactory {
6
6
  protoPath: string | string[];
7
7
  url: string;
8
8
  channelOptions?: Record<string, any>;
9
+ defaultTimeout?: string;
9
10
  }): ClientGrpc;
10
11
  register(token: string, client: ClientGrpc): void;
11
12
  getClient<T extends ClientGrpc = ClientGrpc>(token: string): T;
@@ -55,14 +55,21 @@ let GrpcClientFactory = (() => {
55
55
  createClient(options) {
56
56
  const channelOptions = {
57
57
  'grpc.service_config': JSON.stringify({
58
- loadBalancingConfig: [{ round_robin: {} }]
58
+ loadBalancingConfig: [{ round_robin: {} }],
59
+ methodConfig: [
60
+ {
61
+ name: [{}],
62
+ timeout: options.defaultTimeout ?? '10s'
63
+ }
64
+ ]
59
65
  }),
60
66
  ...options.channelOptions
61
67
  };
68
+ const { defaultTimeout: _defaultTimeout, ...grpcOptions } = options;
62
69
  return microservices_1.ClientProxyFactory.create({
63
70
  transport: microservices_1.Transport.GRPC,
64
71
  options: {
65
- ...options,
72
+ ...grpcOptions,
66
73
  channelOptions,
67
74
  loader: {
68
75
  keepCase: false,
@@ -69,6 +69,7 @@ let GrpcModule = (() => {
69
69
  package: cfg.package,
70
70
  protoPath: cfg.protoPath,
71
71
  url,
72
+ defaultTimeout: cfg.timeout,
72
73
  channelOptions: {
73
74
  'grpc.max_receive_message_length': 1024 * 1024 * 50, // 50 MB
74
75
  'grpc.max_send_message_length': 1024 * 1024 * 50 // 50 MB
@@ -33,6 +33,7 @@ export declare const GRPC_CLIENTS: {
33
33
  readonly package: "media.v1";
34
34
  readonly protoPath: readonly [string];
35
35
  readonly env: "MEDIA_GRPC_URL";
36
+ readonly timeout: "60s";
36
37
  };
37
38
  readonly PROMO_PACKAGE: {
38
39
  readonly package: "promo.v1";
@@ -52,7 +52,8 @@ exports.GRPC_CLIENTS = {
52
52
  MEDIA_PACKAGE: {
53
53
  package: 'media.v1',
54
54
  protoPath: [contracts_1.PROTO_PATHS.MEDIA],
55
- env: 'MEDIA_GRPC_URL'
55
+ env: 'MEDIA_GRPC_URL',
56
+ timeout: '60s'
56
57
  },
57
58
  PROMO_PACKAGE: {
58
59
  package: 'promo.v1',
@@ -27,6 +27,10 @@ export interface BootstrapRmqDlxOptions {
27
27
  * DLQ queue + binding. Run once at service bootstrap, before connecting RMQ
28
28
  * microservice. Safe to repeat — RabbitMQ no-ops on identical re-declares.
29
29
  *
30
+ * `amqplib` is loaded lazily so services that import other helpers from this
31
+ * module but don't actually run RMQ (e.g. gateway-service) don't need amqplib
32
+ * in their node_modules.
33
+ *
30
34
  * Why fanout: dead-lettered messages keep their original routing key, but
31
35
  * we want every message into the DLX to land in the DLQ regardless of key.
32
36
  */
@@ -1,44 +1,10 @@
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.dlxNameFor = dlxNameFor;
37
4
  exports.dlqNameFor = dlqNameFor;
38
5
  exports.rmqQueueDlxArguments = rmqQueueDlxArguments;
39
6
  exports.bootstrapRmqDlx = bootstrapRmqDlx;
40
7
  const common_1 = require("@nestjs/common");
41
- const amqp = __importStar(require("amqplib"));
42
8
  /**
43
9
  * Convention: dead-letter exchange and queue names are derived from the
44
10
  * primary queue name. `cart_queue` → `cart.dlx` + `cart.dlq`. The `_queue`
@@ -71,6 +37,10 @@ function rmqQueueDlxArguments(queue) {
71
37
  * DLQ queue + binding. Run once at service bootstrap, before connecting RMQ
72
38
  * microservice. Safe to repeat — RabbitMQ no-ops on identical re-declares.
73
39
  *
40
+ * `amqplib` is loaded lazily so services that import other helpers from this
41
+ * module but don't actually run RMQ (e.g. gateway-service) don't need amqplib
42
+ * in their node_modules.
43
+ *
74
44
  * Why fanout: dead-lettered messages keep their original routing key, but
75
45
  * we want every message into the DLX to land in the DLQ regardless of key.
76
46
  */
@@ -78,6 +48,8 @@ async function bootstrapRmqDlx(opts) {
78
48
  const logger = new common_1.Logger('RmqDlxBootstrap');
79
49
  const dlx = dlxNameFor(opts.queue);
80
50
  const dlq = dlqNameFor(opts.queue);
51
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
52
+ const amqp = require('amqplib');
81
53
  const connection = await amqp.connect(opts.url);
82
54
  try {
83
55
  const channel = await connection.createChannel();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mamindom/common",
3
- "version": "1.0.120",
3
+ "version": "1.0.122",
4
4
  "type": "commonjs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "typescript": "^5.9.3"
24
24
  },
25
25
  "dependencies": {
26
- "@mamindom/contracts": "^1.0.150",
26
+ "@mamindom/contracts": "^1.0.152",
27
27
  "@nestjs/common": "^11.1.16",
28
28
  "@nestjs/config": "^4.0.3",
29
29
  "@nestjs/microservices": "^11.1.16"