@mhubcloud/tms_core 3.8.0-beta.2 → 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 +33 -20
- 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,9 +72,12 @@ __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
83
|
async function getRedisClient() {
|
|
@@ -88,12 +92,19 @@ async function getRedisClient() {
|
|
|
88
92
|
return client;
|
|
89
93
|
}
|
|
90
94
|
|
|
91
|
-
// 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"));
|
|
92
101
|
var aiClient = null;
|
|
93
102
|
if (process.env.APPLICATIONINSIGHTS_CONNECTION_STRING) {
|
|
94
103
|
appInsights.setup().setAutoCollectDependencies(false).setAutoCollectConsole(true, false).setSendLiveMetrics(false).setAutoCollectRequests(false).setAutoCollectPerformance(false, false).setUseDiskRetryCaching(false).start();
|
|
95
104
|
aiClient = appInsights.defaultClient;
|
|
96
105
|
}
|
|
106
|
+
|
|
107
|
+
// src/utils/utils.ts
|
|
97
108
|
var EventPublisherBase = class {
|
|
98
109
|
config;
|
|
99
110
|
constructor(config) {
|
|
@@ -121,7 +132,7 @@ async function logRedisEvent(key) {
|
|
|
121
132
|
await redis.hIncrBy(key, "count", 1);
|
|
122
133
|
await redis.expire(key, 660);
|
|
123
134
|
}
|
|
124
|
-
function logAggregatedMetric(prefix, name, dimensions) {
|
|
135
|
+
function logAggregatedMetric({ prefix, name, dimensions }) {
|
|
125
136
|
const windowStart = Math.floor(Date.now() / 6e4) * 6e4;
|
|
126
137
|
const key = dimensions ? `${prefix}:${windowStart}:${dimensions}:${name}` : `${prefix}:${windowStart}:${name}`;
|
|
127
138
|
logRedisEvent(key);
|
|
@@ -138,7 +149,7 @@ function logEvent(publisher2, event, region, status, payload, id) {
|
|
|
138
149
|
if (!process.env["DisableMetrics"]) {
|
|
139
150
|
const metricRegion = process.env["DisableMetricRegionLogging"] ? "default" : region;
|
|
140
151
|
const name = status >= 200 && status < 400 ? "DispatchSuccess" : "DispatchFailure";
|
|
141
|
-
logAggregatedMetric("events",
|
|
152
|
+
logAggregatedMetric({ prefix: "events", dimensions: `${metricRegion}:${publisher2}:${event}`, name });
|
|
142
153
|
}
|
|
143
154
|
;
|
|
144
155
|
if (!process.env["DisableTraces"]) {
|
|
@@ -159,7 +170,7 @@ function logEvent(publisher2, event, region, status, payload, id) {
|
|
|
159
170
|
function logException(exception, publisher2) {
|
|
160
171
|
if (!process.env["DisableMetrics"]) {
|
|
161
172
|
const message = exception.message.split(".")[0]?.substring(0, 100)?.replace(/:/g, "") ?? "Error";
|
|
162
|
-
logAggregatedMetric("errors",
|
|
173
|
+
logAggregatedMetric({ prefix: "errors", dimensions: `${publisher2 ?? "Other"}:${exception.name}`, name: message });
|
|
163
174
|
}
|
|
164
175
|
;
|
|
165
176
|
if (!process.env["DisableTraces"]) {
|
|
@@ -168,7 +179,7 @@ function logException(exception, publisher2) {
|
|
|
168
179
|
;
|
|
169
180
|
}
|
|
170
181
|
function logMilestone(name, value) {
|
|
171
|
-
logAggregatedMetric("milestones", String(value)
|
|
182
|
+
logAggregatedMetric({ prefix: "milestones", dimensions: name, name: String(value) });
|
|
172
183
|
}
|
|
173
184
|
function removeUndefined(originalValue) {
|
|
174
185
|
if (originalValue instanceof Array) {
|
|
@@ -597,6 +608,19 @@ async function scheduleEvent(message, queue, options) {
|
|
|
597
608
|
}
|
|
598
609
|
}
|
|
599
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
|
+
|
|
600
624
|
// src/defaultPublisher.ts
|
|
601
625
|
async function defaultPublisher(azureFunctionContext, serviceBusMessage, source, platformPublisher, trigger) {
|
|
602
626
|
if (serviceBusMessage.$schema === "mhub/pingtest") {
|
|
@@ -1188,19 +1212,6 @@ var universalAnalytics = {
|
|
|
1188
1212
|
}
|
|
1189
1213
|
};
|
|
1190
1214
|
|
|
1191
|
-
// src/utils/testUtils.ts
|
|
1192
|
-
var testUtils_exports = {};
|
|
1193
|
-
__export(testUtils_exports, {
|
|
1194
|
-
context: () => context
|
|
1195
|
-
});
|
|
1196
|
-
var context = {};
|
|
1197
|
-
context.log = function log(str) {
|
|
1198
|
-
console.log(str);
|
|
1199
|
-
};
|
|
1200
|
-
context.log.warn = function warn(str) {
|
|
1201
|
-
console.warn(str);
|
|
1202
|
-
};
|
|
1203
|
-
|
|
1204
1215
|
// src/index.ts
|
|
1205
1216
|
var publisher = {
|
|
1206
1217
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
@@ -1217,8 +1228,10 @@ var publisher = {
|
|
|
1217
1228
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1218
1229
|
0 && (module.exports = {
|
|
1219
1230
|
DefaultPublisher,
|
|
1231
|
+
appInsightsClient,
|
|
1220
1232
|
broker,
|
|
1221
1233
|
publisher,
|
|
1234
|
+
redisClient,
|
|
1222
1235
|
testUtils,
|
|
1223
1236
|
utils
|
|
1224
1237
|
});
|