@mhubcloud/tms_core 3.8.0-beta.1 → 3.8.0-beta.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.
- package/dist/index.js +35 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31,8 +31,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
DefaultPublisher: () => defaultPublisher,
|
|
34
|
+
appInsightsClient: () => appInsightsClient_exports,
|
|
34
35
|
broker: () => broker_exports,
|
|
35
36
|
publisher: () => publisher,
|
|
37
|
+
redisClient: () => redisClient_exports,
|
|
36
38
|
testUtils: () => testUtils_exports,
|
|
37
39
|
utils: () => utils_exports
|
|
38
40
|
});
|
|
@@ -53,7 +55,6 @@ var import_service_bus = require("@azure/service-bus");
|
|
|
53
55
|
var utils_exports = {};
|
|
54
56
|
__export(utils_exports, {
|
|
55
57
|
EventPublisherBase: () => EventPublisherBase,
|
|
56
|
-
aiClient: () => aiClient,
|
|
57
58
|
encodeEmail: () => encodeEmail,
|
|
58
59
|
extractAdCode: () => extractAdCode,
|
|
59
60
|
extractClickId: () => extractClickId,
|
|
@@ -71,16 +72,18 @@ __export(utils_exports, {
|
|
|
71
72
|
removeUndefined: () => removeUndefined
|
|
72
73
|
});
|
|
73
74
|
var crypto = __toESM(require("crypto"));
|
|
74
|
-
var appInsights = __toESM(require("applicationinsights"));
|
|
75
75
|
|
|
76
76
|
// src/utils/redisClient.ts
|
|
77
|
+
var redisClient_exports = {};
|
|
78
|
+
__export(redisClient_exports, {
|
|
79
|
+
getRedisClient: () => getRedisClient
|
|
80
|
+
});
|
|
77
81
|
var import_redis = require("redis");
|
|
78
82
|
var client;
|
|
79
|
-
var port = process.env["RedisPort"] ?? "6380";
|
|
80
83
|
async function getRedisClient() {
|
|
81
84
|
if (!client) {
|
|
82
85
|
client = (0, import_redis.createClient)({
|
|
83
|
-
url: `rediss://${process.env["RedisUrl"]}
|
|
86
|
+
url: `rediss://${process.env["RedisUrl"]}`,
|
|
84
87
|
password: process.env["RedisPassword"],
|
|
85
88
|
socket: { tls: true }
|
|
86
89
|
});
|
|
@@ -89,12 +92,19 @@ async function getRedisClient() {
|
|
|
89
92
|
return client;
|
|
90
93
|
}
|
|
91
94
|
|
|
92
|
-
// src/utils/
|
|
95
|
+
// src/utils/appInsightsClient.ts
|
|
96
|
+
var appInsightsClient_exports = {};
|
|
97
|
+
__export(appInsightsClient_exports, {
|
|
98
|
+
aiClient: () => aiClient
|
|
99
|
+
});
|
|
100
|
+
var appInsights = __toESM(require("applicationinsights"));
|
|
93
101
|
var aiClient = null;
|
|
94
102
|
if (process.env.APPLICATIONINSIGHTS_CONNECTION_STRING) {
|
|
95
103
|
appInsights.setup().setAutoCollectDependencies(false).setAutoCollectConsole(true, false).setSendLiveMetrics(false).setAutoCollectRequests(false).setAutoCollectPerformance(false, false).setUseDiskRetryCaching(false).start();
|
|
96
104
|
aiClient = appInsights.defaultClient;
|
|
97
105
|
}
|
|
106
|
+
|
|
107
|
+
// src/utils/utils.ts
|
|
98
108
|
var EventPublisherBase = class {
|
|
99
109
|
config;
|
|
100
110
|
constructor(config) {
|
|
@@ -122,7 +132,7 @@ async function logRedisEvent(key) {
|
|
|
122
132
|
await redis.hIncrBy(key, "count", 1);
|
|
123
133
|
await redis.expire(key, 660);
|
|
124
134
|
}
|
|
125
|
-
function logAggregatedMetric(prefix, name, dimensions) {
|
|
135
|
+
function logAggregatedMetric({ prefix, name, dimensions }) {
|
|
126
136
|
const windowStart = Math.floor(Date.now() / 6e4) * 6e4;
|
|
127
137
|
const key = dimensions ? `${prefix}:${windowStart}:${dimensions}:${name}` : `${prefix}:${windowStart}:${name}`;
|
|
128
138
|
logRedisEvent(key);
|
|
@@ -139,7 +149,7 @@ function logEvent(publisher2, event, region, status, payload, id) {
|
|
|
139
149
|
if (!process.env["DisableMetrics"]) {
|
|
140
150
|
const metricRegion = process.env["DisableMetricRegionLogging"] ? "default" : region;
|
|
141
151
|
const name = status >= 200 && status < 400 ? "DispatchSuccess" : "DispatchFailure";
|
|
142
|
-
logAggregatedMetric("events",
|
|
152
|
+
logAggregatedMetric({ prefix: "events", dimensions: `${metricRegion}:${publisher2}:${event}`, name });
|
|
143
153
|
}
|
|
144
154
|
;
|
|
145
155
|
if (!process.env["DisableTraces"]) {
|
|
@@ -159,8 +169,8 @@ function logEvent(publisher2, event, region, status, payload, id) {
|
|
|
159
169
|
}
|
|
160
170
|
function logException(exception, publisher2) {
|
|
161
171
|
if (!process.env["DisableMetrics"]) {
|
|
162
|
-
const message = exception.message.split(".")[0]?.substring(0, 100)
|
|
163
|
-
logAggregatedMetric("errors",
|
|
172
|
+
const message = exception.message.split(".")[0]?.substring(0, 100)?.replace(/:/g, "") ?? "Error";
|
|
173
|
+
logAggregatedMetric({ prefix: "errors", dimensions: `${publisher2 ?? "Other"}:${exception.name}`, name: message });
|
|
164
174
|
}
|
|
165
175
|
;
|
|
166
176
|
if (!process.env["DisableTraces"]) {
|
|
@@ -169,7 +179,7 @@ function logException(exception, publisher2) {
|
|
|
169
179
|
;
|
|
170
180
|
}
|
|
171
181
|
function logMilestone(name, value) {
|
|
172
|
-
logAggregatedMetric("milestones", String(value)
|
|
182
|
+
logAggregatedMetric({ prefix: "milestones", dimensions: name, name: String(value) });
|
|
173
183
|
}
|
|
174
184
|
function removeUndefined(originalValue) {
|
|
175
185
|
if (originalValue instanceof Array) {
|
|
@@ -598,6 +608,19 @@ async function scheduleEvent(message, queue, options) {
|
|
|
598
608
|
}
|
|
599
609
|
}
|
|
600
610
|
|
|
611
|
+
// src/utils/testUtils.ts
|
|
612
|
+
var testUtils_exports = {};
|
|
613
|
+
__export(testUtils_exports, {
|
|
614
|
+
context: () => context
|
|
615
|
+
});
|
|
616
|
+
var context = {};
|
|
617
|
+
context.log = function log(str) {
|
|
618
|
+
console.log(str);
|
|
619
|
+
};
|
|
620
|
+
context.log.warn = function warn(str) {
|
|
621
|
+
console.warn(str);
|
|
622
|
+
};
|
|
623
|
+
|
|
601
624
|
// src/defaultPublisher.ts
|
|
602
625
|
async function defaultPublisher(azureFunctionContext, serviceBusMessage, source, platformPublisher, trigger) {
|
|
603
626
|
if (serviceBusMessage.$schema === "mhub/pingtest") {
|
|
@@ -1189,19 +1212,6 @@ var universalAnalytics = {
|
|
|
1189
1212
|
}
|
|
1190
1213
|
};
|
|
1191
1214
|
|
|
1192
|
-
// src/utils/testUtils.ts
|
|
1193
|
-
var testUtils_exports = {};
|
|
1194
|
-
__export(testUtils_exports, {
|
|
1195
|
-
context: () => context
|
|
1196
|
-
});
|
|
1197
|
-
var context = {};
|
|
1198
|
-
context.log = function log(str) {
|
|
1199
|
-
console.log(str);
|
|
1200
|
-
};
|
|
1201
|
-
context.log.warn = function warn(str) {
|
|
1202
|
-
console.warn(str);
|
|
1203
|
-
};
|
|
1204
|
-
|
|
1205
1215
|
// src/index.ts
|
|
1206
1216
|
var publisher = {
|
|
1207
1217
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
@@ -1218,8 +1228,10 @@ var publisher = {
|
|
|
1218
1228
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1219
1229
|
0 && (module.exports = {
|
|
1220
1230
|
DefaultPublisher,
|
|
1231
|
+
appInsightsClient,
|
|
1221
1232
|
broker,
|
|
1222
1233
|
publisher,
|
|
1234
|
+
redisClient,
|
|
1223
1235
|
testUtils,
|
|
1224
1236
|
utils
|
|
1225
1237
|
});
|