@memberjunction/server 2.26.1 → 2.27.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.
@@ -4,6 +4,7 @@ import {
4
4
  CompositeKey,
5
5
  EntityFieldTSType,
6
6
  EntityPermissionType,
7
+ LogDebug,
7
8
  LogError,
8
9
  LogStatus,
9
10
  Metadata,
@@ -30,7 +31,18 @@ import { Subscription } from 'rxjs';
30
31
  export class ResolverBase {
31
32
  private static _emit = process.env.CLOUDEVENTS_HTTP_TRANSPORT ? emitterFor(httpTransport(process.env.CLOUDEVENTS_HTTP_TRANSPORT)) : null;
32
33
  private static _cloudeventsHeaders = process.env.CLOUDEVENTS_HTTP_HEADERS ? JSON.parse(process.env.CLOUDEVENTS_HTTP_HEADERS) : {};
33
- private static _eventSubscriptions = new Map<string, Subscription>;
34
+
35
+ private static _eventSubscriptionKey: string = '___MJServer___ResolverBase___EventSubscriptions';
36
+ private get EventSubscriptions(): Map<string, Subscription> {
37
+ // here we use the global object store instead of a static member becuase in some cases based on import code paths/bundling/etc, the static member
38
+ // could actually be duplicated and we'd end up with multiple instances of the same map, which would be bad.
39
+ const g = MJGlobal.Instance.GetGlobalObjectStore();
40
+ if (!g[ResolverBase._eventSubscriptionKey]) {
41
+ LogDebug(`>>>>> MJServer.ResolverBase.EventSubscriptions: Creating new Map - this should only happen once per server instance <<<<<<`);
42
+ g[ResolverBase._eventSubscriptionKey] = new Map<string, Subscription>();
43
+ }
44
+ return g[ResolverBase._eventSubscriptionKey];
45
+ }
34
46
 
35
47
  protected MapFieldNamesToCodeNames(entityName: string, dataObject: any) {
36
48
  // for the given entity name provided, check to see if there are any fields
@@ -576,15 +588,22 @@ export class ResolverBase {
576
588
  // cause issues with multiple messages for the same event.
577
589
  const uniqueKey = entityObject.EntityInfo.Name;
578
590
 
579
- if (!ResolverBase._eventSubscriptions.has(uniqueKey)) {
591
+ if (!this.EventSubscriptions.has(uniqueKey)) {
580
592
  // listen for events from the entityObject in case it is a long running task and we can push messages back to the client via pubSub
593
+ LogDebug(`ResolverBase.ListenForEntityMessages: About to call MJGlobal.Instance.GetEventListener() to get the event listener subscription for ${uniqueKey}`);
581
594
  const theSub = MJGlobal.Instance.GetEventListener(false).subscribe(async (event: MJEvent) => {
582
595
  if (event) {
596
+ const baseEntity = <BaseEntity>event.args?.baseEntity;
597
+ const baseEntityValues = baseEntity ? baseEntity.GetAll() : null;
598
+ const eventToLog = { entityName: entityObject.EntityInfo.Name, baseEntity: baseEntityValues, event: event.event, eventCode: event.eventCode };
599
+ LogDebug(`ResolverBase.ListenForEntityMessages: Received Event from within MJGlobal.Instance.GetEventListener() callback. Will call EmitCloudEvent() next\nEvent data:\n${JSON.stringify(eventToLog)}`);
583
600
  await this.EmitCloudEvent(event);
601
+ LogDebug(`ResolverBase.ListenForEntityMessages: EmitCloudEvent() completed successfully`);
584
602
 
585
603
  if (event.args && event.args instanceof BaseEntityEvent) {
586
604
  const baseEntityEvent = event.args as BaseEntityEvent;
587
605
  // message from our entity object, relay it to the client
606
+ LogDebug('ResolverBase.ListenForEntityMessages: About to publish PUSH_STATUS_UPDATES_TOPIC');
588
607
  pubSub.publish(PUSH_STATUS_UPDATES_TOPIC, {
589
608
  message: JSON.stringify({
590
609
  status: 'OK',
@@ -598,7 +617,7 @@ export class ResolverBase {
598
617
  }
599
618
  }
600
619
  });
601
- ResolverBase._eventSubscriptions.set(uniqueKey, theSub);
620
+ this.EventSubscriptions.set(uniqueKey, theSub);
602
621
  }
603
622
  }
604
623