@conduitplatform/module-tools 0.16.6 → 0.16.7

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.
@@ -2,7 +2,7 @@
2
2
  import { EventEmitter } from 'events';
3
3
  import { ServerWritableStream } from '@grpc/grpc-js';
4
4
  import { GrpcServer } from './GrpcServer.js';
5
- import ConduitGrpcSdk, { GrpcCallback, GrpcRequest, GrpcResponse, HealthCheckRequest, HealthCheckResponse, HealthCheckStatus, SetConfigRequest, SetConfigResponse } from '@conduitplatform/grpc-sdk';
5
+ import { ConduitGrpcSdk, GrpcCallback, GrpcRequest, GrpcResponse, HealthCheckRequest, HealthCheckResponse, HealthCheckStatus, SetConfigRequest, SetConfigResponse } from '@conduitplatform/grpc-sdk';
6
6
  export declare abstract class ConduitServiceModule {
7
7
  protected readonly _moduleName: string;
8
8
  protected _serviceName?: string;
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var ConduitGrpcSdk = require('@conduitplatform/grpc-sdk');
3
+ var grpcSdk = require('@conduitplatform/grpc-sdk');
4
4
  var grpcJs = require('@grpc/grpc-js');
5
5
  var protoLoader = require('@grpc/proto-loader');
6
6
  var fastJwt = require('fast-jwt');
7
- var lodashEs = require('lodash-es');
7
+ var lodash = require('lodash');
8
8
  var path = require('path');
9
9
  var events = require('events');
10
10
  var node_url = require('node:url');
@@ -19,7 +19,7 @@ var abortControllerX = require('abort-controller-x');
19
19
  var niceGrpcCommon = require('nice-grpc-common');
20
20
 
21
21
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
22
- class ConduitActiveSchema extends ConduitGrpcSdk.ConduitSchema {
22
+ class ConduitActiveSchema extends grpcSdk.ConduitSchema {
23
23
  dbInstance;
24
24
  constructor(dbInstance, name, fields, modelOptions, collectionName) {
25
25
  super(name, fields ?? {}, modelOptions, collectionName);
@@ -67,10 +67,10 @@ class ConduitStringConstructor {
67
67
  // private to disallow creating other instances of this type
68
68
  constructor() { }
69
69
  static get Optional() {
70
- return ConduitGrpcSdk.TYPE.String;
70
+ return grpcSdk.TYPE.String;
71
71
  }
72
72
  static get Required() {
73
- return { type: ConduitGrpcSdk.TYPE.String, required: true };
73
+ return { type: grpcSdk.TYPE.String, required: true };
74
74
  }
75
75
  }
76
76
  const ConduitString = ConduitStringConstructor;
@@ -78,10 +78,10 @@ class ConduitNumberConstructor {
78
78
  // private to disallow creating other instances of this type
79
79
  constructor() { }
80
80
  static get Optional() {
81
- return ConduitGrpcSdk.TYPE.Number;
81
+ return grpcSdk.TYPE.Number;
82
82
  }
83
83
  static get Required() {
84
- return { type: ConduitGrpcSdk.TYPE.Number, required: true };
84
+ return { type: grpcSdk.TYPE.Number, required: true };
85
85
  }
86
86
  }
87
87
  const ConduitNumber = ConduitNumberConstructor;
@@ -89,10 +89,10 @@ class ConduitBooleanConstructor {
89
89
  // private to disallow creating other instances of this type
90
90
  constructor() { }
91
91
  static get Optional() {
92
- return ConduitGrpcSdk.TYPE.Boolean;
92
+ return grpcSdk.TYPE.Boolean;
93
93
  }
94
94
  static get Required() {
95
- return { type: ConduitGrpcSdk.TYPE.Boolean, required: true };
95
+ return { type: grpcSdk.TYPE.Boolean, required: true };
96
96
  }
97
97
  }
98
98
  const ConduitBoolean = ConduitBooleanConstructor;
@@ -100,10 +100,10 @@ class ConduitDateConstructor {
100
100
  // private to disallow creating other instances of this type
101
101
  constructor() { }
102
102
  static get Optional() {
103
- return ConduitGrpcSdk.TYPE.Date;
103
+ return grpcSdk.TYPE.Date;
104
104
  }
105
105
  static get Required() {
106
- return { type: ConduitGrpcSdk.TYPE.Date, required: true };
106
+ return { type: grpcSdk.TYPE.Date, required: true };
107
107
  }
108
108
  }
109
109
  const ConduitDate = ConduitDateConstructor;
@@ -111,10 +111,10 @@ class ConduitObjectIdConstructor {
111
111
  // private to disallow creating other instances of this type
112
112
  constructor() { }
113
113
  static get Optional() {
114
- return ConduitGrpcSdk.TYPE.ObjectId;
114
+ return grpcSdk.TYPE.ObjectId;
115
115
  }
116
116
  static get Required() {
117
- return { type: ConduitGrpcSdk.TYPE.ObjectId, required: true };
117
+ return { type: grpcSdk.TYPE.ObjectId, required: true };
118
118
  }
119
119
  }
120
120
  const ConduitObjectId = ConduitObjectIdConstructor;
@@ -122,10 +122,10 @@ class ConduitJSONConstructor {
122
122
  // private to disallow creating other instances of this type
123
123
  constructor() { }
124
124
  static get Optional() {
125
- return ConduitGrpcSdk.TYPE.JSON;
125
+ return grpcSdk.TYPE.JSON;
126
126
  }
127
127
  static get Required() {
128
- return { type: ConduitGrpcSdk.TYPE.JSON, required: true };
128
+ return { type: grpcSdk.TYPE.JSON, required: true };
129
129
  }
130
130
  }
131
131
  const ConduitJson = ConduitJSONConstructor;
@@ -133,10 +133,10 @@ class ConduitRelationConstructor {
133
133
  // private to disallow creating other instances of this type
134
134
  constructor() { }
135
135
  static Optional(model) {
136
- return { type: ConduitGrpcSdk.TYPE.Relation, model, required: false };
136
+ return { type: grpcSdk.TYPE.Relation, model, required: false };
137
137
  }
138
138
  static Required(model) {
139
- return { type: ConduitGrpcSdk.TYPE.Relation, model, required: true };
139
+ return { type: grpcSdk.TYPE.Relation, model, required: true };
140
140
  }
141
141
  }
142
142
  const ConduitRelation = ConduitRelationConstructor;
@@ -182,7 +182,7 @@ function wrapGrpcFunctions(functions, postponeRestart) {
182
182
  const wrappedFunctions = {};
183
183
  Object.keys(functions).forEach(name => {
184
184
  wrappedFunctions[name] = (call, callback) => {
185
- ConduitGrpcSdk.Metrics?.increment('internal_grpc_requests_total');
185
+ grpcSdk.ConduitGrpcSdk.Metrics?.increment('internal_grpc_requests_total');
186
186
  postponeRestart();
187
187
  if (grpcKey) {
188
188
  const verify = fastJwt.createVerifier({ key: grpcKey });
@@ -249,7 +249,7 @@ class GrpcServer {
249
249
  this._url = `0.0.0.0:${port ?? '5000'}`;
250
250
  }
251
251
  async waitForReady() {
252
- while (!lodashEs.isNil(this.scheduledRestart)) {
252
+ while (!lodash.isNil(this.scheduledRestart)) {
253
253
  await this.wait(200);
254
254
  }
255
255
  }
@@ -258,7 +258,7 @@ class GrpcServer {
258
258
  return this._url;
259
259
  }
260
260
  async createNewServer(useForce = false) {
261
- if (lodashEs.isNil(this._useForce)) {
261
+ if (lodash.isNil(this._useForce)) {
262
262
  this._useForce = useForce;
263
263
  }
264
264
  const serverResult = await createServer(this._url);
@@ -269,7 +269,7 @@ class GrpcServer {
269
269
  async addService(protoPath, protoDescription, functions) {
270
270
  functions = wrapGrpcFunctions(functions, this.postponeRestart.bind(this));
271
271
  if (this._serviceNames.indexOf(protoDescription) !== -1) {
272
- ConduitGrpcSdk.Logger.log('Service already exists, performing replace');
272
+ grpcSdk.ConduitGrpcSdk.Logger.log('Service already exists, performing replace');
273
273
  this._services[this._serviceNames.indexOf(protoDescription)] = {
274
274
  protoPath,
275
275
  protoDescription,
@@ -282,7 +282,7 @@ class GrpcServer {
282
282
  this._services.push({ protoPath, protoDescription, functions });
283
283
  this._serviceNames.push(protoDescription);
284
284
  if (this.started) {
285
- ConduitGrpcSdk.Logger.log('Server already started, scheduling refresh..');
285
+ grpcSdk.ConduitGrpcSdk.Logger.log('Server already started, scheduling refresh..');
286
286
  this.scheduleRefresh();
287
287
  return this;
288
288
  }
@@ -329,9 +329,9 @@ class GrpcServer {
329
329
  }
330
330
  const self = this;
331
331
  this.scheduledRestart = setTimeout(async () => {
332
- ConduitGrpcSdk.Logger.log('Begin refresh');
332
+ grpcSdk.ConduitGrpcSdk.Logger.log('Begin refresh');
333
333
  await self.refresh();
334
- ConduitGrpcSdk.Logger.log('Refresh complete');
334
+ grpcSdk.ConduitGrpcSdk.Logger.log('Refresh complete');
335
335
  clearTimeout(self.scheduledRestart);
336
336
  self.scheduledRestart = undefined;
337
337
  self._postponeRequests = 0;
@@ -339,11 +339,11 @@ class GrpcServer {
339
339
  }
340
340
  start() {
341
341
  if (this.started) {
342
- ConduitGrpcSdk.Logger.error('gRPC server is already running!');
342
+ grpcSdk.ConduitGrpcSdk.Logger.error('gRPC server is already running!');
343
343
  return;
344
344
  }
345
345
  else if (!this.started && this.startedOnce) {
346
- ConduitGrpcSdk.Logger.error('gRPC server is down for refresh!');
346
+ grpcSdk.ConduitGrpcSdk.Logger.error('gRPC server is down for refresh!');
347
347
  }
348
348
  this.started = true;
349
349
  this.startedOnce = true;
@@ -418,7 +418,7 @@ class RouteBuilder {
418
418
  return this;
419
419
  }
420
420
  return(name, fields) {
421
- this._returns = new ConduitGrpcSdk.ConduitRouteReturnDefinition(name, fields);
421
+ this._returns = new grpcSdk.ConduitRouteReturnDefinition(name, fields);
422
422
  return this;
423
423
  }
424
424
  handler(fn) {
@@ -469,11 +469,11 @@ function generateLog(routerType, routerRequest, requestReceive, call, status) {
469
469
  log += `(${routerType}) Socket: ${call.request.event} socket: ${call.request.socket}`;
470
470
  }
471
471
  log += ` ${status ?? '200'} ${latency}`;
472
- ConduitGrpcSdk.Logger.log(log);
473
- ConduitGrpcSdk.Metrics?.set('grpc_request_latency_seconds', latency / 1000);
474
- ConduitGrpcSdk.Metrics?.set(`${routerType}_grpc_request_latency_seconds`, latency / 1000);
472
+ grpcSdk.ConduitGrpcSdk.Logger.log(log);
473
+ grpcSdk.ConduitGrpcSdk.Metrics?.set('grpc_request_latency_seconds', latency / 1000);
474
+ grpcSdk.ConduitGrpcSdk.Metrics?.set(`${routerType}_grpc_request_latency_seconds`, latency / 1000);
475
475
  const successStatus = !status || status.toString().charAt(0) === '2';
476
- ConduitGrpcSdk.Metrics?.increment(`${routerType}_grpc_response_statuses_total`, 1, {
476
+ grpcSdk.ConduitGrpcSdk.Metrics?.increment(`${routerType}_grpc_response_statuses_total`, 1, {
477
477
  success: successStatus ? 'true' : 'false',
478
478
  });
479
479
  }
@@ -534,7 +534,7 @@ function wrapRouterGrpcFunction(fun, routerType) {
534
534
  return (call, callback) => {
535
535
  const requestReceive = Date.now();
536
536
  let routerRequest = true;
537
- ConduitGrpcSdk.Metrics?.increment(`${routerType}_grpc_requests_total`);
537
+ grpcSdk.ConduitGrpcSdk.Metrics?.increment(`${routerType}_grpc_requests_total`);
538
538
  try {
539
539
  call.request.context = parseRequestData(call.request.context);
540
540
  call.request.params = parseRequestData(call.request.params);
@@ -548,9 +548,9 @@ function wrapRouterGrpcFunction(fun, routerType) {
548
548
  }
549
549
  }
550
550
  catch (e) {
551
- ConduitGrpcSdk.Metrics?.increment(`${routerType}_grpc_errors_total`);
551
+ grpcSdk.ConduitGrpcSdk.Metrics?.increment(`${routerType}_grpc_errors_total`);
552
552
  generateLog(routerType, routerRequest, requestReceive, call, grpcJs.status.INTERNAL);
553
- ConduitGrpcSdk.Logger.error(e.message ?? 'Something went wrong');
553
+ grpcSdk.ConduitGrpcSdk.Logger.error(e.message ?? 'Something went wrong');
554
554
  return callback({
555
555
  code: grpcJs.status.INTERNAL,
556
556
  message: e.message ?? 'Something went wrong',
@@ -562,9 +562,9 @@ function wrapRouterGrpcFunction(fun, routerType) {
562
562
  })
563
563
  .then(r => parseResponseData(r, routerRequest, requestReceive, call, callback, responded, routerType))
564
564
  .catch(error => {
565
- ConduitGrpcSdk.Metrics?.increment(`${routerType}_grpc_errors_total`);
565
+ grpcSdk.ConduitGrpcSdk.Metrics?.increment(`${routerType}_grpc_errors_total`);
566
566
  generateLog(routerType, routerRequest, requestReceive, call, error.code ?? grpcJs.status.INTERNAL);
567
- ConduitGrpcSdk.Logger.error(error.message ?? 'Something went wrong');
567
+ grpcSdk.ConduitGrpcSdk.Logger.error(error.message ?? 'Something went wrong');
568
568
  callback({
569
569
  code: error.code ?? grpcJs.status.INTERNAL,
570
570
  message: error.details ?? error.message ?? 'Something went wrong',
@@ -668,24 +668,24 @@ class RoutingManager {
668
668
  constructor(_router, _server) {
669
669
  this._router = _router;
670
670
  this._server = _server;
671
- if (_router instanceof ConduitGrpcSdk.Admin) {
671
+ if (_router instanceof grpcSdk.Admin) {
672
672
  this.isAdmin = true;
673
673
  }
674
674
  }
675
675
  get(path) {
676
- return new RouteBuilder(this).method(ConduitGrpcSdk.ConduitRouteActions.GET).path(path);
676
+ return new RouteBuilder(this).method(grpcSdk.ConduitRouteActions.GET).path(path);
677
677
  }
678
678
  post(path) {
679
- return new RouteBuilder(this).method(ConduitGrpcSdk.ConduitRouteActions.POST).path(path);
679
+ return new RouteBuilder(this).method(grpcSdk.ConduitRouteActions.POST).path(path);
680
680
  }
681
681
  delete(path) {
682
- return new RouteBuilder(this).method(ConduitGrpcSdk.ConduitRouteActions.DELETE).path(path);
682
+ return new RouteBuilder(this).method(grpcSdk.ConduitRouteActions.DELETE).path(path);
683
683
  }
684
684
  update(path) {
685
- return new RouteBuilder(this).method(ConduitGrpcSdk.ConduitRouteActions.UPDATE).path(path);
685
+ return new RouteBuilder(this).method(grpcSdk.ConduitRouteActions.UPDATE).path(path);
686
686
  }
687
687
  patch(path) {
688
- return new RouteBuilder(this).method(ConduitGrpcSdk.ConduitRouteActions.PATCH).path(path);
688
+ return new RouteBuilder(this).method(grpcSdk.ConduitRouteActions.PATCH).path(path);
689
689
  }
690
690
  proxy() {
691
691
  return new ProxyRouteBuilder(this);
@@ -803,9 +803,9 @@ class ConduitServiceModule {
803
803
  _address; // external address:port of service (LoadBalancer)
804
804
  grpcServer;
805
805
  events = new events.EventEmitter();
806
- _serviceHealthState = ConduitGrpcSdk.HealthCheckStatus.SERVING; // default for health-agnostic modules
806
+ _serviceHealthState = grpcSdk.HealthCheckStatus.SERVING; // default for health-agnostic modules
807
807
  constructor(moduleName) {
808
- this._moduleName = lodashEs.camelCase(moduleName);
808
+ this._moduleName = lodash.camelCase(moduleName);
809
809
  }
810
810
  _registered = false;
811
811
  set registered(registered) {
@@ -830,12 +830,12 @@ class ConduitServiceModule {
830
830
  return this._serviceHealthState;
831
831
  }
832
832
  updateHealth(state, init = false) {
833
- if ((state === ConduitGrpcSdk.HealthCheckStatus.UNKNOWN && !init) ||
834
- state === ConduitGrpcSdk.HealthCheckStatus.SERVICE_UNKNOWN) {
835
- throw new Error(`Cannot explicitly set gRPC health state to ${ConduitGrpcSdk.HealthCheckStatus[state]}`);
833
+ if ((state === grpcSdk.HealthCheckStatus.UNKNOWN && !init) ||
834
+ state === grpcSdk.HealthCheckStatus.SERVICE_UNKNOWN) {
835
+ throw new Error(`Cannot explicitly set gRPC health state to ${grpcSdk.HealthCheckStatus[state]}`);
836
836
  }
837
837
  if (!init) {
838
- ConduitGrpcSdk.Metrics?.set('module_health_state', state === ConduitGrpcSdk.HealthCheckStatus.SERVING ? 1 : 0);
838
+ grpcSdk.ConduitGrpcSdk.Metrics?.set('module_health_state', state === grpcSdk.HealthCheckStatus.SERVING ? 1 : 0);
839
839
  }
840
840
  if (init) {
841
841
  this._serviceHealthState = state;
@@ -854,13 +854,13 @@ class ConduitServiceModule {
854
854
  const service = call.request.service.substring(call.request.service.indexOf('.') + 1);
855
855
  if (service && service !== this._serviceName) {
856
856
  callback(null, {
857
- status: ConduitGrpcSdk.HealthCheckStatus.SERVICE_UNKNOWN,
857
+ status: grpcSdk.HealthCheckStatus.SERVICE_UNKNOWN,
858
858
  });
859
859
  }
860
860
  else {
861
861
  if (!this._registered) {
862
862
  return callback(null, {
863
- status: ConduitGrpcSdk.HealthCheckResponse_ServingStatus.UNKNOWN,
863
+ status: grpcSdk.HealthCheckResponse_ServingStatus.UNKNOWN,
864
864
  });
865
865
  }
866
866
  callback(null, {
@@ -872,7 +872,7 @@ class ConduitServiceModule {
872
872
  const service = call.request.service.substring(call.request.service.indexOf('.') + 1);
873
873
  if (service && service !== this._serviceName) {
874
874
  call.write({
875
- status: ConduitGrpcSdk.HealthCheckStatus.SERVICE_UNKNOWN,
875
+ status: grpcSdk.HealthCheckStatus.SERVICE_UNKNOWN,
876
876
  });
877
877
  }
878
878
  else {
@@ -946,7 +946,7 @@ const createFormat = (logMeta = true) => {
946
946
  return `[${info.timestamp}] [${info.level.toUpperCase()}]: ${info.message} ${info.stack}`;
947
947
  }
948
948
  if (logMeta) {
949
- return `[${info.timestamp}] [${info.level.toUpperCase()}]: ${info.message} ${!lodashEs.isEmpty(info.meta) ? processMeta(info.meta) : ''}`;
949
+ return `[${info.timestamp}] [${info.level.toUpperCase()}]: ${info.message} ${!lodash.isEmpty(info.meta) ? processMeta(info.meta) : ''}`;
950
950
  }
951
951
  else {
952
952
  return `[${info.timestamp}] [${info.level.toUpperCase()}]: ${info.message}`;
@@ -1026,7 +1026,7 @@ async function setupLoki(module, instance) {
1026
1026
  const onTry = async () => {
1027
1027
  return await lokiReadyCheck(lokiUrl)
1028
1028
  .then(() => {
1029
- ConduitGrpcSdk.Logger.addTransport(new LokiTransport({
1029
+ grpcSdk.ConduitGrpcSdk.Logger.addTransport(new LokiTransport({
1030
1030
  level: 'debug',
1031
1031
  host: lokiUrl,
1032
1032
  batching: false,
@@ -1044,7 +1044,7 @@ async function setupLoki(module, instance) {
1044
1044
  .catch(() => true); // retry
1045
1045
  };
1046
1046
  const onFailure = () => {
1047
- ConduitGrpcSdk.Logger.error(`Failed to connect to Loki on '${lokiUrl}'`);
1047
+ grpcSdk.ConduitGrpcSdk.Logger.error(`Failed to connect to Loki on '${lokiUrl}'`);
1048
1048
  };
1049
1049
  await linearBackoffTimeoutAsync(onTry, 250, 15, onFailure, true);
1050
1050
  }
@@ -1064,7 +1064,7 @@ class MetricsServer {
1064
1064
  const port = this.getHttpPort();
1065
1065
  const url = '0.0.0.0:' + port.toString();
1066
1066
  server.listen(port, () => {
1067
- ConduitGrpcSdk.Logger.info(`Metrics server listening on: ${url}`);
1067
+ grpcSdk.ConduitGrpcSdk.Logger.info(`Metrics server listening on: ${url}`);
1068
1068
  });
1069
1069
  server.get('/', (req, res) => {
1070
1070
  return res
@@ -1080,12 +1080,12 @@ class MetricsServer {
1080
1080
  getHttpPort() {
1081
1081
  const value = process.env['METRICS_PORT'];
1082
1082
  if (!value) {
1083
- ConduitGrpcSdk.Logger.error(`Metrics HTTP port not set`);
1083
+ grpcSdk.ConduitGrpcSdk.Logger.error(`Metrics HTTP port not set`);
1084
1084
  process.exit(-1);
1085
1085
  }
1086
1086
  const port = parseInt(value, 10);
1087
- if (lodashEs.isNaN(port) || port < 1 || port > 65535) {
1088
- ConduitGrpcSdk.Logger.error(`Invalid HTTP port value: ${port}`);
1087
+ if (lodash.isNaN(port) || port < 1 || port > 65535) {
1088
+ grpcSdk.ConduitGrpcSdk.Logger.error(`Invalid HTTP port value: ${port}`);
1089
1089
  process.exit(-1);
1090
1090
  }
1091
1091
  return port;
@@ -1094,70 +1094,70 @@ class MetricsServer {
1094
1094
 
1095
1095
  var defaultMetrics = {
1096
1096
  internalGrpcRequests: {
1097
- type: ConduitGrpcSdk.MetricType.Counter,
1097
+ type: grpcSdk.MetricType.Counter,
1098
1098
  config: {
1099
1099
  name: 'internal_grpc_requests_total',
1100
1100
  help: "Tracks the total number of Conduit's internal gRPC requests",
1101
1101
  },
1102
1102
  },
1103
1103
  clientGrpcRequests: {
1104
- type: ConduitGrpcSdk.MetricType.Counter,
1104
+ type: grpcSdk.MetricType.Counter,
1105
1105
  config: {
1106
1106
  name: 'client_grpc_requests_total',
1107
1107
  help: 'Tracks the total number of the client gRPC requests',
1108
1108
  },
1109
1109
  },
1110
1110
  adminGrpcRequests: {
1111
- type: ConduitGrpcSdk.MetricType.Counter,
1111
+ type: grpcSdk.MetricType.Counter,
1112
1112
  config: {
1113
1113
  name: 'admin_grpc_requests_total',
1114
1114
  help: 'Tracks the total number of the admin gRPC requests',
1115
1115
  },
1116
1116
  },
1117
1117
  clientGrpcErrors: {
1118
- type: ConduitGrpcSdk.MetricType.Counter,
1118
+ type: grpcSdk.MetricType.Counter,
1119
1119
  config: {
1120
1120
  name: 'client_grpc_errors_total',
1121
1121
  help: 'Tracks the total number of client grpc errors',
1122
1122
  },
1123
1123
  },
1124
1124
  adminGrpcErrors: {
1125
- type: ConduitGrpcSdk.MetricType.Counter,
1125
+ type: grpcSdk.MetricType.Counter,
1126
1126
  config: {
1127
1127
  name: 'admin_grpc_errors_total',
1128
1128
  help: 'Tracks the total number of admin grpc errors',
1129
1129
  },
1130
1130
  },
1131
1131
  moduleHealthState: {
1132
- type: ConduitGrpcSdk.MetricType.Gauge,
1132
+ type: grpcSdk.MetricType.Gauge,
1133
1133
  config: {
1134
1134
  name: 'module_health_state',
1135
1135
  help: 'Tracks the health state of the module',
1136
1136
  },
1137
1137
  },
1138
1138
  grpcRequestLatency: {
1139
- type: ConduitGrpcSdk.MetricType.Gauge,
1139
+ type: grpcSdk.MetricType.Gauge,
1140
1140
  config: {
1141
1141
  name: 'grpc_request_latency_seconds',
1142
1142
  help: 'Tracks the latency of grpc requests in seconds',
1143
1143
  },
1144
1144
  },
1145
1145
  adminGrpcRequestLatency: {
1146
- type: ConduitGrpcSdk.MetricType.Gauge,
1146
+ type: grpcSdk.MetricType.Gauge,
1147
1147
  config: {
1148
1148
  name: 'admin_grpc_request_latency_seconds',
1149
1149
  help: 'Tracks the latency of admin grpc requests in seconds',
1150
1150
  },
1151
1151
  },
1152
1152
  clientGrpcRequestLatency: {
1153
- type: ConduitGrpcSdk.MetricType.Gauge,
1153
+ type: grpcSdk.MetricType.Gauge,
1154
1154
  config: {
1155
1155
  name: 'client_grpc_request_latency_seconds',
1156
1156
  help: 'Tracks the latency of client grpc requests in seconds',
1157
1157
  },
1158
1158
  },
1159
1159
  grpcResponseStatuses: {
1160
- type: ConduitGrpcSdk.MetricType.Counter,
1160
+ type: grpcSdk.MetricType.Counter,
1161
1161
  config: {
1162
1162
  name: 'grpc_response_statuses_total',
1163
1163
  help: 'Tracks the total number of grpc response codes',
@@ -1165,7 +1165,7 @@ var defaultMetrics = {
1165
1165
  },
1166
1166
  },
1167
1167
  adminGrpcResponseStatuses: {
1168
- type: ConduitGrpcSdk.MetricType.Counter,
1168
+ type: grpcSdk.MetricType.Counter,
1169
1169
  config: {
1170
1170
  name: 'admin_grpc_response_statuses_total',
1171
1171
  help: 'Tracks the total number of admin grpc response codes',
@@ -1173,7 +1173,7 @@ var defaultMetrics = {
1173
1173
  },
1174
1174
  },
1175
1175
  clientGrpcResponseStatuses: {
1176
- type: ConduitGrpcSdk.MetricType.Counter,
1176
+ type: grpcSdk.MetricType.Counter,
1177
1177
  config: {
1178
1178
  name: 'client_grpc_response_statuses_total',
1179
1179
  help: 'Tracks the total number of client grpc response codes',
@@ -1210,16 +1210,16 @@ class ConduitMetrics {
1210
1210
  const metricConfig = JSON.parse(JSON.stringify(config));
1211
1211
  metricConfig.name = this.addPrefix(config.name);
1212
1212
  switch (type) {
1213
- case ConduitGrpcSdk.MetricType.Counter:
1213
+ case grpcSdk.MetricType.Counter:
1214
1214
  this.createCounter(metricConfig);
1215
1215
  break;
1216
- case ConduitGrpcSdk.MetricType.Gauge:
1216
+ case grpcSdk.MetricType.Gauge:
1217
1217
  this.createGauge(metricConfig);
1218
1218
  break;
1219
- case ConduitGrpcSdk.MetricType.Histogram:
1219
+ case grpcSdk.MetricType.Histogram:
1220
1220
  this.createHistogram(metricConfig);
1221
1221
  break;
1222
- case ConduitGrpcSdk.MetricType.Summary:
1222
+ case grpcSdk.MetricType.Summary:
1223
1223
  this.createSummary(metricConfig);
1224
1224
  break;
1225
1225
  }
@@ -1410,7 +1410,7 @@ function clientMiddleware() {
1410
1410
 
1411
1411
  const __filename$1 = node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
1412
1412
  const __dirname$1 = path.dirname(__filename$1);
1413
- const initializeSdk = (coreUrl, moduleName, watchModules = true, serviceHealthStatusGetter = () => ConduitGrpcSdk.HealthCheckStatus.SERVING) => {
1413
+ const initializeSdk = (coreUrl, moduleName, watchModules = true, serviceHealthStatusGetter = () => grpcSdk.HealthCheckStatus.SERVING) => {
1414
1414
  let logger;
1415
1415
  try {
1416
1416
  logger = new ConduitLogger([
@@ -1427,13 +1427,13 @@ const initializeSdk = (coreUrl, moduleName, watchModules = true, serviceHealthSt
1427
1427
  catch (e) {
1428
1428
  logger = new ConduitLogger();
1429
1429
  }
1430
- const grpcSdk = new ConduitGrpcSdk(coreUrl, moduleName, watchModules, logger, serviceHealthStatusGetter);
1431
- setupLoki(grpcSdk.name, grpcSdk.instance).then();
1430
+ const grpcSdk$1 = new grpcSdk.ConduitGrpcSdk(coreUrl, moduleName, watchModules, logger, serviceHealthStatusGetter);
1431
+ setupLoki(grpcSdk$1.name, grpcSdk$1.instance).then();
1432
1432
  if (process.env.METRICS_PORT) {
1433
- ConduitGrpcSdk.Metrics = new ConduitMetrics(grpcSdk.name, grpcSdk.instance);
1434
- grpcSdk.addMiddleware(clientMiddleware());
1433
+ grpcSdk.ConduitGrpcSdk.Metrics = new ConduitMetrics(grpcSdk$1.name, grpcSdk$1.instance);
1434
+ grpcSdk$1.addMiddleware(clientMiddleware());
1435
1435
  }
1436
- return grpcSdk;
1436
+ return grpcSdk$1;
1437
1437
  };
1438
1438
 
1439
1439
  /**
@@ -1499,7 +1499,7 @@ function merge(objA, objB) {
1499
1499
  return srcValue;
1500
1500
  }
1501
1501
  };
1502
- return lodashEs.mergeWith({}, objA, objB, customizer);
1502
+ return lodash.mergeWith({}, objA, objB, customizer);
1503
1503
  }
1504
1504
 
1505
1505
  const convictConfigParser = (config) => {
@@ -1574,13 +1574,13 @@ class ManagedModule extends ConduitServiceModule {
1574
1574
  await this.grpcSdk.config.registerModule(this.name, this.address, this.healthState);
1575
1575
  }
1576
1576
  catch (err) {
1577
- ConduitGrpcSdk.Logger.error('Failed to initialize server');
1578
- ConduitGrpcSdk.Logger.error(err);
1577
+ grpcSdk.ConduitGrpcSdk.Logger.error('Failed to initialize server');
1578
+ grpcSdk.ConduitGrpcSdk.Logger.error(err);
1579
1579
  process.exit(-1);
1580
1580
  }
1581
1581
  await this.postRegisterLifecycle().catch((err) => {
1582
- ConduitGrpcSdk.Logger.error('Failed to activate module');
1583
- ConduitGrpcSdk.Logger.error(err);
1582
+ grpcSdk.ConduitGrpcSdk.Logger.error('Failed to activate module');
1583
+ grpcSdk.ConduitGrpcSdk.Logger.error(err);
1584
1584
  process.exit(-1);
1585
1585
  });
1586
1586
  }
@@ -1642,11 +1642,11 @@ class ManagedModule extends ConduitServiceModule {
1642
1642
  * Registers common and module-specific metric types.
1643
1643
  */
1644
1644
  async registerMetrics() {
1645
- if (ConduitGrpcSdk.Metrics) {
1646
- ConduitGrpcSdk.Metrics.initializeDefaultMetrics();
1645
+ if (grpcSdk.ConduitGrpcSdk.Metrics) {
1646
+ grpcSdk.ConduitGrpcSdk.Metrics.initializeDefaultMetrics();
1647
1647
  if (this.metricsSchema) {
1648
1648
  Object.values(this.metricsSchema).forEach(metric => {
1649
- ConduitGrpcSdk.Metrics.registerMetric(metric.type, metric.config);
1649
+ grpcSdk.ConduitGrpcSdk.Metrics.registerMetric(metric.type, metric.config);
1650
1650
  });
1651
1651
  }
1652
1652
  }
@@ -1670,7 +1670,7 @@ class ManagedModule extends ConduitServiceModule {
1670
1670
  await this.addHealthCheckService();
1671
1671
  await this.addModuleService();
1672
1672
  await this.grpcServer.start();
1673
- ConduitGrpcSdk.Logger.log('gRPC server listening on ' + this._port);
1673
+ grpcSdk.ConduitGrpcSdk.Logger.log('gRPC server listening on ' + this._port);
1674
1674
  }
1675
1675
  async setConfig(call, callback) {
1676
1676
  try {
@@ -1701,7 +1701,7 @@ class ManagedModule extends ConduitServiceModule {
1701
1701
  }
1702
1702
  ConfigController.getInstance().config = config;
1703
1703
  await this.onConfig();
1704
- this.grpcSdk.bus?.publish(lodashEs.kebabCase(this.name) + ':config:update', JSON.stringify(config));
1704
+ this.grpcSdk.bus?.publish(lodash.kebabCase(this.name) + ':config:update', JSON.stringify(config));
1705
1705
  }
1706
1706
  catch (e) {
1707
1707
  return callback({ code: grpcJs.status.INTERNAL, message: e.message });
@@ -1711,7 +1711,7 @@ class ManagedModule extends ConduitServiceModule {
1711
1711
  async handleConfigSyncUpdate() {
1712
1712
  if (!this.config)
1713
1713
  return;
1714
- this.grpcSdk.bus.subscribe(`${lodashEs.kebabCase(this.name)}:config:update`, async (message) => {
1714
+ this.grpcSdk.bus.subscribe(`${lodash.kebabCase(this.name)}:config:update`, async (message) => {
1715
1715
  ConfigController.getInstance().config = await this.preConfig(JSON.parse(message));
1716
1716
  await this.onConfig();
1717
1717
  });