@mhubcloud/tms_core 3.7.0 → 3.7.1-beta.0

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 +40 -35
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -108,13 +108,13 @@ function logEvent(publisher2, event, region, status, payload, id) {
108
108
  if (status || status === 0) {
109
109
  if (status >= 200 && status < 300) {
110
110
  aiClient?.trackMetric({
111
- name: `Dispatched/${publisher2}-${event}-${region}`,
111
+ name: `Dispatched/${publisher2}:${event}:${region}`,
112
112
  value: 1
113
113
  });
114
114
  message = "Event dispatched to platform";
115
115
  } else {
116
116
  aiClient?.trackMetric({
117
- name: `Failed/${publisher2}-${event}-${region}`,
117
+ name: `Failed/${publisher2}:${event}:${region}`,
118
118
  value: 1
119
119
  });
120
120
  message = "Event dispatch failed";
@@ -516,8 +516,9 @@ function parseScheduleOptions(options) {
516
516
  0
517
517
  );
518
518
  } else if ("scheduleInterval" in options && "startHour" in options) {
519
- const hour = now.getHours();
520
- const nextHour = Math.ceil(hour / options.scheduleInterval) * options.scheduleInterval;
519
+ const hour = now.getHours() + now.getMinutes() / 60;
520
+ const offset = options.startHour % options.scheduleInterval;
521
+ const nextHour = Math.ceil((hour - offset) / options.scheduleInterval) * options.scheduleInterval + offset;
521
522
  dispatchTime = new Date(
522
523
  now.getFullYear(),
523
524
  now.getMonth(),
@@ -529,7 +530,7 @@ function parseScheduleOptions(options) {
529
530
  );
530
531
  if (nextHour >= 24) {
531
532
  dispatchTime.setDate(dispatchTime.getDate() + 1);
532
- dispatchTime.setHours(options.startHour, options.startMinute);
533
+ dispatchTime.setHours(options.startHour, options.startMinute ?? 0);
533
534
  }
534
535
  } else {
535
536
  throw new Error("Invalid scheduling configuration");
@@ -615,13 +616,15 @@ async function processMessage(message, log2, platformPublisher, trigger) {
615
616
  const failedToPublishAll = false;
616
617
  for (const eventPublisher of publishers) {
617
618
  const mapped = await eventPublisher.map(message, log2);
619
+ const name = message.event.name?.toLowerCase();
620
+ const code = message.event.code?.toLowerCase();
618
621
  const res = await publishMessage(
619
622
  log2,
620
623
  mapped,
621
624
  eventPublisher.config,
622
625
  platformPublisher,
623
626
  {
624
- event: message.event.code + (message.event.name ? "/" + message.event.name : ""),
627
+ event: name ? name === code ? name : `${code}-${name}` : code,
625
628
  region: message.event.region,
626
629
  id: message.messageId
627
630
  }
@@ -806,8 +809,7 @@ var googleAds = {
806
809
  const body = {
807
810
  conversions: [data],
808
811
  partialFailure: true,
809
- validateOnly: false,
810
- debugEnabled: false
812
+ validateOnly: false
811
813
  };
812
814
  const requestOptions = {
813
815
  method: "POST",
@@ -819,7 +821,7 @@ var googleAds = {
819
821
  },
820
822
  body: JSON.stringify(body)
821
823
  };
822
- const baseUrl = `https://googleads.googleapis.com/v20/customers/${config.customerId}:uploadClickConversions`;
824
+ const baseUrl = `https://googleads.googleapis.com/v24/customers/${config.customerId}:uploadClickConversions`;
823
825
  const response = await fetch(baseUrl, requestOptions);
824
826
  const responseJson = await response.json();
825
827
  const knownErrors = [
@@ -863,34 +865,37 @@ var googleAds = {
863
865
  }
864
866
  if (!tokenPromise) {
865
867
  tokenPromise = (async () => {
866
- const tokenResponse = await fetch(
867
- `https://oauth2.googleapis.com/token`,
868
- {
869
- method: "POST",
870
- headers: {
871
- // eslint-disable-next-line @typescript-eslint/naming-convention
872
- "Content-Type": "application/x-www-form-urlencoded"
873
- },
874
- body: new URLSearchParams({
875
- // eslint-disable-next-line @typescript-eslint/naming-convention
876
- client_id: config.client.id,
877
- // eslint-disable-next-line @typescript-eslint/naming-convention
878
- client_secret: config.client.secret,
879
- // eslint-disable-next-line @typescript-eslint/naming-convention
880
- refreshToken: config.refreshToken,
881
- // eslint-disable-next-line @typescript-eslint/naming-convention
882
- grant_type: "refresh_token"
883
- })
868
+ try {
869
+ const tokenResponse = await fetch(
870
+ `https://oauth2.googleapis.com/token`,
871
+ {
872
+ method: "POST",
873
+ headers: {
874
+ // eslint-disable-next-line @typescript-eslint/naming-convention
875
+ "Content-Type": "application/x-www-form-urlencoded"
876
+ },
877
+ body: new URLSearchParams({
878
+ // eslint-disable-next-line @typescript-eslint/naming-convention
879
+ client_id: config.client.id,
880
+ // eslint-disable-next-line @typescript-eslint/naming-convention
881
+ client_secret: config.client.secret,
882
+ // eslint-disable-next-line @typescript-eslint/naming-convention
883
+ refreshToken: config.refreshToken,
884
+ // eslint-disable-next-line @typescript-eslint/naming-convention
885
+ grant_type: "refresh_token"
886
+ })
887
+ }
888
+ );
889
+ if (!tokenResponse.ok) {
890
+ throw new Error("Access token fetch failed");
884
891
  }
885
- );
886
- if (!tokenResponse.ok) {
887
- throw new Error("Access token fetch failed");
892
+ const parsedTokenResponse = await tokenResponse.json();
893
+ const createdAt = Date.now();
894
+ tokenCache = { token: parsedTokenResponse.access_token, createdAt };
895
+ return tokenCache;
896
+ } finally {
897
+ tokenPromise = null;
888
898
  }
889
- const parsedTokenResponse = await tokenResponse.json();
890
- const createdAt = Date.now();
891
- tokenCache = { token: parsedTokenResponse.access_token, createdAt };
892
- tokenPromise = null;
893
- return tokenCache;
894
899
  })();
895
900
  }
896
901
  return tokenPromise;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mhubcloud/tms_core",
3
- "version": "3.7.0",
3
+ "version": "3.7.1-beta.0",
4
4
  "description": "Core function for mHub Cloud TMS publishers",
5
5
  "homepage": "https://mhubcloud.com/",
6
6
  "license": "Apache 2.0",