@mhubcloud/tms_core 3.4.0-beta.0 → 3.4.0-beta.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mhubcloud/tms_core",
3
- "version": "3.4.0-beta.0",
3
+ "version": "3.4.0-beta.1",
4
4
  "description": "Core function for mHub Cloud TMS publishers",
5
5
  "homepage": "https://mhubcloud.com/",
6
6
  "license": "Apache 2.0",
package/src/broker.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { CosmosClient } from '@azure/cosmos';
2
- import { Logger } from '@azure/functions';
3
2
  import { ServiceBusClient, ServiceBusSender } from '@azure/service-bus';
4
3
  import { utils } from '.';
5
4
  import { ServiceBusMessage } from './types/ServiceBusMessage';
@@ -13,6 +12,12 @@ const senders: Record<string, ServiceBusSender> = {};
13
12
 
14
13
  export type PublisherConfig = Record<string, string[] | string[][]>;
15
14
 
15
+ /**
16
+ * Evaluates an event against publisher configurations
17
+ * @param eventCode event.code parameter of the event
18
+ * @param publisherConfig object containing publisher event consumption configurations
19
+ * @returns list of publishers for which an event is relevant.
20
+ */
16
21
  export function resolveEvent(
17
22
  eventCode: string,
18
23
  publisherConfig?: PublisherConfig,
@@ -67,6 +72,11 @@ export function resolveEvent(
67
72
  return publishers;
68
73
  }
69
74
 
75
+ /**
76
+ * Sends an event to Service Bus
77
+ * @param message event to be sent
78
+ * @param queues list of Service Bus queues to send the event to
79
+ */
70
80
  export async function dispatchEvent(
71
81
  message: Record<string, string>,
72
82
  queues: string[],
@@ -96,10 +106,11 @@ export async function dispatchEvent(
96
106
  );
97
107
  }
98
108
 
99
- export async function logToCosmosDb(
100
- message: ServiceBusMessage,
101
- logger: Logger,
102
- ) {
109
+ /**
110
+ * Logs an event to Cosmos DB
111
+ * @param message event to be logged
112
+ */
113
+ export async function logToCosmosDb(message: ServiceBusMessage) {
103
114
  if (!cosmosClient) {
104
115
  if (!cosmosConnectionString) {
105
116
  throw new Error('Cosmos DB connection string is missing.');
@@ -121,6 +132,6 @@ export async function logToCosmosDb(
121
132
  .container(cosmosContainerName)
122
133
  .items.create(message);
123
134
  } catch (e) {
124
- utils.logException(logger, e as Error);
135
+ utils.logException(e as Error);
125
136
  }
126
137
  }
@@ -88,7 +88,7 @@ export function logEvent(
88
88
  /**
89
89
  * Logs exception to Azure Function context and to Application Insights (if configured)
90
90
  */
91
- export function logException(log: Logger, exception: Error) {
91
+ export function logException(exception: Error) {
92
92
  // log.warn(exception.message);
93
93
  aiClient?.trackException({ exception: exception });
94
94
  }