@shushed/helpers 0.0.53 → 0.0.55
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 +54 -16
- package/dist/index.js +214 -63
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -28789,6 +28789,7 @@ declare const validateGoogleAuth: (opts: Opts & {
|
|
|
28789
28789
|
}, headers: Record<string, string>, firestore: Firestore) => Promise<void>;
|
|
28790
28790
|
declare const parseDateOrDefault: (date: string | null | Date, defaultValue?: Date | null) => Date | null;
|
|
28791
28791
|
declare function getEventTime(x: any, defaultValue: Date | null): Date | null;
|
|
28792
|
+
declare function shortHash(input: string): string;
|
|
28792
28793
|
|
|
28793
28794
|
type Level = 'env' | 'workflow' | 'trigger';
|
|
28794
28795
|
declare class EnvEngine extends Runtime {
|
|
@@ -28844,17 +28845,34 @@ declare class PubSubHelper extends Runtime {
|
|
|
28844
28845
|
}, payload: AtLeastOne<MessageBody, LastModifiedKeys>, orgMessage?: Message): Promise<string[]>;
|
|
28845
28846
|
createOrUpdate(opts: {
|
|
28846
28847
|
topicName: string;
|
|
28847
|
-
|
|
28848
|
-
|
|
28849
|
-
|
|
28850
|
-
|
|
28851
|
-
|
|
28848
|
+
createDeadLetterQueues: boolean;
|
|
28849
|
+
pull?: null | {
|
|
28850
|
+
retryLimit: number;
|
|
28851
|
+
ackDeadline: number;
|
|
28852
|
+
retryMinDelay: number;
|
|
28853
|
+
retryMaxDelay: number;
|
|
28854
|
+
};
|
|
28855
|
+
push?: null | {
|
|
28856
|
+
retryLimit: number;
|
|
28857
|
+
ackDeadline: number;
|
|
28858
|
+
retryMinDelay: number;
|
|
28859
|
+
retryMaxDelay: number;
|
|
28860
|
+
};
|
|
28861
|
+
table?: null | {
|
|
28862
|
+
tableId: string;
|
|
28863
|
+
retryLimit: number;
|
|
28864
|
+
retryMinDelay: number;
|
|
28865
|
+
retryMaxDelay: number;
|
|
28866
|
+
ackDeadline: number;
|
|
28867
|
+
};
|
|
28852
28868
|
}): Promise<{
|
|
28853
|
-
|
|
28854
|
-
|
|
28855
|
-
|
|
28856
|
-
|
|
28857
|
-
|
|
28869
|
+
mainTopic: Topic | undefined;
|
|
28870
|
+
mainDlqTopic: Topic | undefined;
|
|
28871
|
+
tableDlqTopic: Topic | undefined;
|
|
28872
|
+
mainSubscription: Subscription | null;
|
|
28873
|
+
mainDlqSubscription: Subscription | null;
|
|
28874
|
+
tableDlqSubscription: Subscription | null;
|
|
28875
|
+
tableSubscription: Subscription | null;
|
|
28858
28876
|
}>;
|
|
28859
28877
|
private findTopic;
|
|
28860
28878
|
private ensureTopicExists;
|
|
@@ -28862,24 +28880,41 @@ declare class PubSubHelper extends Runtime {
|
|
|
28862
28880
|
private updateSubscription;
|
|
28863
28881
|
private ensureSubscribtionExists;
|
|
28864
28882
|
private ensureDLQSubscriptionExists;
|
|
28883
|
+
deleteSubscriptions(topicName: string): Promise<{
|
|
28884
|
+
mainTopic: Topic | undefined;
|
|
28885
|
+
mainDlqTopic: Topic | undefined;
|
|
28886
|
+
tableDlqTopic: Topic | undefined;
|
|
28887
|
+
mainSubscription: Subscription | null;
|
|
28888
|
+
mainDlqSubscription: Subscription | null;
|
|
28889
|
+
tableDlqSubscription: Subscription | null;
|
|
28890
|
+
tableSubscription: Subscription | null;
|
|
28891
|
+
}>;
|
|
28892
|
+
pause(topicName: string): Promise<{
|
|
28893
|
+
subscriptionId: string;
|
|
28894
|
+
} | {
|
|
28895
|
+
subscriptionId: null;
|
|
28896
|
+
}>;
|
|
28897
|
+
resume(topicName: string): Promise<{
|
|
28898
|
+
subscriptionId: string;
|
|
28899
|
+
} | {
|
|
28900
|
+
subscriptionId: null;
|
|
28901
|
+
}>;
|
|
28865
28902
|
deleteSubscription(subscriptionURN: string): Promise<any>;
|
|
28866
28903
|
}
|
|
28867
28904
|
|
|
28868
28905
|
declare class SchedulerHelper extends Runtime {
|
|
28869
|
-
private extraQuery;
|
|
28870
28906
|
private pubSubTarget;
|
|
28871
28907
|
private pubSubProjectId;
|
|
28872
28908
|
private schedulerLocationId;
|
|
28873
28909
|
private schedulerClient;
|
|
28874
28910
|
constructor(opts: Opts & {
|
|
28875
|
-
extraQuery: Record<string, string>;
|
|
28876
28911
|
serviceAccount: string;
|
|
28877
28912
|
defaultServiceAccount: string;
|
|
28878
28913
|
pubSubTarget?: Topic | null;
|
|
28879
28914
|
schedulerLocationId?: string | null;
|
|
28880
28915
|
}, schedulerClient: CloudSchedulerClient);
|
|
28881
28916
|
get locationIds(): string[];
|
|
28882
|
-
getTarget(): {
|
|
28917
|
+
getTarget(extraQuery?: Record<string, string>): {
|
|
28883
28918
|
pubsubTarget: {
|
|
28884
28919
|
topicName: string;
|
|
28885
28920
|
data: Buffer<ArrayBuffer>;
|
|
@@ -28899,9 +28934,10 @@ declare class SchedulerHelper extends Runtime {
|
|
|
28899
28934
|
};
|
|
28900
28935
|
pubsubTarget?: undefined;
|
|
28901
28936
|
};
|
|
28902
|
-
create({ schedule, timezone }: {
|
|
28937
|
+
create({ schedule, timezone, extraQuery }: {
|
|
28903
28938
|
schedule: string;
|
|
28904
28939
|
timezone: string;
|
|
28940
|
+
extraQuery: Record<string, string>;
|
|
28905
28941
|
}): Promise<{
|
|
28906
28942
|
status: _google_cloud_scheduler_build_protos_protos.google.rpc.IStatus | null | undefined;
|
|
28907
28943
|
state: "STATE_UNSPECIFIED" | _google_cloud_scheduler_build_protos_protos.google.cloud.scheduler.v1.Job.State | "ENABLED" | "PAUSED" | "DISABLED" | "UPDATE_FAILED" | null | undefined;
|
|
@@ -28909,9 +28945,10 @@ declare class SchedulerHelper extends Runtime {
|
|
|
28909
28945
|
httpTarget: _google_cloud_scheduler_build_protos_protos.google.cloud.scheduler.v1.IHttpTarget | null | undefined;
|
|
28910
28946
|
pubsubTarget: _google_cloud_scheduler_build_protos_protos.google.cloud.scheduler.v1.IPubsubTarget | null | undefined;
|
|
28911
28947
|
}>;
|
|
28912
|
-
update({ schedule, timezone }: {
|
|
28948
|
+
update({ schedule, timezone, extraQuery }: {
|
|
28913
28949
|
schedule: string;
|
|
28914
28950
|
timezone: string;
|
|
28951
|
+
extraQuery: Record<string, string>;
|
|
28915
28952
|
}): Promise<{
|
|
28916
28953
|
status: _google_cloud_scheduler_build_protos_protos.google.rpc.IStatus | null | undefined;
|
|
28917
28954
|
state: "STATE_UNSPECIFIED" | _google_cloud_scheduler_build_protos_protos.google.cloud.scheduler.v1.Job.State | "ENABLED" | "PAUSED" | "DISABLED" | "UPDATE_FAILED" | null | undefined;
|
|
@@ -29208,10 +29245,11 @@ declare const index_isPubSubRequest: typeof isPubSubRequest;
|
|
|
29208
29245
|
declare const index_parseDateOrDefault: typeof parseDateOrDefault;
|
|
29209
29246
|
declare const index_sanitize: typeof sanitize;
|
|
29210
29247
|
declare const index_sanitizeToString: typeof sanitizeToString;
|
|
29248
|
+
declare const index_shortHash: typeof shortHash;
|
|
29211
29249
|
declare const index_validate: typeof validate;
|
|
29212
29250
|
declare const index_validateGoogleAuth: typeof validateGoogleAuth;
|
|
29213
29251
|
declare namespace index {
|
|
29214
|
-
export { index_BigQueryHelper as BigQueryHelper, index_EnvEngine as EnvEngine, index_JWKSHelper as JWKSHelper, type index_Message as Message, type index_NodeOptions as NodeOptions, index_PubSubHelper as PubSubHelper, index_Runtime as Runtime, index_SchedulerHelper as SchedulerHelper, index_Secrets as Secrets, type index_TriggerOnCreateOptions as TriggerOnCreateOptions, type index_TriggerOnExecuteOptions as TriggerOnExecuteOptions, index_getEventTime as getEventTime, index_isCronMessage as isCronMessage, index_isPubSubRequest as isPubSubRequest, index_parseDateOrDefault as parseDateOrDefault, index_sanitize as sanitize, index_sanitizeToString as sanitizeToString, index_validate as validate, index_validateGoogleAuth as validateGoogleAuth };
|
|
29252
|
+
export { index_BigQueryHelper as BigQueryHelper, index_EnvEngine as EnvEngine, index_JWKSHelper as JWKSHelper, type index_Message as Message, type index_NodeOptions as NodeOptions, index_PubSubHelper as PubSubHelper, index_Runtime as Runtime, index_SchedulerHelper as SchedulerHelper, index_Secrets as Secrets, type index_TriggerOnCreateOptions as TriggerOnCreateOptions, type index_TriggerOnExecuteOptions as TriggerOnExecuteOptions, index_getEventTime as getEventTime, index_isCronMessage as isCronMessage, index_isPubSubRequest as isPubSubRequest, index_parseDateOrDefault as parseDateOrDefault, index_sanitize as sanitize, index_sanitizeToString as sanitizeToString, index_shortHash as shortHash, index_validate as validate, index_validateGoogleAuth as validateGoogleAuth };
|
|
29215
29253
|
}
|
|
29216
29254
|
|
|
29217
29255
|
export { index as lib, index$9 as schema, index$1 as types };
|
package/dist/index.js
CHANGED
|
@@ -298,6 +298,7 @@ __export(src_public_exports, {
|
|
|
298
298
|
parseDateOrDefault: () => parseDateOrDefault,
|
|
299
299
|
sanitize: () => sanitize,
|
|
300
300
|
sanitizeToString: () => sanitizeToString,
|
|
301
|
+
shortHash: () => shortHash,
|
|
301
302
|
validate: () => validate,
|
|
302
303
|
validateGoogleAuth: () => validateGoogleAuth
|
|
303
304
|
});
|
|
@@ -354,6 +355,9 @@ var sanitize = new import_deep_redact.DeepRedact({
|
|
|
354
355
|
replaceStringByLength: true
|
|
355
356
|
});
|
|
356
357
|
|
|
358
|
+
// src-public/utils.ts
|
|
359
|
+
var import_crypto = __toESM(require("crypto"));
|
|
360
|
+
|
|
357
361
|
// src-public/jwks.ts
|
|
358
362
|
var import_jose = require("jose");
|
|
359
363
|
|
|
@@ -536,9 +540,16 @@ function getEventTime(x, defaultValue) {
|
|
|
536
540
|
}
|
|
537
541
|
return defaultValue;
|
|
538
542
|
}
|
|
543
|
+
function shortHash(input) {
|
|
544
|
+
const hash = import_crypto.default.createHash("sha256").update(input).digest();
|
|
545
|
+
const base64 = hash.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
546
|
+
return base64.substring(0, 8);
|
|
547
|
+
}
|
|
539
548
|
|
|
540
549
|
// src-public/env.ts
|
|
541
|
-
var
|
|
550
|
+
var crypto2 = __toESM(require("crypto"));
|
|
551
|
+
global.storeLoading = global.storeLoading || {};
|
|
552
|
+
var storeLoading = global.storeLoading;
|
|
542
553
|
var EnvEngine = class extends Runtime {
|
|
543
554
|
docRef;
|
|
544
555
|
store;
|
|
@@ -556,7 +567,13 @@ var EnvEngine = class extends Runtime {
|
|
|
556
567
|
};
|
|
557
568
|
}
|
|
558
569
|
async set(envs, level = "trigger", encryptWithValue) {
|
|
559
|
-
|
|
570
|
+
const timeout = 300;
|
|
571
|
+
await Promise.race([this.initializeIfNeeded(level), new Promise((resolve, reject) => setTimeout(() => {
|
|
572
|
+
reject(new Error(`Waitied ${timeout}ms. Terminating firestore initialize during the set function`));
|
|
573
|
+
}, timeout))]).catch((err) => {
|
|
574
|
+
console.warn("Invariant: While initializing the env engine during set - " + err.message + ` - ${this.envName} - ${this.workflowId} - ${this.triggerId}.
|
|
575
|
+
Failing quietly as the set might proceed, but this is not a good thing.`);
|
|
576
|
+
});
|
|
560
577
|
let aes = null;
|
|
561
578
|
if (encryptWithValue) {
|
|
562
579
|
aes = new AES256GCM(Buffer.from(encryptWithValue, "utf8"));
|
|
@@ -587,13 +604,27 @@ var EnvEngine = class extends Runtime {
|
|
|
587
604
|
async initializeIfNeeded(level = "trigger") {
|
|
588
605
|
if (!this.store[level]) {
|
|
589
606
|
if (this.docRef[level]) {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
607
|
+
if (!storeLoading[this.docRef[level].path]) {
|
|
608
|
+
const promise = (async () => {
|
|
609
|
+
const docSnapshot = await this.docRef[level].get();
|
|
610
|
+
return docSnapshot;
|
|
611
|
+
})().then((x) => {
|
|
612
|
+
storeLoading[this.docRef[level].path] = null;
|
|
613
|
+
return x;
|
|
614
|
+
}).catch((err) => {
|
|
615
|
+
storeLoading[this.docRef[level].path] = null;
|
|
616
|
+
throw err;
|
|
617
|
+
});
|
|
618
|
+
storeLoading[this.docRef[level].path] = promise;
|
|
596
619
|
}
|
|
620
|
+
return storeLoading[this.docRef[level].path].then((docSnapshot) => {
|
|
621
|
+
const data = docSnapshot.data() || {};
|
|
622
|
+
this.store[level] = {};
|
|
623
|
+
for (const k in data) {
|
|
624
|
+
const v = data[k];
|
|
625
|
+
this.store[level][k] = typeof v !== "string" ? `${v === null || typeof v === "undefined" ? "" : `${v}`}` : v;
|
|
626
|
+
}
|
|
627
|
+
});
|
|
597
628
|
} else {
|
|
598
629
|
this.store[level] = {};
|
|
599
630
|
}
|
|
@@ -633,7 +664,7 @@ var EnvEngine = class extends Runtime {
|
|
|
633
664
|
var AES256GCM = class {
|
|
634
665
|
normalizedKey;
|
|
635
666
|
constructor(key) {
|
|
636
|
-
this.normalizedKey =
|
|
667
|
+
this.normalizedKey = crypto2.createHash("sha256").update(key).digest().slice(0, 32);
|
|
637
668
|
}
|
|
638
669
|
// Pad payload to a multiple of 8 bytes
|
|
639
670
|
pad(payload) {
|
|
@@ -647,8 +678,8 @@ var AES256GCM = class {
|
|
|
647
678
|
encrypt(payload) {
|
|
648
679
|
const normalizedWrappingKey = this.normalizedKey;
|
|
649
680
|
const paddedPayload = this.pad(Buffer.from(payload));
|
|
650
|
-
const iv =
|
|
651
|
-
const cipher =
|
|
681
|
+
const iv = crypto2.randomBytes(12);
|
|
682
|
+
const cipher = crypto2.createCipheriv(
|
|
652
683
|
"aes-256-gcm",
|
|
653
684
|
normalizedWrappingKey,
|
|
654
685
|
iv
|
|
@@ -665,7 +696,7 @@ var AES256GCM = class {
|
|
|
665
696
|
const encryptedPayload = Buffer.from(encryptedKey64, "base64");
|
|
666
697
|
const iv = Buffer.from(iv64, "base64");
|
|
667
698
|
const authTag = Buffer.from(authTag64, "base64");
|
|
668
|
-
const decipher =
|
|
699
|
+
const decipher = crypto2.createDecipheriv(
|
|
669
700
|
"aes-256-gcm",
|
|
670
701
|
this.normalizedKey,
|
|
671
702
|
iv
|
|
@@ -760,53 +791,112 @@ var PubSubHelper = class extends Runtime {
|
|
|
760
791
|
return Promise.all(promises);
|
|
761
792
|
}
|
|
762
793
|
async createOrUpdate(opts) {
|
|
763
|
-
const
|
|
794
|
+
const [topics] = await this.pubSub.getTopics();
|
|
795
|
+
const mainDlqTopicName = `${opts.topicName}-${shortHash(this.triggerId)}-dlq`;
|
|
796
|
+
const tableDlqTopicName = `${opts.topicName}-${shortHash(this.triggerId)}-bq-dlq`;
|
|
797
|
+
let mainTopic = topics.find((x) => this.getNameFromFullyQualifiedName(x.name) === opts.topicName);
|
|
798
|
+
let mainDlqTopic = topics.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainDlqTopicName);
|
|
799
|
+
let tableDlqTopic = topics.find((x) => this.getNameFromFullyQualifiedName(x.name) === tableDlqTopicName);
|
|
800
|
+
const mainSubscriptionName = `${opts.topicName}--${shortHash(this.triggerId)}`;
|
|
801
|
+
const mainDlqSubscriptionName = `${opts.topicName}--${shortHash(this.triggerId)}-dlq`;
|
|
802
|
+
const tableSubscriptionName = `${opts.topicName}--${shortHash(this.triggerId)}-bq`;
|
|
803
|
+
const tableDlqSubscriptionName = `${opts.topicName}--${shortHash(this.triggerId)}-bq-dlq`;
|
|
804
|
+
let mainTopicSubscriptions = null;
|
|
805
|
+
let mainDlqTopicSubscriptions = null;
|
|
806
|
+
let tableDlqTopicSubscriptions = null;
|
|
807
|
+
if (mainTopic) {
|
|
808
|
+
[mainTopicSubscriptions] = await mainTopic.getSubscriptions();
|
|
809
|
+
}
|
|
810
|
+
if (mainDlqTopic) {
|
|
811
|
+
[mainDlqTopicSubscriptions] = await mainDlqTopic.getSubscriptions();
|
|
812
|
+
}
|
|
813
|
+
if (tableDlqTopic) {
|
|
814
|
+
[tableDlqTopicSubscriptions] = await tableDlqTopic.getSubscriptions();
|
|
815
|
+
}
|
|
816
|
+
let mainSubscription = mainTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainSubscriptionName) || null;
|
|
817
|
+
let mainDlqSubscription = mainDlqTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainDlqSubscriptionName) || null;
|
|
818
|
+
let tableSubscription = mainTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === tableSubscriptionName) || null;
|
|
819
|
+
let tableDlqSubscription = tableDlqTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === tableDlqSubscriptionName) || null;
|
|
764
820
|
const topic = await this.ensureTopicExists(opts.topicName);
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
if (opts.dlq) {
|
|
768
|
-
const dlqTopicName = `${opts.topicName}-dlq`;
|
|
769
|
-
const dlqSubscriptionName = `${subscriptionName}-dlq`;
|
|
770
|
-
dlqTopic = await this.ensureTopicExists(dlqTopicName);
|
|
771
|
-
dlqSubscription = await this.ensureDLQSubscriptionExists(dlqSubscriptionName, {
|
|
772
|
-
topic: dlqTopic
|
|
773
|
-
});
|
|
774
|
-
} else {
|
|
775
|
-
await this.deleteSubscription(`${subscriptionName}-dlq`);
|
|
821
|
+
if (opts.table || opts.pull || opts.push) {
|
|
822
|
+
mainTopic = await this.ensureTopicExists(opts.topicName);
|
|
776
823
|
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
}
|
|
786
|
-
|
|
824
|
+
if (!opts.table) {
|
|
825
|
+
if (tableSubscription) {
|
|
826
|
+
await tableSubscription.delete();
|
|
827
|
+
tableSubscription = null;
|
|
828
|
+
}
|
|
829
|
+
if (tableDlqSubscription) {
|
|
830
|
+
await tableDlqSubscription.delete();
|
|
831
|
+
tableDlqSubscription = null;
|
|
832
|
+
}
|
|
833
|
+
} else {
|
|
834
|
+
if (opts.createDeadLetterQueues) {
|
|
835
|
+
tableDlqTopic = await this.ensureTopicExists(tableDlqTopicName);
|
|
836
|
+
tableDlqSubscription = await this.ensureDLQSubscriptionExists(tableDlqSubscriptionName, {
|
|
837
|
+
topic: tableDlqTopic
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
tableSubscription = await this.ensureSubscribtionExists(tableSubscriptionName, {
|
|
787
841
|
topic,
|
|
788
|
-
tableId: opts.
|
|
789
|
-
|
|
842
|
+
tableId: opts.table.tableId,
|
|
843
|
+
ackDeadline: opts.table.ackDeadline,
|
|
844
|
+
retryLimit: opts.table.retryLimit,
|
|
845
|
+
retryMinDelay: opts.table.retryMinDelay,
|
|
846
|
+
retryMaxDelay: opts.table.retryMaxDelay,
|
|
847
|
+
dlqTopic: mainTopic
|
|
790
848
|
});
|
|
849
|
+
}
|
|
850
|
+
const pullPushSubscription = opts.pull || opts.push;
|
|
851
|
+
if (!pullPushSubscription) {
|
|
852
|
+
if (mainSubscription) {
|
|
853
|
+
await mainSubscription.delete();
|
|
854
|
+
mainSubscription = null;
|
|
855
|
+
}
|
|
856
|
+
if (mainDlqSubscription) {
|
|
857
|
+
await mainDlqSubscription.delete();
|
|
858
|
+
mainDlqSubscription = null;
|
|
859
|
+
}
|
|
791
860
|
} else {
|
|
792
|
-
|
|
793
|
-
|
|
861
|
+
if (opts.createDeadLetterQueues) {
|
|
862
|
+
mainDlqTopic = await this.ensureTopicExists(mainDlqTopicName);
|
|
863
|
+
mainDlqSubscription = await this.ensureDLQSubscriptionExists(mainDlqSubscriptionName, {
|
|
864
|
+
topic: mainDlqTopic
|
|
865
|
+
});
|
|
866
|
+
mainSubscription = await this.ensureSubscribtionExists(mainSubscriptionName, {
|
|
867
|
+
topic,
|
|
868
|
+
dlqTopic: mainDlqTopic,
|
|
869
|
+
endpointUrl: opts.push ? this.runtimeUrl + `/executeWorkflow/${this.workflowId}/${this.triggerId}?topic_name=${opts.topicName}` : null,
|
|
870
|
+
retryMinDelay: pullPushSubscription.retryMinDelay,
|
|
871
|
+
retryMaxDelay: pullPushSubscription.retryMaxDelay,
|
|
872
|
+
retryLimit: pullPushSubscription.retryLimit,
|
|
873
|
+
ackDeadline: pullPushSubscription.ackDeadline
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
if (!opts.createDeadLetterQueues) {
|
|
878
|
+
if (mainDlqSubscription) {
|
|
879
|
+
await mainDlqSubscription.delete();
|
|
880
|
+
mainDlqSubscription = null;
|
|
881
|
+
}
|
|
882
|
+
if (tableDlqSubscription) {
|
|
883
|
+
await tableDlqSubscription.delete();
|
|
884
|
+
tableDlqSubscription = null;
|
|
885
|
+
}
|
|
886
|
+
if (tableDlqTopic) {
|
|
887
|
+
await tableDlqTopic.delete();
|
|
888
|
+
}
|
|
889
|
+
if (mainDlqTopic)
|
|
890
|
+
await mainDlqTopic.delete();
|
|
794
891
|
}
|
|
795
|
-
const subscription = await this.ensureSubscribtionExists(subscriptionName, {
|
|
796
|
-
topic,
|
|
797
|
-
dlqTopic,
|
|
798
|
-
retryMinDelay: opts.retryDelay,
|
|
799
|
-
retryMaxDelay: opts.retryDelay,
|
|
800
|
-
retryLimit: opts.retryLimit,
|
|
801
|
-
endpointUrl: this.runtimeUrl + `/executeWorkflow/${this.workflowId}/${this.triggerId}`,
|
|
802
|
-
ackDeadline: opts.ackDeadline
|
|
803
|
-
});
|
|
804
892
|
return {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
893
|
+
mainTopic,
|
|
894
|
+
mainDlqTopic,
|
|
895
|
+
tableDlqTopic,
|
|
896
|
+
mainSubscription,
|
|
897
|
+
mainDlqSubscription,
|
|
898
|
+
tableDlqSubscription,
|
|
899
|
+
tableSubscription
|
|
810
900
|
};
|
|
811
901
|
}
|
|
812
902
|
async findTopic(topicName) {
|
|
@@ -959,7 +1049,7 @@ var PubSubHelper = class extends Runtime {
|
|
|
959
1049
|
}
|
|
960
1050
|
if (subscription && nextMetadata) {
|
|
961
1051
|
try {
|
|
962
|
-
|
|
1052
|
+
await subscription.setMetadata(nextMetadata);
|
|
963
1053
|
} catch (err) {
|
|
964
1054
|
console.error("Invariant: While updating subscription - " + err.message + ` - ${this.pubSub.projectId} - ${subscriptionName} - ${JSON.stringify(nextMetadata)}`);
|
|
965
1055
|
throw new Error("Invariant: While updating subscription - " + err.message);
|
|
@@ -1000,6 +1090,63 @@ var PubSubHelper = class extends Runtime {
|
|
|
1000
1090
|
}
|
|
1001
1091
|
return subscription;
|
|
1002
1092
|
}
|
|
1093
|
+
async deleteSubscriptions(topicName) {
|
|
1094
|
+
return this.createOrUpdate({
|
|
1095
|
+
topicName,
|
|
1096
|
+
createDeadLetterQueues: false,
|
|
1097
|
+
pull: null,
|
|
1098
|
+
push: null,
|
|
1099
|
+
table: null
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
async pause(topicName) {
|
|
1103
|
+
const [topics] = await this.pubSub.getTopics();
|
|
1104
|
+
const mainTopic = topics.find((x) => this.getNameFromFullyQualifiedName(x.name) === topicName);
|
|
1105
|
+
let mainTopicSubscriptions = null;
|
|
1106
|
+
if (mainTopic) {
|
|
1107
|
+
[mainTopicSubscriptions] = await mainTopic.getSubscriptions();
|
|
1108
|
+
}
|
|
1109
|
+
const mainSubscriptionName = `${topicName}--${shortHash(this.triggerId)}`;
|
|
1110
|
+
const mainSubscription = mainTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainSubscriptionName) || null;
|
|
1111
|
+
if (mainSubscription) {
|
|
1112
|
+
await mainSubscription.setMetadata({
|
|
1113
|
+
pushConfig: null
|
|
1114
|
+
});
|
|
1115
|
+
return {
|
|
1116
|
+
subscriptionId: mainSubscription.name
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
return {
|
|
1120
|
+
subscriptionId: null
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
async resume(topicName) {
|
|
1124
|
+
const [topics] = await this.pubSub.getTopics();
|
|
1125
|
+
const mainTopic = topics.find((x) => this.getNameFromFullyQualifiedName(x.name) === topicName);
|
|
1126
|
+
let mainTopicSubscriptions = null;
|
|
1127
|
+
if (mainTopic) {
|
|
1128
|
+
[mainTopicSubscriptions] = await mainTopic.getSubscriptions();
|
|
1129
|
+
}
|
|
1130
|
+
const mainSubscriptionName = `${topicName}--${shortHash(this.triggerId)}`;
|
|
1131
|
+
const mainSubscription = mainTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainSubscriptionName) || null;
|
|
1132
|
+
if (mainSubscription) {
|
|
1133
|
+
await mainSubscription.setMetadata({
|
|
1134
|
+
pushConfig: {
|
|
1135
|
+
pushEndpoint: this.runtimeUrl + "/executeWorkflow/" + this.workflowId + "/" + this.triggerId + `?topic_name=${topicName}`,
|
|
1136
|
+
oidcToken: {
|
|
1137
|
+
serviceAccountEmail: this.serviceAccountEmail,
|
|
1138
|
+
audience: process.env.GCLOUD_PROJECT + "/" + this.triggerId
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
return {
|
|
1143
|
+
subscriptionId: mainSubscription.name
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
return {
|
|
1147
|
+
subscriptionId: null
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1003
1150
|
async deleteSubscription(subscriptionURN) {
|
|
1004
1151
|
const sub = this.pubSub.subscription(subscriptionURN);
|
|
1005
1152
|
return sub.delete().catch((err) => {
|
|
@@ -1016,14 +1163,12 @@ var pubsub_default = PubSubHelper;
|
|
|
1016
1163
|
|
|
1017
1164
|
// src-public/scheduler.ts
|
|
1018
1165
|
var SchedulerHelper = class extends Runtime {
|
|
1019
|
-
extraQuery;
|
|
1020
1166
|
pubSubTarget;
|
|
1021
1167
|
pubSubProjectId;
|
|
1022
1168
|
schedulerLocationId;
|
|
1023
1169
|
schedulerClient;
|
|
1024
1170
|
constructor(opts, schedulerClient) {
|
|
1025
1171
|
super(opts);
|
|
1026
|
-
this.extraQuery = opts.extraQuery;
|
|
1027
1172
|
this.pubSubTarget = opts.pubSubTarget || null;
|
|
1028
1173
|
this.pubSubProjectId = this.pubSubTarget?.name?.split("/")[1] || null;
|
|
1029
1174
|
this.schedulerLocationId = opts.schedulerLocationId || "europe-west2";
|
|
@@ -1041,7 +1186,13 @@ var SchedulerHelper = class extends Runtime {
|
|
|
1041
1186
|
"us-west1"
|
|
1042
1187
|
];
|
|
1043
1188
|
}
|
|
1044
|
-
getTarget() {
|
|
1189
|
+
getTarget(extraQuery = {}) {
|
|
1190
|
+
extraQuery = Object.assign({}, extraQuery, {
|
|
1191
|
+
"created_by_wid": this.workflowId,
|
|
1192
|
+
"created_by_tid": this.triggerId,
|
|
1193
|
+
"created_by_sevn": this.systemEnvName,
|
|
1194
|
+
"cron": "1"
|
|
1195
|
+
});
|
|
1045
1196
|
if (this.pubSubTarget) {
|
|
1046
1197
|
return {
|
|
1047
1198
|
pubsubTarget: {
|
|
@@ -1054,7 +1205,7 @@ var SchedulerHelper = class extends Runtime {
|
|
|
1054
1205
|
}
|
|
1055
1206
|
return {
|
|
1056
1207
|
httpTarget: {
|
|
1057
|
-
uri: `${this.runtimeUrl}/executeWorkflow/${this.workflowId}/${this.triggerId}?${new URLSearchParams(
|
|
1208
|
+
uri: `${this.runtimeUrl}/executeWorkflow/${this.workflowId}/${this.triggerId}?${new URLSearchParams(extraQuery).toString()}`,
|
|
1058
1209
|
httpMethod: "POST",
|
|
1059
1210
|
headers: {
|
|
1060
1211
|
"Content-Type": "application/json"
|
|
@@ -1066,7 +1217,7 @@ var SchedulerHelper = class extends Runtime {
|
|
|
1066
1217
|
}
|
|
1067
1218
|
};
|
|
1068
1219
|
}
|
|
1069
|
-
async create({ schedule, timezone }) {
|
|
1220
|
+
async create({ schedule, timezone, extraQuery }) {
|
|
1070
1221
|
let parent;
|
|
1071
1222
|
let name;
|
|
1072
1223
|
if (this.pubSubProjectId) {
|
|
@@ -1085,7 +1236,7 @@ var SchedulerHelper = class extends Runtime {
|
|
|
1085
1236
|
name,
|
|
1086
1237
|
schedule,
|
|
1087
1238
|
timeZone: timezone,
|
|
1088
|
-
...this.getTarget()
|
|
1239
|
+
...this.getTarget(extraQuery)
|
|
1089
1240
|
}
|
|
1090
1241
|
});
|
|
1091
1242
|
return {
|
|
@@ -1098,14 +1249,14 @@ var SchedulerHelper = class extends Runtime {
|
|
|
1098
1249
|
} catch (error) {
|
|
1099
1250
|
if (error.code === 6) {
|
|
1100
1251
|
return this.update(
|
|
1101
|
-
{ schedule, timezone }
|
|
1252
|
+
{ schedule, timezone, extraQuery }
|
|
1102
1253
|
);
|
|
1103
1254
|
} else {
|
|
1104
1255
|
throw error;
|
|
1105
1256
|
}
|
|
1106
1257
|
}
|
|
1107
1258
|
}
|
|
1108
|
-
async update({ schedule, timezone }) {
|
|
1259
|
+
async update({ schedule, timezone, extraQuery }) {
|
|
1109
1260
|
let parent;
|
|
1110
1261
|
let name;
|
|
1111
1262
|
if (this.pubSubProjectId) {
|
|
@@ -1120,7 +1271,7 @@ var SchedulerHelper = class extends Runtime {
|
|
|
1120
1271
|
try {
|
|
1121
1272
|
const response = await this.schedulerClient.updateJob({
|
|
1122
1273
|
job: {
|
|
1123
|
-
...this.getTarget(),
|
|
1274
|
+
...this.getTarget(extraQuery),
|
|
1124
1275
|
name,
|
|
1125
1276
|
schedule,
|
|
1126
1277
|
timeZone: timezone
|
|
@@ -1140,7 +1291,7 @@ var SchedulerHelper = class extends Runtime {
|
|
|
1140
1291
|
name,
|
|
1141
1292
|
schedule,
|
|
1142
1293
|
timeZone: timezone,
|
|
1143
|
-
...this.getTarget()
|
|
1294
|
+
...this.getTarget(extraQuery)
|
|
1144
1295
|
}
|
|
1145
1296
|
});
|
|
1146
1297
|
return {
|