@shushed/helpers 0.0.47 → 0.0.49

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 +30 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -826,7 +826,12 @@ var PubSubHelper = class extends Runtime {
826
826
  [`${this.workflowId}-${this.triggerId}`.toLowerCase()]: "true"
827
827
  }
828
828
  };
829
- const [topicMetadata] = await topic?.getMetadata() || [null];
829
+ let topicMetadata;
830
+ try {
831
+ [topicMetadata] = await topic?.getMetadata() || [null];
832
+ } catch (err) {
833
+ throw new Error("Invariant: While getting topic metadata - " + err.message);
834
+ }
830
835
  if (topic) {
831
836
  const simMetadata = Object.assign({}, topicMetadata?.labels || {}, metadata.labels);
832
837
  if (!(0, import_lodash.default)(topicMetadata?.labels, simMetadata)) {
@@ -863,13 +868,17 @@ var PubSubHelper = class extends Runtime {
863
868
  if (isSubscriptionOptionsPush(opts)) {
864
869
  if (opts.endpointUrl !== subscriptionMetaData?.pushConfig?.pushEndpoint || this.serviceAccountEmail !== subscriptionMetaData?.pushConfig.oidcToken?.serviceAccountEmail || process.env.GCLOUD_PROJECT + "/" + this.triggerId !== subscriptionMetaData.pushConfig.oidcToken.audience) {
865
870
  if (subscriptionMetaData?.pushConfig?.pushEndpoint && subscription) {
866
- await subscription.modifyPushConfig({
867
- pushEndpoint: opts.endpointUrl,
868
- oidcToken: {
869
- serviceAccountEmail: this.serviceAccountEmail,
870
- audience: process.env.GCLOUD_PROJECT + "/" + this.triggerId
871
- }
872
- });
871
+ try {
872
+ await subscription.modifyPushConfig({
873
+ pushEndpoint: opts.endpointUrl,
874
+ oidcToken: {
875
+ serviceAccountEmail: this.serviceAccountEmail,
876
+ audience: process.env.GCLOUD_PROJECT + "/" + this.triggerId
877
+ }
878
+ });
879
+ } catch (err) {
880
+ throw new Error("Invariant: While updating push subscription - " + err.message);
881
+ }
873
882
  } else {
874
883
  nextMetadata = nextMetadata || {};
875
884
  nextMetadata.pushConfig = {
@@ -949,16 +958,24 @@ var PubSubHelper = class extends Runtime {
949
958
  nextMetadata.bigqueryConfig = null;
950
959
  }
951
960
  if (subscription && nextMetadata) {
952
- await subscription.setMetadata(nextMetadata);
961
+ try {
962
+ await subscription.setMetadata(nextMetadata);
963
+ } catch (err) {
964
+ throw new Error("Invariant: While updating subscription - " + err.message);
965
+ }
953
966
  return null;
954
967
  }
955
968
  return nextMetadata;
956
969
  }
957
970
  async ensureSubscribtionExists(subscriptionName, opts) {
958
971
  let [subscriptions] = await opts.topic.getSubscriptions();
959
- console.log("subscriptions x", JSON.stringify(subscriptions), subscriptionName);
960
972
  let subscription = subscriptions.find((subscription2) => this.getNameFromFullyQualifiedName(subscription2.name) === subscriptionName) || null;
961
- const [subscriptionMetaData] = await subscription?.getMetadata() || [null];
973
+ let subscriptionMetaData;
974
+ try {
975
+ [subscriptionMetaData] = await subscription?.getMetadata() || [null];
976
+ } catch (err) {
977
+ throw new Error("Invariant: While getting subscription metadata - " + err.message);
978
+ }
962
979
  const createPayload = await this.updateSubscription(subscriptionName, subscription, subscriptionMetaData, opts);
963
980
  if (createPayload) {
964
981
  await opts.topic.createSubscription(subscriptionName, createPayload);
@@ -990,6 +1007,8 @@ var PubSubHelper = class extends Runtime {
990
1007
  return err.message;
991
1008
  }
992
1009
  throw err;
1010
+ }).catch((err) => {
1011
+ throw new Error("Invariant: While deleting subscription - " + err.message);
993
1012
  });
994
1013
  }
995
1014
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.47",
3
+ "version": "0.0.49",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",