@shushed/helpers 0.0.48 → 0.0.50
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.js +33 -10
- 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
|
-
|
|
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
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
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,7 +958,14 @@ var PubSubHelper = class extends Runtime {
|
|
|
949
958
|
nextMetadata.bigqueryConfig = null;
|
|
950
959
|
}
|
|
951
960
|
if (subscription && nextMetadata) {
|
|
952
|
-
|
|
961
|
+
try {
|
|
962
|
+
await subscription.setMetadata(nextMetadata);
|
|
963
|
+
} catch (err) {
|
|
964
|
+
if (err.message.toLowerCase().indexOf("permission denied") !== -1) {
|
|
965
|
+
console.error("Invariant: While updating subscription - " + err.message + ` - ${this.pubSub.projectId} - ${subscriptionName} - ${JSON.stringify(nextMetadata)}`);
|
|
966
|
+
}
|
|
967
|
+
throw new Error("Invariant: While updating subscription - " + err.message);
|
|
968
|
+
}
|
|
953
969
|
return null;
|
|
954
970
|
}
|
|
955
971
|
return nextMetadata;
|
|
@@ -957,7 +973,12 @@ var PubSubHelper = class extends Runtime {
|
|
|
957
973
|
async ensureSubscribtionExists(subscriptionName, opts) {
|
|
958
974
|
let [subscriptions] = await opts.topic.getSubscriptions();
|
|
959
975
|
let subscription = subscriptions.find((subscription2) => this.getNameFromFullyQualifiedName(subscription2.name) === subscriptionName) || null;
|
|
960
|
-
|
|
976
|
+
let subscriptionMetaData;
|
|
977
|
+
try {
|
|
978
|
+
[subscriptionMetaData] = await subscription?.getMetadata() || [null];
|
|
979
|
+
} catch (err) {
|
|
980
|
+
throw new Error("Invariant: While getting subscription metadata - " + err.message);
|
|
981
|
+
}
|
|
961
982
|
const createPayload = await this.updateSubscription(subscriptionName, subscription, subscriptionMetaData, opts);
|
|
962
983
|
if (createPayload) {
|
|
963
984
|
await opts.topic.createSubscription(subscriptionName, createPayload);
|
|
@@ -989,6 +1010,8 @@ var PubSubHelper = class extends Runtime {
|
|
|
989
1010
|
return err.message;
|
|
990
1011
|
}
|
|
991
1012
|
throw err;
|
|
1013
|
+
}).catch((err) => {
|
|
1014
|
+
throw new Error("Invariant: While deleting subscription - " + err.message);
|
|
992
1015
|
});
|
|
993
1016
|
}
|
|
994
1017
|
};
|