@mhubcloud/tms_core 3.8.0-beta.8 → 3.8.0-beta.9

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.
Files changed (2) hide show
  1. package/dist/index.js +37 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  DefaultPublisher: () => defaultPublisher,
34
34
  broker: () => broker_exports,
35
- getRedisClient: () => getRedisClient,
35
+ createRedisClient: () => createRedisClient,
36
36
  publisher: () => publisher,
37
37
  testUtils: () => testUtils_exports,
38
38
  utils: () => utils_exports
@@ -77,20 +77,28 @@ var appInsights = __toESM(require("applicationinsights"));
77
77
 
78
78
  // src/utils/redisClient.ts
79
79
  var import_redis = require("redis");
80
- var client;
81
- async function getRedisClient() {
82
- const redisUrl = process.env["RedisUrl"];
83
- if (!redisUrl) {
84
- return null;
85
- }
86
- if (!client) {
80
+ async function createRedisClient(url, password) {
81
+ let client;
82
+ if (!url || !password) {
83
+ if (process.env.RedisUrl && process.env.RedisPassword) {
84
+ client = (0, import_redis.createClient)({
85
+ url: `rediss://${process.env.RedisUrl}`,
86
+ password: process.env.RedisPassword,
87
+ socket: { tls: true }
88
+ });
89
+ } else {
90
+ throw new Error(
91
+ "Redis url and password are missing with no fallback available"
92
+ );
93
+ }
94
+ } else {
87
95
  client = (0, import_redis.createClient)({
88
- url: `rediss://${redisUrl}`,
89
- password: process.env["RedisPassword"],
96
+ url,
97
+ password,
90
98
  socket: { tls: true }
91
99
  });
92
- await client.connect();
93
100
  }
101
+ await client.connect();
94
102
  return client;
95
103
  }
96
104
 
@@ -122,10 +130,10 @@ var EventPublisherBase = class {
122
130
  }
123
131
  };
124
132
  async function logRedisEvent(key) {
125
- const redis = await getRedisClient();
126
- if (!redis) {
133
+ if (!process.env.RedisUrl || !process.env.RedisPassword) {
127
134
  return;
128
135
  }
136
+ const redis = await createRedisClient();
129
137
  await redis.multi().hIncrBy(key, "count", 1).expire(key, 660).exec();
130
138
  }
131
139
  var DestinationError = class _DestinationError extends Error {
@@ -153,9 +161,8 @@ function logAggregatedMetric({
153
161
  let key = "tms:";
154
162
  key += dimensions ? `${prefix}:${windowStart}:${dimensions}:${name}` : `${prefix}:${windowStart}:${name}`;
155
163
  void logRedisEvent(key).catch((error) => {
156
- if (error instanceof Error) {
157
- logException(new Error(`Metric log error: ${error.message}`));
158
- }
164
+ const message = error instanceof Error ? error.message : String(error);
165
+ logMessage(3, `Metric log error: ${message}`);
159
166
  });
160
167
  }
161
168
  function logMetric(name, value, properties) {
@@ -629,19 +636,6 @@ async function scheduleEvent(message, queue, options) {
629
636
  }
630
637
  }
631
638
 
632
- // src/utils/testUtils.ts
633
- var testUtils_exports = {};
634
- __export(testUtils_exports, {
635
- context: () => context
636
- });
637
- var context = {};
638
- context.log = function log(str) {
639
- console.log(str);
640
- };
641
- context.log.warn = function warn(str) {
642
- console.warn(str);
643
- };
644
-
645
639
  // src/defaultPublisher.ts
646
640
  async function defaultPublisher(azureFunctionContext, serviceBusMessage, source, platformPublisher, trigger) {
647
641
  if (serviceBusMessage.$schema === "mhub/pingtest") {
@@ -1240,6 +1234,19 @@ var universalAnalytics = {
1240
1234
  }
1241
1235
  };
1242
1236
 
1237
+ // src/utils/testUtils.ts
1238
+ var testUtils_exports = {};
1239
+ __export(testUtils_exports, {
1240
+ context: () => context
1241
+ });
1242
+ var context = {};
1243
+ context.log = function log(str) {
1244
+ console.log(str);
1245
+ };
1246
+ context.log.warn = function warn(str) {
1247
+ console.warn(str);
1248
+ };
1249
+
1243
1250
  // src/index.ts
1244
1251
  var publisher = {
1245
1252
  /* eslint-disable @typescript-eslint/naming-convention */
@@ -1257,7 +1264,7 @@ var publisher = {
1257
1264
  0 && (module.exports = {
1258
1265
  DefaultPublisher,
1259
1266
  broker,
1260
- getRedisClient,
1267
+ createRedisClient,
1261
1268
  publisher,
1262
1269
  testUtils,
1263
1270
  utils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mhubcloud/tms_core",
3
- "version": "3.8.0-beta.8",
3
+ "version": "3.8.0-beta.9",
4
4
  "description": "Core function for mHub Cloud TMS publishers",
5
5
  "homepage": "https://mhubcloud.com/",
6
6
  "license": "Apache 2.0",