@shushed/helpers 0.0.73 → 0.0.75

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.d.ts CHANGED
@@ -28830,6 +28830,7 @@ declare class EnvEngine extends Runtime {
28830
28830
  type Message = {
28831
28831
  buildshipId: string;
28832
28832
  exportableToBigQuery: boolean;
28833
+ subscriptionName?: string;
28833
28834
  body: any;
28834
28835
  sourceSystem: string;
28835
28836
  targetSystem: string;
@@ -28863,6 +28864,7 @@ declare class PubSubHelper extends Runtime {
28863
28864
  topicName: string;
28864
28865
  sourceSystem: string;
28865
28866
  }, payload: AtLeastOne<MessageBody, LastModifiedKeys>, orgMessage?: Message): Promise<string[]>;
28867
+ getSubscriptionName(topicName: string): string;
28866
28868
  createOrUpdate(opts: {
28867
28869
  topicName: string;
28868
28870
  createDeadLetterQueues: boolean;
@@ -28908,9 +28910,41 @@ declare class PubSubHelper extends Runtime {
28908
28910
  tableDlqSubscription: Subscription | null;
28909
28911
  tableSubscription: Subscription | null;
28910
28912
  }>;
28911
- isRunning(topicName: string): Promise<{
28912
- subscriptionId: string | undefined;
28913
- isPushingMessages: boolean;
28913
+ getStatus(topicName: string): Promise<{
28914
+ subscriptions: {
28915
+ main: {
28916
+ name: string;
28917
+ shortName: string;
28918
+ isPush: boolean;
28919
+ } | null;
28920
+ table: {
28921
+ name: string;
28922
+ shortName: string;
28923
+ tableId: string | null | undefined;
28924
+ } | null;
28925
+ tableDlq: {
28926
+ name: string;
28927
+ shortName: string;
28928
+ } | null;
28929
+ mainDlq: {
28930
+ name: string;
28931
+ shortName: string;
28932
+ } | null;
28933
+ };
28934
+ topics: {
28935
+ main: {
28936
+ name: string;
28937
+ shortName: string;
28938
+ } | null;
28939
+ mainDlq: {
28940
+ name: string;
28941
+ shortName: string;
28942
+ } | null;
28943
+ tableDlq: {
28944
+ name: string;
28945
+ shortName: string;
28946
+ } | null;
28947
+ };
28914
28948
  }>;
28915
28949
  pause(topicName: string): Promise<{
28916
28950
  subscriptionId: string;
package/dist/index.js CHANGED
@@ -810,16 +810,17 @@ var PubSubHelper = class extends Runtime {
810
810
  throw new Error("Could not parse the message body. Original body: " + rawMessageText + " . Error: " + err.message);
811
811
  }
812
812
  const message = {
813
- sourceSystem: rawMessage.attributes?.source_system || "unknown",
814
- targetSystem: rawMessage.attributes?.target_system || "*",
815
- processStartedAt: parseDateOrDefault(rawMessage.attributes?.process_started_at),
813
+ sourceSystem: rawMessage.message?.attributes?.source_system || "unknown",
814
+ targetSystem: rawMessage.message?.attributes?.target_system || "*",
815
+ processStartedAt: parseDateOrDefault(rawMessage.message?.attributes?.process_started_at),
816
816
  recordModifiedAt: parseDateOrDefault(getEventTime(messageBody, rawMessage.attributes?.record_modified_at)),
817
- originalPublishTime: parseDateOrDefault(rawMessage.attributes?.original_publish_time, parseDateOrDefault(rawMessage.publish_time)),
817
+ originalPublishTime: parseDateOrDefault(rawMessage.message?.attributes?.original_publish_time, parseDateOrDefault(rawMessage.message?.publish_time)),
818
818
  buildshipId: rawMessage.attributes?.buildship_id || "unknown",
819
- publishTime: parseDateOrDefault(rawMessage.publish_time),
819
+ publishTime: parseDateOrDefault(rawMessage.message?.publish_time),
820
820
  body: messageBody,
821
- exportableToBigQuery: !!rawMessage.attributes?.bigquery,
822
- extraAttributes: (0, import_lodash2.default)(rawMessage.attributes || {}, ["source_system", "target_system", "process_started_at", "record_modified_at", "original_publish_time", "buildship_id", "publish_time", "bigquery"])
821
+ exportableToBigQuery: !!rawMessage.message?.attributes?.bigquery,
822
+ extraAttributes: (0, import_lodash2.default)(rawMessage.message?.attributes || {}, ["source_system", "target_system", "process_started_at", "record_modified_at", "original_publish_time", "buildship_id", "publish_time", "bigquery"]),
823
+ subscriptionName: rawMessage.subscription.split("/").pop()
823
824
  };
824
825
  return message;
825
826
  }
@@ -867,10 +868,13 @@ var PubSubHelper = class extends Runtime {
867
868
  throw err;
868
869
  });
869
870
  }
871
+ getSubscriptionName(topicName) {
872
+ const infraPrefix = topicName.indexOf("---") !== -1 ? topicName : `${this.envName}---${topicName}`;
873
+ return `${infraPrefix}-${shortHash(this.triggerId)}`;
874
+ }
870
875
  async createOrUpdate(opts) {
871
876
  this.logging.log("createOrUpdate called with", opts);
872
877
  const [topics] = await this.pubSub.getTopics();
873
- this.logging.log("topics discovered", topics);
874
878
  const infraPrefix = opts.topicName.indexOf("---") !== -1 ? opts.topicName : `${this.envName}---${opts.topicName}`;
875
879
  const mainDlqTopicName = `${infraPrefix}-${shortHash(this.triggerId)}-dlq`;
876
880
  const tableDlqTopicName = `${infraPrefix}-${shortHash(this.triggerId)}-bq-dlq`;
@@ -897,22 +901,6 @@ var PubSubHelper = class extends Runtime {
897
901
  let mainDlqSubscription = mainDlqTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainDlqSubscriptionName) || null;
898
902
  let tableSubscription = mainTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === tableSubscriptionName) || null;
899
903
  let tableDlqSubscription = tableDlqTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === tableDlqSubscriptionName) || null;
900
- this.logging.log("environment discovery", {
901
- mainTopicName: opts.topicName,
902
- mainDlqTopicName,
903
- tableDlqTopicName,
904
- mainSubscriptionName,
905
- mainDlqSubscriptionName,
906
- tableSubscriptionName,
907
- tableDlqSubscriptionName,
908
- mainTopicExists: mainTopic,
909
- mainDlqTopicExists: mainDlqTopic,
910
- tableDlqTopicExists: tableDlqTopic,
911
- mainSubscriptionExists: mainSubscription,
912
- mainDlqSubscriptionExists: mainDlqSubscription,
913
- tableSubscriptionExists: tableSubscription,
914
- tableDlqSubscriptionExists: tableDlqSubscription
915
- });
916
904
  const topic = await this.ensureTopicExists(opts.topicName);
917
905
  if (opts.table || opts.pull || opts.push) {
918
906
  mainTopic = await this.ensureTopicExists(opts.topicName);
@@ -1231,24 +1219,70 @@ var PubSubHelper = class extends Runtime {
1231
1219
  table: null
1232
1220
  });
1233
1221
  }
1234
- async isRunning(topicName) {
1222
+ async getStatus(topicName) {
1223
+ this.logging.log("getStatus called with", topicName);
1235
1224
  const [topics] = await this.pubSub.getTopics();
1236
- const mainTopic = topics.find((x) => this.getNameFromFullyQualifiedName(x.name) === topicName);
1237
- this.logging.log("isRunning called with", topicName);
1238
1225
  const infraPrefix = topicName.indexOf("---") !== -1 ? topicName : `${this.envName}---${topicName}`;
1226
+ const mainDlqTopicName = `${infraPrefix}-${shortHash(this.triggerId)}-dlq`;
1227
+ const tableDlqTopicName = `${infraPrefix}-${shortHash(this.triggerId)}-bq-dlq`;
1228
+ const mainTopic = topics.find((x) => this.getNameFromFullyQualifiedName(x.name) === topicName);
1229
+ const mainDlqTopic = topics.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainDlqTopicName);
1230
+ const tableDlqTopic = topics.find((x) => this.getNameFromFullyQualifiedName(x.name) === tableDlqTopicName);
1231
+ const mainSubscriptionName = `${infraPrefix}-${shortHash(this.triggerId)}`;
1232
+ const mainDlqSubscriptionName = `${infraPrefix}-${shortHash(this.triggerId)}-dlq`;
1233
+ const tableSubscriptionName = `${infraPrefix}-${shortHash(this.triggerId)}-bq`;
1234
+ const tableDlqSubscriptionName = `${infraPrefix}-${shortHash(this.triggerId)}-bq-dlq`;
1239
1235
  let mainTopicSubscriptions = null;
1236
+ let mainDlqTopicSubscriptions = null;
1237
+ let tableDlqTopicSubscriptions = null;
1240
1238
  if (mainTopic) {
1241
1239
  [mainTopicSubscriptions] = await mainTopic.getSubscriptions();
1242
1240
  }
1243
- const mainSubscriptionName = `${infraPrefix}-${shortHash(this.triggerId)}`;
1244
- this.logging.log("isRunning checking the", mainSubscriptionName);
1241
+ if (mainDlqTopic) {
1242
+ [mainDlqTopicSubscriptions] = await mainDlqTopic.getSubscriptions();
1243
+ }
1244
+ if (tableDlqTopic) {
1245
+ [tableDlqTopicSubscriptions] = await tableDlqTopic.getSubscriptions();
1246
+ }
1245
1247
  const mainSubscription = mainTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainSubscriptionName) || null;
1246
- this.logging.log("isRunning found the", mainSubscription?.name);
1247
- const [metadata] = await mainSubscription?.getMetadata() || [null];
1248
- this.logging.log("isRunning received metadata", metadata);
1248
+ const mainDlqSubscription = mainDlqTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainDlqSubscriptionName) || null;
1249
+ const tableSubscription = mainTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === tableSubscriptionName) || null;
1250
+ const tableDlqSubscription = tableDlqTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === tableDlqSubscriptionName) || null;
1249
1251
  return {
1250
- subscriptionId: mainSubscription?.name,
1251
- isPushingMessages: !!metadata?.pushConfig?.pushEndpoint
1252
+ subscriptions: {
1253
+ main: mainSubscription ? {
1254
+ name: mainSubscription.name,
1255
+ shortName: this.getNameFromFullyQualifiedName(mainSubscription.name),
1256
+ isPush: (await mainSubscription.getMetadata())[0]?.pushConfig?.pushEndpoint ? true : false
1257
+ } : null,
1258
+ table: tableSubscription ? {
1259
+ name: tableSubscription.name,
1260
+ shortName: this.getNameFromFullyQualifiedName(tableSubscription.name),
1261
+ tableId: (await tableSubscription.getMetadata())[0]?.bigqueryConfig?.table
1262
+ } : null,
1263
+ tableDlq: tableDlqSubscription ? {
1264
+ name: tableDlqSubscription.name,
1265
+ shortName: this.getNameFromFullyQualifiedName(tableDlqSubscription.name)
1266
+ } : null,
1267
+ mainDlq: mainDlqSubscription ? {
1268
+ name: mainDlqSubscription.name,
1269
+ shortName: this.getNameFromFullyQualifiedName(mainDlqSubscription.name)
1270
+ } : null
1271
+ },
1272
+ topics: {
1273
+ main: mainTopic ? {
1274
+ name: mainTopic.name,
1275
+ shortName: this.getNameFromFullyQualifiedName(mainTopic.name)
1276
+ } : null,
1277
+ mainDlq: mainDlqTopic ? {
1278
+ name: mainDlqTopic.name,
1279
+ shortName: this.getNameFromFullyQualifiedName(mainDlqTopic.name)
1280
+ } : null,
1281
+ tableDlq: tableDlqTopic ? {
1282
+ name: tableDlqTopic.name,
1283
+ shortName: this.getNameFromFullyQualifiedName(tableDlqTopic.name)
1284
+ } : null
1285
+ }
1252
1286
  };
1253
1287
  }
1254
1288
  async pause(topicName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.73",
3
+ "version": "0.0.75",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",